From 3218d87a75ca5e32d33eb5fee9c6b6885b9dc1e5 Mon Sep 17 00:00:00 2001 From: Sonia Zorba Date: Mon, 20 Mar 2017 16:16:41 +0100 Subject: [PATCH] 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 --- TapSchemaManagerAPI/pom.xml | 6 +- .../inaf/ia2/tsm/api/ConsistencyChecks.java | 2 +- .../inaf/ia2/tsm/api/InconsistentValue.java | 2 +- TapSchemaManagerWebApp/pom.xml | 63 +++++- .../ia2/tsm/webapp/ConfigurationData.java | 16 +- .../ia2/tsm/webapp/ConsistencyChecksBean.java | 6 +- .../tsm/webapp/CredentialsDialogResource.java | 2 +- .../ia2/tsm/webapp/CredentialsEditing.java | 24 +-- .../ia2/tsm/webapp/CustomizedUCDParser.java | 8 +- .../it/inaf/ia2/tsm/webapp/FirstSetup.java | 2 +- .../java/it/inaf/ia2/tsm/webapp/Login.java | 2 +- .../it/inaf/ia2/tsm/webapp/ParsedUCD.java | 3 +- .../ia2/tsm/webapp/SchemaSelectionBean.java | 15 +- .../it/inaf/ia2/tsm/webapp/SearchUCD.java | 94 ++------- .../inaf/ia2/tsm/webapp/SearchUCDDialog.java | 100 +++++++--- .../ia2/tsm/webapp/TapSchemaEditingBean.java | 15 +- .../it/inaf/ia2/tsm/webapp/UCDEditor.java | 6 +- .../java/it/inaf/ia2/tsm/webapp/UCDInfo.java | 36 +++- .../java/it/inaf/ia2/tsm/webapp/User.java | 2 +- .../it/inaf/ia2/tsm/webapp/UsersEditing.java | 76 +++++++ .../inaf/ia2/tsm/webapp/VOUnitValidator.java | 2 +- .../tsm/webapp/checker/FirstSetupChecker.java | 2 +- .../tsm/webapp/checker/LoggedInChecker.java | 2 +- .../ia2/tsm/webapp/env/ApplicationConfig.java | 2 +- .../ia2/tsm/webapp/env/KeepAliveBean.java | 14 +- .../ia2/tsm/webapp/env/KeepAliveResource.java | 12 +- .../tsm/webapp/env/NullOrEmptyConverter.java | 2 +- .../webapp/env/TSMResourceHandlerWrapper.java | 2 +- .../webapp/xmlconfig/UCDConfiguration.java | 2 +- .../webapp/xmlconfig/UserConfiguration.java | 2 +- .../webapp/WEB-INF/templates/master.xhtml | 10 +- .../src/main/webapp/WEB-INF/web.xml | 6 +- .../src/main/webapp/consistencyChecks.xhtml | 2 +- .../src/main/webapp/credentialsEditing.xhtml | 14 +- .../src/main/webapp/resources/css/style.css | 3 + .../main/webapp/resources/js/credentials.js | 23 +-- .../webapp/resources/js/edit-tapschema.js | 17 +- .../src/main/webapp/resources/js/keepalive.js | 4 +- .../tsm_components/user_navbar.xhtml | 2 +- .../src/main/webapp/schemaSelection.xhtml | 45 +++-- .../src/main/webapp/tapSchemaEditing.xhtml | 186 +++++++++++------- .../src/main/webapp/usersEditing.xhtml | 87 ++++++++ 42 files changed, 600 insertions(+), 321 deletions(-) create mode 100644 TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UsersEditing.java create mode 100644 TapSchemaManagerWebApp/src/main/webapp/usersEditing.xhtml diff --git a/TapSchemaManagerAPI/pom.xml b/TapSchemaManagerAPI/pom.xml index 276b50a..9e6f3fa 100644 --- a/TapSchemaManagerAPI/pom.xml +++ b/TapSchemaManagerAPI/pom.xml @@ -2,9 +2,10 @@ 4.0.0 it.inaf.ia2.tap - TapSchemaManagerAPI - 1.0.4 + tasman-core + 1.1.0 jar + tasman-core UTF-8 1.7 @@ -46,5 +47,4 @@ - TapSchemaManagerAPI \ No newline at end of file diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/ConsistencyChecks.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/ConsistencyChecks.java index dd0da75..7ac0a25 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/ConsistencyChecks.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/ConsistencyChecks.java @@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ public class ConsistencyChecks implements Serializable { diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/InconsistentValue.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/InconsistentValue.java index bac1764..6f68923 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/InconsistentValue.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/InconsistentValue.java @@ -24,7 +24,7 @@ package it.inaf.ia2.tsm.api; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ public class InconsistentValue { diff --git a/TapSchemaManagerWebApp/pom.xml b/TapSchemaManagerWebApp/pom.xml index 21dbfed..2afaa32 100644 --- a/TapSchemaManagerWebApp/pom.xml +++ b/TapSchemaManagerWebApp/pom.xml @@ -3,17 +3,18 @@ 4.0.0 it.inaf.ia2.tap - TapSchemaManagerWebApp - 1.0.4 + tasman-webapp + 1.1.0 war - TapSchemaManagerWebApp + tasman-webapp ${project.build.directory}/endorsed UTF-8 inaf-license-netbeans 2.23.2 + 1.7.2 @@ -86,8 +87,8 @@ it.inaf.ia2.tap - TapSchemaManagerAPI - 1.0.4 + tasman-core + 1.1.0 ari.ucidy @@ -123,8 +124,60 @@ 4.10 test + + org.apache.deltaspike.modules + deltaspike-jsf-module-impl + runtime + + + org.apache.deltaspike.modules + deltaspike-jsf-module-api + runtime + + + org.apache.deltaspike.core + deltaspike-core-api + compile + + + org.apache.deltaspike.core + deltaspike-core-impl + runtime + + + org.apache.deltaspike.cdictrl + deltaspike-cdictrl-weld + runtime + + + org.apache.deltaspike.cdictrl + deltaspike-cdictrl-api + compile + + + org.apache.deltaspike.modules + deltaspike-servlet-module-impl + runtime + + + org.apache.deltaspike.modules + deltaspike-servlet-module-api + compile + + + + + org.apache.deltaspike.distribution + distributions-bom + ${deltaspike.version} + pom + import + + + + diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConfigurationData.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConfigurationData.java index b270a3b..8c0f5b7 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConfigurationData.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConfigurationData.java @@ -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 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 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() { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java index 9c4b3e7..a179c43 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ConsistencyChecksBean.java @@ -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 + * @author Sonia Zorba {@literal } */ -@ConversationScoped +@WindowScoped @Named("consistency") public class ConsistencyChecksBean implements Serializable { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsDialogResource.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsDialogResource.java index f45a0c4..7916bb3 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsDialogResource.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsDialogResource.java @@ -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 + * @author Sonia Zorba {@literal } */ @Path("credentialsDialog") @RequestScoped diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsEditing.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsEditing.java index b7d74c8..96f374f 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsEditing.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CredentialsEditing.java @@ -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 } */ @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); } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CustomizedUCDParser.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CustomizedUCDParser.java index be7fa15..837592b 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CustomizedUCDParser.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/CustomizedUCDParser.java @@ -1,9 +1,9 @@ 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 customUCDs) { + public CustomizedUCDParser(List 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)); } } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/FirstSetup.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/FirstSetup.java index 57bb1da..34e1a7b 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/FirstSetup.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/FirstSetup.java @@ -10,7 +10,7 @@ import javax.inject.Named; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named @RequestScoped diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/Login.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/Login.java index 33baa26..8c58bb0 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/Login.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/Login.java @@ -31,7 +31,7 @@ import javax.inject.Named; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named @RequestScoped diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ParsedUCD.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ParsedUCD.java index 4586a32..a2736ec 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ParsedUCD.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/ParsedUCD.java @@ -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 customUCDs) { + public ParsedUCD(String ucdText, List customUCDs) { this(customUCDs == null ? UCDParser.parseUCD(ucdText) : new CustomizedUCDParser(customUCDs).parse(ucdText) diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java index 9d60772..c64f114 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SchemaSelectionBean.java @@ -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 } */ @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; diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCD.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCD.java index 175370f..101e2fc 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCD.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCD.java @@ -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"); - } - } - } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java index 6e2ad78..91c8d07 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/SearchUCDDialog.java @@ -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 selectableUCDs; private List 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); - } - } - public boolean isManualInsertion() { return manualInsertion; } @@ -151,24 +148,81 @@ public class SearchUCDDialog implements Serializable { public void setUCDManualText(String UCDManualText) { this.UCDManualText = UCDManualText; } -// -// public void validateManualUCD() { -// if (UCDManualText == null || UCDManualText.isEmpty() || UCDManualText.trim().isEmpty()) { -// parsedUCD = null; -// } else { -// parsedUCD = new ParsedUCD(UCDManualText, config.getConfig().getCustomUCDs()); -// } -// } - public String getUCDRegExp() { - return SearchUCD.REG_EXP_UCD; - } - - public String getNamespaceRegExp() { - return SearchUCD.REG_EXP_START_WITH_NAMESPACE; + public void validateManualUCD() { + if (UCDManualText == null || UCDManualText.isEmpty() || UCDManualText.trim().isEmpty()) { + parsedUCD = null; + } else { + parsedUCD = new ParsedUCD(UCDManualText, user.getUserConfiguration().getCustomUCDs()); + } } public ParsedUCD getParsedUCD() { return parsedUCD; } + + public void rebuildUCD() { + // Retrieving all words selected by the user. + List wordsToPermutate = new ArrayList<>(); + for (UCDInfo ucd : suggestedUCDs) { + if (ucd.isSelected()) { + wordsToPermutate.add(ucd.getWord()); + } + } + + // Building UCD candidates list (all possible word permutations, including invalid UCDs) + List ucdCandidates = new ArrayList<>(); + for (int i = 1; i < 4; i++) { + buildAllWordsPermutations(wordsToPermutate, ucdCandidates, i, 0, null); + } + + // Filtering candidates list taking only fully valid UCDs + selectableUCDs.clear(); + for (String ucdCandidate : ucdCandidates) { + UCD ucd = UCDParser.parseUCD(ucdCandidate); + if (ucd.isFullyValid()) { + selectableUCDs.add(ucdCandidate); + } + } + } + + /** + * This recursive method allows to retrieve all UCD candidates for a given + * list of UCD words. It computes all possible permutations of words that + * could be an UCD of a given length. Resulting UCD candidates are added to + * the result list passed as a parameters. These values are only candidates, + * so they could be invalid UCD, so the list needs to be validated after its + * creation. For the first recursive step set currentSize to 0 and + * currentPerm to null. + * + * @param wordsList the list of words on which do the permutation + * @param result the list in which store the result of the permutations + * @param limit the number of words that will compose the UCD candidate + * (permutation size limit) + * @param currentSize number of words concatenated in the current recursive + * step (it will stop the recursion when it will be equals to the limit + * value) + * @param currentPerm the word built by current recursive step + */ + private void buildAllWordsPermutations(List wordsList, List result, int limit, int currentSize, String currentPerm) { + if (currentSize == limit) { + result.add(currentPerm); + } else { + for (String item : wordsList) { + List remaining = new ArrayList<>(wordsList); + remaining.remove(item); + String ucd; + if (currentPerm != null) { + ucd = currentPerm + ";" + item; + } else { + ucd = item; + } + buildAllWordsPermutations(remaining, result, limit, currentSize + 1, ucd); + } + } + } + + public List getSelectableUCDs() { + return selectableUCDs; + } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java index 9cd6e3f..f8df2e9 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java @@ -39,11 +39,10 @@ import java.io.Serializable; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import javax.enterprise.context.Conversation; -import javax.enterprise.context.ConversationScoped; 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; @@ -52,17 +51,14 @@ import org.slf4j.LoggerFactory; * @author Sonia Zorba {@literal } */ @Named("tapSchemaEditing") -@ConversationScoped +@WindowScoped public class TapSchemaEditingBean implements Serializable { private static final long serialVersionUID = -6251004452688984277L; - private static final Logger log = LoggerFactory.getLogger(TapSchemaEditingBean.class); + private static final Logger LOG = LoggerFactory.getLogger(TapSchemaEditingBean.class); private static final String COLUMNS_COMPONENT_ID = "main:columns-list"; - @Inject - private Conversation conversation; - @Inject SchemaSelectionBean schemaSelection; @@ -255,11 +251,6 @@ public class TapSchemaEditingBean implements Serializable { return "schemaSelection.xhtml?faces-redirect=true"; } - public String logout() { - conversation.end(); - return "index.xhtml?faces-redirect=true"; - } - public void undoRemove(ChildEntity entity) throws SQLException { // re-add what was removed entity.getParent().addChild(entity.getName()); diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDEditor.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDEditor.java index 2171c58..2ea0939 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDEditor.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDEditor.java @@ -7,16 +7,16 @@ import it.inaf.ia2.tsm.webapp.xmlconfig.UserConfiguration; import java.io.IOException; import java.io.Serializable; import java.util.List; -import javax.enterprise.context.SessionScoped; import javax.inject.Inject; import javax.inject.Named; +import org.apache.deltaspike.core.api.scope.WindowScoped; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named("ucdEditor") -@SessionScoped +@WindowScoped public class UCDEditor implements Serializable { private static final long serialVersionUID = -9117203239681234534L; diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDInfo.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDInfo.java index 4a94982..44e2ae6 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDInfo.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UCDInfo.java @@ -35,12 +35,14 @@ public class UCDInfo implements Serializable { private final String score; private final String flag; private final String word; - private String definition; + private final String definition; + private boolean selected; - UCDInfo(String score, String flag, String word) { + UCDInfo(String score, String flag, String word, String definition) { this.score = score; this.flag = flag; this.word = word; + this.definition = definition; } public String getScore() { @@ -59,7 +61,33 @@ public class UCDInfo implements Serializable { return definition; } - public void setDefinition(String definition) { - this.definition = definition; + /** + * Selection is used for UCD Rebuild functionality. + */ + public boolean isSelected() { + return selected; + } + + public void setSelected(boolean selected) { + this.selected = selected; + } + + public String getFlagExplanation() { + switch (flag) { + case "P": + return "The code \"P\" means that the word can only be used as “primary” or first word"; + case "S": + return "\"S\" stands for only secondary: the word cannot be used as the first word to describe a single quantity"; + case "Q": + return "\"Q\" means that the word can be used indifferently as first or secondary word"; + case "E": + return "\"E\" means a photometric quantity, and can be followed by a word describing a part of the electromagnetic spectrum"; + case "C": + return "\"C\" is a colour index, and can be followed by two successive word describing a part of the electromagnetic spectrum"; + case "V": + return "\"V\" stands for vector. Such a word can be followed by another describing the axis or reference frame in which the measurement is done"; + default: + return null; + } } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/User.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/User.java index 7b253de..ee72326 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/User.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/User.java @@ -32,7 +32,7 @@ import javax.servlet.http.HttpServletRequest; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named @SessionScoped diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UsersEditing.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UsersEditing.java new file mode 100644 index 0000000..93c42a5 --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/UsersEditing.java @@ -0,0 +1,76 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2016 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.webapp; + +import it.inaf.ia2.tsm.webapp.xmlconfig.UserConfiguration; +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import org.apache.deltaspike.core.api.scope.WindowScoped; + +/** + * + * @author Sonia Zorba {@literal } + */ +@Named +@WindowScoped +public class UsersEditing implements Serializable { + + private static final long serialVersionUID = -8758568990541836689L; + + @Inject + private ConfigurationData config; + + private List users; + + @PostConstruct + public void init() { + users = new ArrayList<>(); + } + + public String open() { + // Copying users list (to avoid issues caused by simultaneously changes) + users = config.cloneUsersConfiguration(); + return "usersEditing.xhtml?faces-redirect=true"; + } + + public List getUsers() { + return users; + } + + public void save() throws IOException { + config.updateUsersList(users); + } + + public void addUser() { + users.add(new UserConfiguration()); + } + + public void removeUser(int index) { + users.remove(index); + } +} diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/VOUnitValidator.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/VOUnitValidator.java index 485681f..cae4f38 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/VOUnitValidator.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/VOUnitValidator.java @@ -30,7 +30,7 @@ import uk.me.nxg.unity.UnitParser; /** * Serializable wrapper for VOUnit UnitExpr * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ public class VOUnitValidator implements Serializable { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/FirstSetupChecker.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/FirstSetupChecker.java index cf6aee2..6450c4e 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/FirstSetupChecker.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/FirstSetupChecker.java @@ -32,7 +32,7 @@ import javax.inject.Named; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named @RequestScoped diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/LoggedInChecker.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/LoggedInChecker.java index 605d49b..226e6b2 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/LoggedInChecker.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/checker/LoggedInChecker.java @@ -8,7 +8,7 @@ import javax.inject.Named; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named @RequestScoped diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java index 771603b..a6b768b 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/ApplicationConfig.java @@ -27,7 +27,7 @@ import javax.ws.rs.core.Application; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @javax.ws.rs.ApplicationPath("rest") public class ApplicationConfig extends Application { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveBean.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveBean.java index 256b2bb..1b4a422 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveBean.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveBean.java @@ -23,25 +23,25 @@ package it.inaf.ia2.tsm.webapp.env; import java.io.Serializable; -import javax.enterprise.context.Conversation; -import javax.enterprise.context.ConversationScoped; import javax.inject.Inject; import javax.inject.Named; +import org.apache.deltaspike.core.api.scope.WindowScoped; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Named("keepalive") -@ConversationScoped +@WindowScoped public class KeepAliveBean implements Serializable { private static final long serialVersionUID = 8899457623621886668L; @Inject - private Conversation conversation; + private WindowContext windowContext; - public String getConversationId() { - return conversation.getId(); + public String getWindowId() { + return windowContext.getCurrentWindowId(); } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveResource.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveResource.java index f6f89da..e8baeaa 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveResource.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/KeepAliveResource.java @@ -23,32 +23,32 @@ package it.inaf.ia2.tsm.webapp.env; import java.io.Serializable; -import javax.enterprise.context.Conversation; -import javax.enterprise.context.ConversationScoped; import javax.ws.rs.Produces; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.inject.Inject; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.apache.deltaspike.core.api.scope.WindowScoped; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; /** * REST Web Service * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @Path("keepalive") -@ConversationScoped +@WindowScoped public class KeepAliveResource implements Serializable { private static final long serialVersionUID = 3477976029207874216L; @Inject - Conversation conversation; + private WindowContext windowContext; @GET @Produces(MediaType.TEXT_PLAIN) public Response keepAlive() { - return Response.ok(conversation.getId()).build(); + return Response.ok(windowContext.getCurrentWindowId()).build(); } } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/NullOrEmptyConverter.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/NullOrEmptyConverter.java index 9626762..726b22a 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/NullOrEmptyConverter.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/NullOrEmptyConverter.java @@ -39,7 +39,7 @@ import javax.faces.convert.FacesConverter; * could be confusing for the user, so this converter checks if the previous * value is an empty string and in that case bypass the conversion to null. * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ @FacesConverter("it.inaf.ia2.NullOrEmptyConverter") public class NullOrEmptyConverter implements Converter { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/TSMResourceHandlerWrapper.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/TSMResourceHandlerWrapper.java index 69efda0..3accec0 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/TSMResourceHandlerWrapper.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/env/TSMResourceHandlerWrapper.java @@ -30,7 +30,7 @@ import javax.faces.application.ResourceWrapper; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ public class TSMResourceHandlerWrapper extends ResourceHandlerWrapper { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UCDConfiguration.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UCDConfiguration.java index d6d8c7c..3cd80ff 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UCDConfiguration.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UCDConfiguration.java @@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlElement; /** * JAXB class for defining custom UCDs. * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ public class UCDConfiguration implements Serializable { diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UserConfiguration.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UserConfiguration.java index 41009c3..6300479 100644 --- a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UserConfiguration.java +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/xmlconfig/UserConfiguration.java @@ -34,7 +34,7 @@ import javax.xml.bind.annotation.XmlElements; /** * - * @author Sonia Zorba + * @author Sonia Zorba {@literal } */ public class UserConfiguration implements Serializable { diff --git a/TapSchemaManagerWebApp/src/main/webapp/WEB-INF/templates/master.xhtml b/TapSchemaManagerWebApp/src/main/webapp/WEB-INF/templates/master.xhtml index 09acb15..86b90bd 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/WEB-INF/templates/master.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/WEB-INF/templates/master.xhtml @@ -3,7 +3,8 @@ xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" - xmlns:ui="http://java.sun.com/jsf/facelets"> + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:ds="http://deltaspike.apache.org/jsf"> @@ -23,10 +24,13 @@ + -

-