|
|
@ -28,6 +28,7 @@ import it.tref.liferay.portos.bo.model.IntPratica; |
|
|
|
import it.tref.liferay.portos.bo.model.Territorio; |
|
|
|
import it.tref.liferay.portos.bo.model.Territorio; |
|
|
|
import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; |
|
|
|
import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; |
|
|
|
import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; |
|
|
|
import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; |
|
|
|
|
|
|
|
import it.tref.liferay.portos.bo.shared.protocollo.model.Protocollo.TipoProtocollo; |
|
|
|
import it.tref.liferay.portos.bo.shared.util.Constants; |
|
|
|
import it.tref.liferay.portos.bo.shared.util.Constants; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
@ -164,8 +165,9 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
return object; |
|
|
|
return object; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JSONObject prepareUpdateBatch(long companyId){ |
|
|
|
private JSONObject prepareReadBatch(long companyId){ |
|
|
|
final String clientContext = "PAESAGGISTICA"; |
|
|
|
final String clientContext = "PAESAGGISTICA"; |
|
|
|
|
|
|
|
JSONObject readBatchResult = JSONFactoryUtil.createJSONObject(); |
|
|
|
DynamicQuery query = IntPraticaLocalServiceUtil.dynamicQuery(); |
|
|
|
DynamicQuery query = IntPraticaLocalServiceUtil.dynamicQuery(); |
|
|
|
query.add(RestrictionsFactoryUtil.eq("companyId", companyId)); |
|
|
|
query.add(RestrictionsFactoryUtil.eq("companyId", companyId)); |
|
|
|
//TODO: scoprire in quali stati possono essere le pratiche ed ottimizzare la query
|
|
|
|
//TODO: scoprire in quali stati possono essere le pratiche ed ottimizzare la query
|
|
|
@ -178,6 +180,7 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
long intPraticaId = intPratica.getIntPraticaId(); |
|
|
|
long intPraticaId = intPratica.getIntPraticaId(); |
|
|
|
String praticaId = String.valueOf(intPraticaId); |
|
|
|
String praticaId = String.valueOf(intPraticaId); |
|
|
|
JSONObject object = QuarkusBridgeMessageFactoryUtil.writeUpdateData(clientContext, praticaId); |
|
|
|
JSONObject object = QuarkusBridgeMessageFactoryUtil.writeUpdateData(clientContext, praticaId); |
|
|
|
|
|
|
|
JSONArray readPartialResult = JSONFactoryUtil.createJSONArray(); |
|
|
|
_log.debug(object.toString()); |
|
|
|
_log.debug(object.toString()); |
|
|
|
JSONArray aggiornamentiPratiche = object.getJSONArray("result"); |
|
|
|
JSONArray aggiornamentiPratiche = object.getJSONArray("result"); |
|
|
|
for(int i = 0; i < aggiornamentiPratiche.length(); i++){ |
|
|
|
for(int i = 0; i < aggiornamentiPratiche.length(); i++){ |
|
|
@ -188,33 +191,96 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
JSONObject payload = Sportello.getJSONObject(QuarkusBridgeConstants.contenuto); |
|
|
|
JSONObject payload = Sportello.getJSONObject(QuarkusBridgeConstants.contenuto); |
|
|
|
switch(payloadContentType){ |
|
|
|
switch(payloadContentType){ |
|
|
|
case "INSTANCE_DELETE": |
|
|
|
case "INSTANCE_READ": |
|
|
|
_log.debug("Checking if we can delete Instance of Pratica with Id " + intPraticaId); |
|
|
|
JSONObject instance = serializeInstance(intPratica, clientContext); |
|
|
|
if (PraticaValidator.canDeletePratica(intPratica.getIntPraticaId())){ |
|
|
|
instance.put("esito", true); |
|
|
|
_log.debug("Deleting Instance of Pratica with Id " + intPraticaId); |
|
|
|
readPartialResult.put(instance); |
|
|
|
IntPraticaLocalServiceUtil.deleteIntPratica(intPratica, false); |
|
|
|
|
|
|
|
} else _log.debug("Cannot delete Instance of Pratica with Id "+ intPraticaId); |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case "DATA_READ": |
|
|
|
case "DATA_READ": |
|
|
|
_log.debug("Reading current Data from database for Pratica with Id "+ intPraticaId); |
|
|
|
_log.debug("Reading current Data from database for Pratica with Id "+ intPraticaId); |
|
|
|
JSONObject currentData = readData(payload, intPraticaId); |
|
|
|
JSONObject currentData = readData(payload, intPraticaId); |
|
|
|
if(currentData.length() == 0){ |
|
|
|
if(currentData.length() == 0){ |
|
|
|
|
|
|
|
currentData.put("esito", false); |
|
|
|
_log.error("Unable to read Data from database for Pratica with Id "+ intPraticaId); |
|
|
|
_log.error("Unable to read Data from database for Pratica with Id "+ intPraticaId); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//TODO: send payload to Quarkus Middleware
|
|
|
|
currentData.put("esito", true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
readPartialResult.put(currentData); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "COMPLIANCE_READ": |
|
|
|
|
|
|
|
//TODO: validare i dati
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
_log.debug(pratica.toString()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
readBatchResult.put("results_".concat(praticaId), readPartialResult); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
_log.error(e,e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return readBatchResult; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject serializeInstance(IntPratica pratica, String context){ |
|
|
|
|
|
|
|
JSONObject INSTANCE = JSONFactoryUtil.createJSONObject(); |
|
|
|
|
|
|
|
INSTANCE.put("context", context); |
|
|
|
|
|
|
|
String url = "" ; |
|
|
|
|
|
|
|
//TODO: retrieve url for json answer
|
|
|
|
|
|
|
|
INSTANCE.put("url", url); |
|
|
|
|
|
|
|
String instanceId = String.valueOf(pratica.getIntPraticaId()); |
|
|
|
|
|
|
|
INSTANCE.put("instanceId", instanceId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String ipaCode = ""; |
|
|
|
|
|
|
|
//TODO: retrieve ipaCode
|
|
|
|
|
|
|
|
String clientId = ""; |
|
|
|
|
|
|
|
//TODO: retrieve clientId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String proceedingType = pratica.getTipoProcedura(); |
|
|
|
|
|
|
|
INSTANCE.put("proceedingType", proceedingType); |
|
|
|
|
|
|
|
return INSTANCE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject prepareUpdateBatch(long companyId){ |
|
|
|
|
|
|
|
final String clientContext = "PAESAGGISTICA"; |
|
|
|
|
|
|
|
DynamicQuery query = IntPraticaLocalServiceUtil.dynamicQuery(); |
|
|
|
|
|
|
|
query.add(RestrictionsFactoryUtil.eq("companyId", companyId)); |
|
|
|
|
|
|
|
//TODO: scoprire in quali stati possono essere le pratiche ed ottimizzare la query
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
List<IntPratica> praticheDaAggiornare = IntPraticaLocalServiceUtil.dynamicQuery(query); |
|
|
|
|
|
|
|
//TODO: splittare le pratiche da aggiornare
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: ciclare per effettuare gli update delle singole pratiche
|
|
|
|
|
|
|
|
for(IntPratica intPratica : praticheDaAggiornare){ |
|
|
|
|
|
|
|
long intPraticaId = intPratica.getIntPraticaId(); |
|
|
|
|
|
|
|
String praticaId = String.valueOf(intPraticaId); |
|
|
|
|
|
|
|
JSONObject object = QuarkusBridgeMessageFactoryUtil.writeUpdateData(clientContext, praticaId); |
|
|
|
|
|
|
|
_log.debug(object.toString()); |
|
|
|
|
|
|
|
JSONArray aggiornamentiPratiche = object.getJSONArray("result"); |
|
|
|
|
|
|
|
for(int i = 0; i < aggiornamentiPratiche.length(); i++){ |
|
|
|
|
|
|
|
JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); |
|
|
|
|
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
|
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
|
|
|
|
JSONObject payload = Sportello.getJSONObject(QuarkusBridgeConstants.contenuto); |
|
|
|
|
|
|
|
switch(payloadContentType){ |
|
|
|
|
|
|
|
case "INSTANCE_DELETE": // Elimina la pratica
|
|
|
|
|
|
|
|
_log.debug("Checking if we can delete Instance of Pratica with Id " + intPraticaId); |
|
|
|
|
|
|
|
if (PraticaValidator.canDeletePratica(intPratica.getIntPraticaId())){ |
|
|
|
|
|
|
|
_log.debug("Deleting Instance of Pratica with Id " + intPraticaId); |
|
|
|
|
|
|
|
IntPraticaLocalServiceUtil.deleteIntPratica(intPratica, false); |
|
|
|
|
|
|
|
} else _log.debug("Cannot delete Instance of Pratica with Id "+ intPraticaId); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "DATA_WRITE": |
|
|
|
case "DATA_WRITE": // Aggiorna i dati dei campi del DettPratica associato ad IntPratica
|
|
|
|
_log.debug("Writing new data to database for Pratica with Id "+ intPraticaId); |
|
|
|
_log.debug("Writing new data to database for Pratica with Id "+ intPraticaId); |
|
|
|
writeData(payload, intPraticaId); |
|
|
|
writeData(payload, intPraticaId); |
|
|
|
_log.debug("Data written to database for Pratica with Id "+ intPraticaId); |
|
|
|
_log.debug("Data written to database for Pratica with Id "+ intPraticaId); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "DATA_DELETE": |
|
|
|
case "DATA_DELETE": // Elimina i dati dei campi del DettPratica associato ad IntPratica
|
|
|
|
//TODO: eliminazione dati dentro entità
|
|
|
|
//TODO: eliminazione dati dentro entità
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case "COMPLIANCE_READ": |
|
|
|
|
|
|
|
//TODO: validare i dati
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
_log.debug(pratica.toString()); |
|
|
|
_log.debug(pratica.toString()); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -233,21 +299,36 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
String dataType = payload.getJSONObject("data").getString("dataType"); |
|
|
|
String dataType = payload.getJSONObject("data").getString("dataType"); |
|
|
|
switch(dataType){ |
|
|
|
switch(dataType){ |
|
|
|
case QuarkusBridgeConstants.DataTypes.MAIN_DETAILS: |
|
|
|
case QuarkusBridgeConstants.DataTypes.MAIN_DETAILS: |
|
|
|
//TODO: leggere da DB i dati di
|
|
|
|
JSONArray TC = TipologiaCostruttivaUtil.getTipologiaCostruttiva(intPraticaId); |
|
|
|
// - Tipologia Costruttiva
|
|
|
|
if(TC.length() > 0) result.put("constructionType", TC.getJSONObject(0)); |
|
|
|
// - Descrizione
|
|
|
|
|
|
|
|
// - Destinazione
|
|
|
|
JSONArray description = DescrizioneUtil.getDescrizione(intPraticaId); |
|
|
|
// - Tipologia di Intervento
|
|
|
|
if(description.length() > 0) result.put("description", description.getJSONObject(0)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray destination = DestinazioneUtil.getDestinazione(intPraticaId); |
|
|
|
|
|
|
|
if(destination.length() > 0) result.put("destination", destination.getJSONObject(0)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray tipoInterventoANDNormativa = TipologieInterventoUtil.getTipologiaIntervento(intPraticaId); |
|
|
|
|
|
|
|
if(tipoInterventoANDNormativa.length() > 0) { |
|
|
|
|
|
|
|
result.put("projectType", tipoInterventoANDNormativa.getJSONObject(0) |
|
|
|
|
|
|
|
.getJSONObject("projectType")); |
|
|
|
|
|
|
|
result.put("regulatory", tipoInterventoANDNormativa.getJSONObject(0) |
|
|
|
|
|
|
|
.getJSONObject("regulatory")); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case QuarkusBridgeConstants.DataTypes.ACTORS: |
|
|
|
case QuarkusBridgeConstants.DataTypes.ACTORS: |
|
|
|
JSONArray actors = payload.getJSONArray("actors"); |
|
|
|
JSONArray actors = payload.getJSONArray("actors"); |
|
|
|
|
|
|
|
JSONArray partial = JSONFactoryUtil.createJSONArray(); |
|
|
|
for(int i = 0; i < actors.length() ; i++){ |
|
|
|
for(int i = 0; i < actors.length() ; i++){ |
|
|
|
JSONObject soggetto = actors.getJSONObject(i); |
|
|
|
JSONObject soggetto = actors.getJSONObject(i); |
|
|
|
SoggettiUtil.getSoggetto(soggetto, intPraticaId); |
|
|
|
JSONArray actor = SoggettiUtil.getSoggetto(soggetto, intPraticaId); |
|
|
|
|
|
|
|
if(actor.length() > 0) partial.put(actor.getJSONObject(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
result.put("actors", partial); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case QuarkusBridgeConstants.DataTypes.ATTACHMENTS_WITH_FILE: |
|
|
|
case QuarkusBridgeConstants.DataTypes.ATTACHMENTS_WITH_FILE: |
|
|
|
//TODO: leggere da Document and Media Library i documenti della pratica
|
|
|
|
JSONArray attachments = AllegatiUtil.recuperaDocumentiAllegatiPratica(intPraticaId); |
|
|
|
|
|
|
|
result.put("attachments", attachments); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: |
|
|
|
case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: |
|
|
|
//TODO: aspettare che vengano definite le buildingMetrics
|
|
|
|
//TODO: aspettare che vengano definite le buildingMetrics
|
|
|
|