Sfoglia il codice sorgente

Correzione tipi dati

master
Salvatore La Manna 3 anni fa
parent
commit
1d343f2dcd
  1. 1
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/Parameters.java
  2. 3
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java
  3. 20
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ListValues.java
  4. 215
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/DettPraticaUtil.java

1
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 USERNAME = "username";
public static final String USES = "uses"; public static final String USES = "uses";
public static final String VALUE = "value"; public static final String VALUE = "value";
public static final String VALUES = "values";
public static final String VAT_ID = "vatId"; public static final String VAT_ID = "vatId";
public static final String X_AUTH_TOKEN = "X-Auth-Token"; public static final String X_AUTH_TOKEN = "X-Auth-Token";
} }

3
liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java

@ -94,12 +94,11 @@ public abstract class Command {
parameters = deserializer.deserialize(new InputStreamReader(request.getInputStream())); parameters = deserializer.deserialize(new InputStreamReader(request.getInputStream()));
} catch (Exception e) { } catch (Exception e) {
} }
} else if (request.getMethod().equals(HttpMethods.GET)) { }
String token = request.getHeader(Parameters.X_AUTH_TOKEN); String token = request.getHeader(Parameters.X_AUTH_TOKEN);
if (Validator.isNotNull(token)) { if (Validator.isNotNull(token)) {
parameters.put(Parameters.TOKEN, token); parameters.put(Parameters.TOKEN, token);
} }
}
return parameters; return parameters;
} }

