diff --git a/TapSchemaManagerAPI/pom.xml b/TapSchemaManagerAPI/pom.xml index 276b50a9c0ac8ee0ec55b49167df20be0265188a..9e6f3facd63b1f1bb0d5204edd0fd46d70d3b992 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 dd0da754d256f492d38e072f53bf3e58d0007252..7ac0a25bde68883cbc267cd6cc9b48dc26c87b60 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 bac17645b3d9f5dd392a6b5efee183c8a6135619..6f6892328f60d2a9de6d3c60f27d9150b3b24871 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 21dbfed1a8c7ec0480752dd515eed61c97201475..2afaa32e5114ceb259d5d522b070ba224cc559be 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 b270a3bf85103c844addc1ade3d8f28e72fc9356..8c0f5b77e227c77b6fd4316a61a6d6d76ea2e0d1 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 9c4b3e7ed6030fd8f783621942728f975653d06a..a179c43f1d99f7571a2bb3f4fb569abfa4ef06e7 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 f45a0c4475bb8f34d82b041e7d570a5fa5813e56..7916bb3204741b613af62aa250178edeb7b36cd6 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 b7d74c8561f518c21fd528a63d63309d2b1dffd0..96f374ff9501fb0839f3001e75f1abb82e27e7d4 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 be7fa152f812e2aedc6f928b6b2809b42dd67e64..837592bde5c30a000fc3b52c79ac2b642429127b 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 57bb1da816a9da0908ae7213a83d920b2085d463..34e1a7b6e5da34fc85d2718c40d167b5f07593af 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 33baa264c25602721b0029a38206d769a882eeb5..8c58bb0ce86dd54e3b8baf7cbacb14843b5f0e6b 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 4586a32cd609971e930086227561be983309f629..a2736ece20895bece010e1d9bbc84b647018b8c2 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 9d6077230f5d10c5c3592fd48aa49aba51f7e8ba..c64f11404c08a10e86aeaeee23057243828ab756 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 175370fefed7fd7578a1b4b675a8863fc465f9c5..101e2fc4d1fd18bd0d11351afeb2ad3f87257a33 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 6e2ad780680ca829064eb9bf8ee2863736009908..91c8d07ca2482b0a10fde166f0e313b7f14536ec 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 9cd6e3fc182f7c687eab59e05982a977afdbe4c2..f8df2e948030bff94fde2caaa5725c86a339d590 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 2171c58ff623163a02ecd286478478b43f546275..2ea0939941535635cd29eba3e7d35cef3d384e0d 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 4a94982fbd2bbb5a8a2b5f43d907416148ed384d..44e2ae626837f6e9383e71177cfef5f109643e78 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 7b253deb0e8026c3b249476ac3c855a23e8f886b..ee72326c7fdf362cfb75db390c5105fda91d8989 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 0000000000000000000000000000000000000000..93c42a5f8e889ad5f28069f46d27ad9cb00f7361 --- /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 485681f03e66bec14e3562958dfcb7d4a8be31ff..cae4f38360ec00674cd66190b5d8bfe1f29aecf4 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 cf6aee291ae552d40bc76f3c0b6212e000e59e6a..6450c4e6a31445ffb8801a572e3648de26525815 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 605d49b3bac912496425c022707b9834ab255454..226e6b2ab165b8a15752651a456e59dc9423987b 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 771603b1d0ac69ed896a4de09cf71c5cf10b00c1..a6b768bd93f21d17eb5668178f54ee871dd7be82 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 256b2bb73f0e0a22e69f807b0f9984e47553fac8..1b4a422e961c992b935ca27e861d39932790fc8e 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 f6f89da3a3c7d5e11d07a1d46db52ce0acbbed36..e8baeaa275214d4d1c4d09ba1bc561b9563179e1 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 962676260369ff13321d73176f6f1a4154680526..726b22ac8e1e4f9bee342b972725c5b35c1386f0 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 69efda0e8fd8359f8ba80c107e88090fbb5827d9..3accec0a6102a875316e810dc3f203e7cc742af8 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 d6d8c7c6024dd19b446944403a4989a60f68a883..3cd80fff7dc9821716b9e01f194e10c421c958d3 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 41009c345109ebcda2b6a6c0d87a24042fb9e1b3..6300479c59789894624cb8208d95a38297ac9d7c 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 09acb15745773baaf6b0b06d801926851059761b..86b90bd1ca80a0c3443eb3fec976c0b01ef1965e 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 @@ + -

-