Skip to content
Snippets Groups Projects
Commit 151135a3 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Improved consistency checking, added NullOrEmptyConverter class

parent 775a8dea
No related branches found
No related tags found
No related merge requests found
......@@ -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<String> inconsistencies;
private final List<InconsistentValue> inconsistencies;
private final List<String> unexisingSchemas;
private final List<String> unexisingTables;
private final Map<String, String> 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<String> getInconsistencies() {
public List<InconsistentValue> getInconsistencies() {
return inconsistencies;
}
......
/*
* _____________________________________________________________________________
*
* 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 <zorba at oats.inaf.it>
*/
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;
}
}
......@@ -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);
}
......
/*
* _____________________________________________________________________________
*
* 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 <zorba at oats.inaf.it>
*/
@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;
}
}
......@@ -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);
}
......
......@@ -15,11 +15,28 @@
<h:panelGroup rendered="#{consistency.tapSchema.consistencyChecks.inconsistencies.size() gt 0}">
<h2>Inconsistent values</h2>
<ul>
<ui:repeat value="#{consistency.tapSchema.consistencyChecks.inconsistencies}" var="problem">
<li>${problem}</li>
<table class="table table-bordered">
<thead>
<tr>
<th>TAP_SCHEMA entity</th>
<th>Name/Description</th>
<th>Wrong field</th>
<th>Wrong value</th>
<th>Correct value</th>
</tr>
</thead>
<tbody>
<ui:repeat value="#{consistency.tapSchema.consistencyChecks.inconsistencies}" var="inconsistency">
<tr>
<td>${inconsistency.tapSchemaEntityType}</td>
<td>${inconsistency.tapSchemaEntityDescription}</td>
<td>${inconsistency.wrongPropertyName}</td>
<td class="text-danger">${inconsistency.currentValue}</td>
<td class="text-success">${inconsistency.correctValue}</td>
</tr>
</ui:repeat>
</ul>
</tbody>
</table>
</h:panelGroup>
<h:panelGroup rendered="#{consistency.tapSchema.consistencyChecks.unexisingSchemas.size() gt 0}">
......@@ -50,9 +67,9 @@
</h:panelGroup>
<br/>
<div class="alert alert-info">
<span class="glyphicon glyphicon-info-sign"></span>
If you proceed the TAP_SCHEMA Manager will fix these values.
<div class="alert alert-warning text-center">
<span class="glyphicon glyphicon-warning-sign"></span>
<strong>If you proceed the TAP_SCHEMA Manager will fix these values.</strong>
</div>
<div class="text-center">
......@@ -67,6 +84,7 @@
</h:commandLink>
</div>
</h:form>
<br/><br/>
</div>
</div>
</div>
......
......@@ -93,6 +93,7 @@
id="schema_utype"
class="form-control #{tapSchemaEditing.selectedSchema.isChanged('utype') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedSchema.utype}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedSchema, 'utype')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......@@ -104,6 +105,7 @@
id="schema_description"
class="form-control #{tapSchemaEditing.selectedSchema.isChanged('description') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedSchema.description}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedSchema, 'description')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......@@ -159,6 +161,7 @@
id="table_utype"
class="form-control #{tapSchemaEditing.selectedTable.isChanged('utype') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedTable.utype}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedTable, 'utype')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......@@ -170,6 +173,7 @@
id="table_description"
class="form-control #{tapSchemaEditing.selectedTable.isChanged('description') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedTable.description}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedTable, 'description')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......@@ -285,6 +289,7 @@
id="column_utype"
class="form-control #{tapSchemaEditing.selectedColumn.isChanged('utype') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedColumn.utype}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'utype')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......@@ -301,6 +306,7 @@
id="column_unit"
class="form-control #{tapSchemaEditing.selectedColumn.isChanged('unit') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedColumn.unit}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'unit')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......@@ -310,6 +316,7 @@
id="column_description"
class="form-control #{tapSchemaEditing.selectedColumn.isChanged('description') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedColumn.description}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'description')}" onevent="TSM.textInputChanged" />
</h:inputText>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment