|
|
@ -18,7 +18,6 @@ import com.liferay.portal.model.Company; |
|
|
|
import com.liferay.portal.model.User; |
|
|
|
import com.liferay.portal.model.User; |
|
|
|
import com.liferay.portal.service.CompanyLocalServiceUtil; |
|
|
|
import com.liferay.portal.service.CompanyLocalServiceUtil; |
|
|
|
import com.liferay.portal.service.ServiceContext; |
|
|
|
import com.liferay.portal.service.ServiceContext; |
|
|
|
import com.liferay.portal.service.ServiceContextThreadLocal; |
|
|
|
|
|
|
|
import com.liferay.portlet.expando.model.ExpandoBridge; |
|
|
|
import com.liferay.portlet.expando.model.ExpandoBridge; |
|
|
|
import com.liferay.portlet.expando.model.ExpandoColumnConstants; |
|
|
|
import com.liferay.portlet.expando.model.ExpandoColumnConstants; |
|
|
|
|
|
|
|
|
|
|
@ -28,12 +27,12 @@ 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 java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.bind.DatatypeConverter; |
|
|
|
|
|
|
|
|
|
|
|
import portos.nextmind.liferay.bridge.persistence.PraticaValidator; |
|
|
|
import portos.nextmind.liferay.bridge.persistence.PraticaValidator; |
|
|
|
import portos.nextmind.liferay.documents.util.AllegatiUtil; |
|
|
|
import portos.nextmind.liferay.documents.util.AllegatiUtil; |
|
|
|
import portos.nextmind.liferay.entities.util.DescrizioneUtil; |
|
|
|
import portos.nextmind.liferay.entities.util.DescrizioneUtil; |
|
|
@ -62,26 +61,91 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
for(Company company : companies){ |
|
|
|
for(Company company : companies){ |
|
|
|
JSONObject createPayload = prepareCreateBatch(company.getCompanyId()); |
|
|
|
JSONArray createPayload = prepareCreateBatch(company.getCompanyId()); |
|
|
|
JSONObject updatePayload = prepareUpdateBatch(company.getCompanyId()); |
|
|
|
for(int i = 0; i < createPayload.length() ; i++){ |
|
|
|
//TODO: persist pratiche
|
|
|
|
signalWritten(createPayload.getJSONObject(i)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
JSONArray updatePayload = prepareUpdateBatch(company.getCompanyId()); |
|
|
|
|
|
|
|
for(int i = 0; i < updatePayload.length() ; i++){ |
|
|
|
|
|
|
|
JSONArray jsonResultByIntPraticaId = updatePayload.getJSONArray(i); |
|
|
|
|
|
|
|
signalUpdated(jsonResultByIntPraticaId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
JSONArray readPayload = prepareReadBatch(company.getCompanyId()); |
|
|
|
|
|
|
|
for(int i = 0; i < updatePayload.length() ; i++){ |
|
|
|
|
|
|
|
JSONArray jsonResultByIntPraticaId = readPayload.getJSONArray(i); |
|
|
|
|
|
|
|
signalRead(jsonResultByIntPraticaId); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_log.info("### Quarkus Bridge Scheduler batch ready."); |
|
|
|
_log.info("### Quarkus Bridge Scheduler batch ready."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JSONObject prepareCreateBatch(long companyId){ |
|
|
|
private void signalWritten(JSONObject content){ |
|
|
|
|
|
|
|
// ogni oggetto viene segnalato all'endpoint univoco per l'operazione INSTANCE_WRITE
|
|
|
|
|
|
|
|
String context = content.getString("context"); |
|
|
|
|
|
|
|
Long scheduledActionId = content.getLong("scheduled_action_id"); |
|
|
|
|
|
|
|
QuarkusBridgeMessageFactoryUtil.createCallback(context, scheduledActionId, content); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void signalUpdated(JSONArray content){ |
|
|
|
|
|
|
|
for(int i = 0; i < content.length() ; i++){ |
|
|
|
|
|
|
|
// Get each operation result 1 by 1 and signal the result to quarkus middleware
|
|
|
|
|
|
|
|
JSONObject instance = content.getJSONObject(i); |
|
|
|
|
|
|
|
String context = instance.getString("context"); |
|
|
|
|
|
|
|
Long scheduledActionId = instance.getLong("scheduled_action_id"); |
|
|
|
|
|
|
|
String operation = instance.getString("operation"); |
|
|
|
|
|
|
|
Boolean operationResult = instance.getBoolean("esito"); |
|
|
|
|
|
|
|
String intPraticaId = instance.getString("instanceId"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder("### Sending signal for the ") |
|
|
|
|
|
|
|
.append(operationResult ? "success" : "failure") |
|
|
|
|
|
|
|
.append(" of the ").append(operation) |
|
|
|
|
|
|
|
.append(" on Instance with id ").append(intPraticaId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.debug(sb.toString()); |
|
|
|
|
|
|
|
QuarkusBridgeMessageFactoryUtil.updateCallback(context, scheduledActionId, instance); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void signalRead(JSONArray content){ |
|
|
|
|
|
|
|
//TODO: callback to quarkus middleware
|
|
|
|
|
|
|
|
for(int i = 0; i < content.length() ; i++){ |
|
|
|
|
|
|
|
// Get each operation result 1 by 1 and signal the result to quarkus middleware
|
|
|
|
|
|
|
|
JSONObject instance = content.getJSONObject(i); |
|
|
|
|
|
|
|
String context = instance.getString("context"); |
|
|
|
|
|
|
|
Long scheduledActionId = instance.getLong("scheduled_action_id"); |
|
|
|
|
|
|
|
String operation = instance.getString("operation"); |
|
|
|
|
|
|
|
Boolean operationResult = instance.getBoolean("esito"); |
|
|
|
|
|
|
|
String intPraticaId = instance.getString("instanceId"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder("### Sending signal for the ") |
|
|
|
|
|
|
|
.append(operationResult ? "success" : "failure") |
|
|
|
|
|
|
|
.append(" of the ").append(operation) |
|
|
|
|
|
|
|
.append(" on Instance with id ").append(intPraticaId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.debug(sb.toString()); |
|
|
|
|
|
|
|
QuarkusBridgeMessageFactoryUtil.readCallback(context, scheduledActionId, instance); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JSONArray prepareCreateBatch(long companyId){ |
|
|
|
|
|
|
|
JSONArray createBatchResult = JSONFactoryUtil.createJSONArray(); |
|
|
|
//TODO: Aggiornare quando Enrico chiede da dove recuperare i dati per la creazione
|
|
|
|
//TODO: Aggiornare quando Enrico chiede da dove recuperare i dati per la creazione
|
|
|
|
// (Nome, Cognome, Email, digitalHolderTaxCode, CadastralCode)
|
|
|
|
// (Nome, Cognome, Email, digitalHolderTaxCode, CadastralCode)
|
|
|
|
final String clientContext = "PAESAGGISTICA"; |
|
|
|
final String clientContext = "SUAP"; |
|
|
|
JSONObject object = QuarkusBridgeMessageFactoryUtil.readNewData(clientContext); |
|
|
|
JSONObject object = QuarkusBridgeMessageFactoryUtil.readNewData(clientContext); |
|
|
|
_log.debug(object.toString()); |
|
|
|
_log.debug(object.toString()); |
|
|
|
JSONArray pratiche = object.getJSONArray("result"); |
|
|
|
JSONArray pratiche = object.getJSONArray("result"); |
|
|
|
for(int i = 0; i < pratiche.length() ; i++){ |
|
|
|
for(int i = 0; i < pratiche.length() ; i++){ |
|
|
|
|
|
|
|
JSONObject item = JSONFactoryUtil.createJSONObject(); |
|
|
|
|
|
|
|
//TODO: remove debug -->
|
|
|
|
|
|
|
|
if(true) continue; |
|
|
|
|
|
|
|
////TODO: remove debug <--
|
|
|
|
|
|
|
|
item = item.put("context", clientContext); |
|
|
|
JSONObject pratica = pratiche.getJSONObject(i); |
|
|
|
JSONObject pratica = pratiche.getJSONObject(i); |
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
//TODO: check requestAction da Header?
|
|
|
|
|
|
|
|
//TODO: check operation da Header?
|
|
|
|
|
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
|
|
|
|
JSONObject Action = pratica.getJSONObject(QuarkusBridgeConstants.SCHEDULED_ACTION); |
|
|
|
|
|
|
|
item = item.put("scheduled_action_id", Action.getLong("id")); |
|
|
|
String codiceIstat = Sportello.getString(QuarkusBridgeConstants.codiceIstat); |
|
|
|
String codiceIstat = Sportello.getString(QuarkusBridgeConstants.codiceIstat); |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Cerca comune di appartenenza
|
|
|
|
// Cerca comune di appartenenza
|
|
|
@ -117,7 +181,7 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
// Aggiungi DettPratica ed IntPratica
|
|
|
|
// Aggiungi DettPratica ed IntPratica
|
|
|
|
long territorioId = territorio.getTerritorioId(); |
|
|
|
long territorioId = territorio.getTerritorioId(); |
|
|
|
//TODO: verifica che la pratica non esista già
|
|
|
|
//TODO: verifica che la pratica non esista già
|
|
|
|
if(!Constants.PRATICA_ZONE.containsKey(tipoProcedura)){ |
|
|
|
if(!PraticaValidator.PROCEDURE.contains(tipoProcedura)){ |
|
|
|
_log.error("#[!]# " + tipoProcedura + " is not a Valid TipoPratica"); |
|
|
|
_log.error("#[!]# " + tipoProcedura + " is not a Valid TipoPratica"); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -137,7 +201,6 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
customFieldsExpando.addAttribute("HeaderSportelloId", ExpandoColumnConstants.LONG); |
|
|
|
customFieldsExpando.addAttribute("HeaderSportelloId", ExpandoColumnConstants.LONG); |
|
|
|
customFieldsExpando.addAttribute("SportelloId", ExpandoColumnConstants.LONG); |
|
|
|
customFieldsExpando.addAttribute("SportelloId", ExpandoColumnConstants.LONG); |
|
|
|
|
|
|
|
|
|
|
|
String instanceId = Header.getString(QuarkusBridgeConstants.instanceId); |
|
|
|
|
|
|
|
String correlationId = Header.getString(QuarkusBridgeConstants.correlationId); |
|
|
|
String correlationId = Header.getString(QuarkusBridgeConstants.correlationId); |
|
|
|
String clientId = Header.getString(QuarkusBridgeConstants.clientId); |
|
|
|
String clientId = Header.getString(QuarkusBridgeConstants.clientId); |
|
|
|
|
|
|
|
|
|
|
@ -145,7 +208,6 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
Long sportelloId = Sportello.getLong(QuarkusBridgeConstants.recordId); |
|
|
|
Long sportelloId = Sportello.getLong(QuarkusBridgeConstants.recordId); |
|
|
|
|
|
|
|
|
|
|
|
customFieldsExpando.setAttribute(QuarkusBridgeConstants.correlationId, correlationId); |
|
|
|
customFieldsExpando.setAttribute(QuarkusBridgeConstants.correlationId, correlationId); |
|
|
|
customFieldsExpando.setAttribute(QuarkusBridgeConstants.instanceId, instanceId); |
|
|
|
|
|
|
|
customFieldsExpando.setAttribute(QuarkusBridgeConstants.clientId, clientId); |
|
|
|
customFieldsExpando.setAttribute(QuarkusBridgeConstants.clientId, clientId); |
|
|
|
|
|
|
|
|
|
|
|
customFieldsExpando.setAttribute("HeaderSportelloId", headerSportelloId); |
|
|
|
customFieldsExpando.setAttribute("HeaderSportelloId", headerSportelloId); |
|
|
@ -154,20 +216,23 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
intPratica.setExpandoBridgeAttributes(customFieldsExpando); |
|
|
|
intPratica.setExpandoBridgeAttributes(customFieldsExpando); |
|
|
|
|
|
|
|
|
|
|
|
// Persist changes to custom fields
|
|
|
|
// Persist changes to custom fields
|
|
|
|
IntPraticaLocalServiceUtil.updateIntPratica(intPratica); |
|
|
|
IntPratica finalizedPratica = IntPraticaLocalServiceUtil.updateIntPratica(intPratica); |
|
|
|
|
|
|
|
item = item.put("intPraticaId", finalizedPratica.getIntPraticaId()); |
|
|
|
} catch (SystemException e) { |
|
|
|
} catch (SystemException e) { |
|
|
|
_log.error(e ,e); |
|
|
|
_log.error(e ,e); |
|
|
|
} catch (PortalException e) { |
|
|
|
} catch (PortalException e) { |
|
|
|
_log.error(e, e); |
|
|
|
_log.error(e, e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
item = item.put("header", Header); |
|
|
|
|
|
|
|
item = item.put("body", Sportello); |
|
|
|
|
|
|
|
createBatchResult.put(item); |
|
|
|
} |
|
|
|
} |
|
|
|
return object; |
|
|
|
return createBatchResult; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JSONObject prepareReadBatch(long companyId){ |
|
|
|
private JSONArray prepareReadBatch(long companyId){ |
|
|
|
final String clientContext = "PAESAGGISTICA"; |
|
|
|
final String clientContext = "SUAP"; |
|
|
|
JSONObject readBatchResult = JSONFactoryUtil.createJSONObject(); |
|
|
|
JSONArray readBatchResult = JSONFactoryUtil.createJSONArray(); |
|
|
|
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
|
|
|
@ -179,33 +244,44 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
for(IntPratica intPratica : praticheDaAggiornare){ |
|
|
|
for(IntPratica intPratica : praticheDaAggiornare){ |
|
|
|
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.readData(clientContext, praticaId); |
|
|
|
JSONArray readPartialResult = JSONFactoryUtil.createJSONArray(); |
|
|
|
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++){ |
|
|
|
JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); |
|
|
|
JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); |
|
|
|
|
|
|
|
//TODO: remove debug -->
|
|
|
|
|
|
|
|
if(true) continue; |
|
|
|
|
|
|
|
////TODO: remove debug <--
|
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
|
|
|
|
JSONObject Action = pratica.getJSONObject(QuarkusBridgeConstants.SCHEDULED_ACTION); |
|
|
|
|
|
|
|
|
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
JSONObject payload = Sportello.getJSONObject(QuarkusBridgeConstants.contenuto); |
|
|
|
//TODO: gestire più tipi di payload? (Sia JSONObject che JSONArray??)
|
|
|
|
|
|
|
|
String base64Payload = Sportello.getString(QuarkusBridgeConstants.contenuto); |
|
|
|
|
|
|
|
byte[] decodedBytes = DatatypeConverter.parseBase64Binary(base64Payload); |
|
|
|
|
|
|
|
JSONObject payload = JSONFactoryUtil.createJSONObject(new String(decodedBytes)); |
|
|
|
|
|
|
|
JSONObject instance = serializeInstance(intPratica, clientContext); |
|
|
|
|
|
|
|
instance.put("scheduled_action_id", Action.getLong("id")); |
|
|
|
switch(payloadContentType){ |
|
|
|
switch(payloadContentType){ |
|
|
|
case "INSTANCE_READ": |
|
|
|
case "INSTANCE_READ": |
|
|
|
JSONObject instance = serializeInstance(intPratica, clientContext); |
|
|
|
instance.put("operation", "INSTANCE_READ"); |
|
|
|
instance.put("esito", true); |
|
|
|
instance.put("esito", true); |
|
|
|
readPartialResult.put(instance); |
|
|
|
readPartialResult.put(instance); |
|
|
|
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 = readDataPratica(payload, intPraticaId); |
|
|
|
if(currentData.length() == 0){ |
|
|
|
if(currentData.length() == 0){ |
|
|
|
currentData.put("esito", false); |
|
|
|
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 { |
|
|
|
currentData.put("esito", true); |
|
|
|
currentData.put("esito", true); |
|
|
|
} |
|
|
|
} |
|
|
|
readPartialResult.put(currentData); |
|
|
|
instance.put("operation", "DATA_READ"); |
|
|
|
|
|
|
|
instance.put("DATA_READ", currentData); |
|
|
|
|
|
|
|
readPartialResult.put(instance); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "COMPLIANCE_READ": |
|
|
|
case "COMPLIANCE_READ": |
|
|
|
//TODO: validare i dati
|
|
|
|
//TODO: validare i dati
|
|
|
@ -215,7 +291,7 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
readBatchResult.put("results_".concat(praticaId), readPartialResult); |
|
|
|
readBatchResult.put(readPartialResult); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
_log.error(e,e); |
|
|
|
_log.error(e,e); |
|
|
@ -227,6 +303,7 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
JSONObject INSTANCE = JSONFactoryUtil.createJSONObject(); |
|
|
|
JSONObject INSTANCE = JSONFactoryUtil.createJSONObject(); |
|
|
|
INSTANCE.put("context", context); |
|
|
|
INSTANCE.put("context", context); |
|
|
|
String url = "" ; |
|
|
|
String url = "" ; |
|
|
|
|
|
|
|
|
|
|
|
//TODO: retrieve url for json answer
|
|
|
|
//TODO: retrieve url for json answer
|
|
|
|
INSTANCE.put("url", url); |
|
|
|
INSTANCE.put("url", url); |
|
|
|
String instanceId = String.valueOf(pratica.getIntPraticaId()); |
|
|
|
String instanceId = String.valueOf(pratica.getIntPraticaId()); |
|
|
@ -239,11 +316,13 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
|
|
|
|
|
|
|
|
String proceedingType = pratica.getTipoProcedura(); |
|
|
|
String proceedingType = pratica.getTipoProcedura(); |
|
|
|
INSTANCE.put("proceedingType", proceedingType); |
|
|
|
INSTANCE.put("proceedingType", proceedingType); |
|
|
|
|
|
|
|
INSTANCE.put("content", JSONFactoryUtil.looseSerialize(pratica)); |
|
|
|
return INSTANCE; |
|
|
|
return INSTANCE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JSONObject prepareUpdateBatch(long companyId){ |
|
|
|
private JSONArray prepareUpdateBatch(long companyId){ |
|
|
|
final String clientContext = "PAESAGGISTICA"; |
|
|
|
final String clientContext = "SUAP"; |
|
|
|
|
|
|
|
JSONArray updateResult = JSONFactoryUtil.createJSONArray(); |
|
|
|
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
|
|
|
@ -251,32 +330,58 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
List<IntPratica> praticheDaAggiornare = IntPraticaLocalServiceUtil.dynamicQuery(query); |
|
|
|
List<IntPratica> praticheDaAggiornare = IntPraticaLocalServiceUtil.dynamicQuery(query); |
|
|
|
//TODO: splittare le pratiche da aggiornare
|
|
|
|
//TODO: splittare le pratiche da aggiornare
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: ciclare per effettuare gli update delle singole pratiche
|
|
|
|
|
|
|
|
for(IntPratica intPratica : praticheDaAggiornare){ |
|
|
|
for(IntPratica intPratica : praticheDaAggiornare){ |
|
|
|
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); |
|
|
|
_log.debug(object.toString()); |
|
|
|
_log.debug(object.toString()); |
|
|
|
|
|
|
|
if(object.length() == 0) continue; |
|
|
|
|
|
|
|
JSONArray updatePartialResult = JSONFactoryUtil.createJSONArray(); // Batch delle operazioni completate su una IntPratica
|
|
|
|
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++){ |
|
|
|
JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); |
|
|
|
JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); |
|
|
|
|
|
|
|
//TODO: remove debug -->
|
|
|
|
|
|
|
|
if(true) continue; |
|
|
|
|
|
|
|
////TODO: remove debug <--
|
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); |
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); |
|
|
|
|
|
|
|
JSONObject Action = pratica.getJSONObject(QuarkusBridgeConstants.SCHEDULED_ACTION); |
|
|
|
|
|
|
|
|
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
String payloadContentType = Sportello.getString(QuarkusBridgeConstants.tipoContenuto); |
|
|
|
JSONObject payload = Sportello.getJSONObject(QuarkusBridgeConstants.contenuto); |
|
|
|
//TODO: gestire più tipi di payload? (Sia JSONObject che JSONArray??)
|
|
|
|
|
|
|
|
String base64Payload = Sportello.getString(QuarkusBridgeConstants.contenuto); |
|
|
|
|
|
|
|
byte[] decodedBytes = DatatypeConverter.parseBase64Binary(base64Payload); |
|
|
|
|
|
|
|
JSONObject payload = JSONFactoryUtil.createJSONObject(new String(decodedBytes)); |
|
|
|
|
|
|
|
JSONObject instance = serializeInstance(intPratica, clientContext); |
|
|
|
|
|
|
|
instance.put("scheduled_action_id", Action.getLong("id")); |
|
|
|
switch(payloadContentType){ |
|
|
|
switch(payloadContentType){ |
|
|
|
case "INSTANCE_DELETE": // Elimina la pratica
|
|
|
|
case "INSTANCE_DELETE": // Elimina la pratica
|
|
|
|
_log.debug("Checking if we can delete Instance of Pratica with Id " + intPraticaId); |
|
|
|
_log.debug("Checking if we can delete Instance of Pratica with Id " + intPraticaId); |
|
|
|
if (PraticaValidator.canDeletePratica(intPratica.getIntPraticaId())){ |
|
|
|
if (PraticaValidator.canDeletePratica(intPratica.getIntPraticaId())){ |
|
|
|
_log.debug("Deleting Instance of Pratica with Id " + intPraticaId); |
|
|
|
_log.debug("Deleting Instance of Pratica with Id " + intPraticaId); |
|
|
|
IntPraticaLocalServiceUtil.deleteIntPratica(intPratica, false); |
|
|
|
IntPraticaLocalServiceUtil.deleteIntPratica(intPratica, false); |
|
|
|
} else _log.debug("Cannot delete Instance of Pratica with Id "+ intPraticaId); |
|
|
|
instance.put("esito", true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_log.debug("Cannot delete Instance of Pratica with Id "+ intPraticaId); |
|
|
|
|
|
|
|
instance.put("esito", false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
instance.put("operation", "INSTANCE_DELETE"); |
|
|
|
|
|
|
|
updatePartialResult.put(instance); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "DATA_WRITE": // Aggiorna i dati dei campi del DettPratica associato ad IntPratica
|
|
|
|
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); |
|
|
|
JSONObject currentData = writeData(payload, intPraticaId); |
|
|
|
_log.debug("Data written to database for Pratica with Id "+ intPraticaId); |
|
|
|
if(currentData.length() == 0){ |
|
|
|
|
|
|
|
instance.put("esito", false); |
|
|
|
|
|
|
|
_log.error("Unable to write Data data database for Pratica with Id "+ intPraticaId); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
instance.put("esito", true); |
|
|
|
|
|
|
|
_log.debug("Data written to database for Pratica with Id "+ intPraticaId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
instance.put("operation", "DATA_WRITE"); |
|
|
|
|
|
|
|
instance.put("DATA_WRITE", currentData); |
|
|
|
|
|
|
|
updatePartialResult.put(instance); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "DATA_DELETE": // Elimina i dati dei campi del DettPratica associato ad IntPratica
|
|
|
|
case "DATA_DELETE": // Elimina i dati dei campi del DettPratica associato ad IntPratica
|
|
|
|
//TODO: eliminazione dati dentro entità
|
|
|
|
//TODO: eliminazione dati dentro entità
|
|
|
@ -290,11 +395,10 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
} catch (SystemException | PortalException e) { |
|
|
|
} catch (SystemException | PortalException e) { |
|
|
|
_log.error(e,e); |
|
|
|
_log.error(e,e); |
|
|
|
} |
|
|
|
} |
|
|
|
//TODO: return something?
|
|
|
|
return updateResult; |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected JSONObject readData(JSONObject payload, long intPraticaId){ |
|
|
|
protected JSONObject readDataPratica(JSONObject payload, long intPraticaId){ |
|
|
|
JSONObject result = JSONFactoryUtil.createJSONObject(); |
|
|
|
JSONObject result = JSONFactoryUtil.createJSONObject(); |
|
|
|
String dataType = payload.getJSONObject("data").getString("dataType"); |
|
|
|
String dataType = payload.getJSONObject("data").getString("dataType"); |
|
|
|
switch(dataType){ |
|
|
|
switch(dataType){ |
|
|
@ -337,7 +441,7 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void writeData(JSONObject payload, long intPraticaId){ |
|
|
|
protected JSONObject writeData(JSONObject payload, long intPraticaId){ |
|
|
|
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: |
|
|
@ -369,6 +473,7 @@ public class QuarkusBridgeScheduler implements MessageListener { |
|
|
|
case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: |
|
|
|
case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: |
|
|
|
//TODO: aspettare che vengano definite le buildingMetrics
|
|
|
|
//TODO: aspettare che vengano definite le buildingMetrics
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return readDataPratica(payload, intPraticaId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|