Commit 151135a3 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Improved consistency checking, added NullOrEmptyConverter class

parent 775a8dea
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -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;
    }

+68 −0
Original line number Diff line number Diff line
/*
 * _____________________________________________________________________________
 * 
 * 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;
    }
}
+6 −4
Original line number Diff line number Diff line
@@ -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);
                            }
+64 −0
Original line number Diff line number Diff line
/*
 * _____________________________________________________________________________
 * 
 * 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;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);
        }
Loading