Salvatore La Manna
4 anni fa
19 ha cambiato i file con 365 aggiunte e 180 eliminazioni
@ -0,0 +1,123 @@
|
||||
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.command.Command; |
||||
import it.mwg.sicilia.sue.api.v1.parameter.Parameter; |
||||
import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES; |
||||
import it.tref.liferay.portos.bo.model.DettPratica; |
||||
import it.tref.liferay.portos.bo.model.IntPratica; |
||||
import it.tref.liferay.portos.bo.model.Territorio; |
||||
import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; |
||||
import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; |
||||
import it.tref.liferay.portos.bo.service.TerritorioLocalServiceUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Map.Entry; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException; |
||||
import com.liferay.portal.kernel.exception.SystemException; |
||||
import com.liferay.portal.kernel.servlet.ServletResponseUtil; |
||||
import com.liferay.portal.kernel.util.MapUtil; |
||||
.portal.kernel.util.MapUtil; |
||||
|
||||
public class SetFields extends Command { |
||||
|
||||
private static final List<Parameter> INPUT_PARAMETERS = new ArrayList<>(); |
||||
static { |
||||
INPUT_PARAMETERS.add(new Parameter(Parameters.APPLICATION_ID, TYPES.INTEGER, "Id dell'istanza")); |
||||
Parameter p = new Parameter(Parameters.FIELDS, TYPES.ARRAY, "Elenco di campi da impostare"); |
||||
p.addSubParameter(new Parameter(Parameters.NAME, TYPES.STRING, "Nome del campo")); |
||||
p.addSubParameter(new Parameter(Parameters.VALUE, TYPES.VARYING, "Valore da impostare per il campo")); |
||||
} |
||||
|
||||
public SetFields(String description, String... methods) { |
||||
super(description, methods); |
||||
} |
||||
|
||||
@Override |
||||
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
|
||||
if (verifyAccessToken(request, response)) { |
||||
List<String> additionalInfo = new ArrayList<String>(); |
||||
if (!parameters.containsKey(Parameters.APPLICATION_ID)) { |
||||
additionalInfo.add("Parametro " + Parameters.APPLICATION_ID + " mancante"); |
||||
ServletResponseUtil.write(response, Response.get(Status.MALFORMED_REQUEST, additionalInfo)); |
||||
return; |
||||
} |
||||
if (!parameters.containsKey(Parameters.FIELDS)) { |
||||
additionalInfo.add("Parametro " + Parameters.FIELDS + " mancante"); |
||||
ServletResponseUtil.write(response, Response.get(Status.MALFORMED_REQUEST, additionalInfo)); |
||||
return; |
||||
} |
||||
Object mapObj = parameters.get(Parameters.FIELDS); |
||||
if (!(mapObj instanceof Map<?, ?>)) { |
||||
additionalInfo.add("Formato del parametro " + Parameters.FIELDS + " errato"); |
||||
ServletResponseUtil.write(response, Response.get(Status.MALFORMED_REQUEST, additionalInfo)); |
||||
return; |
||||
} |
||||
@SuppressWarnings("unchecked") |
||||
Map<Object, Object> mapMap = (Map<Object, Object>) mapObj; |
||||
if (mapMap.size() > 0) { |
||||
Entry<Object, Object> i = mapMap.entrySet().iterator().next(); |
||||
System.out.println("====== " + i.getValue().getClass().getName()); |
||||
if (!(i.getKey() instanceof String) || !(i.getValue() instanceof Serializable)) { |
||||
System.out.println("****** " + i.getValue().getClass().getName()); |
||||
} |
||||
if (i.getValue() instanceof String) { |
||||
System.out.println("String"); |
||||
} |
||||
if (i.getValue() instanceof Date) { |
||||
System.out.println("Date"); |
||||
} |
||||
if (i.getValue() instanceof Long) { |
||||
System.out.println("Long"); |
||||
} |
||||
System.out.println(i.getValue() + "!!!"); |
||||
} |
||||
long applicationId = MapUtil.getLong(parameters, Parameters.APPLICATION_ID); |
||||
IntPratica intPratica = null; |
||||
Object obj = parameters.get(Parameters.FIELDS); |
||||
try { |
||||
intPratica = IntPraticaLocalServiceUtil.getIntPratica(applicationId); |
||||
} catch (PortalException | SystemException e) { |
||||
additionalInfo.add("Istanza " + applicationId + " non trovata"); |
||||
ServletResponseUtil.write(response, Response.get(Status.INVALID_INPUT, additionalInfo)); |
||||
return; |
||||
} |
||||
DettPratica dettPratica = null; |
||||
try { |
||||
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(intPratica.getTerritorioId()); |
||||
if (territorio.getComuneId() != sportello.getComuneId() || !intPratica.isInLavorazioneSue()) { |
||||
additionalInfo.add("Istanza " + applicationId + " non modificabile"); |
||||
ServletResponseUtil.write(response, Response.get(Status.INVALID_INPUT, additionalInfo)); |
||||
return; |
||||
} |
||||
dettPratica = DettPraticaLocalServiceUtil.getLastEditableByIntPratica(applicationId); |
||||
} catch (PortalException | SystemException e) { |
||||
additionalInfo.add("Errore del server durante il caricamento dell'istanza"); |
||||
ServletResponseUtil.write(response, Response.get(Status.INVALID_INPUT, additionalInfo)); |
||||
return; |
||||
} |
||||
ServletResponseUtil.write(response, Response.get(Status.OK)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public List<Parameter> getInputParameters() { |
||||
return INPUT_PARAMETERS; |
||||
} |
||||
|
||||
@Override |
||||
public List<Parameter> getOutputParameters() { |
||||
return BASE_OUTPUT_PARAMETERS; |
||||
} |
||||
|
||||
} |
Caricamento…
Reference in new issue