Commit 3218d87a authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added UsersManagement page for admin, added 'UCD Rebuild' functionality based...

Added UsersManagement page for admin, added 'UCD Rebuild' functionality based on CDS web services, refactoring, removed ConversationScoped in favour of DeltaSpike WindowScoped, set version number to 1.1.0
parent 563cf1c5
......@@ -2,9 +2,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerAPI</artifactId>
<version>1.0.4</version>
<artifactId>tasman-core</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>tasman-core</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
......@@ -46,5 +47,4 @@
</plugin>
</plugins>
</build>
<name>TapSchemaManagerAPI</name>
</project>
\ No newline at end of file
......@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
public class ConsistencyChecks implements Serializable {
......
......@@ -24,7 +24,7 @@ package it.inaf.ia2.tsm.api;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
public class InconsistentValue {
......
......@@ -3,17 +3,18 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerWebApp</artifactId>
<version>1.0.4</version>
<artifactId>tasman-webapp</artifactId>
<version>1.1.0</version>
<packaging>war</packaging>
<name>TapSchemaManagerWebApp</name>
<name>tasman-webapp</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license>
<jersey.version>2.23.2</jersey.version>
<deltaspike.version>1.7.2</deltaspike.version>
</properties>
<profiles>
......@@ -86,8 +87,8 @@
<dependencies>
<dependency>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerAPI</artifactId>
<version>1.0.4</version>
<artifactId>tasman-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>ari.ucidy</groupId>
......@@ -123,8 +124,60 @@
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-jsf-module-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-jsf-module-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.cdictrl</groupId>
<artifactId>deltaspike-cdictrl-weld</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.cdictrl</groupId>
<artifactId>deltaspike-cdictrl-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-servlet-module-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-servlet-module-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.deltaspike.distribution</groupId>
<artifactId>distributions-bom</artifactId>
<version>${deltaspike.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
......
......@@ -27,6 +27,7 @@ import it.inaf.ia2.tsm.webapp.xmlconfig.UserConfiguration;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
......@@ -81,6 +82,11 @@ public class ConfigurationData {
return configuration;
}
public synchronized List<UserConfiguration> cloneUsersConfiguration() {
// JAXB is exploited for doing deep copy.
return JAXB.unmarshal(configFile, Configuration.class).getUsers();
}
public void updateConfigurationFile() throws IOException {
JAXB.marshal(configuration, configFile);
}
......@@ -90,8 +96,16 @@ public class ConfigurationData {
updateConfigurationFile();
}
public synchronized void updateUsersList(List<UserConfiguration> users) throws IOException {
configuration.getUsers().clear();
for (UserConfiguration user : users) {
configuration.getUsers().add(user);
}
updateConfigurationFile();
}
public String getRestPath() {
return FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/rest";
return FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/faces/rest";
}
public String getVersion() {
......
......@@ -26,15 +26,15 @@ import it.inaf.ia2.tsm.api.DBWrapper;
import it.inaf.ia2.tsm.api.contract.TapSchema;
import java.io.Serializable;
import java.sql.SQLException;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.deltaspike.core.api.scope.WindowScoped;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@ConversationScoped
@WindowScoped
@Named("consistency")
public class ConsistencyChecksBean implements Serializable {
......
......@@ -32,7 +32,7 @@ import javax.ws.rs.QueryParam;
* REST Web Service for setting opening dialog status using JavaScript. This is
* necessary to conditionally disable JSF validation when dialog is closed.
*
* @author Sonia Zorba <zorba at oats.inaf.it>
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@Path("credentialsDialog")
@RequestScoped
......
......@@ -24,16 +24,16 @@ package it.inaf.ia2.tsm.webapp;
import it.inaf.ia2.tsm.api.Credentials;
import it.inaf.ia2.tsm.api.DBWrapper;
import it.inaf.ia2.tsm.webapp.xmlconfig.UserConfiguration;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.deltaspike.core.api.scope.WindowScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@Named("credentialsInsertion")
@SessionScoped
@WindowScoped
public class CredentialsEditing implements Serializable {
private static final long serialVersionUID = -2688980249773483198L;
......@@ -54,9 +54,6 @@ public class CredentialsEditing implements Serializable {
@Inject
private ConfigurationData config;
@Inject
Conversation conversation;
@Inject
private SchemaSelectionBean schemaSelectionBean;
......@@ -69,16 +66,8 @@ public class CredentialsEditing implements Serializable {
@PostConstruct
public void init() {
if (!conversation.isTransient()) {
conversation.end();
}
sourceCredentials = new Credentials();
tapSchemaCredentials = new Credentials();
for (UserConfiguration u : config.getData().getUsers()) {
}
}
public List getSavedCredentials() {
......@@ -119,13 +108,11 @@ public class CredentialsEditing implements Serializable {
try {
dbWrapper.testConnections();
conversation.setTimeout(30 * 60000L); // 30 minutes
conversation.begin();
schemaSelectionBean.setDbWrapper(dbWrapper);
return "schemaSelection.xhtml?faces-redirect=true";
} catch (SQLException e) {
LOG.error("Exception caught", e);
//loginError = "Connection error: " + e.getMessage();
FacesContext.getCurrentInstance().addMessage("main", new FacesMessage("Connection error: " + e.getMessage()));
return null;
}
}
......@@ -137,6 +124,7 @@ public class CredentialsEditing implements Serializable {
public void saveCredentialsEdited() throws IOException {
// If is editing existing, remove old for creating a new one
if (currentEditingRow < getSavedCredentials().size()) {
getSavedCredentials().remove(currentEditingRow);
}
......
package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCDParser;
import ari.ucidy.UCDSyntax;
import ari.ucidy.UCDWord;
import ari.ucidy.UCDWordList;
import it.inaf.ia2.tsm.webapp.xmlconfig.UCDConfiguration;
import java.io.IOException;
import java.util.List;
......@@ -14,7 +14,7 @@ import java.util.List;
*/
public class CustomizedUCDParser extends UCDParser {
public CustomizedUCDParser(List<String> customUCDs) {
public CustomizedUCDParser(List<UCDConfiguration> customUCDs) {
super();
try {
......@@ -26,8 +26,8 @@ public class CustomizedUCDParser extends UCDParser {
if (customUCDs != null) {
// Add custom UCDs
for (String customUCD : customUCDs) {
knownWords.add(new UCDWord(UCDSyntax.BOTH, customUCD, null, false));
for (UCDConfiguration customUCD : customUCDs) {
knownWords.add(new UCDWord(customUCD.getSyntax(), customUCD.getWord(), customUCD.getDescription(), false));
}
}
}
......
......@@ -10,7 +10,7 @@ import javax.inject.Named;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@Named
@RequestScoped
......
......@@ -31,7 +31,7 @@ import javax.inject.Named;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@Named
@RequestScoped
......
......@@ -24,6 +24,7 @@ package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCD;
import ari.ucidy.UCDParser;
import it.inaf.ia2.tsm.webapp.xmlconfig.UCDConfiguration;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
......@@ -72,7 +73,7 @@ public class ParsedUCD implements Serializable {
}
}
public ParsedUCD(String ucdText, List<String> customUCDs) {
public ParsedUCD(String ucdText, List<UCDConfiguration> customUCDs) {
this(customUCDs == null
? UCDParser.parseUCD(ucdText)
: new CustomizedUCDParser(customUCDs).parse(ucdText)
......
......@@ -33,14 +33,13 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.deltaspike.core.api.scope.WindowScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -49,14 +48,11 @@ import org.slf4j.LoggerFactory;
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@Named("schemaSelection")
@ConversationScoped
@WindowScoped
public class SchemaSelectionBean implements Serializable {
private static final long serialVersionUID = -5745720427701334323L;
private static final Logger log = LoggerFactory.getLogger(SchemaSelectionBean.class);
@Inject
private Conversation conversation;
private static final Logger LOG = LoggerFactory.getLogger(SchemaSelectionBean.class);
@Inject
TapSchemaEditingBean tapSchemaEditingBean;
......@@ -214,11 +210,6 @@ public class SchemaSelectionBean implements Serializable {
this.dbWrapper = dbWrapper;
}
public String logout() {
conversation.end();
return "index.xhtml?faces-redirect=true";
}
public void validateTapSchemaName(FacesContext context, UIComponent inputComponent, Object value) {
String textValue = (String) value;
......
......@@ -22,6 +22,8 @@
*/
package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCD;
import ari.ucidy.UCDParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
......@@ -34,7 +36,6 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
/**
* Collection of static methods for accessing to the UCD REST service and
......@@ -47,12 +48,6 @@ public class SearchUCD {
private static final String UCD_SERVICE_URL;
private static final String UCD_NOT_FOUND = "**** Could not find UCD ****";
public static final String REG_EXP_UCD;
public static final String REG_EXP_START_WITH_NAMESPACE;
private static final Pattern PATTERN_UCD;
private static final Pattern PATTERN_START_WITH_NAMESPACE;
static {
try {
Properties prop = new Properties();
......@@ -61,30 +56,8 @@ public class SearchUCD {
}
UCD_SERVICE_URL = prop.getProperty("ucd_service_url");
} catch (IOException e) {
throw new RuntimeException("Unable to load UCD service URL from webapp.properties configuration!");
}
String namespaceRegExpPart = "[a-zA-Z]+\\:"; // validate e.g. "mynamespace:"
String[] ucdCategories = new String[]{"arith", "em", "instr", "meta", "obs", "phot", "phys", "pos", "spect", "src", "stat", "time"};
StringBuilder sbCategories = new StringBuilder();
boolean first = true;
for (String category : ucdCategories) {
if (!first) {
sbCategories.append("|");
}
first = false;
sbCategories.append(category);
throw new ExceptionInInitializerError("Unable to load UCD service URL from webapp.properties configuration!");
}
String regExpWordPart = String.format("(%s)([\\.][\\-a-zA-Z0-9]+)*", sbCategories.toString()); // validate single word
REG_EXP_UCD = String.format("^(%s)?%s(;%s)*$", namespaceRegExpPart, regExpWordPart, regExpWordPart);
REG_EXP_START_WITH_NAMESPACE = String.format("^%s.+$", namespaceRegExpPart);
PATTERN_UCD = Pattern.compile(REG_EXP_UCD);
PATTERN_START_WITH_NAMESPACE = Pattern.compile(REG_EXP_START_WITH_NAMESPACE);
}
private static String encodeText(String searchText) throws UCDServiceException {
......@@ -150,7 +123,18 @@ public class SearchUCD {
if (split2.length == 2) {
String flag = split2[0];
String word = split2[1];
resultList.add(new UCDInfo(score, flag, word));
String definition;
// If UCD description is already inside Ucidy library
// it is possibile to avoid calling the web service.
UCD ucd = UCDParser.parseUCD(word);
if (ucd.size() == 1) {
definition = ucd.getWord(0).description;
} else {
definition = getDefinition(word);
}
resultList.add(new UCDInfo(score, flag, word, definition));
}
}
}
......@@ -168,8 +152,8 @@ public class SearchUCD {
}
}
public static void explain(UCDInfo ucdInfo) throws UCDServiceException {
String searchText = encodeText(ucdInfo.getWord());
public static String getDefinition(String word) throws UCDServiceException {
String searchText = encodeText(word);
String urlStr = UCD_SERVICE_URL + "explain?value=" + searchText;
try {
......@@ -185,7 +169,7 @@ public class SearchUCD {
response += line;
}
ucdInfo.setDefinition(response);
return response;
} else {
throw new UCDServiceException("Server responded with a status of " + responseCode);
}
......@@ -195,46 +179,4 @@ public class SearchUCD {
throw new UCDServiceException("Error while reading server response");
}
}
public static boolean validateManualUCD(String inputText) throws UCDServiceException {
if (inputText == null) {
return false;
}
if (!PATTERN_UCD.matcher(inputText).matches()) {
return false;
}
boolean customUCD = PATTERN_START_WITH_NAMESPACE.matcher(inputText).matches();
if (customUCD) {
return true;
} else {
String searchText = encodeText(inputText);
String urlStr = UCD_SERVICE_URL + "validate?value=" + searchText;
try {
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line, response = "";
while ((line = br.readLine()) != null) {
response += line;
}
return response.equals("0"); // String "0" means valid UCD
} else {
throw new UCDServiceException("Server responded with a status of " + responseCode);
}
} catch (MalformedURLException e) {
throw new UCDServiceException("Malformed url: " + urlStr);
} catch (IOException e) {
throw new UCDServiceException("Error while reading server response");
}
}
}
}
......@@ -22,6 +22,8 @@
*/
package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCD;
import ari.ucidy.UCDParser;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......@@ -38,7 +40,7 @@ public class SearchUCDDialog implements Serializable {
private static final long serialVersionUID = -3503024742241865133L;
@Inject
ConfigurationData config;
User user;
private boolean manualInsertion;
......@@ -49,12 +51,14 @@ public class SearchUCDDialog implements Serializable {
private String UCDServiceErrorMessage;
private String selectedUCD;
private String suggestedUCD;
private List<String> selectableUCDs;
private List<UCDInfo> suggestedUCDs;
private ParsedUCD parsedUCD;
public SearchUCDDialog() {
suggestedUCDs = new ArrayList<>();
selectableUCDs = new ArrayList<>();
}
public String getDescription() {
......@@ -90,6 +94,7 @@ public class SearchUCDDialog implements Serializable {
selectedUCD = null;
suggestedUCD = null;
suggestedUCDs.clear();
selectableUCDs.clear();
UCDServiceErrorMessage = null;
}
......@@ -119,14 +124,6 @@ public class SearchUCDDialog implements Serializable {
this.selectedUCD = selectedUCD;
}
public void explain(UCDInfo ucdInfo) {
try {
SearchUCD.explain(ucdInfo);
} catch (UCDServiceException e) {
setUCDServiceErrorMessage(e);
}
}