From 3e2c74784b145f31978b53f63fda8c9c8c50e826 Mon Sep 17 00:00:00 2001 From: marcoalderighi Date: Tue, 16 May 2023 12:54:29 +0200 Subject: [PATCH] =?UTF-8?q?aggiunta=20funzionalit=C3=A0=20per=20fix=20user?= =?UTF-8?q?=20ID=20su=20AOP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../portlet/AdvancedOperationPortlet.java | 20 ++ .../operation/util/AdvancedOperationUtil.java | 230 +++++++++++------- .../docroot/html/view.jsp | 27 +- 3 files changed, 185 insertions(+), 92 deletions(-) diff --git a/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/portlet/AdvancedOperationPortlet.java b/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/portlet/AdvancedOperationPortlet.java index 1b359ed5..0f0d8ffb 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/portlet/AdvancedOperationPortlet.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/portlet/AdvancedOperationPortlet.java @@ -12,6 +12,7 @@ import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.kernel.workflow.WorkflowConstants; import com.liferay.portal.kernel.workflow.WorkflowTask; +import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.util.PortalUtil; import com.liferay.util.bridges.mvc.MVCPortlet; @@ -191,6 +192,25 @@ public class AdvancedOperationPortlet extends MVCPortlet { } actionResponse.setRenderParameter("intPraticaId", String.valueOf(intPraticaId)); } + + public void fixUserID(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception{ + + _checkIfUserIsCompanyAdmin(actionRequest); + + long intPraticaId = ParamUtil.getLong(actionRequest, "intPraticaId", -1L); + IntPratica intPratica = IntPraticaLocalServiceUtil.fetchIntPratica(intPraticaId); + + if(!AdvancedOperationUtil.evalInt_Dett_UserID(intPratica)){ + DettPratica dettPratica = DettPraticaLocalServiceUtil.getLastEditableByIntPratica(intPratica.getIntPraticaId()); + if(Validator.isNotNull(dettPratica)){ + long userId = intPratica.getUserId(); + dettPratica.setUserId(userId); + dettPratica.setUserName(UserLocalServiceUtil.getUser(userId).getScreenName()); + DettPraticaLocalServiceUtil.updateDettPratica(dettPratica); + } + } + actionResponse.setRenderParameter("intPraticaId", String.valueOf(intPraticaId)); + } public void ripristinaPraticaConforme(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception{ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/util/AdvancedOperationUtil.java b/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/util/AdvancedOperationUtil.java index 6491dc0c..e5f94cbc 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/util/AdvancedOperationUtil.java +++ b/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/WEB-INF/src/it/nextmind/liferay/portos/advanced/operation/util/AdvancedOperationUtil.java @@ -31,217 +31,265 @@ import java.util.Date; import java.util.List; public class AdvancedOperationUtil { - - public static final int[] STATUS_ARRAY = - {WorkflowConstants.STATUS_DRAFT, WorkflowConstants.STATUS_INACTIVE, WorkflowConstants.STATUS_PENDING}; - - public static boolean isNotWorkflowManuallyStarted(IntPratica intPratica){ + + public static final int[] STATUS_ARRAY = { WorkflowConstants.STATUS_DRAFT, + WorkflowConstants.STATUS_INACTIVE, WorkflowConstants.STATUS_PENDING }; + + public static boolean isNotWorkflowManuallyStarted(IntPratica intPratica) { switch (intPratica.getStatoPratica()) { - case StatoPraticaConstants.VIDIMATA : + case StatoPraticaConstants.VIDIMATA: case StatoPraticaConstants.AUTORIZZATA: - case StatoPraticaConstants.CONFORME: + case StatoPraticaConstants.CONFORME: return true; default: return false; } } - - public static boolean hasControlloPratica_ProceduraC(IntPratica intPratica){ - if(Constants.PROCEDURA_C.equalsIgnoreCase(intPratica.getTipoProcedura())){ - try{ + + public static boolean hasControlloPratica_ProceduraC(IntPratica intPratica) { + if (Constants.PROCEDURA_C.equalsIgnoreCase(intPratica + .getTipoProcedura())) { + try { long intPraticaId = intPratica.getIntPraticaId(); - for(int i : STATUS_ARRAY){ - List controlloPraticas = - ControlloPraticaLocalServiceUtil.findByIntPraticaId_Status(intPraticaId, i); - if(!controlloPraticas.isEmpty()){ + for (int i : STATUS_ARRAY) { + List controlloPraticas = ControlloPraticaLocalServiceUtil + .findByIntPraticaId_Status(intPraticaId, i); + if (!controlloPraticas.isEmpty()) { return true; } } - } catch (SystemException e){ - _log.error(e,e); + } catch (SystemException e) { + _log.error(e, e); return false; } } return false; } - + public static List getListaTask(IntPratica intPratica) { - if(Validator.isNull(intPratica)){ + if (Validator.isNull(intPratica)) { return null; } try { ControlloPratica controlloPratica = null; - List controlloPraticaList = - ControlloPraticaLocalServiceUtil.findByIntPraticaId_Status(intPratica.getIntPraticaId(), intPratica.getStatus()); - if(controlloPraticaList.size() > 1){ - for(ControlloPratica cp : controlloPraticaList){ - if(Validator.isNull(controlloPratica) || cp.getCreateDate().after(controlloPratica.getCreateDate())) { + List controlloPraticaList = ControlloPraticaLocalServiceUtil + .findByIntPraticaId_Status(intPratica.getIntPraticaId(), + intPratica.getStatus()); + if (controlloPraticaList.size() > 1) { + for (ControlloPratica cp : controlloPraticaList) { + if (Validator.isNull(controlloPratica) + || cp.getCreateDate().after( + controlloPratica.getCreateDate())) { controlloPratica = cp; } } - } else if(controlloPraticaList.size() == 1){ + } else if (controlloPraticaList.size() == 1) { controlloPratica = controlloPraticaList.get(0); } else { return null; } - WorkflowInstanceLink workflowInstanceLink = WorkflowInstanceLinkLocalServiceUtil.fetchWorkflowInstanceLink( - controlloPratica.getCompanyId(),controlloPratica.getGroupId(), ControlloPratica.class.getName(), - controlloPratica.getPrimaryKey()); + WorkflowInstanceLink workflowInstanceLink = WorkflowInstanceLinkLocalServiceUtil + .fetchWorkflowInstanceLink(controlloPratica.getCompanyId(), + controlloPratica.getGroupId(), + ControlloPratica.class.getName(), + controlloPratica.getPrimaryKey()); List listaTask = null; if (workflowInstanceLink == null) { return null; } else { - return listaTask = WorkflowTaskManagerUtil.getWorkflowTasksByWorkflowInstance(controlloPratica.getCompanyId(), null, - workflowInstanceLink.getWorkflowInstanceId(), false, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); + return listaTask = WorkflowTaskManagerUtil + .getWorkflowTasksByWorkflowInstance( + controlloPratica.getCompanyId(), null, + workflowInstanceLink.getWorkflowInstanceId(), + false, QueryUtil.ALL_POS, QueryUtil.ALL_POS, + null); } - } catch (SystemException | PortalException e){ - _log.error(e,e); + } catch (SystemException | PortalException e) { + _log.error(e, e); return null; } } - public static boolean isPraticaAnnullata(IntPratica intPratica){ - if(Validator.isNotNull(intPratica)){ + public static boolean isPraticaAnnullata(IntPratica intPratica) { + if (Validator.isNotNull(intPratica)) { return WorkflowConstants.STATUS_INACTIVE == intPratica.getStatus(); } return false; } - public static List getDocPraticaOrfani(long intPraticaId){ + public static List getDocPraticaOrfani(long intPraticaId) { List docPraticaOrfaniList = new ArrayList(); try { - List docPraticaList = DocPraticaLocalServiceUtil.findByIntPratica(intPraticaId); - for(DocPratica docPratica : docPraticaList){ - if(Validator.isNull(DettPraticaLocalServiceUtil.fetchDettPratica(docPratica.getClassPk())) - && DettPratica.class.getName().equals(docPratica.getClassName())){ + List docPraticaList = DocPraticaLocalServiceUtil + .findByIntPratica(intPraticaId); + for (DocPratica docPratica : docPraticaList) { + if (Validator.isNull(DettPraticaLocalServiceUtil + .fetchDettPratica(docPratica.getClassPk())) + && DettPratica.class.getName().equals( + docPratica.getClassName())) { docPraticaOrfaniList.add(docPratica); } } } catch (SystemException e) { - _log.error(e,e); + _log.error(e, e); } return docPraticaOrfaniList; } - public static boolean hasDettPratica(long intPraticaId){ + public static boolean hasDettPratica(long intPraticaId) { return !_getDettPraticaList(intPraticaId).isEmpty(); } - public static boolean getNormLavoriInProprioFlag(long intPraticaId){ + public static boolean getNormLavoriInProprioFlag(long intPraticaId) { List dettPraticaList = _getDettPraticaList(intPraticaId); - if(!dettPraticaList.isEmpty()){ + if (!dettPraticaList.isEmpty()) { return dettPraticaList.get(0).getNormLavoriInProprio(); } return false; } - public static boolean getCollaudoStaticoFlag(long intPraticaId){ + public static boolean getCollaudoStaticoFlag(long intPraticaId) { List dettPraticaList = _getDettPraticaList(intPraticaId); - if(!dettPraticaList.isEmpty()){ + if (!dettPraticaList.isEmpty()) { return dettPraticaList.get(0).getCollaudoStatico(); } return false; } - public static String getLavoriInEconomiaBtnLabel(boolean normLavoriInProprioFlag){ - return normLavoriInProprioFlag ? "Rimuovi flag normLavoriInProprio" : "Aggiungi flag normLavoriInProprio"; + public static String getLavoriInEconomiaBtnLabel( + boolean normLavoriInProprioFlag) { + return normLavoriInProprioFlag ? "Rimuovi flag normLavoriInProprio" + : "Aggiungi flag normLavoriInProprio"; } - public static String getCollaudoStaticoBtnLabel(boolean collaudoStaticoFlag){ - return collaudoStaticoFlag ? "Rimuovi flag collaudoStatico" : "Aggiungi flag collaudoStatico"; + public static String getCollaudoStaticoBtnLabel(boolean collaudoStaticoFlag) { + return collaudoStaticoFlag ? "Rimuovi flag collaudoStatico" + : "Aggiungi flag collaudoStatico"; } - public static boolean isStatoPraticaIN(IntPratica intPratica){ - if(Validator.isNotNull(intPratica)){ + public static boolean isStatoPraticaIN(IntPratica intPratica) { + if (Validator.isNotNull(intPratica)) { return "IN".equals(intPratica.getStatoPratica()); } return false; } - - public static long getCurrentAssignee(IntPratica intPratica){ + + public static long getCurrentAssignee(IntPratica intPratica) { long currentAssignee = 0; WorkflowTask lastTask = getLastTask(intPratica); - if(Validator.isNotNull(lastTask)){ - if(it.tref.liferay.portos.bo.util.WorkflowConstants.WORKFLOW_TASKNAME_ESITO.equalsIgnoreCase(lastTask.getName())){ + if (Validator.isNotNull(lastTask)) { + if (it.tref.liferay.portos.bo.util.WorkflowConstants.WORKFLOW_TASKNAME_ESITO + .equalsIgnoreCase(lastTask.getName())) { currentAssignee = lastTask.getAssigneeUserId(); } } return currentAssignee; } - - public static WorkflowTask getLastTask(IntPratica intPratica){ - if(Validator.isNotNull(intPratica)){ + + public static WorkflowTask getLastTask(IntPratica intPratica) { + if (Validator.isNotNull(intPratica)) { try { - List controlloPraticas = ControlloPraticaLocalServiceUtil.findByIntPratica(intPratica.getIntPraticaId()); - if(!controlloPraticas.isEmpty()){ - for(ControlloPratica controlloPratica : controlloPraticas){ - if(controlloPratica.getStatus() == WorkflowConstants.STATUS_PENDING){ - return WorkflowUtil.getLastTask(controlloPratica.getCompanyId(), - controlloPratica.getGroupId(), null, controlloPratica); + List controlloPraticas = ControlloPraticaLocalServiceUtil + .findByIntPratica(intPratica.getIntPraticaId()); + if (!controlloPraticas.isEmpty()) { + for (ControlloPratica controlloPratica : controlloPraticas) { + if (controlloPratica.getStatus() == WorkflowConstants.STATUS_PENDING) { + return WorkflowUtil.getLastTask( + controlloPratica.getCompanyId(), + controlloPratica.getGroupId(), null, + controlloPratica); } } } - }catch (SystemException | PortalException e){ - _log.error(e,e); + } catch (SystemException | PortalException e) { + _log.error(e, e); } - } + } return null; } - - public static boolean evalCurrentAssignee(IntPratica intPratica, User tecnico){ + + public static boolean evalCurrentAssignee(IntPratica intPratica, + User tecnico) { WorkflowTask lastTask = getLastTask(intPratica); - if(Validator.isNotNull(lastTask) && lastTask.getName().equalsIgnoreCase("Esito")){ - return tecnico.getUserId() != lastTask.getAssigneeUserId() || lastTask.getAssigneeUserId() == 0; + if (Validator.isNotNull(lastTask) + && lastTask.getName().equalsIgnoreCase("Esito")) { + return tecnico.getUserId() != lastTask.getAssigneeUserId() + || lastTask.getAssigneeUserId() == 0; } return false; } - - public static boolean isWorkFlowCompleted(ControlloPratica controlloPratica){ + + public static boolean isWorkFlowCompleted(ControlloPratica controlloPratica) { try { - WorkflowTask task = WorkflowUtil.getLastTask(controlloPratica.getCompanyId(), + WorkflowTask task = WorkflowUtil.getLastTask( + controlloPratica.getCompanyId(), controlloPratica.getGroupId(), null, controlloPratica); return task.isCompleted(); } catch (PortalException | SystemException e) { - _log.error(e,e); + _log.error(e, e); } return false; } - public static List fetchDettPraticaListWithInizioLavori(IntPratica intPratica){ - if(Validator.isNotNull(intPratica)){ - DynamicQuery dynamicQuery = DettPraticaLocalServiceUtil.dynamicQuery(); - dynamicQuery.add(RestrictionsFactoryUtil.eq("intPraticaId", intPratica.getIntPraticaId())); - dynamicQuery.add(RestrictionsFactoryUtil.isNotNull("dataInizioLavoriOpera")); - try{ - return (List) DettPraticaLocalServiceUtil.dynamicQuery(dynamicQuery); - } catch (SystemException e){ - _log.error(e,e); + public static List fetchDettPraticaListWithInizioLavori( + IntPratica intPratica) { + if (Validator.isNotNull(intPratica)) { + DynamicQuery dynamicQuery = DettPraticaLocalServiceUtil + .dynamicQuery(); + dynamicQuery.add(RestrictionsFactoryUtil.eq("intPraticaId", + intPratica.getIntPraticaId())); + dynamicQuery.add(RestrictionsFactoryUtil + .isNotNull("dataInizioLavoriOpera")); + try { + return (List) DettPraticaLocalServiceUtil + .dynamicQuery(dynamicQuery); + } catch (SystemException e) { + _log.error(e, e); return null; } } return null; } - public static Date fetchDataInizioLavoriOpera(IntPratica intPratica){ + public static Date fetchDataInizioLavoriOpera(IntPratica intPratica) { List dettPraticaListWithInizioLavori = fetchDettPraticaListWithInizioLavori(intPratica); - if(!dettPraticaListWithInizioLavori.isEmpty()){ - return dettPraticaListWithInizioLavori.get(0).getDataInizioLavoriOpera(); + if (!dettPraticaListWithInizioLavori.isEmpty()) { + return dettPraticaListWithInizioLavori.get(0) + .getDataInizioLavoriOpera(); } return null; } - private static List _getDettPraticaList(long intPraticaId){ + public static boolean evalInt_Dett_UserID(IntPratica intPratica){ + return getLastDettPraticaUserID(intPratica) == intPratica.getUserId(); + } + + public static long getLastDettPraticaUserID(IntPratica intPratica){ + try { + DettPratica dettPratica = DettPraticaLocalServiceUtil.getLastEditableByIntPratica(intPratica.getIntPraticaId()); + if(Validator.isNotNull(dettPratica)){ + return dettPratica.getUserId(); + } + } catch (SystemException e){ + _log.error(e,e); + } + return -1; + } + + private static List _getDettPraticaList(long intPraticaId) { List dettPraticaList = new ArrayList(); try { - dettPraticaList = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId); + dettPraticaList = DettPraticaLocalServiceUtil + .findByIntPraticaId(intPraticaId); } catch (SystemException e) { - _log.error(e,e); + _log.error(e, e); } return dettPraticaList; } - private static final Log _log = LogFactoryUtil.getLog(AdvancedOperationUtil.class); + private static final Log _log = LogFactoryUtil + .getLog(AdvancedOperationUtil.class); } diff --git a/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/html/view.jsp b/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/html/view.jsp index ec2d891f..cbcbcea6 100644 --- a/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/html/view.jsp +++ b/liferay-plugins-sdk-6.2/portlets/portos-advanced-operation-portlet/docroot/html/view.jsp @@ -245,6 +245,30 @@ <% } %> + <% if(AdvancedOperationUtil.hasDettPratica(intPraticaId) + && !AdvancedOperationUtil.evalInt_Dett_UserID(intPratica)){ + %> +
+ + + + + <% + String functionFixUserID = "javascript:"+renderResponse.getNamespace()+"openConfirmationDialog('"+renderResponse.getNamespace()+"fixUserID','Sei sicuro di voler cambiare lo User dell'ultimo dettPratica?')"; + %> + + + +
+ <% } %> + <% if(AdvancedOperationUtil.isStatoPraticaIN(intPratica)){ %>
- +