diff --git a/TapSchemaManagerWebApp/pom.xml b/TapSchemaManagerWebApp/pom.xml index 8f3e7088f4c03fb487122f118c803e34982a2e3f..8926c58e27d6682427a372fa6b4a7f3e9db76c75 100644 --- a/TapSchemaManagerWebApp/pom.xml +++ b/TapSchemaManagerWebApp/pom.xml @@ -4,7 +4,7 @@ it.inaf.ia2.tap TapSchemaManagerWebApp - 1.0.1 + 1.0.2 war TapSchemaManagerWebApp @@ -87,7 +87,7 @@ it.inaf.ia2.tap TapSchemaManagerAPI - 1.0.1 + 1.0.2 ari.ucd @@ -100,6 +100,11 @@ 7.0 provided + + uk.me.nxg + unity + 1.0 + mysql mysql-connector-java 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 e4753686841a80818d511fd59f986b2b9d339c44..f06737e6b4abe16202a1ea8a0551e36d34560ff8 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 @@ -72,6 +72,7 @@ public class TapSchemaEditingBean implements Serializable { private EntitiesContainer currentAddingContainer; private List currentAddables; + private VOUnitValidator voUnitValidator; @Inject private SearchUCDDialog searchUCDDialog; @@ -88,6 +89,10 @@ public class TapSchemaEditingBean implements Serializable { return selectedColumn; } + public VOUnitValidator getVoUnitValidator() { + return voUnitValidator; + } + public void setSelectedSchema(Schema selectedSchema) { this.selectedSchema = selectedSchema; if (selectedSchema == null) { @@ -118,6 +123,7 @@ public class TapSchemaEditingBean implements Serializable { public void setSelectedColumn(Column selectedColumn) { this.selectedColumn = selectedColumn; + selectedColumnChanged(); } public UpdateOperations getUpdateOperations() { @@ -218,6 +224,15 @@ public class TapSchemaEditingBean implements Serializable { } } } + selectedColumnChanged(); + } + + private void selectedColumnChanged() { + if (selectedColumn == null) { + voUnitValidator = new VOUnitValidator(null); + } else { + voUnitValidator = new VOUnitValidator(selectedColumn.getUnit()); + } } public void setTapSchema(TapSchema tapSchema) { @@ -328,6 +343,9 @@ public class TapSchemaEditingBean implements Serializable { public void textInputChanged(TapSchemaEntity entity, String key) { final boolean isChanged = entity.isChanged(key); + if (key.equals("unit")) { + voUnitValidator = new VOUnitValidator(entity.getValue(key, String.class)); + } CustomPartialResponseWriter.getCurrentInstance().addCustomJSUpdate(new JSUpdateHandler() { @Override 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 new file mode 100644 index 0000000000000000000000000000000000000000..485681f03e66bec14e3562958dfcb7d4a8be31ff --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/VOUnitValidator.java @@ -0,0 +1,89 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2017 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 java.io.Serializable; +import uk.me.nxg.unity.Syntax; +import uk.me.nxg.unity.UnitExpr; +import uk.me.nxg.unity.UnitParser; + +/** + * Serializable wrapper for VOUnit UnitExpr + * + * @author Sonia Zorba + */ +public class VOUnitValidator implements Serializable { + + private static final long serialVersionUID = -1019359441934896102L; + + private static final Syntax syntax = Syntax.lookup("vounits"); + + private final boolean unset; + private boolean parsable; + private boolean allUnitsRecognised; + private boolean allUnitsRecommended; + private boolean allUsageConstraintsSatisfied; + private String exceptionMessage; + + public VOUnitValidator(String value) { + + unset = value == null || value.isEmpty(); + + if (!unset) { + try { + UnitParser parser = new UnitParser(syntax, value); + UnitExpr expr = parser.getParsed(); + allUnitsRecognised = expr.allUnitsRecognised(syntax); + allUnitsRecommended = expr.allUnitsRecommended(syntax); + allUsageConstraintsSatisfied = expr.allUsageConstraintsSatisfied(syntax); + parsable = true; + } catch (Throwable t) { + exceptionMessage = t.getMessage(); + } + } + } + + public boolean isUnset() { + return unset; + } + + public boolean isParsable() { + return parsable; + } + + public boolean isAllUnitsRecognised() { + return allUnitsRecognised; + } + + public boolean isAllUnitsRecommended() { + return allUnitsRecommended; + } + + public boolean isAllUsageConstraintsSatisfied() { + return allUsageConstraintsSatisfied; + } + + public String getExceptionMessage() { + return exceptionMessage; + } +} diff --git a/TapSchemaManagerWebApp/src/main/resources/webapp.properties b/TapSchemaManagerWebApp/src/main/resources/webapp.properties index 9de6d7dd2faf32f5aaa31edae1925c32499f18a3..74d3e4b1c890d47ec208f0ff07aca0c11da981a5 100644 --- a/TapSchemaManagerWebApp/src/main/resources/webapp.properties +++ b/TapSchemaManagerWebApp/src/main/resources/webapp.properties @@ -1,3 +1,3 @@ -ucd_service_url=http://ia2-vo.oats.inaf.it:8080/ucd/ +ucd_service_url=http://ia2-vo.oats.inaf.it/ucd/ credentials_config_path=/home/sonia/.tsm/config.xml password=pippo \ No newline at end of file diff --git a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml index 113af63e1c8adb02ebb45c9e6ce268f5b601833b..9806f514a58c94283c3292b10dbce525720db97a 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml @@ -314,10 +314,44 @@ + value="#{tapSchemaEditing.selectedColumn.unit}" + autocomplete="off"> - + + + + +
    +
  • + all units recognised + + + +
  • +
  • + all units recommended + + + +
  • +
  • + all constraints satisfied + + + +
  • +
+
+ +

+ + Invalid VOUnit: + #{tapSchemaEditing.voUnitValidator.exceptionMessage} +

+
+
+
Description: