From 1d343f2dcdc7a792f2ab31e0d3bdd702a809263c Mon Sep 17 00:00:00 2001 From: Salvatore La Manna Date: Mon, 28 Jun 2021 14:18:15 +0200 Subject: [PATCH] Correzione tipi dati --- .../it/mwg/sicilia/sue/api/v1/Parameters.java | 1 + .../sicilia/sue/api/v1/command/Command.java | 9 +- .../sue/api/v1/command/impl/ListValues.java | 20 ++ .../sue/api/v1/util/DettPraticaUtil.java | 227 +++++++++++------- 4 files changed, 165 insertions(+), 92 deletions(-) diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/Parameters.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/Parameters.java index 97f6bf88..fae28579 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/Parameters.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/Parameters.java @@ -23,6 +23,7 @@ public class Parameters { public static final String USERNAME = "username"; public static final String USES = "uses"; public static final String VALUE = "value"; + public static final String VALUES = "values"; public static final String VAT_ID = "vatId"; public static final String X_AUTH_TOKEN = "X-Auth-Token"; } diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java index 6aa3d5f1..a9c2d461 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java @@ -94,11 +94,10 @@ public abstract class Command { parameters = deserializer.deserialize(new InputStreamReader(request.getInputStream())); } catch (Exception e) { } - } else if (request.getMethod().equals(HttpMethods.GET)) { - String token = request.getHeader(Parameters.X_AUTH_TOKEN); - if (Validator.isNotNull(token)) { - parameters.put(Parameters.TOKEN, token); - } + } + String token = request.getHeader(Parameters.X_AUTH_TOKEN); + if (Validator.isNotNull(token)) { + parameters.put(Parameters.TOKEN, token); } return parameters; } diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ListValues.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ListValues.java index daf8d787..fc7881bc 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ListValues.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ListValues.java @@ -1,16 +1,25 @@ package it.mwg.sicilia.sue.api.v1.command.impl; import it.mwg.sicilia.sue.api.v1.Parameters; +import it.mwg.sicilia.sue.api.v1.Response; +import it.mwg.sicilia.sue.api.v1.Status; +import it.mwg.sicilia.sue.api.v1.bean.Value; import it.mwg.sicilia.sue.api.v1.command.Command; import it.mwg.sicilia.sue.api.v1.parameter.Parameter; import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES; +import it.mwg.sicilia.sue.api.v1.util.DettPraticaUtil; +import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.liferay.portal.kernel.util.MapUtil; + public class ListValues extends Command { @SuppressWarnings("serial") @@ -36,6 +45,17 @@ public class ListValues extends Command { @Override public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { + + readParameters(request); + String fieldName = MapUtil.getString(parameters, Parameters.NAME); + List values = DettPraticaUtil.getFieldList(fieldName); + if (null == values) { + Response.write(response, Status.INVALID_INPUT); + } else { + Map result = new HashMap<>(); + result.put(Parameters.VALUES, (Serializable) values); + Response.write(response, Status.OK, result); + } } @Override diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/DettPraticaUtil.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/DettPraticaUtil.java index b48c98da..e7233872 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/DettPraticaUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/DettPraticaUtil.java @@ -8,16 +8,23 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.sql.Types; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import com.liferay.portal.kernel.util.StringPool; + public class DettPraticaUtil { private static final List FIELDS = DettPraticaLocalServiceUtil.getDettPraticaFields(); private static final Map FIELD_TYPES; private static final Map> FIELD_VALUES = new HashMap<>(); + private static final List TO_BOOLEAN = Arrays.asList("geoConsolidamento", "geoEvidenzeGeologiche", + "geoEvidenzeGeomorfiche", "geoOperaRilevante", "geoOpereDiSostegno", "geoPresenzaPrescrizioni"); + private static final List TO_INTEGER = Arrays.asList("geoClasseIndagine",""); public static String setFields(DettPratica dettPratica, Map fields) { @@ -25,9 +32,13 @@ public class DettPraticaUtil { if (!FIELDS.contains(fieldName)) { return fieldName; } + List checkValues = checkValues(fields); + if (!checkValues.isEmpty()) { + return checkValues.toString(); + } String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); Serializable field = fields.get(fieldName); - Class clazz = field.getClass(); + Class clazz = null == field ? getClass(fieldName) : field.getClass(); try { Method method; if (Boolean.class.equals(clazz)) { @@ -44,132 +55,174 @@ public class DettPraticaUtil { } method.invoke(dettPratica, field); } catch (Exception e) { + e.printStackTrace(); return fieldName; } } return null; } + private static Class getClass(String fieldName) { + + switch (FIELD_TYPES.get(fieldName)) { + case Types.BIGINT: + case Types.INTEGER: + case Types.TIMESTAMP: + return Long.class; + case Types.BOOLEAN: + return Boolean.class; + case Types.DOUBLE: + return Double.class; + case Types.VARCHAR: + return String.class; + default: + return null; + } + } + public static List checkValues(Map fields) { List result = new ArrayList<>(); for (String fieldName : fields.keySet()) { Serializable field = fields.get(fieldName); - Class clazz = null; - switch (FIELD_TYPES.get(fieldName)) { - case Types.BIGINT: - case Types.INTEGER: - case Types.TIMESTAMP: - clazz = Long.class; - break; - case Types.BOOLEAN: - clazz = Boolean.class; - break; - case Types.DOUBLE: - clazz = Double.class; - break; - case Types.VARCHAR: - clazz = String.class; - break; - } - if (!field.getClass().equals(clazz)) { + Class clazz = getClass(fieldName); + if ((null != field) && !field.getClass().equals(clazz)) { result.add("Tipo dati non corretto per il campo " + fieldName); } } for (String field : fields.keySet()) { - // if (FIELD_MAPS.containsKey(field)) { - // Serializable value = fields.get(field); - // if (!FIELD_MAPS.get(field).keySet().contains(value)) { - // result.add("Valore " + value + " non valido per il campo " + field); - // } - // } else if (FIELD_VALUES.containsKey(field)) { - // Serializable value = fields.get(field); - // if (!FIELD_VALUES.get(field).contains(value)) { - // result.add("Valore non valido " + field + " = " + value); - // } - // } + if (FIELD_VALUES.containsKey(field)) { + Serializable value = fields.get(field); + boolean present = false; + for (Value listItem : FIELD_VALUES.get(field)) { + if (listItem.getValue() == null ? value == null : listItem.getValue().equals(value)) { + present = true; + break; + } + } + if (!present) { + if (value instanceof String) { + result.add("Valore non valido " + field + " = \"" + value + StringPool.QUOTE); + } else { + result.add("Valore non valido " + field + " = " + value); + } + } + } } return result; } public static String getFieldValues(String fieldName) { - String result = getLabelsString(fieldName); - if (null == result) { - result = getValuesString(fieldName); + if (FIELD_VALUES.containsKey(fieldName)) { + StringBuilder sb = new StringBuilder(); + Iterator values = FIELD_VALUES.get(fieldName).iterator(); + while (values.hasNext()) { + Value value = values.next(); + if (value.getValue() instanceof String) { + sb.append(StringPool.QUOTE); "NA" + } + sb.append(value.getValue()); + if (value.getValue() instanceof String) { + sb.append(StringPool.QUOTE); + } + if (values.hasNext()) { + sb.append(StringPool.COMMA_AND_SPACE); + } + } + return sb.toString(); + } else { + return null; } - return result; } - private static String getLabelsString(String fieldName) { - - String result = null; - // if (FIELD_MAPS.containsKey(fieldName)) { - // StringBuilder sb = new StringBuilder(); - // for (Serializable value : FIELD_MAPS.get(fieldName)) { - // if (sb.length() > 0) { - // sb.append(StringPool.COMMA_AND_SPACE); - // } - // sb.append(StringPool.QUOTE).append(value).append(StringPool.QUOTE); - // } - // result = sb.toString(); - // } - return result; + public static List getFieldList(String fieldName) { + return FIELD_VALUES.get(fieldName); } - private static String getValuesString(String fieldName) { - - String result = null; - // if (FIELD_VALUES.containsKey(fieldName)) { - // StringBuilder sb = new StringBuilder(); - // for (Serializable value : FIELD_VALUES.get(fieldName)) { - // if (sb.length() > 0) { - // sb.append(StringPool.COMMA_AND_SPACE); - // } - // if (String.class.equals(value.getClass())) { - // sb.append(StringPool.QUOTE).append(value).append(StringPool.QUOTE); - // } else { - // sb.append(value); - // } - // } - // result = sb.toString(); - // } - return result; - } - - private static List withoutLabel(Serializable... values) { - - List result = new ArrayList<>(); - for (int i = 0; i < values.length; i++) { - result.add(new Value(values[i], (String) values[i])); - } - return result; - } - - private static List withLabel(Serializable... values) { + private static List listOfValues(Serializable... values) { List result = new ArrayList<>(); for (int i = 0; i < values.length; i += 2) { - result.add(new Value(values[i], (String) values[i + 1])); + result.add(new Value(values[i], String.valueOf(values[i + 1]))); } return result; } static { FIELD_TYPES = DettPraticaLocalServiceUtil.getDettPraticaFieldsTypes(); - FIELD_TYPES.put("geoConsolidamento", Types.BOOLEAN); - FIELD_TYPES.put("geoEvidenzeGeologiche", Types.BOOLEAN); - FIELD_TYPES.put("geoEvidenzeGeomorfiche", Types.BOOLEAN); - FIELD_TYPES.put("geoOperaRilevante", Types.BOOLEAN); - FIELD_TYPES.put("geoOpereDiSostegno", Types.BOOLEAN); - FIELD_TYPES.put("geoPresenzaPrescrizioni", Types.BOOLEAN); + for (String field : TO_BOOLEAN) { + FIELD_TYPES.put(field, Types.BOOLEAN); + FIELD_VALUES.put(field, listOfValues(null, "", true, true, false, false)); + } List uses = new ArrayList<>(); for (Entry e : DettPraticaLocalServiceUtil.getDestinazioniUso().entrySet()) { uses.add(new Value(e.getKey(), e.getValue())); } FIELD_VALUES.put("destinazione", uses); + FIELD_VALUES.put("dccCopertura", + listOfValues(null, "", "spingente", "Spingente", "non-spingente", "Non spingente")); FIELD_VALUES.put("geoClasseIndagine", - withLabel("1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); - FIELD_VALUES.put("geoOperaRilevante", withLabel(null, "NULL", true, "Sì", false, "No")); + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put("geoCategoriaSottosuolo", + listOfValues(null, "", "A", "A", "B", "B", "C", "C", "D", "D", "E", "E", "F", "RSL")); + FIELD_VALUES.put("geoCategoriaTopografica", + listOfValues(null, "", "T1", "T1", "T2", "T2", "T3", "T3", "T4", "T4")); + FIELD_VALUES.put("geoPericolositaGeologica", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put( + "geoPericolositaGeomorfica", + listOfValues(null, "", "0", "P0", "1", "P1", "2", "P2", "3", "P3", "4", "P4", "NA", + "Non presente")); + FIELD_VALUES.put( + "geoRischioGeomorfologicoPai", + listOfValues(null, "", "1", "R1", "2", "R2", "3", "R3", "4", "R4", "5", "Sito d'attenzione", + "NA", "Non presente")); + FIELD_VALUES.put( + "geoPericolositaIdraulicaPai", + listOfValues(null, "", "1", "P1", "2", "P2", "3", "P3", "4", "P4", "5", "Sito d'attenzione", + "NA", "Non presente")); + FIELD_VALUES.put("geoRischioIdraulicoPai", + listOfValues(null, "", "1", "R1", "2", "R2", "3", "R3", "4", "R4", "NA", "Non presente")); + FIELD_VALUES.put("geoPericolositaSismica", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put("geoFattibilitaSismica", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put("geoPericolositaIdraulica", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put("geoFattibilitaIdraulica", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put("geoFattibilitaGeologica", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); + FIELD_VALUES.put( + "dePiani", + listOfValues(null, "", "1", "1", "2", "2", "3", "3", "4", "4", "5", "5", "6", "6", "7", "7", "8", + "8", "9", "9", "10", "10", "11", "11", "12", "12", "13", ">12")); + FIELD_VALUES.put("deAltezza", + listOfValues(null, "", "1", "≤2.50", "2", "2.50÷3.50", "3", "3.50÷5.0", "4", ">5.0")); + FIELD_VALUES.put("dePiani", listOfValues(null, "", "0", "0", "1", "1", "2", "2", "3", "≥3")); + FIELD_VALUES.put( + "deSuperficie", + listOfValues(null, "", "1", "≤50", "2", "50÷69", "3", "70÷99", "4", "100÷129", "5", "130÷169", + "6", "170÷229", "7", "230÷299", "8", "300÷399", "9", "400÷499", "10", "500÷649", "11", + "650÷899", "12", "900÷1199", "13", "1200÷1599", "14", "1600÷2199", "15", "2200÷3000", "16", + ">3000")); + FIELD_VALUES.put( + "deCostruzione", + listOfValues(null, "", "1", "≤1942 - centro abitato", "2", "<1967 - area extraurbana", "3", + "> 1967", "4", "Nuova Costruzione")); + FIELD_VALUES.put( + "deRistutturazione", + listOfValues(null, "", "1", "≤1919", "2", "19÷45", "3", "46÷61", "4", "62÷71", "5", "72÷75", "6", + "76÷81", "7", "82÷86", "8", "87÷91", "9", "92÷96", "10", "97÷01", "11", "02÷08", "12", "09÷11", + "13", ">2011")); + FIELD_VALUES.put( + "deUso", + listOfValues(null, "", "abitativo", "Abitativo", "produttivo", "Produttivo", "commercio", + "Commercio", "uffici", "Uffici", "servizi", "Servizi Pub.", "deposito", "Deposito", + "strategico", "Strategico", "turistico", "Turist.-ricett.")); + FIELD_VALUES.put("deUtilizzazione", listOfValues(null, "", "1", ">65%", "2", "30÷65%", "3", "<30%")); + FIELD_VALUES.put("dePosizioneEdificio", + listOfValues(null, "", "1", "Isolato", "2", "Interno", "3", "D'estremità", "4", "D'angolo")); } }