diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.classpath b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.classpath index 2897838c..fcd69dcf 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.classpath +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.classpath @@ -19,6 +19,6 @@ - + diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.project b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.project index 9e71782f..d619e7cd 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.project +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/.project @@ -33,4 +33,11 @@ org.eclipse.jdt.core.javanature org.eclipse.wst.jsdt.core.jsNature + + + src + 2 + C:/liferay-sviluppo/6_2/Sicilia - Paesaggistica/eclipse/portos-bo-shared/src + + diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/build.xml b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/build.xml index 187d5a84..92031ce2 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/build.xml +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/build.xml @@ -2,5 +2,6 @@ - + + \ No newline at end of file diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/lib/portos-bo-shared.jar b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/lib/portos-bo-shared.jar new file mode 100644 index 00000000..41b2a644 Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/lib/portos-bo-shared.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/bridge/persistence/PraticaValidator.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/bridge/persistence/PraticaValidator.java index 64728fd6..88110612 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/bridge/persistence/PraticaValidator.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/bridge/persistence/PraticaValidator.java @@ -13,7 +13,6 @@ import com.liferay.portal.service.RoleLocalServiceUtil; import com.liferay.portal.service.ServiceContext; import com.liferay.portal.service.UserLocalServiceUtil; -import it.mwg.sismica.bo.shared.util.WorkflowConstants; import it.tref.liferay.portos.bo.model.Comune; import it.tref.liferay.portos.bo.model.IntPratica; import it.tref.liferay.portos.bo.model.Territorio; @@ -22,12 +21,53 @@ 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.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; public class PraticaValidator { static Log _log = LogFactoryUtil.getLog(PraticaValidator.class); + protected static final String PROCEDURA_P0 = "P0"; + protected static final String PROCEDURA_P1 = "P1"; + protected static final String PROCEDURA_P2 = "P2"; + protected static final String PROCEDURA_P3 = "P3"; + protected static final String PROCEDURA_P4 = "P4"; + protected static final String PROCEDURA_P5 = "P5"; + protected static final String PROCEDURA_P6 = "P6"; + protected static final String PROCEDURA_P7 = "P7"; + protected static final String PROCEDURA_P8 = "P8"; + protected static final String PROCEDURA_P9 = "P9"; + protected static final String PROCEDURA_P10 = "P10"; + + protected static final String PROCEDURA_Q1 = "Q1"; + protected static final String PROCEDURA_Q2 = "Q2"; + protected static final String PROCEDURA_Q3 = "Q3"; + protected static final String PROCEDURA_Q4 = "Q4"; + protected static final String PROCEDURA_Q5 = "Q5"; + protected static final String PROCEDURA_Q6 = "Q6"; + protected static final String PROCEDURA_Q7 = "Q7"; + protected static final String PROCEDURA_Q8 = "Q8"; + protected static final String PROCEDURA_Q9 = "Q9"; + protected static final String PROCEDURA_Q10 = "Q10"; + + public static final Set PROCEDURE = new HashSet(){ + { + add(PROCEDURA_P0); + add(PROCEDURA_P1); add(PROCEDURA_Q1); + add(PROCEDURA_P2); add(PROCEDURA_Q2); + add(PROCEDURA_P3); add(PROCEDURA_Q3); + add(PROCEDURA_P4); add(PROCEDURA_Q4); + add(PROCEDURA_P5); add(PROCEDURA_Q5); + add(PROCEDURA_P6); add(PROCEDURA_Q6); + add(PROCEDURA_P7); add(PROCEDURA_Q7); + add(PROCEDURA_P8); add(PROCEDURA_Q8); + add(PROCEDURA_P9); add(PROCEDURA_Q9); + add(PROCEDURA_P10);add(PROCEDURA_Q10); + } + }; + public static Comune fetchComune(long companyId, String codiceIstat) throws SystemException { Comune comune = ComuneLocalServiceUtil.fetchByC_CI(companyId, codiceIstat); if (comune == null) { @@ -84,7 +124,7 @@ public class PraticaValidator { _log.debug("IntPratica with Id "+intPraticaId+" status "+ statoPratica ); int dettPraticaCountByIntPratica = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId).size(); _log.debug("IntPratica with Id "+intPraticaId+" has associated "+ dettPraticaCountByIntPratica +" dettPraticas" ); - return statoPratica == WorkflowConstants.STATUS_ANY || dettPraticaCountByIntPratica == 1; + return statoPratica == -1 || dettPraticaCountByIntPratica == 1; } catch (PortalException | SystemException e) { _log.error(e, e); } diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/documents/util/AllegatiUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/documents/util/AllegatiUtil.java index 6f555f23..02f549c1 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/documents/util/AllegatiUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/documents/util/AllegatiUtil.java @@ -28,7 +28,6 @@ import it.tref.liferay.portos.bo.service.ConfigurazioneLocalServiceUtil; 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 it.tref.liferay.portos.bo.shared.util.ConfigurazioneConstants; import it.tref.liferay.portos.bo.util.PraticaUtil; import java.io.ByteArrayOutputStream; @@ -41,6 +40,9 @@ import java.util.Date; import java.util.List; public class AllegatiUtil { + + static final String ATTACHMENT_FOLDER_ID = "conf.geniocivile.attachment.folder.id"; + static Log _log = LogFactoryUtil.getLog(AllegatiUtil.class); public static JSONArray recuperaDocumentiAllegatiPratica(long intPraticaId){ @@ -51,7 +53,7 @@ public class AllegatiUtil { Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(intPratica.getTerritorioId()); long companyId = territorio.getCompanyId(); long defaultFolderId = ConfigurazioneLocalServiceUtil - .findByC_ChiaveLong(companyId, ConfigurazioneConstants.ATTACHMENT_FOLDER_ID); + .findByC_ChiaveLong(companyId, ATTACHMENT_FOLDER_ID); Folder defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId); String folderName = PraticaUtil.getFolderName(dettPratica.getDettPraticaId()); Folder folder = DLAppLocalServiceUtil.getFolder(defaultFolder.getRepositoryId(), @@ -140,7 +142,7 @@ public class AllegatiUtil { serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(admin.getUserId()); long defaultFolderId = ConfigurazioneLocalServiceUtil - .findByC_ChiaveLong(companyId, ConfigurazioneConstants.ATTACHMENT_FOLDER_ID); + .findByC_ChiaveLong(companyId, ATTACHMENT_FOLDER_ID); Folder defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId); String folderName = PraticaUtil.getFolderName(dettPratica.getDettPraticaId()); Folder folder = null; diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java index 425658ec..c0898cfd 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java @@ -4,6 +4,7 @@ public class QuarkusBridgeConstants { public final static String HEADER_REQUEST = "HeaderPratica"; public final static String BODY_REQUEST = "SportelloPratica"; + public final static String SCHEDULED_ACTION = "scheduledAction"; public final static String codiceIstat = "cadastralCode"; public final static String codiceFiscale = "digitalHolderTaxCode"; public final static String email = "address"; diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeMessageFactoryUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeMessageFactoryUtil.java index 081b6b90..fe6e7dcd 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeMessageFactoryUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeMessageFactoryUtil.java @@ -8,10 +8,12 @@ import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.messaging.Message; import com.liferay.portal.kernel.util.StringPool; +import com.liferay.portal.kernel.util.Validator; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; @@ -46,6 +48,58 @@ public class QuarkusBridgeMessageFactoryUtil { READ, WRITE, DELETE } + public static void createCallback(String context, Long id, JSONObject content){ + HttpURLConnection HttpConnection = null; + try{ + URL url = new URL("http://localhost:50000/portos/mw/new/" + .concat(context).concat(StringPool.FORWARD_SLASH) + .concat(String.valueOf(id))); + + HttpConnection = (HttpURLConnection) url.openConnection(); + + // Set MediaType Accepted in Accept Header + HttpConnection.addRequestProperty("Content-Type", "application/json"); + + // Set request method + HttpConnection.setRequestMethod("POST"); + + // Set connection timeout + HttpConnection.setConnectTimeout(5000); + + // Enable output stream to send the payload + HttpConnection.setDoOutput(true); + + // Send the payload over the output stream + String payload = content.toString(); + + OutputStream outputStream = HttpConnection.getOutputStream(); + outputStream.write(payload.getBytes("UTF-8")); + outputStream.close(); + + // Get the response code + int responseCode = HttpConnection.getResponseCode(); + switch(responseCode){ + case 200: + _log.debug("### Quarkus Bridge [Read :: 200 OK]"); + break; + case 500: + _log.debug("### Quarkus Bridge [Read :: 500 Quarkus Server Error]"); + break; + } + }catch(RuntimeException e){ + _log.error(e,e); + } catch (MalformedURLException e) { + _log.error(e,e); + } catch (IOException e) { + _log.error(e,e); + } finally { + // Close the connection + if(Validator.isNotNull(HttpConnection)){ + HttpConnection.disconnect(); + } + } + } + public static JSONObject readNewData(String context){ JSONObject responseBody = JSONFactoryUtil.createJSONObject(); HttpURLConnection HttpConnection = null; @@ -109,9 +163,67 @@ public class QuarkusBridgeMessageFactoryUtil { return responseBody; } - public static boolean callBackUpdateIntPraticaOnMiddleware(String context, String praticaId){ - //TODO: send request to update the praticaId - return true; + public static JSONObject readData(String context, String praticaId){ + JSONObject responseBody = JSONFactoryUtil.createJSONObject(); + HttpURLConnection HttpConnection = null; + try{ + URL url = new URL("http://localhost:50000/portos/mw/read/".concat(context).concat(praticaId)); + + HttpConnection = (HttpURLConnection) url.openConnection(); + + // Set MediaType Accepted in Accept Header + HttpConnection.addRequestProperty("Accept", "application/json"); + + // Set request method + HttpConnection.setRequestMethod("GET"); + + // Set connection timeout + HttpConnection.setConnectTimeout(5000); + + // Enable input/output streams + HttpConnection.setDoInput(true); + HttpConnection.setDoOutput(true); + + // Get the response code + StringBuilder response = new StringBuilder(); + int responseCode = HttpConnection.getResponseCode(); + switch(responseCode){ + case 200: + _log.debug("### Quarkus Bridge [Read :: 200 OK]"); + // Read the response + BufferedReader reader = new BufferedReader(new InputStreamReader(HttpConnection.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + reader.close(); + //TODO Process the response + if(response.charAt(0) == '{'){ + JSONObject resultSet = JSONFactoryUtil.createJSONObject(response.toString()); + responseBody = responseBody.put("result", resultSet); + } + if(response.charAt(0) == '['){ + JSONArray resultSet = JSONFactoryUtil.createJSONArray(response.toString()); + responseBody = responseBody.put("result", resultSet); + } + break; + case 500: + _log.debug("### Quarkus Bridge [Read :: 500 Quarkus Server Error]"); + break; + } + }catch(RuntimeException e){ + _log.error(e,e); + } catch (MalformedURLException e) { + _log.error(e,e); + } catch (IOException e) { + _log.error(e,e); + } catch (JSONException e) { + _log.error(e,e); + } finally { + // Close the connection + HttpConnection.disconnect(); + } + return responseBody; } public static JSONObject writeUpdateData(String context, String praticaId){ @@ -173,8 +285,114 @@ public class QuarkusBridgeMessageFactoryUtil { _log.error(e,e); } finally { // Close the connection - HttpConnection.disconnect(); + if(Validator.isNotNull(HttpConnection)){ + HttpConnection.disconnect(); + } } return responseBody; } + + public static void updateCallback(String context, Long id, JSONObject content){ + HttpURLConnection HttpConnection = null; + try{ + URL url = new URL("http://localhost:50000/portos/mw/update/" + .concat(context).concat(StringPool.FORWARD_SLASH) + .concat(String.valueOf(id))); + + HttpConnection = (HttpURLConnection) url.openConnection(); + + // Set MediaType Accepted in Accept Header + HttpConnection.addRequestProperty("Content-Type", "application/json"); + + // Set request method + HttpConnection.setRequestMethod("POST"); + + // Set connection timeout + HttpConnection.setConnectTimeout(5000); + + // Enable output stream to send the payload + HttpConnection.setDoOutput(true); + + // Send the payload over the output stream + String payload = content.toString(); + + OutputStream outputStream = HttpConnection.getOutputStream(); + outputStream.write(payload.getBytes("UTF-8")); + outputStream.close(); + + // Get the response code + int responseCode = HttpConnection.getResponseCode(); + switch(responseCode){ + case 200: + _log.debug("### Quarkus Bridge [Read :: 200 OK]"); + break; + case 500: + _log.debug("### Quarkus Bridge [Read :: 500 Quarkus Server Error]"); + break; + } + }catch(RuntimeException e){ + _log.error(e,e); + } catch (MalformedURLException e) { + _log.error(e,e); + } catch (IOException e) { + _log.error(e,e); + } finally { + // Close the connection + if(Validator.isNotNull(HttpConnection)){ + HttpConnection.disconnect(); + } + } + } + + public static void readCallback(String context, Long id, JSONObject content){ + HttpURLConnection HttpConnection = null; + try{ + URL url = new URL("http://localhost:50000/portos/mw/read/" + .concat(context).concat(StringPool.FORWARD_SLASH) + .concat(String.valueOf(id))); + + HttpConnection = (HttpURLConnection) url.openConnection(); + + // Set MediaType Accepted in Accept Header + HttpConnection.addRequestProperty("Content-Type", "application/json"); + + // Set request method + HttpConnection.setRequestMethod("POST"); + + // Set connection timeout + HttpConnection.setConnectTimeout(5000); + + // Enable output stream to send the payload + HttpConnection.setDoOutput(true); + + // Send the payload over the output stream + String payload = content.toString(); + + OutputStream outputStream = HttpConnection.getOutputStream(); + outputStream.write(payload.getBytes("UTF-8")); + outputStream.close(); + + // Get the response code + int responseCode = HttpConnection.getResponseCode(); + switch(responseCode){ + case 200: + _log.debug("### Quarkus Bridge [Read :: 200 OK]"); + break; + case 500: + _log.debug("### Quarkus Bridge [Read :: 500 Quarkus Server Error]"); + break; + } + }catch(RuntimeException e){ + _log.error(e,e); + } catch (MalformedURLException e) { + _log.error(e,e); + } catch (IOException e) { + _log.error(e,e); + } finally { + // Close the connection + if(Validator.isNotNull(HttpConnection)){ + HttpConnection.disconnect(); + } + } + } } diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java index 4e1b102b..69f73c30 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java @@ -18,7 +18,6 @@ import com.liferay.portal.model.Company; import com.liferay.portal.model.User; import com.liferay.portal.service.CompanyLocalServiceUtil; 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.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.service.DettPraticaLocalServiceUtil; 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.List; +import javax.xml.bind.DatatypeConverter; + import portos.nextmind.liferay.bridge.persistence.PraticaValidator; import portos.nextmind.liferay.documents.util.AllegatiUtil; import portos.nextmind.liferay.entities.util.DescrizioneUtil; @@ -62,26 +61,91 @@ public class QuarkusBridgeScheduler implements MessageListener { return; } for(Company company : companies){ - JSONObject createPayload = prepareCreateBatch(company.getCompanyId()); - JSONObject updatePayload = prepareUpdateBatch(company.getCompanyId()); - //TODO: persist pratiche + JSONArray createPayload = prepareCreateBatch(company.getCompanyId()); + for(int i = 0; i < createPayload.length() ; i++){ + 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."); } - 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 // (Nome, Cognome, Email, digitalHolderTaxCode, CadastralCode) - final String clientContext = "PAESAGGISTICA"; + final String clientContext = "SUAP"; JSONObject object = QuarkusBridgeMessageFactoryUtil.readNewData(clientContext); _log.debug(object.toString()); JSONArray pratiche = object.getJSONArray("result"); 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 Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); - //TODO: check requestAction da Header? - //TODO: check operation da Header? 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); try { // Cerca comune di appartenenza @@ -117,7 +181,7 @@ public class QuarkusBridgeScheduler implements MessageListener { // Aggiungi DettPratica ed IntPratica long territorioId = territorio.getTerritorioId(); //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"); continue; } @@ -137,7 +201,6 @@ public class QuarkusBridgeScheduler implements MessageListener { customFieldsExpando.addAttribute("HeaderSportelloId", ExpandoColumnConstants.LONG); customFieldsExpando.addAttribute("SportelloId", ExpandoColumnConstants.LONG); - String instanceId = Header.getString(QuarkusBridgeConstants.instanceId); String correlationId = Header.getString(QuarkusBridgeConstants.correlationId); String clientId = Header.getString(QuarkusBridgeConstants.clientId); @@ -145,7 +208,6 @@ public class QuarkusBridgeScheduler implements MessageListener { Long sportelloId = Sportello.getLong(QuarkusBridgeConstants.recordId); customFieldsExpando.setAttribute(QuarkusBridgeConstants.correlationId, correlationId); - customFieldsExpando.setAttribute(QuarkusBridgeConstants.instanceId, instanceId); customFieldsExpando.setAttribute(QuarkusBridgeConstants.clientId, clientId); customFieldsExpando.setAttribute("HeaderSportelloId", headerSportelloId); @@ -154,20 +216,23 @@ public class QuarkusBridgeScheduler implements MessageListener { intPratica.setExpandoBridgeAttributes(customFieldsExpando); // Persist changes to custom fields - IntPraticaLocalServiceUtil.updateIntPratica(intPratica); - + IntPratica finalizedPratica = IntPraticaLocalServiceUtil.updateIntPratica(intPratica); + item = item.put("intPraticaId", finalizedPratica.getIntPraticaId()); } catch (SystemException e) { _log.error(e ,e); } catch (PortalException 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){ - final String clientContext = "PAESAGGISTICA"; - JSONObject readBatchResult = JSONFactoryUtil.createJSONObject(); + private JSONArray prepareReadBatch(long companyId){ + final String clientContext = "SUAP"; + JSONArray readBatchResult = JSONFactoryUtil.createJSONArray(); DynamicQuery query = IntPraticaLocalServiceUtil.dynamicQuery(); query.add(RestrictionsFactoryUtil.eq("companyId", companyId)); //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){ long intPraticaId = intPratica.getIntPraticaId(); String praticaId = String.valueOf(intPraticaId); - JSONObject object = QuarkusBridgeMessageFactoryUtil.writeUpdateData(clientContext, praticaId); + JSONObject object = QuarkusBridgeMessageFactoryUtil.readData(clientContext, praticaId); JSONArray readPartialResult = JSONFactoryUtil.createJSONArray(); _log.debug(object.toString()); JSONArray aggiornamentiPratiche = object.getJSONArray("result"); for(int i = 0; i < aggiornamentiPratiche.length(); i++){ JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); + //TODO: remove debug --> + if(true) continue; + ////TODO: remove debug <-- JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); + JSONObject Action = pratica.getJSONObject(QuarkusBridgeConstants.SCHEDULED_ACTION); 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){ case "INSTANCE_READ": - JSONObject instance = serializeInstance(intPratica, clientContext); + instance.put("operation", "INSTANCE_READ"); instance.put("esito", true); readPartialResult.put(instance); break; case "DATA_READ": _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){ currentData.put("esito", false); _log.error("Unable to read Data from database for Pratica with Id "+ intPraticaId); } else { currentData.put("esito", true); } - readPartialResult.put(currentData); + instance.put("operation", "DATA_READ"); + instance.put("DATA_READ", currentData); + readPartialResult.put(instance); break; case "COMPLIANCE_READ": //TODO: validare i dati @@ -215,7 +291,7 @@ public class QuarkusBridgeScheduler implements MessageListener { break; } } - readBatchResult.put("results_".concat(praticaId), readPartialResult); + readBatchResult.put(readPartialResult); } } catch (Exception e) { _log.error(e,e); @@ -227,6 +303,7 @@ public class QuarkusBridgeScheduler implements MessageListener { 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()); @@ -239,11 +316,13 @@ public class QuarkusBridgeScheduler implements MessageListener { String proceedingType = pratica.getTipoProcedura(); INSTANCE.put("proceedingType", proceedingType); + INSTANCE.put("content", JSONFactoryUtil.looseSerialize(pratica)); return INSTANCE; } - private JSONObject prepareUpdateBatch(long companyId){ - final String clientContext = "PAESAGGISTICA"; + private JSONArray prepareUpdateBatch(long companyId){ + final String clientContext = "SUAP"; + JSONArray updateResult = JSONFactoryUtil.createJSONArray(); DynamicQuery query = IntPraticaLocalServiceUtil.dynamicQuery(); query.add(RestrictionsFactoryUtil.eq("companyId", companyId)); //TODO: scoprire in quali stati possono essere le pratiche ed ottimizzare la query @@ -251,32 +330,58 @@ public class QuarkusBridgeScheduler implements MessageListener { List 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()); + if(object.length() == 0) continue; + JSONArray updatePartialResult = JSONFactoryUtil.createJSONArray(); // Batch delle operazioni completate su una IntPratica JSONArray aggiornamentiPratiche = object.getJSONArray("result"); + for(int i = 0; i < aggiornamentiPratiche.length(); i++){ JSONObject pratica = aggiornamentiPratiche.getJSONObject(i); + //TODO: remove debug --> + if(true) continue; + ////TODO: remove debug <-- JSONObject Header = pratica.getJSONObject(QuarkusBridgeConstants.HEADER_REQUEST); JSONObject Sportello = pratica.getJSONObject(QuarkusBridgeConstants.BODY_REQUEST); + JSONObject Action = pratica.getJSONObject(QuarkusBridgeConstants.SCHEDULED_ACTION); 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){ 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); + 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; 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); - writeData(payload, intPraticaId); - _log.debug("Data written to database for Pratica with Id "+ intPraticaId); + JSONObject currentData = writeData(payload, 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; case "DATA_DELETE": // Elimina i dati dei campi del DettPratica associato ad IntPratica //TODO: eliminazione dati dentro entitą @@ -290,11 +395,10 @@ public class QuarkusBridgeScheduler implements MessageListener { } catch (SystemException | PortalException e) { _log.error(e,e); } - //TODO: return something? - return null; + return updateResult; } - protected JSONObject readData(JSONObject payload, long intPraticaId){ + protected JSONObject readDataPratica(JSONObject payload, long intPraticaId){ JSONObject result = JSONFactoryUtil.createJSONObject(); String dataType = payload.getJSONObject("data").getString("dataType"); switch(dataType){ @@ -337,7 +441,7 @@ public class QuarkusBridgeScheduler implements MessageListener { return result; } - protected void writeData(JSONObject payload, long intPraticaId){ + protected JSONObject writeData(JSONObject payload, long intPraticaId){ String dataType = payload.getJSONObject("data").getString("dataType"); switch(dataType){ case QuarkusBridgeConstants.DataTypes.MAIN_DETAILS: @@ -369,6 +473,7 @@ public class QuarkusBridgeScheduler implements MessageListener { case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: //TODO: aspettare che vengano definite le buildingMetrics break; - } + } + return readDataPratica(payload, intPraticaId); } }