@ -2,27 +2,44 @@ package it.nextmind.liferay.portos.advanced.operation.portlet;
import com.liferay.portal.kernel.exception.PortalException ;
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 com.liferay.portal.kernel.search.Indexer ;
import com.liferay.portal.kernel.search.IndexerRegistryUtil ;
import com.liferay.portal.kernel.search.SearchException ;
import com.liferay.portal.kernel.servlet.SessionErrors ;
import com.liferay.portal.kernel.util.ParamUtil ;
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.theme.ThemeDisplay ;
import com.liferay.portal.util.PortalUtil ;
import com.liferay.util.bridges.mvc.MVCPortlet ;
import it.nextmind.liferay.portos.advanced.operation.util.AdvancedOperationUtil ;
import it.tref.liferay.portos.bo.model.ControlloPratica ;
import it.tref.liferay.portos.bo.model.DocPratica ;
import it.tref.liferay.portos.bo.model.IntPratica ;
import it.tref.liferay.portos.bo.service.ControlloPraticaLocalServiceUtil ;
import it.tref.liferay.portos.bo.service.DocPraticaLocalServiceUtil ;
import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil ;
import it.tref.liferay.portos.bo.util.WorkflowUtil ;
import java.io.IOException ;
import java.util.ArrayList ;
import java.util.List ;
import javax.portlet.ActionRequest ;
import javax.portlet.ActionResponse ;
import javax.portlet.PortletException ;
import javax.portlet.RenderRequest ;
import javax.portlet.RenderResponse ;
import javax.portlet.ResourceRequest ;
import javax.portlet.ResourceResponse ;
public class AdvancedOperationPortlet extends MVCPortlet {
private static class Privati {
@ -42,6 +59,27 @@ public class AdvancedOperationPortlet extends MVCPortlet {
}
}
@Override
public void serveResource ( ResourceRequest resourceRequest ,
ResourceResponse resourceResponse ) throws IOException ,
PortletException {
String id = resourceRequest . getResourceID ( ) ;
if ( "brokenUO" . equals ( id ) ) {
List < IntPratica > brokenUOList = AdvancedOperationUtil . getBrokenUOList ( ) ;
JSONArray jsonArray = JSONFactoryUtil . createJSONArray ( ) ;
for ( IntPratica intPratica : brokenUOList ) {
JSONObject jsonObject = JSONFactoryUtil . createJSONObject ( ) ;
jsonObject . put ( "id" , intPratica . getIntPraticaId ( ) ) ;
jsonObject . put ( "UO" , intPratica . getUnitaOperativa ( ) ) ;
jsonObject . put ( "destUO" , AdvancedOperationUtil . getDestinationUO ( intPratica ) ) ;
jsonArray . put ( jsonObject ) ;
}
writeJSON ( resourceRequest , resourceResponse , jsonArray ) ;
}
}
public void fixStatusPratica ( ActionRequest actionRequest , ActionResponse actionResponse ) throws Exception {
@ -55,6 +93,40 @@ public class AdvancedOperationPortlet extends MVCPortlet {
} else {
SessionErrors . add ( actionRequest , "operazione-impossibile" ) ;
}
actionResponse . setRenderParameter ( "intPraticaId" , String . valueOf ( intPraticaId ) ) ;
}
public void fixUO ( ActionRequest actionRequest , ActionResponse actionResponse ) throws Exception {
Privati . checkIfUserIsCompanyAdmin ( actionRequest ) ;
long intPraticaId = ParamUtil . getLong ( actionRequest , "intPraticaId" , - 1L ) ;
IntPratica intPratica = IntPraticaLocalServiceUtil . fetchIntPratica ( intPraticaId ) ;
int destinationUO = AdvancedOperationUtil . getDestinationUO ( intPratica ) ;
if ( AdvancedOperationUtil . evalUO ( intPratica ) ) {
_setUO ( intPratica , destinationUO ) ;
}
actionResponse . setRenderParameter ( "intPraticaId" , String . valueOf ( intPraticaId ) ) ;
}
private void _setUO ( IntPratica intPratica , int uo ) throws SystemException , SearchException {
intPratica . setUnitaOperativa ( uo ) ;
IntPraticaLocalServiceUtil . updateIntPratica ( intPratica ) ;
Indexer intPraticaIndexer = IndexerRegistryUtil . getIndexer ( IntPratica . class ) ;
intPraticaIndexer . reindex ( intPratica ) ;
Indexer controlloPraticaIndexer = IndexerRegistryUtil . getIndexer ( ControlloPratica . class ) ;
List < ControlloPratica > controlloPraticas = ControlloPraticaLocalServiceUtil . findByIntPratica ( intPratica . getIntPraticaId ( ) ) ;
if ( ! controlloPraticas . isEmpty ( ) ) {
for ( ControlloPratica controlloPratica : controlloPraticas ) {
if ( controlloPratica . getStatus ( ) = = WorkflowConstants . STATUS_PENDING ) {
controlloPraticaIndexer . reindex ( intPratica ) ;
}
}
}
}
public void ripristinaPraticaVidimata ( ActionRequest actionRequest , ActionResponse actionResponse ) throws Exception {
@ -66,6 +138,7 @@ public class AdvancedOperationPortlet extends MVCPortlet {
if ( WorkflowConstants . STATUS_INCOMPLETE = = intPratica . getStatus ( ) ) {
Privati . ripristinaPratica ( intPratica , WorkflowConstants . STATUS_DRAFT ) ;
actionResponse . setRenderParameter ( "intPraticaId" , String . valueOf ( intPraticaId ) ) ;
} else {
SessionErrors . add ( actionRequest , "operazione-impossibile" ) ;
throw new Exception ( "This Pratica is not in status=5, action RIPRISTINA is not available" ) ;
@ -81,6 +154,7 @@ public class AdvancedOperationPortlet extends MVCPortlet {
if ( WorkflowConstants . STATUS_INCOMPLETE = = intPratica . getStatus ( ) ) {
Privati . ripristinaPratica ( intPratica , WorkflowConstants . STATUS_APPROVED ) ;
actionResponse . setRenderParameter ( "intPraticaId" , String . valueOf ( intPraticaId ) ) ;
} else {
SessionErrors . add ( actionRequest , "operazione-impossibile" ) ;
throw new Exception ( "This Pratica is not in status=5, action RIPRISTINA is not available" ) ;
@ -97,6 +171,7 @@ public class AdvancedOperationPortlet extends MVCPortlet {
for ( DocPratica docPratica : docPraticaOrfani ) {
DocPraticaLocalServiceUtil . deleteDocPratica ( docPratica ) ;
}
actionResponse . setRenderParameter ( "intPraticaId" , String . valueOf ( intPraticaId ) ) ;
}
public void findIntPratica ( ActionRequest actionRequest , ActionResponse actionResponse ) throws Exception {