From f0e4997b3d4c08b3e281fc9c9b73ffcc33f3ccfb Mon Sep 17 00:00:00 2001 From: Gabriele Zigurella Date: Mon, 27 Feb 2023 12:38:42 +0100 Subject: [PATCH] fix: wrap resetFirme in try/catch to handle NPE --- .../it/mwg/sismica/bo/util/SismicaUtil.java | 93 ++++++++++--------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/SismicaUtil.java b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/SismicaUtil.java index dfb90a8f..655622cc 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/SismicaUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/SismicaUtil.java @@ -1268,53 +1268,56 @@ public class SismicaUtil { public static List resetFirme(long companyId, String numeroProgetto) throws SystemException, PortalException { - - List esito = new ArrayList<>(); - if (Validator.isNull(numeroProgetto)) { - esito.addAll(firmeBloccate(companyId)); - } else { - IntPratica pratica = IntPraticaLocalServiceUtil.findByNumeroProgetto(numeroProgetto); - ControlloPratica controllo = getLastControlloPratica(pratica.getIntPraticaId()); - KaleoInstanceToken instanceToken = findInstanceToken(controllo.getControlloPraticaId()); - if (Validator.isNotNull(instanceToken)) { - esitoLog(esito, "Trovato KaleoInstanceToken " + instanceToken.getKaleoInstanceTokenId() - + ", currentKaleoNodeName = \"" + instanceToken.getCurrentKaleoNodeName() + StringPool.QUOTE); - if (instanceToken.getCurrentKaleoNodeName().equalsIgnoreCase("signal_ff")) { - List taskInstanceTokens = findTaskInstanceTokens(instanceToken - .getKaleoInstanceTokenId()); - esitoLog(esito, "Trovati " + taskInstanceTokens.size() + " KaleoTaskInstanceToken"); - List taskAssignmentInstances = findTaskAssignmentInstances(instanceToken - .getKaleoInstanceId()); - esitoLog(esito, "Trovati " + taskAssignmentInstances.size() + " KaleoTaskAssignmentInstance"); - - KaleoTaskInstanceToken taskInstanceToken = taskInstanceTokens.get(taskInstanceTokens.size() - 1); - KaleoTaskAssignmentInstance taskAssignmentInstance = taskAssignmentInstances - .get(taskAssignmentInstances.size() - 1); - - esitoLog(esito, - "Cancello KaleoTaskInstanceToken " + taskInstanceToken.getKaleoTaskInstanceTokenId()); - KaleoTaskInstanceTokenLocalServiceUtil.deleteKaleoTaskInstanceToken(taskInstanceToken); - esitoLog( - esito, - "Cancello KaleoTaskAssignmentInstance " - + taskAssignmentInstance.getKaleoTaskAssignmentInstanceId()); - KaleoTaskAssignmentInstanceLocalServiceUtil - .deleteKaleoTaskAssignmentInstance(taskAssignmentInstance); - - taskInstanceToken = taskInstanceTokens.get(taskInstanceTokens.size() - 2); - esitoLog(esito, - "Aggiorno KaleoTaskInstanceToken " + taskInstanceToken.getKaleoTaskInstanceTokenId()); - taskInstanceToken.setCompleted(false); - taskInstanceToken.setCompletionUserId(0); - taskInstanceToken.setCompletionDate(null); - KaleoTaskInstanceTokenLocalServiceUtil.updateKaleoTaskInstanceToken(taskInstanceToken); - - esitoLog(esito, "Aggiorno KaleoInstanceToken " + instanceToken.getKaleoInstanceTokenId()); - instanceToken.setCurrentKaleoNodeId(21639); - instanceToken.setCurrentKaleoNodeName("Esito"); - KaleoInstanceTokenLocalServiceUtil.updateKaleoInstanceToken(instanceToken); + try{ + List esito = new ArrayList<>(); + if (Validator.isNull(numeroProgetto)) { + esito.addAll(firmeBloccate(companyId)); + } else { + IntPratica pratica = IntPraticaLocalServiceUtil.findByNumeroProgetto(numeroProgetto); + ControlloPratica controllo = getLastControlloPratica(pratica.getIntPraticaId()); + KaleoInstanceToken instanceToken = findInstanceToken(controllo.getControlloPraticaId()); + if (Validator.isNotNull(instanceToken)) { + esitoLog(esito, "Trovato KaleoInstanceToken " + instanceToken.getKaleoInstanceTokenId() + + ", currentKaleoNodeName = \"" + instanceToken.getCurrentKaleoNodeName() + StringPool.QUOTE); + if (instanceToken.getCurrentKaleoNodeName().equalsIgnoreCase("signal_ff")) { + List taskInstanceTokens = findTaskInstanceTokens(instanceToken + .getKaleoInstanceTokenId()); + esitoLog(esito, "Trovati " + taskInstanceTokens.size() + " KaleoTaskInstanceToken"); + List taskAssignmentInstances = findTaskAssignmentInstances(instanceToken + .getKaleoInstanceId()); + esitoLog(esito, "Trovati " + taskAssignmentInstances.size() + " KaleoTaskAssignmentInstance"); + + KaleoTaskInstanceToken taskInstanceToken = taskInstanceTokens.get(taskInstanceTokens.size() - 1); + KaleoTaskAssignmentInstance taskAssignmentInstance = taskAssignmentInstances + .get(taskAssignmentInstances.size() - 1); + + esitoLog(esito, + "Cancello KaleoTaskInstanceToken " + taskInstanceToken.getKaleoTaskInstanceTokenId()); + KaleoTaskInstanceTokenLocalServiceUtil.deleteKaleoTaskInstanceToken(taskInstanceToken); + esitoLog( + esito, + "Cancello KaleoTaskAssignmentInstance " + + taskAssignmentInstance.getKaleoTaskAssignmentInstanceId()); + KaleoTaskAssignmentInstanceLocalServiceUtil + .deleteKaleoTaskAssignmentInstance(taskAssignmentInstance); + + taskInstanceToken = taskInstanceTokens.get(taskInstanceTokens.size() - 2); + esitoLog(esito, + "Aggiorno KaleoTaskInstanceToken " + taskInstanceToken.getKaleoTaskInstanceTokenId()); + taskInstanceToken.setCompleted(false); + taskInstanceToken.setCompletionUserId(0); + taskInstanceToken.setCompletionDate(null); + KaleoTaskInstanceTokenLocalServiceUtil.updateKaleoTaskInstanceToken(taskInstanceToken); + + esitoLog(esito, "Aggiorno KaleoInstanceToken " + instanceToken.getKaleoInstanceTokenId()); + instanceToken.setCurrentKaleoNodeId(21639); + instanceToken.setCurrentKaleoNodeName("Esito"); + KaleoInstanceTokenLocalServiceUtil.updateKaleoInstanceToken(instanceToken); + } } } + }catch(Exception e){ + _log.error(e, e); } return esito; }