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 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";
}

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()));
} 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);
}
}
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;
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<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

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.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<String> FIELDS = DettPraticaLocalServiceUtil.getDettPraticaFields();
private static final Map<String, Integer> FIELD_TYPES;
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) {
@ -25,9 +32,13 @@ public class DettPraticaUtil {
if (!FIELDS.contains(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);
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;
}
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)) {
case Types.BIGINT:
case Types.INTEGER:
case Types.TIMESTAMP:
clazz = Long.class;
break;
return Long.class;
case Types.BOOLEAN:
clazz = Boolean.class;
break;
return Boolean.class;
case Types.DOUBLE:
clazz = Double.class;
break;
return Double.class;
case Types.VARCHAR:
clazz = String.class;
break;
return String.class;
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);
}
}
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<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);
}
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;
if (values.hasNext()) {
sb.append(StringPool.COMMA_AND_SPACE);
}
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<Value> withoutLabel(Serializable... values) {
List<Value> result = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
result.add(new Value(values[i], (String) values[i]));
return sb.toString();
} else {
return null;
}
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<>();
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, "<NULL>", true, true, false, false));
}
List<Value> uses = new ArrayList<>();
for (Entry<String, String> e : DettPraticaLocalServiceUtil.getDestinazioniUso().entrySet()) {
uses.add(new Value(e.getKey(), e.getValue()));
}
FIELD_VALUES.put("destinazione", uses);
FIELD_VALUES.put("dccCopertura",
listOfValues(null, "<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, "<NULL>", "1", "1", "2", "2", "3", "3", "4", "4", "NA", "Non applicabile"));
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