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 94179fb4..64728fd6 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 @@ -1,5 +1,6 @@ package portos.nextmind.liferay.bridge.persistence; +import com.liferay.portal.kernel.dao.orm.DynamicQuery; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; @@ -12,9 +13,13 @@ 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; import it.tref.liferay.portos.bo.service.ComuneLocalServiceUtil; +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.List; @@ -71,4 +76,18 @@ public class PraticaValidator { return user; } + + public static boolean canDeletePratica(long intPraticaId){ + try { + IntPratica pratica = IntPraticaLocalServiceUtil.getIntPratica(intPraticaId); + int statoPratica = pratica.getStatus(); + _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; + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + return false; + } } 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 new file mode 100644 index 00000000..1c224d35 --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/documents/util/AllegatiUtil.java @@ -0,0 +1,90 @@ +package portos.nextmind.liferay.documents.util; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.repository.model.FileEntry; +import com.liferay.portal.kernel.repository.model.Folder; +import com.liferay.portal.kernel.util.Base64; +import com.liferay.portal.kernel.util.MimeTypesUtil; +import com.liferay.portal.kernel.util.StringPool; +import com.liferay.portal.model.RoleConstants; +import com.liferay.portal.model.User; +import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil; +import com.liferay.portal.security.permission.PermissionThreadLocal; +import com.liferay.portal.service.RoleLocalServiceUtil; +import com.liferay.portal.service.ServiceContext; +import com.liferay.portal.service.UserLocalServiceUtil; +import com.liferay.portlet.documentlibrary.NoSuchFolderException; +import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil; + +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.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.util.Date; + +public class AllegatiUtil { + static Log _log = LogFactoryUtil.getLog(AllegatiUtil.class); + + public static FileEntry aggiungiDocumentoPratica(JSONObject file, long intPraticaId){ + FileEntry fileEntry = null; + try { + DettPratica dettPratica = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId).get(0); + IntPratica intPratica = IntPraticaLocalServiceUtil.fetchIntPratica(intPraticaId); + Territorio territorio = TerritorioLocalServiceUtil.getTerritorio(intPratica.getTerritorioId()); + long companyId = territorio.getCompanyId(); + long groupId = territorio.getGroupId(); + long admingRoleId = RoleLocalServiceUtil.getRole(companyId, RoleConstants.ADMINISTRATOR).getRoleId(); + User admin = UserLocalServiceUtil.getRoleUsers(admingRoleId).get(0); + ServiceContext serviceContext = new ServiceContext(); + serviceContext.setCompanyId(companyId); + serviceContext.setScopeGroupId(groupId); + serviceContext.setUserId(admin.getUserId()); + long defaultFolderId = ConfigurazioneLocalServiceUtil + .findByC_ChiaveLong(companyId, ConfigurazioneConstants.ATTACHMENT_FOLDER_ID); + Folder defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId); + String folderName = PraticaUtil.getFolderName(dettPratica.getDettPraticaId()); + Folder folder = null; + try { + folder = DLAppLocalServiceUtil + .getFolder(defaultFolder.getRepositoryId(), + defaultFolder.getFolderId(), folderName); + } catch (NoSuchFolderException e) { + // cartella non presente -> creo cartella + folder = DLAppLocalServiceUtil.addFolder(admin.getUserId(), + defaultFolder.getRepositoryId(), defaultFolder.getFolderId(), + folderName, StringPool.BLANK, serviceContext); + } + + // Get file info from JSON payload + String tipoAllegato = file.getString("type"); + String fileName = file.getString("fileName"); + String description = file.getString("sha256"); + String mimeType = file.getString("mimeType"); + String BASE64_encodedContent = file.getString("content"); + byte[] content = Base64.decode(BASE64_encodedContent); + + Date now = new Date(); + String title = tipoAllegato + StringPool.UNDERLINE + fileName; + String changeLog = StringPool.BLANK; + + fileEntry = DLAppLocalServiceUtil.addFileEntry( + admin.getUserId(), folder.getRepositoryId(), folder.getFolderId(), + now.getTime() + StringPool.UNDERLINE + fileName, mimeType, + title, description, changeLog, + content, serviceContext); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + return fileEntry; + } +} diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/DescrizioneUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/DescrizioneUtil.java new file mode 100644 index 00000000..9fb6ebaa --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/DescrizioneUtil.java @@ -0,0 +1,44 @@ +package portos.nextmind.liferay.entities.util; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; + +import java.util.List; + +import it.tref.liferay.portos.bo.model.DettPratica; +import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; + +public class DescrizioneUtil { + static Log _log = LogFactoryUtil.getLog(DescrizioneUtil.class); + + private static void aggiornaCoordinateCatastali(long dettPraticaId, JSONObject cadastralCoordinates){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + String Particelle = cadastralCoordinates.getString("particle"); + String Foglio = cadastralCoordinates.getString("sheet"); + pratica.setDcParticelle(Particelle); + pratica.setDcFoglio(Foglio); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + } + + public static void aggiornaDescrizione(long intPraticaId, JSONObject description){ + try { + List dettPraticasByIntPratica = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + for(DettPratica pratica : dettPraticasByIntPratica){ + pratica.setVia(description.getString("address")); + aggiornaCoordinateCatastali(pratica.getDettPraticaId(), description.getJSONObject("cadastralCoordinates")); + pratica.setLocalita(description.getString("location")); + pratica.setDcAllegato(description.getString("subject")); // TODO: analizzare se corrisponde a subject? + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } + } catch (RuntimeException | 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/entities/util/DestinazioneUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/DestinazioneUtil.java new file mode 100644 index 00000000..ae02409c --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/DestinazioneUtil.java @@ -0,0 +1,31 @@ +package portos.nextmind.liferay.entities.util; + +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; + +import it.tref.liferay.portos.bo.model.DettPratica; +import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; + +import java.util.List; + +public class DestinazioneUtil { + static Log _log = LogFactoryUtil.getLog(DestinazioneUtil.class); + + public static void aggiornaDestinazione(long intPraticaId, JSONObject destination){ + try { + List dettPraticasByIntPratica = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + for(DettPratica pratica : dettPraticasByIntPratica){ + String destinationType = destination.getString("destinationType"); + pratica.setDestinazione(destinationType); + if(destinationType.contentEquals("I0Z") || destination.has("i0zDescription")){ + pratica.setDestinazioneAltroIntervento(destination.getString("i0zDescription")); + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } + } catch (RuntimeException | 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/entities/util/TipologiaCostruttivaUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/TipologiaCostruttivaUtil.java new file mode 100644 index 00000000..b4e280b2 --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/TipologiaCostruttivaUtil.java @@ -0,0 +1,140 @@ +package portos.nextmind.liferay.entities.util; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; + +import it.tref.liferay.portos.bo.model.DettPratica; +import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; + +import java.util.List; + +public class TipologiaCostruttivaUtil { + static Log _log = LogFactoryUtil.getLog(TipologiaCostruttivaUtil.class); + + private static void inMuratura(long dettPraticaId, JSONObject masonry){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + Boolean inMuratura = masonry.getBoolean("checked"); + pratica.setTcInMuratura(inMuratura); + if (inMuratura && masonry.has("item")) { + JSONObject tipoMuratura = masonry.getJSONObject("item"); + if(tipoMuratura.has("mixed")){ + pratica.setTcInMuraturaMista(tipoMuratura.getBoolean("mixed")); + } + if(tipoMuratura.has("ordinary")){ + pratica.setTcInMuraturaOrdinaria(tipoMuratura.getBoolean("ordinary")); + } + if(tipoMuratura.has("reinforced")){ + pratica.setTcInMuraturaArmata(tipoMuratura.getBoolean("reinforced")); + } + } else { + pratica.setTcInMuraturaMista(false); + pratica.setTcInMuraturaOrdinaria(false); + pratica.setTcInMuraturaArmata(false); + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + } + + private static void inAcciaio(long dettPraticaId, JSONObject steel){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + Boolean inAcciaio = steel.getBoolean("checked"); + pratica.setTcInAcciaio(inAcciaio); + if (inAcciaio && steel.has("item")) { + JSONObject tipoAcciaio = steel.getJSONObject("item"); + if(tipoAcciaio.has("mixed")){ + pratica.setTcMista(tipoAcciaio.getBoolean("mixed")); + } + } else { + pratica.setTcMista(false); + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + } + + private static void inAltraTipologiaCostruttiva(long dettPraticaId, JSONObject otherConstructionType){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + Boolean inAltraTipologia = otherConstructionType.getBoolean("checked"); + pratica.setTcAltro(inAltraTipologia);; + if (inAltraTipologia && otherConstructionType.has("item")) { + JSONObject altraTipologia = otherConstructionType.getJSONObject("item"); + if(altraTipologia.has("descrizione")){ + pratica.setTcAltroDescrizione(altraTipologia.getString("descrizione")); + } + } else { + pratica.setTcAltroDescrizione(null); + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + } + + private static void inCementoArmato(long dettPraticaId, JSONObject reinforcedConcrete){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + Boolean inCementoArmato = reinforcedConcrete.getBoolean("checked"); + pratica.setTcInCA(inCementoArmato);; + if (inCementoArmato && reinforcedConcrete.has("item")) { + JSONObject tipoCementoArmato = reinforcedConcrete.getJSONObject("item"); + if(tipoCementoArmato.has("inSitu")){ + pratica.setTcInOpera(tipoCementoArmato.getBoolean("inSitu")); + } + if(tipoCementoArmato.has("prefabricated")){ + pratica.setTcPrefabbricato(tipoCementoArmato.getBoolean("prefabricated")); + } + } else { + pratica.setTcInOpera(false); + pratica.setTcPrefabbricato(false); + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + } + + private static void inLegno(long dettPraticaId, Boolean inLegno){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + pratica.setTcInLegno(inLegno); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (PortalException | SystemException e) { + _log.error(e, e); + } + } + + public static void aggiornaTipologiaCostruttiva(long intPraticaId, JSONObject constructionType){ + try { + List dettPraticasByIntPratica = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + for(DettPratica dettPratica : dettPraticasByIntPratica){ + long dettPraticaId = dettPratica.getDettPraticaId(); + if(constructionType.has("wood")){ + inLegno(dettPraticaId, constructionType.getBoolean("wood")); + } + if(constructionType.has("steel")){ + inAcciaio(dettPraticaId, constructionType.getJSONObject("steel")); + } + if(constructionType.has("reinforcedConcrete")){ + inCementoArmato(dettPraticaId, constructionType.getJSONObject("reinforcedConcrete")); + } + if(constructionType.has("masonry")){ + inMuratura(dettPraticaId, constructionType.getJSONObject("masonry")); + } + if(constructionType.has("otherConstructionType")){ + inAltraTipologiaCostruttiva(dettPraticaId, constructionType.getJSONObject("otherConstructionType")); + } + } + } catch (RuntimeException | 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/entities/util/TipologieInterventoUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/TipologieInterventoUtil.java new file mode 100644 index 00000000..f07064f0 --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/entities/util/TipologieInterventoUtil.java @@ -0,0 +1,143 @@ +package portos.nextmind.liferay.entities.util; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.util.Validator; + +import it.tref.liferay.portos.bo.model.DettPratica; +import it.tref.liferay.portos.bo.model.Diocesi; +import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; +import it.tref.liferay.portos.bo.service.DiocesiLocalServiceUtil; + +import java.util.List; + +public class TipologieInterventoUtil { + static Log _log = LogFactoryUtil.getLog(TipologieInterventoUtil.class); + + private static void aggiornaNormativa(long dettPraticaId, JSONObject regulatory){ + try { + DettPratica pratica = DettPraticaLocalServiceUtil.getDettPratica(dettPraticaId); + if(regulatory.has("churchHeritage")){ + JSONObject beniDiocesi = regulatory.getJSONObject("churchHeritage"); + if(beniDiocesi.getBoolean("checked")){ + pratica.setBeneDiocesi(true); + //TODO: check obbligo allegato A31 + if(beniDiocesi.has("item")){ + String jsonDiocesiId = beniDiocesi.getString("item"); + if(Validator.isDigit(jsonDiocesiId.replace("D", ""))){ + long diocesiId = Long.valueOf(jsonDiocesiId.replace("D", "")); + Diocesi diocesi = DiocesiLocalServiceUtil.fetchDiocesi(diocesiId); + if(Validator.isNotNull(diocesi)){ + pratica.setDiocesiId(diocesiId); + } + } + } + } + } + if(regulatory.has("contractorAppointment")){ + if(regulatory.getString("contractorAppointment").contentEquals("SUBORDINATE")){ + pratica.setNormLavoriNoDirettore(true); + pratica.setNormLavoriInProprio(false); + //TODO: check obbligo asservazione + } else { + pratica.setNormLavoriNoDirettore(false); + pratica.setNormLavoriInProprio(true); + //TODO: check obbligo asservazione + } + } + if(regulatory.has("exemptFromExpenses")){ + pratica.setNormEsenteSpese(regulatory.getBoolean("exemptFromExpenses")); + } + if(regulatory.has("exemptFromStampFee")){ + pratica.setNormEsenteBollo(regulatory.getBoolean("exemptFromStampFee")); + } + if(regulatory.has("testerAppointment")){ + if(regulatory.getString("testerAppointment").contentEquals("UNNECESSARY")){ + pratica.setNominaCollaudatore(false); + if(regulatory.has("localAction")){ + pratica.setNormDm2018(regulatory.getBoolean("localAction")); + } + } else pratica.setNominaCollaudatore(true); + } + if(regulatory.has("worksManagerAppointment")){ + pratica.setNominaDirettoreLavori( + regulatory.getString("worksManagerAppointment") + .contentEquals("SUBORDINATE")); + } + if(regulatory.has("publicWork")){ + JSONObject publicWork = regulatory.getJSONObject("publicWork"); + Boolean lavoriPubblici = publicWork.getBoolean("checked"); + pratica.setLavoriPubblici(lavoriPubblici); + pratica.setIntervFinPub(lavoriPubblici); + if(lavoriPubblici){ + //TODO: check obbligo documento A24 o asseverazione di esclusione/non assoggettabilità + // al procedimento di verifica preventiva dell’interesse archeologico + if(publicWork.has("item")){ + String description = publicWork.getJSONObject("item").getString("description"); + pratica.setIntervFinPubDesc(description); + String notQualifying = publicWork.getJSONObject("item").getString("notQualifying"); + switch(notQualifying){ + case "AREA_DI_INTERESSE": + pratica.setIntervInAreaDiInteresse(true); + break; + case "NON_MODIFICANTE": + pratica.setIntervNonModificante(true); + break; + case "NON_ASSOGGETTABILE": + pratica.setIntervNonAssoggettabile(true); + break; + } + } + } + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } catch (SystemException | PortalException e) { + _log.error(e, e); + } + } + + public static void aggiornaTipologieIntervento(long intPraticaId, JSONObject projectType){ + try { + List dettPraticasByIntPratica = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + for(DettPratica pratica : dettPraticasByIntPratica){ + if(projectType.has("regulatory")){ + aggiornaNormativa(pratica.getDettPraticaId(), projectType.getJSONObject("regulatory")); + } + if(projectType.has("newConstruction")){ + pratica.setTcNuovaCostruzione( + projectType.getBoolean("newConstruction")); + } + if(projectType.has("existingConstruction")){ + pratica.setTcCostruzioniEsistenti( + projectType.getBoolean("existingConstruction")); + } + if(projectType.has("newPertainingConstruction")){ + pratica.setTcNuovaCostruzionePertinenza( + projectType.getBoolean("newPertainingConstruction")); + } + if(projectType.has("noExcavationWorks")){ + //TODO: check obbligo asservazione + pratica.setTcNoOpereEscavazione( + projectType.getBoolean("noExcavationWorks")); + } + if(projectType.has("ordinaryExtraordinaryMaintenance")){ + pratica.setTcManutOrdStraord( + projectType.getBoolean("ordinaryExtraordinaryMaintenance")); + } + if(projectType.has("otherType")){ + pratica.setTcAltriInterventi( + projectType.getBoolean("otherType")); + + pratica.setTcAltriInterventiDesc( + projectType.getString("otherTypeDescription")); + } + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + } + } catch (RuntimeException | 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/roles/util/SoggettiUtil.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/roles/util/SoggettiUtil.java new file mode 100644 index 00000000..dd5d5699 --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/liferay/roles/util/SoggettiUtil.java @@ -0,0 +1,491 @@ +package portos.nextmind.liferay.roles.util; + +import com.liferay.counter.service.CounterLocalServiceUtil; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.json.JSONArray; +import com.liferay.portal.kernel.json.JSONFactoryUtil; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; + +import it.tref.liferay.portos.bo.model.DettPratica; +import it.tref.liferay.portos.bo.model.Soggetto; +import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; +import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; +import it.tref.liferay.portos.bo.service.SoggettoLocalServiceUtil; + +import java.sql.Date; +import java.util.List; + +public class SoggettiUtil { + static Log _log = LogFactoryUtil.getLog(SoggettiUtil.class); + + final static String Titolare_Digitale = "R00"; + final static String Collaudatore = "R01"; + final static String Committente = "R02"; + final static String Direttore_Lavori = "R03"; + final static String Ditta_Esecutrice = "R04"; + final static String Geologo = "R05"; + final static String Progettista = "R06"; + final static String Archeologo = "R07"; + final static String AltroProfBeniCulturali = "R08"; + final static String Restauratore = "R09"; + final static String Storico_Arte = "R10"; + + public static JSONArray getSoggetto(JSONObject soggetto, long intPraticaId){ + JSONArray result = JSONFactoryUtil.createJSONArray(); + String role = soggetto.getString("role"); + try { + List dettPraticas = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + for(DettPratica pratica : dettPraticas){ + JSONObject person = soggetto.getJSONObject("subject"); + JSONObject profession = null; + String fieldOfActivity = null; + switch(role){ + case Titolare_Digitale: + + break; + + case Collaudatore: + + break; + + case Committente: + + break; + + case Direttore_Lavori: + + break; + + case Ditta_Esecutrice: + + break; + + case Geologo: + + break; + + case Progettista: + + break; + + case Archeologo: + + break; + + case AltroProfBeniCulturali: + + break; + + case Restauratore: + + break; + + case Storico_Arte: + String cf = pratica.getCodiceFiscalePrincipaleStoricoArte(); + List storicoArteSubjects = SoggettoLocalServiceUtil + .findByDettPratica_CodiceFiscale(pratica.getDettPraticaId(), cf); + for(Soggetto storico : storicoArteSubjects){ + result.put(serializePerson(storico, true)); + } + break; + } + } + } catch (SystemException e) { + _log.error(e,e); + } + return result; + } + + private static JSONObject serializePerson(Soggetto soggetto, boolean alboProfessionale){ + JSONObject element = JSONFactoryUtil.createJSONObject(); + // Dati professione + if(alboProfessionale){ + JSONObject professionalRegistration = JSONFactoryUtil.createJSONObject(); + professionalRegistration.put("fieldOfActivity", soggetto.getAmbitoAttivita()); + professionalRegistration.put("professionalRegister", soggetto.getAlbo()); + if(soggetto.getAlbo().contentEquals("ALTRO")){ + professionalRegistration.put("otherProfessionalRegister", soggetto.getAlboDescr()); + } + professionalRegistration.put("number", soggetto.getNumIscrAlbo()); + + professionalRegistration.put("province", soggetto.getProvinciaAlbo()); + element.put("professionalRegistration", professionalRegistration); + } + // Dati persona + element.put("firstName", soggetto.getNome()); + element.put("taxCode", soggetto.getCodiceFiscale()); + element.put("type", soggetto.getTipologiaSoggetto()); + if(soggetto.getTipologiaSoggetto().contentEquals("NATURAL")){ + element.put("provinceOfBirth", soggetto.getProvinciaNascita()); + element.put("cityOfBirth", soggetto.getComuneNascita()); + element.put("dateOfBirth", soggetto.getDataNascita()); + element.put("email", soggetto.getEmail()); + element.put("phoneNumber", soggetto.getTelefono()); + element.put("lastName", soggetto.getCognome()); + + // Domicilio + JSONObject domicileAddress = JSONFactoryUtil.createJSONObject(); + domicileAddress.put("city", soggetto.getComuneDomicilio()); + domicileAddress.put("postCode", soggetto.getCapDomicilio()); + domicileAddress.put("province", soggetto.getProvinciaDomicilio()); + domicileAddress.put("streetName", soggetto.getViaDomicilio()); + domicileAddress.put("streetNumber", soggetto.getNumeroCivicoDomicilio()); + + // Residenza + JSONObject registeredAddress = JSONFactoryUtil.createJSONObject(); + registeredAddress.put("city", soggetto.getComune()); + registeredAddress.put("postCode", soggetto.getCap()); + registeredAddress.put("province", soggetto.getProvincia()); + registeredAddress.put("streetName", soggetto.getVia()); + registeredAddress.put("streetNumber", soggetto.getNumeroCivico()); + + element.put("registeredAddress", registeredAddress); + element.put("domicileAddress", domicileAddress); + } else { + JSONObject legalRepresentative = JSONFactoryUtil.createJSONObject(); + + //TODO: serializza dati Rappresentante + JSONObject domicileAddress = JSONFactoryUtil.createJSONObject(); + domicileAddress.put("city", soggetto.getComuneRap()); + domicileAddress.put("postCode", soggetto.getCapRap()); + domicileAddress.put("province", soggetto.getProvinciaRap()); + domicileAddress.put("streetName", soggetto.getViaRap()); + domicileAddress.put("streetNumber", soggetto.getNumeroCivicoRap()); + + JSONObject registeredAddress = JSONFactoryUtil.createJSONObject(); + registeredAddress.put("city", soggetto.getComuneRap()); + registeredAddress.put("postCode", soggetto.getCapRap()); + registeredAddress.put("province", soggetto.getProvinciaRap()); + registeredAddress.put("streetName", soggetto.getViaRap()); + registeredAddress.put("streetNumber", soggetto.getNumeroCivicoRap()); + + JSONObject registeredOfficeAddress = JSONFactoryUtil.createJSONObject(); + registeredOfficeAddress.put("city", soggetto.getComune()); + registeredOfficeAddress.put("postCode", soggetto.getCap()); + registeredOfficeAddress.put("province", soggetto.getProvincia()); + registeredOfficeAddress.put("streetName", soggetto.getVia()); + registeredOfficeAddress.put("streetNumber", soggetto.getNumeroCivico()); + + element.put("registeredOfficeAddress", registeredOfficeAddress); + legalRepresentative.put("domicileAddress", domicileAddress); + legalRepresentative.put("registeredAddress", registeredAddress); + element.put("legalRepresentative", legalRepresentative); + } + + return element; + } + + public static void aggiornaSoggetto(JSONObject soggetto, long intPraticaId){ + String role = soggetto.getString("role"); + try { + List dettPraticas = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + for(DettPratica pratica : dettPraticas){ + JSONObject person = soggetto.getJSONObject("subject"); + JSONObject profession = null; + String fieldOfActivity = null; + switch(role){ + case Titolare_Digitale: + String cfTitolareDigitale = addGenericPerson(person, intPraticaId, pratica.getDettPraticaId()); + //TODO: capire come persistere titolareDigitale in DettPratica + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Collaudatore: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfCollaudatore = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + //TODO: capire come persistere collaudatore in DettPratica + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Committente: + String cfCommittente = addGenericPerson(person, intPraticaId, pratica.getDettPraticaId()); + //TODO: capire come persistere committente in DettPratica + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Direttore_Lavori: + String cfDirettoreLavori= addGenericPerson(person, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleDirettoreLavori(cfDirettoreLavori); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Ditta_Esecutrice: + String vatDittaEsecutrice = addGenericPerson(person, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleDitta(vatDittaEsecutrice); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Geologo: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfGeologo = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleGeologo(cfGeologo); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Progettista: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfProgettista = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleProgettista(cfProgettista); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Archeologo: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfArcheologo = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleArcheologo(cfArcheologo); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case AltroProfBeniCulturali: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfBeniCulturali = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + //TODO: capire come persistere Altro Professionista in Beni Culturali in DettPratica + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Restauratore: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfRestauratore = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleRestauratore(cfRestauratore); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + + case Storico_Arte: + if(soggetto.has("fieldOfActivity")){ + fieldOfActivity = soggetto.getString("fieldOfActivity"); + } + if(soggetto.has("professionalRegistration")){ + profession = soggetto.getJSONObject("professionalRegistration"); + } + String cfStoricoArte = addProfessionalPerson(person, profession, fieldOfActivity, intPraticaId, pratica.getDettPraticaId()); + pratica.setCodiceFiscalePrincipaleStoricoArte(cfStoricoArte); + DettPraticaLocalServiceUtil.updateDettPratica(pratica); + break; + } + } + } catch (SystemException e) { + _log.error(e,e); + } + } + + private static String addGenericPerson(JSONObject subject, long intPraticaId, long dettPraticaId){ + try{ + long soggettoId = CounterLocalServiceUtil.increment(Soggetto.class.getName()); + Soggetto soggetto = SoggettoLocalServiceUtil.createSoggetto(soggettoId); + soggetto.setIntPraticaId(intPraticaId); + soggetto.setDettPraticaId(dettPraticaId); + String tipo = subject.getString("type"); + soggetto.setTipologiaSoggetto(tipo); + if(tipo.contentEquals("NATURAL")){ + String provinciaDiNascita = subject.getString("provinceOfBirth"); + soggetto.setProvinciaNascita(provinciaDiNascita); + String comuneDiNascita = subject.getString("cityOfBirth"); + soggetto.setComuneNascita(comuneDiNascita); + Date dataDiNascita = Date.valueOf(subject.getString("dateOfBirth")); + soggetto.setDataNascita(dataDiNascita); + String email = subject.getString("email"); + soggetto.setEmail(email); + String nome = subject.getString("firstName"); + soggetto.setNome(nome); + String cognome = subject.getString("lastName"); + soggetto.setCognome(cognome); + String telefono = subject.getString("phoneNumber"); + soggetto.setTelefono(telefono); + String codiceFiscale = subject.getString("taxCode"); + soggetto.setCodiceFiscale(codiceFiscale); + + // Dati domicilio + JSONObject domicilio = subject.getJSONObject("domicileAddress"); + String comune = domicilio.getString("city"); + soggetto.setComuneDomicilio(comune); + String cap = domicilio.getString("postCode"); + soggetto.setCapDomicilio(cap); + String provincia = domicilio.getString("province"); + soggetto.setProvinciaDomicilio(provincia); + String indirizzo = domicilio.getString("streetName"); + soggetto.setViaDomicilio(indirizzo); + String numeroCivico = domicilio.getString("streetNumber"); + soggetto.setNumeroCivicoDomicilio(numeroCivico); + + // Dati residenza + JSONObject residenza = subject.getJSONObject("registeredAddress"); + String comuneResidenza = residenza.getString("city"); + soggetto.setComune(comuneResidenza); + String capResidenza = residenza.getString("postCode"); + soggetto.setCap(capResidenza); + String provinciaResidenza = residenza.getString("province"); + soggetto.setProvincia(provinciaResidenza); + String indirizzoResidenza = residenza.getString("streetName"); + soggetto.setVia(indirizzoResidenza); + String numeroCivicoResidenza = residenza.getString("streetNumber"); + soggetto.setNumeroCivico(numeroCivicoResidenza); + } else { + String ragioneSociale = subject.getString("companyName"); + soggetto.setNome(ragioneSociale); + String partitaIVA = subject.getString("vatCode"); + soggetto.setCodiceFiscale(partitaIVA); + + // Dati rappresentante legale + JSONObject rappresentanteLegale = subject.getJSONObject("legalRepresentative"); + String provinciaDiNascita = rappresentanteLegale.getString("provinceOfBirth"); + soggetto.setProvinciaNascitaRap(provinciaDiNascita); + String comuneDiNascita = rappresentanteLegale.getString("cityOfBirth"); + soggetto.setComuneNascitaRap(comuneDiNascita); + Date dataDiNascita = Date.valueOf(rappresentanteLegale.getString("dateOfBirth")); + soggetto.setDataNascitaRap(dataDiNascita); + String email = rappresentanteLegale.getString("email"); + soggetto.setEmail(email); + String nome = rappresentanteLegale.getString("firstName"); + soggetto.setNome(nome); + String cognome = rappresentanteLegale.getString("lastName"); + soggetto.setCognome(cognome); + String telefono = rappresentanteLegale.getString("phoneNumber"); + soggetto.setTelefono(telefono); + String codiceFiscale = rappresentanteLegale.getString("taxCode"); + soggetto.setCodiceFiscaleDelegato(codiceFiscale); + + // Dati domicilio rappresentante legale + JSONObject domicilio = rappresentanteLegale.getJSONObject("domicileAddress"); + String comune = domicilio.getString("city"); + soggetto.setComuneRap(comune); + String cap = domicilio.getString("postCode"); + soggetto.setCapRap(cap); + String provincia = domicilio.getString("province"); + soggetto.setProvinciaRap(provincia); + String indirizzo = domicilio.getString("streetName"); + soggetto.setViaRap(indirizzo); + String numeroCivico = domicilio.getString("streetNumber"); + soggetto.setNumeroCivicoRap(numeroCivico); + + // Dati Sede Legale + JSONObject residenza = subject.getJSONObject("registeredOfficeAddress"); + String comuneResidenza = residenza.getString("city"); + soggetto.setComune(comuneResidenza); + String capResidenza = residenza.getString("postCode"); + soggetto.setCap(capResidenza); + String provinciaResidenza = residenza.getString("province"); + soggetto.setProvincia(provinciaResidenza); + String indirizzoResidenza = residenza.getString("streetName"); + soggetto.setVia(indirizzoResidenza); + String numeroCivicoResidenza = residenza.getString("streetNumber"); + soggetto.setNumeroCivico(numeroCivicoResidenza); + soggetto.setSedeLegale( + provinciaResidenza +","+ + comuneResidenza+","+ + indirizzoResidenza+" "+numeroCivicoResidenza+" "+capResidenza); + } + + + SoggettoLocalServiceUtil.addSoggetto(soggetto); + return soggetto.getCodiceFiscale(); + } catch (Exception e){ + _log.error(e,e); + } + return null; + } + + private static String addProfessionalPerson(JSONObject subject, JSONObject professionalRegistration, String fieldOfActivity, long intPraticaId, long dettPraticaId){ + try{ + long soggettoId = CounterLocalServiceUtil.increment(Soggetto.class.getName()); + Soggetto soggetto = SoggettoLocalServiceUtil.createSoggetto(soggettoId); + soggetto.setIntPraticaId(intPraticaId); + soggetto.setDettPraticaId(dettPraticaId); + String provinciaDiNascita = subject.getString("provinceOfBirth"); + soggetto.setProvinciaNascita(provinciaDiNascita); + String comuneDiNascita = subject.getString("cityOfBirth"); + soggetto.setComuneNascita(comuneDiNascita); + Date dataDiNascita = Date.valueOf(subject.getString("dateOfBirth")); + soggetto.setDataNascita(dataDiNascita); + String email = subject.getString("email"); + soggetto.setEmail(email); + String nome = subject.getString("firstName"); + soggetto.setNome(nome); + String cognome = subject.getString("lastName"); + soggetto.setCognome(cognome); + String telefono = subject.getString("phoneNumber"); + soggetto.setTelefono(telefono); + String codiceFiscale = subject.getString("taxCode"); + soggetto.setCodiceFiscale(codiceFiscale); + String tipo = subject.getString("type"); + soggetto.setTipologiaSoggetto(tipo); + + // Dati domicilio + JSONObject domicilio = subject.getJSONObject("domicileAddress"); + String comune = domicilio.getString("city"); + soggetto.setComuneDomicilio(comune); + String cap = domicilio.getString("postCode"); + soggetto.setCapDomicilio(cap); + String provincia = domicilio.getString("province"); + soggetto.setProvinciaDomicilio(provincia); + String indirizzo = domicilio.getString("streetName"); + soggetto.setViaDomicilio(indirizzo); + String numeroCivico = domicilio.getString("streetNumber"); + soggetto.setNumeroCivicoDomicilio(numeroCivico); + + // Dati residenza + JSONObject residenza = subject.getJSONObject("registeredAddress"); + String comuneResidenza = residenza.getString("city"); + soggetto.setComune(comuneResidenza); + String capResidenza = residenza.getString("postCode"); + soggetto.setCap(capResidenza); + String provinciaResidenza = residenza.getString("province"); + soggetto.setProvincia(provinciaResidenza); + String indirizzoResidenza = residenza.getString("streetName"); + soggetto.setVia(indirizzoResidenza); + String numeroCivicoResidenza = residenza.getString("streetNumber"); + soggetto.setNumeroCivico(numeroCivicoResidenza); + + // Dati professione + soggetto.setAmbitoAttivita(fieldOfActivity); + String Albo = professionalRegistration.getString("professionalRegister"); + if(Albo.contentEquals("ALTRO")){ + String altraProfessione = professionalRegistration.getString("otherProfessionalRegister"); + soggetto.setAlboDescr(altraProfessione); + } + soggetto.setAlbo(Albo); + String numeroAlbo = professionalRegistration.getString("number"); + soggetto.setNumIscrAlbo(numeroAlbo); + String provinciaAlbo = professionalRegistration.getString("province"); + soggetto.setProvinciaAlbo(provinciaAlbo); + + SoggettoLocalServiceUtil.addSoggetto(soggetto); + + return soggetto.getCodiceFiscale(); + }catch(Exception e){ + _log.error(e,e); + } + return 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 f3ae0ff3..425658ec 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 @@ -13,6 +13,18 @@ public class QuarkusBridgeConstants { public final static String instanceId = "instanceId"; public final static String correlationId = "correlationId"; public final static String clientId = "clientId"; + public final static String tipoContenuto = "contentType"; public final static String recordId = "id"; // The generated id in the external database + public final static String tipoData = "dataType"; + public final static String contenuto = "content"; + public final static String datiContenuto = "data"; + + public class DataTypes { + public final static String ACTORS = "ACTORS"; + public final static String MAIN_DETAILS = "MAIN_DETAILS"; + public final static String ATTACHMENTS_WITH_FILE = "ATTACHMENTS_WITH_FILE"; + public final static String WORK_DESCRIPTION = "WORK_DESCRIPTION"; + } + } 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 ea3b80a7..081b6b90 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 @@ -7,6 +7,7 @@ import com.liferay.portal.kernel.json.JSONObject; 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 java.io.BufferedReader; import java.io.IOException; @@ -107,4 +108,73 @@ 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 writeUpdateData(String context, String praticaId){ + JSONObject responseBody = JSONFactoryUtil.createJSONObject(); + HttpURLConnection HttpConnection = null; + try{ + URL url = new URL("http://localhost:50000/portos/mw/update/".concat(context) + .concat(StringPool.SLASH).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; + } } 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 3c68eb87..49749805 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,6 +18,7 @@ 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; @@ -33,6 +34,12 @@ import java.util.ArrayList; import java.util.List; import portos.nextmind.liferay.bridge.persistence.PraticaValidator; +import portos.nextmind.liferay.documents.util.AllegatiUtil; +import portos.nextmind.liferay.entities.util.DescrizioneUtil; +import portos.nextmind.liferay.entities.util.DestinazioneUtil; +import portos.nextmind.liferay.entities.util.TipologiaCostruttivaUtil; +import portos.nextmind.liferay.entities.util.TipologieInterventoUtil; +import portos.nextmind.liferay.roles.util.SoggettiUtil; import portos.nextmind.quarkus.bridge.api.QuarkusBridgeConstants; import portos.nextmind.quarkus.bridge.api.QuarkusBridgeMessageFactoryUtil; @@ -62,6 +69,8 @@ public class QuarkusBridgeScheduler implements MessageListener { } private JSONObject prepareCreateBatch(long companyId){ + //TODO: Aggiornare quando Enrico chiede da dove recuperare i dati per la creazione + // (Nome, Cognome, Email, digitalHolderTaxCode, CadastralCode) final String clientContext = "PAESAGGISTICA"; JSONObject object = QuarkusBridgeMessageFactoryUtil.readNewData(clientContext); _log.debug(object.toString()); @@ -156,11 +165,7 @@ public class QuarkusBridgeScheduler implements MessageListener { } private JSONObject prepareUpdateBatch(long companyId){ - JSONObject payload = JSONFactoryUtil.createJSONObject(); final String clientContext = "PAESAGGISTICA"; -// TODO: capire perché Enrico filtrava solo su queste ScheduledActions -// int ORDER_ScheduledAction = 2; -// payload.put("searchedScheduledAction", ORDER_ScheduledAction); DynamicQuery query = IntPraticaLocalServiceUtil.dynamicQuery(); query.add(RestrictionsFactoryUtil.eq("companyId", companyId)); //TODO: scoprire in quali stati possono essere le pratiche ed ottimizzare la query @@ -169,11 +174,120 @@ public class QuarkusBridgeScheduler implements MessageListener { //TODO: splittare le pratiche da aggiornare //TODO: ciclare per effettuare gli update delle singole pratiche - } catch (SystemException e) { + 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": + _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; + case "DATA_READ": + _log.debug("Reading current Data from database for Pratica with Id "+ intPraticaId); + JSONObject currentData = readData(payload, intPraticaId); + if(currentData.length() == 0){ + _log.error("Unable to read Data from database for Pratica with Id "+ intPraticaId); + } else { + //TODO: send payload to Quarkus Middleware + } + break; + case "DATA_WRITE": + _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); + break; + case "DATA_DELETE": + //TODO: eliminazione dati dentro entità + break; + case "COMPLIANCE_READ": + //TODO: validare i dati + break; + default: + _log.debug(pratica.toString()); + break; + } + } + } + } catch (SystemException | PortalException e) { _log.error(e,e); } - return payload; + //TODO: return something? + return null; } + protected JSONObject readData(JSONObject payload, long intPraticaId){ + JSONObject result = JSONFactoryUtil.createJSONObject(); + String dataType = payload.getJSONObject("data").getString("dataType"); + switch(dataType){ + case QuarkusBridgeConstants.DataTypes.MAIN_DETAILS: + //TODO: leggere da DB i dati di + // - Tipologia Costruttiva + // - Descrizione + // - Destinazione + // - Tipologia di Intervento + break; + case QuarkusBridgeConstants.DataTypes.ACTORS: + JSONArray actors = payload.getJSONArray("actors"); + for(int i = 0; i < actors.length() ; i++){ + JSONObject soggetto = actors.getJSONObject(i); + SoggettiUtil.getSoggetto(soggetto, intPraticaId); + } + break; + case QuarkusBridgeConstants.DataTypes.ATTACHMENTS_WITH_FILE: + //TODO: leggere da Document and Media Library i documenti della pratica + break; + case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: + //TODO: aspettare che vengano definite le buildingMetrics + break; + } + return result; + } + protected void writeData(JSONObject payload, long intPraticaId){ + String dataType = payload.getJSONObject("data").getString("dataType"); + switch(dataType){ + case QuarkusBridgeConstants.DataTypes.MAIN_DETAILS: + JSONObject constructionType = payload.getJSONObject("constructionType"); + TipologiaCostruttivaUtil.aggiornaTipologiaCostruttiva(intPraticaId, constructionType); + JSONObject description = payload.getJSONObject("description"); + DescrizioneUtil.aggiornaDescrizione(intPraticaId, description); + JSONObject destination = payload.getJSONObject("destination"); + DestinazioneUtil.aggiornaDestinazione(intPraticaId, destination); + JSONObject projectType = payload.getJSONObject("projectType"); + TipologieInterventoUtil.aggiornaTipologieIntervento(intPraticaId, projectType); + break; + case QuarkusBridgeConstants.DataTypes.ACTORS: + JSONArray actors = payload.getJSONArray("actors"); + for(int i = 0; i < actors.length() ; i++){ + JSONObject soggetto = actors.getJSONObject(i); + SoggettiUtil.aggiornaSoggetto(soggetto, intPraticaId); + } + break; + case QuarkusBridgeConstants.DataTypes.ATTACHMENTS_WITH_FILE: + JSONArray attachments = payload.getJSONArray("attachments"); + for(int i = 0; i < attachments.length() ; i++){ + JSONObject fileObject = attachments.getJSONObject(i); + Object file = AllegatiUtil.aggiungiDocumentoPratica(fileObject, intPraticaId); + if(Validator.isNull(file)) _log.error("Unable to add attachment "+fileObject.toString()); + else _log.debug("Attachment added to pratica with id "+intPraticaId); + } + break; + case QuarkusBridgeConstants.DataTypes.WORK_DESCRIPTION: + //TODO: aspettare che vengano definite le buildingMetrics + break; + } + } }