Salvatore La Manna
4 anni fa
33 ha cambiato i file con 139 aggiunte e 89 eliminazioni
@ -0,0 +1,83 @@
|
||||
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.tref.liferay.portos.bo.model.IntPratica; |
||||
import it.tref.liferay.portos.bo.model.Territorio; |
||||
import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; |
||||
import it.tref.liferay.portos.bo.service.TerritorioLocalServiceUtil; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
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; |
||||
|
||||
public class DeleteApplication extends Command { |
||||
|
||||
@SuppressWarnings("serial") |
||||
private static final List<Parameter> INPUT_PARAMETERS = new ArrayList<Parameter>() { |
||||
{ |
||||
add(new Parameter(Parameters.APPLICATION_ID, Parameter.TYPES.INTEGER, "Id dell'istanza")); |
||||
} |
||||
}; |
||||
|
||||
public DeleteApplication(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; |
||||
} |
||||
long applicationId = MapUtil.getLong(parameters, Parameters.APPLICATION_ID); |
||||
IntPratica intPratica = null; |
||||
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; |
||||
} |
||||
try { |
||||
Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(intPratica.getTerritorioId()); |
||||
if (territorio.getComuneId() != sportello.getComuneId() || !intPratica.isInLavorazioneSue()) { |
||||
additionalInfo.add("Istanza " + applicationId + " non cancellabile"); |
||||
ServletResponseUtil.write(response, Response.get(Status.INVALID_INPUT, additionalInfo)); |
||||
return; |
||||
} |
||||
} catch (PortalException | SystemException e) { |
||||
additionalInfo.add("Errore del server durante il caricamento dell'istanza"); |
||||
ServletResponseUtil.write(response, Response.get(Status.INVALID_INPUT, additionalInfo)); |
||||
return; |
||||
} |
||||
IntPraticaLocalServiceUtil.deleteIntPratica(intPratica, true); |
||||
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