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 5c59ce1a4baa0cfbbabc5d841ed2f3f13b616e96..dd0da754d256f492d38e072f53bf3e58d0007252 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 @@ -29,7 +29,6 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -49,7 +48,7 @@ public class ConsistencyChecks implements Serializable { private static final long serialVersionUID = 4412404312756740093L; private final static Logger log = LoggerFactory.getLogger(ConsistencyChecks.class); - private final List inconsistencies; + private final List inconsistencies; private final List unexisingSchemas; private final List unexisingTables; private final Map unexisingColumns; @@ -61,11 +60,11 @@ public class ConsistencyChecks implements Serializable { unexisingColumns = new HashMap<>(); } - public void addInconsistency(String problemDescription) { + public void addInconsistency(InconsistentValue problemDescription) { inconsistencies.add(problemDescription); } - public List getInconsistencies() { + public List getInconsistencies() { return inconsistencies; } 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 new file mode 100644 index 0000000000000000000000000000000000000000..bac17645b3d9f5dd392a6b5efee183c8a6135619 --- /dev/null +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/InconsistentValue.java @@ -0,0 +1,68 @@ +/* + * _____________________________________________________________________________ + * + * 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.api; + +/** + * + * @author Sonia Zorba + */ +public class InconsistentValue { + + private final String tapSchemaEntityType; + + private final String tapSchemaEntityDescription; + + private final String wrongPropertyName; + + private final Object currentValue; + + private final Object correctValue; + + public InconsistentValue(String tapSchemaEntityType, String tapSchemaEntityDescription, String wrongPropertyName, Object currentValue, Object correctValue) { + this.tapSchemaEntityType = tapSchemaEntityType; + this.tapSchemaEntityDescription = tapSchemaEntityDescription; + this.wrongPropertyName = wrongPropertyName; + this.currentValue = currentValue; + this.correctValue = correctValue; + } + + public String getTapSchemaEntityType() { + return tapSchemaEntityType; + } + + public String getTapSchemaEntityDescription() { + return tapSchemaEntityDescription; + } + + public String getWrongPropertyName() { + return wrongPropertyName; + } + + public Object getCurrentValue() { + return currentValue; + } + + public Object getCorrectValue() { + return correctValue; + } +} diff --git a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/SelectQueryBuilder.java b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/SelectQueryBuilder.java index 62cc876db0e872e7f52fd7047ae2dc665b37b5d8..e17277dd3f970186d92c7f5892edc92c0bb2a4a4 100644 --- a/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/SelectQueryBuilder.java +++ b/TapSchemaManagerAPI/src/main/java/it/inaf/ia2/tsm/api/SelectQueryBuilder.java @@ -104,13 +104,15 @@ public abstract class SelectQueryBuilder { entity.amendProperty(key, correctValue); - String debugInfo = String.format("Property %s of %s %s is %s in TAP_SCHEMA but it should be %s", - key, + InconsistentValue inconsistentValue = new InconsistentValue( TSMUtil.getNaturalLangueName(entity), TSMUtil.getName(entity), - value, correctValue); + key, + value, + correctValue + ); - tapSchema.getConsistencyChecks().addInconsistency(debugInfo); + tapSchema.getConsistencyChecks().addInconsistency(inconsistentValue); //throw new InconsistentTapSchemaException(debugInfo); } diff --git a/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/NullOrEmptyConverter.java b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/NullOrEmptyConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..471ac634ab277a257fd282109580b39e3c2e7c1a --- /dev/null +++ b/TapSchemaManagerWebApp/src/main/java/it/inaf/ia2/tsm/webapp/NullOrEmptyConverter.java @@ -0,0 +1,64 @@ +/* + * _____________________________________________________________________________ + * + * 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 javax.faces.component.UIComponent; +import javax.faces.component.ValueHolder; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TAP_SCHEMA Manager inputText elements convert an empty input to null values. + * This is specified in the web.xml using + * javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL and it's good to + * avoid filling the database with empty values. However, there could be some + * TAP_SCHEMA schemas edited with other tools that contains a lot of empty + * strings instead null values. In that case on each click on the TAP_SCHEMA + * editor that values will be updated to null marking the field as changed. This + * 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 + */ +@FacesConverter("it.inaf.ia2.NullOrEmptyConverter") +public class NullOrEmptyConverter implements Converter { + + private final static Logger log = LoggerFactory.getLogger(NullOrEmptyConverter.class); + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + String previousValue = (String) ((ValueHolder) component).getValue(); + if (value == null && previousValue != null && previousValue.isEmpty()) { + return ""; + } + return value; + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return (String) value; + } +} 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 6531f2fcb9a3a7f524908db1b99a977571240056..75bcb2e69b76f65e6ffd27be86657770f606e2ee 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 @@ -317,7 +317,7 @@ public class TapSchemaEditingBean implements Serializable { public void openUCDDialog() throws Exception { searchUCDDialog.setDefault(); String description = selectedColumn.getDescription(); - if (description != null && !description.equals("")) { + if (description != null && !description.isEmpty()) { searchUCDDialog.setDescription(description); searchUCDDialog.search(description); } diff --git a/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml b/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml index 83884bc7bb4b17c6f437e26ffd35f2cc5357b15d..47c942b22e73bbed06ba833c839d982dcba3b89e 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/consistencyChecks.xhtml @@ -15,11 +15,28 @@

Inconsistent values

-
    - -
  • ${problem}
  • -
    -
+ + + + + + + + + + + + + + + + + + + + + +
TAP_SCHEMA entityName/DescriptionWrong fieldWrong valueCorrect value
${inconsistency.tapSchemaEntityType}${inconsistency.tapSchemaEntityDescription}${inconsistency.wrongPropertyName}${inconsistency.currentValue}${inconsistency.correctValue}
@@ -50,9 +67,9 @@
-
- - If you proceed the TAP_SCHEMA Manager will fix these values. +
+ + If you proceed the TAP_SCHEMA Manager will fix these values.
@@ -67,6 +84,7 @@
+

diff --git a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml index 197184e6df5a52704cf4703fc7d02b7e8a6a5d45..c06439ffca62d5cc15c3558de6cfff4d7cfebd02 100644 --- a/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TapSchemaManagerWebApp/src/main/webapp/tapSchemaEditing.xhtml @@ -93,6 +93,7 @@ id="schema_utype" class="form-control #{tapSchemaEditing.selectedSchema.isChanged('utype') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedSchema.utype}"> + @@ -104,6 +105,7 @@ id="schema_description" class="form-control #{tapSchemaEditing.selectedSchema.isChanged('description') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedSchema.description}"> + @@ -159,6 +161,7 @@ id="table_utype" class="form-control #{tapSchemaEditing.selectedTable.isChanged('utype') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedTable.utype}"> + @@ -170,6 +173,7 @@ id="table_description" class="form-control #{tapSchemaEditing.selectedTable.isChanged('description') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedTable.description}"> + @@ -285,6 +289,7 @@ id="column_utype" class="form-control #{tapSchemaEditing.selectedColumn.isChanged('utype') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedColumn.utype}"> + @@ -301,6 +306,7 @@ id="column_unit" class="form-control #{tapSchemaEditing.selectedColumn.isChanged('unit') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedColumn.unit}"> + @@ -310,6 +316,7 @@ id="column_description" class="form-control #{tapSchemaEditing.selectedColumn.isChanged('description') ? 'changed' : ''}" value="#{tapSchemaEditing.selectedColumn.description}"> +