20
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; package it.mwg.sicilia.sue.api.v1.command.impl;
import it.mwg.sicilia.sue.api.v1.Parameters; 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.command.Command;
import it.mwg.sicilia.sue.api.v1.parameter.Parameter; 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.parameter.Parameter.TYPES;
import it.mwg.sicilia.sue.api.v1.util.DettPraticaUtil;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.util.MapUtil;
public class ListValues extends Command { public class ListValues extends Command {
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ -36,6 +45,17 @@ public class ListValues extends Command {
@Override @Override
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
readParameters(request);
String fieldName = MapUtil.getString(parameters, Parameters.NAME);
List<Value> values = DettPraticaUtil.getFieldList(fieldName);
if (null == values) {
Response.write(response, Status.INVALID_INPUT);
} else {
Map<String, Serializable> result = new HashMap<>();
result.put(Parameters.VALUES, (Serializable) values);
Response.write(response, Status.OK, result);
}
} }
@Override @Override

215
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.lang.reflect.Method;
import java.sql.Types; import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.liferay.portal.kernel.util.StringPool;
public class DettPraticaUtil { public class DettPraticaUtil {
private static final List<String> FIELDS = DettPraticaLocalServiceUtil.getDettPraticaFields(); private static final List<String> FIELDS = DettPraticaLocalServiceUtil.getDettPraticaFields();
private static final Map<String, Integer> FIELD_TYPES; private static final Map<String, Integer> FIELD_TYPES;
private static final Map<String, List<Value>> FIELD_VALUES = new HashMap<>(); private static final Map<String, List<Value>> FIELD_VALUES = new HashMap<>();
private static final List<String> TO_BOOLEAN = Arrays.asList("geoConsolidamento", "geoEvidenzeGeologiche",
"geoEvidenzeGeomorfiche", "geoOperaRilevante", "geoOpereDiSostegno", "geoPresenzaPrescrizioni");
private static final List<String> TO_INTEGER = Arrays.asList("geoClasseIndagine","");
public static String setFields(DettPratica dettPratica, Map<String, Serializable> fields) { public static String setFields(DettPratica dettPratica, Map<String, Serializable> fields) {
@ -25,9 +32,13 @@ public class DettPraticaUtil {
if (!FIELDS.contains(fieldName)) { if (!FIELDS.contains(fieldName)) {
return fieldName; return fieldName;
} }
List<String> checkValues = checkValues(fields);
if (!checkValues.isEmpty()) {
return checkValues.toString();
}
String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
Serializable field = fields.get(fieldName); Serializable field = fields.get(fieldName);
Class<?> clazz = field.getClass(); Class<?> clazz = null == field ? getClass(fieldName) : field.getClass();
try { try {
Method method; Method method;
if (Boolean.class.equals(clazz)) { if (Boolean.class.equals(clazz)) {
@ -44,132 +55,174 @@ public class DettPraticaUtil {
} }
method.invoke(dettPratica, field); method.invoke(dettPratica, field);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return fieldName; return fieldName;
} }
} }
return null; return null;
} }
public static List<String> checkValues(Map<String, Serializable> fields) { private static Class<?> getClass(String fieldName) {
List<String> result = new ArrayList<>();
for (String fieldName : fields.keySet()) {
Serializable field = fields.get(fieldName);
Class<?> clazz = null;
switch (FIELD_TYPES.get(fieldName)) { switch (FIELD_TYPES.get(fieldName)) {
case Types.BIGINT: case Types.BIGINT:
case Types.INTEGER: case Types.INTEGER:
case Types.TIMESTAMP: case Types.TIMESTAMP:
clazz = Long.class; return Long.class;
break;
case Types.BOOLEAN: case Types.BOOLEAN:
clazz = Boolean.class; return Boolean.class;
break;
case Types.DOUBLE: case Types.DOUBLE:
clazz = Double.class; return Double.class;
break;
case Types.VARCHAR: case Types.VARCHAR:
clazz = String.class; return String.class;
break; default:
return null;
}
} }
if (!field.getClass().equals(clazz)) {
public static List<String> checkValues(Map<String, Serializable> fields) {
List<String> result = new ArrayList<>();
for (String fieldName : fields.keySet()) {
Serializable field = fields.get(fieldName);
Class<?> clazz = getClass(fieldName);
if ((null != field) && !field.getClass().equals(clazz)) {
result.add("Tipo dati non corretto per il campo " + fieldName); result.add("Tipo dati non corretto per il campo " + fieldName);
} }
} }
for (String field : fields.keySet()) { for (String field : fields.keySet()) {
// if (FIELD_MAPS.containsKey(field)) { if (FIELD_VALUES.containsKey(field)) {
// Serializable value = fields.get(field); Serializable value = fields.get(field);
// if (!FIELD_MAPS.get(field).keySet().contains(value)) { boolean present = false;
// result.add("Valore " + value + " non valido per il campo " + field); for (Value listItem : FIELD_VALUES.get(field)) {
// } if (listItem.getValue() == null ? value == null : listItem.getValue().equals(value)) {
// } else if (FIELD_VALUES.containsKey(field)) { present = true;
// Serializable value = fields.get(field); break;
// if (!FIELD_VALUES.get(field).contains(value)) { }
// result.add("Valore non valido " + field + " = " + value); }
// } 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; return result;
} }
public static String getFieldValues(String fieldName) { public static String getFieldValues(String fieldName) {
String result = getLabelsString(fieldName); if (FIELD_VALUES.containsKey(fieldName)) {
if (null == result) { StringBuilder sb = new StringBuilder();
result = getValuesString(fieldName); Iterator<Value> values = FIELD_VALUES.get(fieldName).iterator();
while (values.hasNext()) {
Value value = values.next();
if (value.getValue() instanceof String) {
sb.append(StringPool.QUOTE); "NA"
} }
return result; sb.append(value.getValue());
if (value.getValue() instanceof String) {
sb.append(StringPool.QUOTE);
} }
if (values.hasNext()) {
private static String getLabelsString(String fieldName) { sb.append(StringPool.COMMA_AND_SPACE);
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;
} }
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;
} }
return sb.toString();
private static List<Value> withoutLabel(Serializable... values) { } else {
return null;
List<Value> 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<Value> withLabel(Serializable... values) { public static List<Value> getFieldList(String fieldName) {
return FIELD_VALUES.get(fieldName);
}
private static List<Value> listOfValues(Serializable... values) {
List<Value> result = new ArrayList<>(); List<Value> result = new ArrayList<>();
for (int i = 0; i < values.length; i += 2) { 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; return result;
} }
static { static {
FIELD_TYPES = DettPraticaLocalServiceUtil.getDettPraticaFieldsTypes(); FIELD_TYPES = DettPraticaLocalServiceUtil.getDettPraticaFieldsTypes();
FIELD_TYPES.put("geoConsolidamento", Types.BOOLEAN); for (String field : TO_BOOLEAN) {
FIELD_TYPES.put("geoEvidenzeGeologiche", Types.BOOLEAN); FIELD_TYPES.put(field, Types.BOOLEAN);
FIELD_TYPES.put("geoEvidenzeGeomorfiche", Types.BOOLEAN); FIELD_VALUES.put(field, listOfValues(null, "<NULL>", true, true, false, false));
FIELD_TYPES.put("geoOperaRilevante", Types.BOOLEAN); }
FIELD_TYPES.put("geoOpereDiSostegno", Types.BOOLEAN);
FIELD_TYPES.put("geoPresenzaPrescrizioni", Types.BOOLEAN);
List<Value> uses = new ArrayList<>(); List<Value> uses = new ArrayList<>();
for (Entry<String, String> e : DettPraticaLocalServiceUtil.getDestinazioniUso().entrySet()) { for (Entry<String, String> e : DettPraticaLocalServiceUtil.getDestinazioniUso().entrySet()) {
uses.add(new Value(e.getKey(), e.getValue())); uses.add(new Value(e.getKey(), e.getValue()));
} }
FIELD_VALUES.put("destinazione", uses); FIELD_VALUES.put("destinazione", uses);
FIELD_VALUES.put("dccCopertura",
listOfValues(null, "<NULL>", "spingente", "Spingente", "non-spingente", "Non spingente"));
FIELD_VALUES.put("geoClasseIndagine", FIELD_VALUES.put("geoClasseIndagine",
withLabel("1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile")); listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put("geoOperaRilevante", withLabel(null, "NULL", true, "Sì", false, "No")); FIELD_VALUES.put("geoCategoriaSottosuolo",
listOfValues(null, "<NULL>", "A", "A", "B", "B", "C", "C", "D", "D", "E", "E", "F", "RSL"));
FIELD_VALUES.put("geoCategoriaTopografica",
listOfValues(null, "<NULL>", "T1", "T1", "T2", "T2", "T3", "T3", "T4", "T4"));
FIELD_VALUES.put("geoPericolositaGeologica",
listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put(
"geoPericolositaGeomorfica",
listOfValues(null, "<NULL>", "0", "P0", "1", "P1", "2", "P2", "3", "P3", "4", "P4", "NA",
"Non presente"));
FIELD_VALUES.put(
"geoRischioGeomorfologicoPai",
listOfValues(null, "<NULL>", "1", "R1", "2", "R2", "3", "R3", "4", "R4", "5", "Sito d'attenzione",
"NA", "Non presente"));
FIELD_VALUES.put(
"geoPericolositaIdraulicaPai",
listOfValues(null, "<NULL>", "1", "P1", "2", "P2", "3", "P3", "4", "P4", "5", "Sito d'attenzione",
"NA", "Non presente"));
FIELD_VALUES.put("geoRischioIdraulicoPai",
listOfValues(null, "<NULL>", "1", "R1", "2", "R2", "3", "R3", "4", "R4", "NA", "Non presente"));
FIELD_VALUES.put("geoPericolositaSismica",
listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put("geoFattibilitaSismica",
listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put("geoPericolositaIdraulica",
listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put("geoFattibilitaIdraulica",
listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put("geoFattibilitaGeologica",
listOfValues(null, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
FIELD_VALUES.put(
"dePiani",
listOfValues(null, "<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, "<NULL>", "1", "≤2.50", "2", "2.50÷3.50", "3", "3.50÷5.0", "4", ">5.0"));
FIELD_VALUES.put("dePiani", listOfValues(null, "<NULL>", "0", "0", "1", "1", "2", "2", "3", "≥3"));
FIELD_VALUES.put(
"deSuperficie",
listOfValues(null, "<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, "<NULL>", "1", "≤1942 - centro abitato", "2", "<1967 - area extraurbana", "3",
"> 1967", "4", "Nuova Costruzione"));
FIELD_VALUES.put(
"deRistutturazione",
listOfValues(null, "<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, "<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, "<NULL>", "1", ">65%", "2", "30÷65%", "3", "<30%"));
FIELD_VALUES.put("dePosizioneEdificio",
listOfValues(null, "<NULL>", "1", "Isolato", "2", "Interno", "3", "D'estremità", "4", "D'angolo"));
} }
} }

Caricamento…
Annulla
Salva