Commit 6725839c authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Updated ucdvalidator library (Ucidy), changed configuration model in order to...

Updated ucdvalidator library (Ucidy), changed configuration model in order to support custom UCD values. Set version number to 1.0.4
parent 1991f0df
# CHANGELOG
## Version 1.0.4
### Updated ucdvalidator into Ucidy 1.0
Updated ucdvalidator library, renamed into Ucidy.
https://github.com/gmantele/ucidy
### Configuration file changes
In `webapp.properties` file, the property `credentials_config_path` has been renamed into `config_file_path`, because now the config.xml contains other configuration information in addition to the credentials ones.
XML configuration file structure is changed, however the application can update the old existing configuration into the new one without losing previously inserted values.
### Managed custom UCD
It is now possible to configure the web application for using custom UCD values (in addition to the standard ones). These values have to be inserted into the XML configuration file in this way:
<configuration>
<custom-ucds>
<ucd>ia2:custom.test</ucd>
<ucd>ia2:custom.anothertest</ucd>
</custom-ucds>
</configuration>
# TAP_SCHEMA Manager
See also the [CHANGELOG]().
## Build
### Build the API
......@@ -40,3 +42,10 @@ The web app was tested with:
* Tomcat 8.0.33
The web app relies on specific JSF and EL versions, so it could not work in different application servers without a proper configuration.
## Credits
TAP_SCHEMA Manager web application uses the following VO libraries:
* Ucidy, by Grégory Mantelet (https://github.com/gmantele/ucidy)
* Unity, by Norman Gray (https://bitbucket.org/nxg/unity)
\ No newline at end of file
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerAPI</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -4,7 +4,7 @@
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerWebApp</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>war</packaging>
<name>TapSchemaManagerWebApp</name>
......@@ -87,12 +87,12 @@
<dependency>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerAPI</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>ari.ucd</groupId>
<artifactId>ucdvalidator</artifactId>
<version>1.0beta</version>
<groupId>ari.ucidy</groupId>
<artifactId>ucidy</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
......
package it.inaf.ia2.tsm.webapp;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
* JAXB model for TSM web application configuration.
*
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@XmlRootElement(name = "configuration")
public class Configuration {
private CredentialsConfiguration credentialsConfiguration;
private List<String> customUCDs;
private String version;
public Configuration() {
version = Version.NUMBER;
credentialsConfiguration = new CredentialsConfiguration();
customUCDs = new ArrayList<>();
}
@XmlElement(name = "credentials-config")
public CredentialsConfiguration getCredentialsConfiguration() {
return credentialsConfiguration;
}
public void setCredentialsConfiguration(CredentialsConfiguration credentialsConfiguration) {
this.credentialsConfiguration = credentialsConfiguration;
}
@XmlElementWrapper(name = "custom-ucds")
@XmlElement(name = "ucd")
public List<String> getCustomUCDs() {
return customUCDs;
}
public void setCustomUCDs(List<String> customUCDs) {
this.customUCDs = customUCDs;
}
@XmlAttribute(name = "version")
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
......@@ -93,7 +93,7 @@ public class CredentialsBean implements Serializable {
}
public List getSavedCredentials() {
return ccBean.getConfig().getCredentialsInfo();
return ccBean.getConfig().getCredentialsConfiguration().getCredentialsInfo();
}
public void editCredentials(Credentials credentials, int index) {
......@@ -113,7 +113,7 @@ public class CredentialsBean implements Serializable {
separateCredentials = false;
this.sourceCredentials = new Credentials();
this.tapSchemaCredentials = new Credentials();
currentEditingRow = ccBean.getConfig().getCredentialsInfo().size();
currentEditingRow = ccBean.getConfig().getCredentialsConfiguration().getCredentialsInfo().size();
}
public String loginWithSingleCredentials(Credentials credentials) {
......@@ -143,13 +143,13 @@ public class CredentialsBean implements Serializable {
}
public void removeCredentials(int index) throws IOException {
ccBean.getConfig().getCredentialsInfo().remove(index);
ccBean.getConfig().getCredentialsConfiguration().getCredentialsInfo().remove(index);
ccBean.updateConfigurationFile();
}
public void saveCredentialsEdited() throws IOException {
List credentialsList = ccBean.getConfig().getCredentialsInfo();
List credentialsList = ccBean.getConfig().getCredentialsConfiguration().getCredentialsInfo();
if (currentEditingRow < credentialsList.size()) {
credentialsList.remove(currentEditingRow);
......
......@@ -44,8 +44,8 @@ public class CustomPartialResponseWriter extends PartialResponseWriter {
public CustomPartialResponseWriter(ResponseWriter wrapped) {
super(wrapped);
componentsToEncode = new HashSet<String>();
customJSUpdates = new HashMap<String, JSUpdateHandler>();
componentsToEncode = new HashSet<>();
customJSUpdates = new HashMap<>();
}
@Override
......
package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCDParser;
import ari.ucidy.UCDSyntax;
import ari.ucidy.UCDWord;
import ari.ucidy.UCDWordList;
import java.io.IOException;
import java.util.List;
/**
* This UCDParser load standard UCD values and add user-defined UCDs.
*
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
public class CustomizedUCDParser extends UCDParser {
public CustomizedUCDParser(List<String> customUCDs) {
super();
try {
// Load standard UCD list
knownWords.addAll(UCDWordList.class.getResourceAsStream("/ucd1p-words.txt"), true);
} catch (NullPointerException | IOException e) {
throw new ExceptionInInitializerError(e);
}
if (customUCDs != null) {
// Add custom UCDs
for (String customUCD : customUCDs) {
knownWords.add(new UCDWord(UCDSyntax.BOTH, customUCD, null, false));
}
}
}
}
......@@ -22,8 +22,9 @@
*/
package it.inaf.ia2.tsm.webapp;
import ari.ucd.UCD;
import ari.ucd.UCDParser;
import ari.ucidy.UCD;
import ari.ucidy.UCDParser;
import ari.ucidy.UCDWordList;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
......@@ -72,8 +73,11 @@ public class ParsedUCD implements Serializable {
}
}
public ParsedUCD(String ucdText) {
this(UCDParser.parseUCD(ucdText));
public ParsedUCD(String ucdText, List<String> customUCDs) {
this(customUCDs == null
? UCDParser.parseUCD(ucdText)
: new CustomizedUCDParser(customUCDs).parse(ucdText)
);
}
public boolean isValid() {
......
......@@ -26,6 +26,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
/**
*
......@@ -36,6 +37,9 @@ public class SearchUCDDialog implements Serializable {
private static final long serialVersionUID = -3503024742241865133L;
@Inject
WebAppConfigurationBean config;
private boolean manualInsertion;
private String UCDManualText;
......@@ -152,7 +156,7 @@ public class SearchUCDDialog implements Serializable {
if (UCDManualText == null || UCDManualText.isEmpty() || UCDManualText.trim().isEmpty()) {
parsedUCD = null;
} else {
parsedUCD = new ParsedUCD(UCDManualText);
parsedUCD = new ParsedUCD(UCDManualText, config.getConfig().getCustomUCDs());
}
}
......
......@@ -38,18 +38,6 @@ public class TSMResourceHandlerWrapper extends ResourceHandlerWrapper {
private final ResourceHandler wrapped;
private final static String VERSION;
static {
try (InputStream is = TSMResourceHandlerWrapper.class.getClassLoader().getResourceAsStream("version.txt")) {
Scanner s = new Scanner(is).useDelimiter("\\A");
VERSION = s.next().trim();
} catch (IOException e) {
throw new RuntimeException("File version.txt not found in the war package!");
}
}
public TSMResourceHandlerWrapper(ResourceHandler wrapped) {
this.wrapped = wrapped;
}
......@@ -76,7 +64,7 @@ public class TSMResourceHandlerWrapper extends ResourceHandlerWrapper {
@Override
public String getRequestPath() {
return super.getRequestPath() + "&v=" + VERSION;
return super.getRequestPath() + "&v=" + Version.NUMBER;
}
@Override
......
package it.inaf.ia2.tsm.webapp;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
/**
* Static class for sharing version number inside the application.
*
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
public class Version {
public final static String NUMBER;
static {
try (InputStream is = TSMResourceHandlerWrapper.class.getClassLoader().getResourceAsStream("version.txt")) {
Scanner s = new Scanner(is).useDelimiter("\\A");
NUMBER = s.next().trim();
} catch (IOException e) {
throw new ExceptionInInitializerError("File version.txt not found in the war package!");
}
}
}
......@@ -22,16 +22,21 @@
*/
package it.inaf.ia2.tsm.webapp;
import ari.ucidy.UCDSyntax;
import ari.ucidy.UCDWord;
import ari.ucidy.UCDWordList;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.xml.bind.JAXB;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
/**
*
......@@ -40,11 +45,11 @@ import org.slf4j.LoggerFactory;
@ApplicationScoped
public class WebAppConfigurationBean {
private static final Logger log = LoggerFactory.getLogger(WebAppConfigurationBean.class);
private static final Logger LOG = LoggerFactory.getLogger(WebAppConfigurationBean.class);
private File credentialsConfigFile;
private File configFile;
private String password;
private CredentialsConfiguration cc;
private Configuration configuration;
@PostConstruct
public void init() {
......@@ -53,34 +58,69 @@ public class WebAppConfigurationBean {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("webapp.properties")) {
prop.load(in);
}
credentialsConfigFile = new File(prop.getProperty("credentials_config_path"));
configFile = new File(prop.getProperty("config_file_path"));
password = prop.getProperty("password");
if (!credentialsConfigFile.exists()) {
log.debug("Configuration file doesn't exist: creating a new one at " + credentialsConfigFile.getAbsolutePath());
credentialsConfigFile.getParentFile().mkdirs();
credentialsConfigFile.createNewFile();
cc = new CredentialsConfiguration();
JAXB.marshal(cc, credentialsConfigFile);
if (!configFile.exists()) {
LOG.debug("Configuration file doesn't exist: creating a new one at " + configFile.getAbsolutePath());
configFile.getParentFile().mkdirs();
configFile.createNewFile();
configuration = new Configuration();
updateConfigurationFile();
} else {
cc = JAXB.unmarshal(credentialsConfigFile, CredentialsConfiguration.class);
configuration = getOldConfigurationUpdated(configFile);
if (configuration != null) {
updateConfigurationFile();
} else {
// Configuration file was ok, simply unmarshal it
configuration = JAXB.unmarshal(configFile, Configuration.class);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
throw new ExceptionInInitializerError(e);
}
}
public CredentialsConfiguration getConfig() {
return cc;
public Configuration getConfig() {
return configuration;
}
public void updateConfigurationFile() throws IOException {
try (FileWriter fw = new FileWriter(credentialsConfigFile)) {
JAXB.marshal(cc, fw);
}
JAXB.marshal(configuration, configFile);
}
public String getPassword() {
return password;
}
/**
* Checking for old configuration and updating configuration model, if
* necessary. This method returns null if no update is necessary.
*/
private Configuration getOldConfigurationUpdated(File file) throws IOException {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
String nodeName = doc.getDocumentElement().getNodeName();
if (nodeName.equals("credentials-config")) {
LOG.debug("Detected version 1.0.3 or lower. Extracting CredentialsConfiguration and updating the XML model.");
CredentialsConfiguration cc = JAXB.unmarshal(file, CredentialsConfiguration.class);
Configuration updatedConfiguration = new Configuration();
updatedConfiguration.setCredentialsConfiguration(cc);
return updatedConfiguration;
}
// Currently for version 1.0.4+ no updated are necessary.
return null;
} catch (Throwable t) {
LOG.warn("Unable to parse XML configuration. Deleting it and creating a new empy one.");
return new Configuration();
}
}
}
ucd_service_url=http://ia2-vo.oats.inaf.it/ucd/
credentials_config_path=/home/sonia/.tsm/config.xml
config_file_path=/home/sonia/.tsm/config.xml
password=pippo
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment