@ -83,443 +83,458 @@ import com.liferay.portal.workflow.kaleo.service.KaleoTaskInstanceTokenLocalServ
public class EditWorkflowTaskAction extends BaseStrutsPortletAction {
private final static Log _log = LogFactoryUtil . getLog ( EditWorkflowTaskAction . class ) ;
@Override
public void processAction ( StrutsPortletAction originalStrutsPortletAction , PortletConfig portletConfig ,
ActionRequest actionRequest , ActionResponse actionResponse ) throws Exception {
String cmd = ParamUtil . getString ( actionRequest , Constants . CMD ) ;
if ( cmd . equals ( Constants . SAVE ) | | cmd . equals ( Constants . RESET ) ) {
private final static Log _log = LogFactoryUtil . getLog ( EditWorkflowTaskAction . class ) ;
try {
@Override
public void processAction ( StrutsPortletAction originalStrutsPortletAction , PortletConfig portletConfig ,
ActionRequest actionRequest , ActionResponse actionResponse ) throws Exception {
if ( cmd . equals ( Constants . SAVE ) ) {
completeTask ( actionRequest ) ;
} else if ( cmd . equals ( Constants . RESET ) ) {
relaseTask ( actionRequest ) ;
}
String cmd = ParamUtil . getString ( actionRequest , Constants . CMD ) ;
String redirect = ParamUtil . getString ( actionRequest , "redirect" ) ;
String closeRedirect = ParamUtil . getString ( actionRequest , "closeRedirect" ) ;
if ( cmd . equals ( Constants . SAVE ) | | cmd . equals ( Constants . RESET ) ) {
if ( Validator . isNotNull ( closeRedirect ) ) {
redirect = HttpUtil . setParameter ( redirect , "closeRedirect" , closeRedirect ) ;
try {
if ( cmd . equals ( Constants . SAVE ) ) {
completeTask ( actionRequest ) ;
} else if ( cmd . equals ( Constants . RESET ) ) {
relaseTask ( actionRequest ) ;
}
String redirect = ParamUtil . getString ( actionRequest , "redirect" ) ;
String closeRedirect = ParamUtil . getString ( actionRequest , "closeRedirect" ) ;
if ( Validator . isNotNull ( closeRedirect ) ) {
redirect = HttpUtil . setParameter ( redirect , "closeRedirect" , closeRedirect ) ;
SessionMessages . add ( actionRequest , PortalUtil . getPortletId ( actionRequest )
+ SessionMessages . KEY_SUFFIX_CLOSE_REDIRECT , closeRedirect ) ;
}
sendRedirect ( actionRequest , actionResponse , redirect ) ;
} catch ( Exception e ) {
if ( e instanceof WorkflowTaskDueDateException ) {
SessionErrors . add ( actionRequest , e . getClass ( ) ) ;
} else if ( e instanceof PrincipalException | | e instanceof WorkflowException ) {
SessionErrors . add ( actionRequest , e . getClass ( ) ) ;
setForward ( actionRequest , "portlet.workflow_tasks.error" ) ;
} else {
throw e ;
}
}
} else {
originalStrutsPortletAction . processAction ( originalStrutsPortletAction , portletConfig ,
actionRequest , actionResponse ) ;
}
}
SessionMessages . add ( actionRequest , PortalUtil . getPortletId ( actionRequest )
+ SessionMessages . KEY_SUFFIX_CLOSE_REDIRECT , closeRedirect ) ;
}
protected void assignTask ( ActionRequest actionRequest ) throws Exception {
sendRedirect ( actionRequest , actionResponse , redirect ) ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
} catch ( Exception e ) {
if ( e instanceof WorkflowTaskDueDateException ) {
SessionErrors . add ( actionRequest , e . getClass ( ) ) ;
} else if ( e instanceof PrincipalException | | e instanceof WorkflowException ) {
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
SessionErrors . add ( actionRequest , e . getClass ( ) ) ;
long assigneeUserId = ParamUtil . getLong ( actionRequest , "assigneeUserId" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
setForward ( actionRequest , "portlet.workflow_tasks.error" ) ;
} else {
throw e ;
}
}
} else {
originalStrutsPortletAction . processAction ( originalStrutsPortletAction , portletConfig , actionRequest ,
actionResponse ) ;
}
}
WorkflowTaskManagerUtil . assignWorkflowTaskToUser ( themeDisplay . getCompanyId ( ) ,
themeDisplay . getUserId ( ) , workflowTaskId , assigneeUserId , comment , null , null ) ;
}
protected void completeTask ( ActionRequest actionRequest ) throws Exception {
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
protected void assignTask ( ActionRequest actionRequest ) throws Exception {
String transitionName = ParamUtil . getString ( actionRequest , "transitionName" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
// ADT: bug mancata problema assegnazione WF
checkPresenzaIstruttore ( transitionName , workflowTaskId ) ;
// ADT: BUG ANOMALIA REGISTRA ESITO
if ( transitionName . equalsIgnoreCase ( "registra-esito" ) ) {
HttpServletRequest httpServletRequest = PortalUtil . getOriginalServletRequest ( PortalUtil
. getHttpServletRequest ( actionRequest ) ) ;
String esito = httpServletRequest . getParameter ( "kaleo--esito--" ) ! = null ? httpServletRequest
. getParameter ( "kaleo--esito--" ) . trim ( ) : "" ;
String testoDocumento = httpServletRequest . getParameter ( "kaleo--testo_del_documento--" ) ! = null ? httpServletRequest
. getParameter ( "kaleo--testo_del_documento--" ) : "" ;
List < String > valoriAmmessi = Arrays . asList ( "AL" , "NC" , "CO" , "IN" ) ;
if ( ! valoriAmmessi . contains ( esito ) | | ( esito . equalsIgnoreCase ( "IN" ) & & testoDocumento . isEmpty ( ) ) ) {
_log . error ( "controllo validazione completamento task registra-esito = " + workflowTaskId
+ " non riuscito - esito non valorizzato o esito IN con testo del documento vuoto" ) ;
throw new PortalException (
"controllo validazione completamento task registra-esito non riuscito" ) ;
}
} else if ( transitionName . equalsIgnoreCase ( "Riassegna" ) | | transitionName . equalsIgnoreCase ( "assegna" ) ) {
HttpServletRequest httpServletRequest = PortalUtil . getOriginalServletRequest ( PortalUtil
. getHttpServletRequest ( actionRequest ) ) ;
String istr = httpServletRequest . getParameter ( "kaleo--istruttore--" ) ! = null ? httpServletRequest
. getParameter ( "kaleo--istruttore--" ) . trim ( ) : "" ;
if ( istr . isEmpty ( ) ) {
_log . error ( "controllo validazione completamento task = " + transitionName + " -"
+ workflowTaskId
+ " non riuscito - esito non valorizzato o esito IN con testo del documento vuoto" ) ;
throw new PortalException (
"controllo validazione completamento task registra-esito non riuscito" ) ;
}
}
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
Map < String , Serializable > workflowContext = new HashMap < String , Serializable > ( ) ;
long assigneeUserId = ParamUtil . getLong ( actionRequest , "assigneeUserId" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
workflowContext . put ( WorkflowConstants . CONTEXT_TRANSITION_NAME , transitionName ) ;
WorkflowTaskManagerUtil . assignWorkflowTaskToUser ( themeDisplay . getCompanyId ( ) , themeDisplay . getUserId ( ) ,
workflowTaskId , assigneeUserId , comment , null , null ) ;
}
WorkflowUtil . updateWorkflowContextWithTaskFormParameters ( actionRequest , workflowContext ) ;
protected void completeTask ( ActionRequest actionRequest ) throws Exception {
WorkflowTaskManagerUtil . completeWorkflowTask ( themeDisplay . getCompanyId ( ) , themeDisplay . getUserId ( ) ,
workflowTaskId , transitionName , comment , workflowContext ) ;
}
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
protected void relaseTask ( ActionRequest actionRequest ) throws Exception {
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
String transitionName = ParamUtil . getString ( actionRequest , "transitionName" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
//ADT: bug mancata problema assegnazione WF
checkPresenzaIstruttore ( transitionName , workflowTaskId ) ;
//ADT: BUG ANOMALIA REGISTRA ESITO
if ( transitionName . equalsIgnoreCase ( "registra-esito" ) ) {
HttpServletRequest httpServletRequest = PortalUtil . getOriginalServletRequest ( PortalUtil . getHttpServletRequest ( actionRequest ) ) ;
String esito = httpServletRequest . getParameter ( "kaleo--esito--" ) ! = null ? httpServletRequest . getParameter ( "kaleo--esito--" ) . trim ( ) : "" ;
String testoDocumento = httpServletRequest . getParameter ( "kaleo--testo_del_documento--" ) ! = null ? httpServletRequest . getParameter ( "kaleo--testo_del_documento--" ) : "" ;
List < String > valoriAmmessi = Arrays . asList ( "AL" , "NC" , "CO" , "IN" ) ;
if ( ! valoriAmmessi . contains ( esito ) | | ( esito . equalsIgnoreCase ( "IN" ) & & testoDocumento . isEmpty ( ) ) ) {
_log . error ( "controllo validazione completamento task registra-esito = " + workflowTaskId + " non riuscito - esito non valorizzato o esito IN con testo del documento vuoto" ) ;
throw new PortalException ( "controllo validazione completamento task registra-esito non riuscito" ) ;
}
} else if ( transitionName . equalsIgnoreCase ( "Riassegna" ) | | transitionName . equalsIgnoreCase ( "assegna" ) ) {
HttpServletRequest httpServletRequest = PortalUtil . getOriginalServletRequest ( PortalUtil . getHttpServletRequest ( actionRequest ) ) ;
String istr = httpServletRequest . getParameter ( "kaleo--istruttore--" ) ! = null ? httpServletRequest . getParameter ( "kaleo--istruttore--" ) . trim ( ) : "" ;
if ( istr . isEmpty ( ) ) {
_log . error ( "controllo validazione completamento task = " + transitionName + " -" + workflowTaskId + " non riuscito - esito non valorizzato o esito IN con testo del documento vuoto" ) ;
throw new PortalException ( "controllo validazione completamento task registra-esito non riuscito" ) ;
}
}
/////////////////////////////////////////////////////////
Map < String , Serializable > workflowContext = new HashMap < String , Serializable > ( ) ;
long assigneeUserId = ParamUtil . getLong ( actionRequest , "assigneeUserId" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
workflowContext . put ( WorkflowConstants . CONTEXT_TRANSITION_NAME , transitionName ) ;
WorkflowTaskManagerUtil . assignWorkflowTaskToRole ( themeDisplay . getCompanyId ( ) , assigneeUserId ,
workflowTaskId , 0L , comment , null , null ) ;
}
WorkflowUtil . updateWorkflowContextWithTaskFormParameters ( actionRequest , workflowContext ) ;
protected boolean isCheckMethodOnProcessAction ( ) {
WorkflowTaskManagerUtil . completeWorkflowTask ( themeDisplay . getCompanyId ( ) , themeDisplay . getUserId ( ) , workflowTaskId ,
transitionName , comment , workflowContext ) ;
}
return _CHECK_METHOD_ON_PROCESS_ACTION ;
}
protected void relas eTask ( ActionRequest actionRequest ) throws Exception {
protected void updateTask ( ActionRequest actionRequest ) throws Exception {
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
long assigneeUserId = ParamUtil . getLong ( actionRequest , "assigneeUserId" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
WorkflowTaskManagerUtil . assignWorkflowTaskToRole ( themeDisplay . getCompanyId ( ) , assigneeUserId , workflowTaskId , 0L ,
comment , null , null ) ;
}
int dueDateMonth = ParamUtil . getInteger ( actionRequest , "dueDateMonth" ) ;
int dueDateDay = ParamUtil . getInteger ( actionRequest , "dueDateDay" ) ;
int dueDateYear = ParamUtil . getInteger ( actionRequest , "dueDateYear" ) ;
int dueDateHour = ParamUtil . getInteger ( actionRequest , "dueDateHour" ) ;
int dueDateMinute = ParamUtil . getInteger ( actionRequest , "dueDateMinute" ) ;
int dueDateAmPm = ParamUtil . getInteger ( actionRequest , "dueDateAmPm" ) ;
protected boolean isCheckMethodOnProcessAction ( ) {
if ( dueDateAmPm = = Calendar . PM ) {
dueDateHour + = 12 ;
}
return _CHECK_METHOD_ON_PROCESS_ACTION ;
}
Date dueDate = PortalUtil . getDate ( dueDateMonth , dueDateDay , dueDateYear , dueDateHour , dueDateMinute ,
WorkflowTaskDueDateException . class ) ;
protected void updateTask ( ActionRequest actionRequest ) throws Exception {
WorkflowTaskManagerUtil . updateDueDate ( themeDisplay . getCompanyId ( ) , themeDisplay . getUserId ( ) ,
workflowTaskId , comment , dueDate ) ;
}
ThemeDisplay themeDisplay = ( ThemeDisplay ) actionRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false ;
long workflowTaskId = ParamUtil . getLong ( actionRequest , "workflowTaskId" ) ;
protected void sendRedirect ( ActionRequest actionRequest , ActionResponse actionResponse , String redirect )
throws IOException , SystemException {
String comment = ParamUtil . getString ( actionRequest , "comment" ) ;
sendRedirect ( null , actionRequest , actionResponse , redirect , null ) ;
}
int dueDateMonth = ParamUtil . getInteger ( actionRequest , "dueDateMonth" ) ;
int dueDateDay = ParamUtil . getInteger ( actionRequest , "dueDateDay" ) ;
int dueDateYear = ParamUtil . getInteger ( actionRequest , "dueDateYear" ) ;
int dueDateHour = ParamUtil . getInteger ( actionRequest , "dueDateHour" ) ;
int dueDateMinute = ParamUtil . getInteger ( actionRequest , "dueDateMinute" ) ;
int dueDateAmPm = ParamUtil . getInteger ( actionRequest , "dueDateAmPm" ) ;
protected void sendRedirect ( PortletConfig portletConfig , ActionRequest actionRequest ,
ActionResponse actionResponse , String redirect , String closeRedirect ) throws IOException ,
SystemException {
if ( dueDateAmPm = = Calendar . PM ) {
dueDateHour + = 12 ;
}
if ( isDisplaySuccessMessage ( actionRequest ) ) {
addSuccessMessage ( actionRequest , actionResponse ) ;
}
Date dueDate =
PortalUtil . getDate ( dueDateMonth , dueDateDay , dueDateYear , dueDateHour , dueDateMinute ,
WorkflowTaskDueDateException . class ) ;
if ( Validator . isNull ( redirect ) ) {
redirect = ( String ) actionRequest . getAttribute ( WebKeys . REDIRECT ) ;
}
WorkflowTaskManagerUtil . updateDueDate ( themeDisplay . getCompanyId ( ) , themeDisplay . getUserId ( ) , workflowTaskId ,
comment , dueDate ) ;
}
if ( Validator . isNull ( redirect ) ) {
redirect = ParamUtil . getString ( actionRequest , "redirect" ) ;
}
private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false ;
if ( ( portletConfig ! = null ) & & Validator . isNotNull ( redirect ) & & Validator . isNotNull ( closeRedirect ) ) {
protected void sendRedirect ( ActionRequest actionRequest , ActionResponse actionResponse , String redirect )
throws IOException , SystemException {
redirect = HttpUtil . setParameter ( redirect , "closeRedirect" , closeRedirect ) ;
sendRedirect ( null , actionRequest , actionResponse , redirect , null ) ;
}
SessionMessages . add ( actionRequest , PortalUtil . getPortletId ( actionRequest )
+ SessionMessages . KEY_SUFFIX_CLOSE_REDIRECT , closeRedirect ) ;
}
protected void sendRedirect ( PortletConfig portletConfig , ActionRequest actionRequest , ActionResponse actionResponse ,
String redirect , String closeRedirect ) throws IOException , SystemException {
if ( Validator . isNull ( redirect ) ) {
return ;
}
if ( isDisplaySuccessMessage ( actionRequest ) ) {
addSuccessMessage ( actionRequest , actionResponse ) ;
}
// LPS-1928
if ( Validator . isNull ( redirect ) ) {
redirect = ( String ) actionRequest . getAttribute ( WebKeys . REDIRECT ) ;
}
HttpServletRequest request = PortalUtil . getHttpServletRequest ( actionRequest ) ;
if ( Validator . isNull ( redirect ) ) {
redirect = ParamUtil . getString ( actionRequest , "redirect" ) ;
}
if ( BrowserSnifferUtil . isIe ( request ) & & ( BrowserSnifferUtil . getMajorVersion ( request ) = = 6 . 0 )
& & redirect . contains ( StringPool . POUND ) ) {
if ( ( portletConfig ! = null ) & & Validator . isNotNull ( redirect ) & & Validator . isNotNull ( closeRedirect ) ) {
String redirectToken = "&#" ;
redirect = HttpUtil . setParameter ( redirect , "closeRedirect" , closeRedirect ) ;
if ( ! redirect . contains ( StringPool . QUESTION ) ) {
redirectToken = StringPool . QUESTION + redirectToken ;
}
SessionMessages . add ( actionRequest , PortalUtil . getPortletId ( actionRequest )
+ SessionMessages . KEY_SUFFIX_CLOSE_REDIRECT , closeRedirect ) ;
}
redirect = StringUtil . replace ( redirect , StringPool . POUND , redirectToken ) ;
}
if ( Validator . isNull ( redirect ) ) {
return ;
}
redirect = PortalUtil . escapeRedirect ( redirect ) ;
// LPS-1928
if ( Validator . isNotNull ( redirect ) ) {
actionResponse . sendRedirect ( redirect ) ;
}
}
HttpServletRequest request = PortalUtil . getHttpServletRequest ( actionRequest ) ;
protected boolean isDisplaySuccessMessage ( PortletRequest portletRequest ) throws SystemException {
if ( BrowserSnifferUtil . isIe ( request ) & & ( BrowserSnifferUtil . getMajorVersion ( request ) = = 6 . 0 )
& & redirect . contains ( StringPool . POUND ) ) {
if ( ! SessionErrors . isEmpty ( portletRequest ) ) {
return false ;
}
String redirectToken = "&#" ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) portletRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
if ( ! redirect . contains ( StringPool . QUESTION ) ) {
redirectToken = StringPool . QUESTION + redirectToken ;
}
Layout layout = themeDisplay . getLayout ( ) ;
redirect = StringUtil . replace ( redirect , StringPool . POUND , redirectToken ) ;
}
if ( layout . isTypeControlPanel ( ) ) {
return true ;
}
redirect = PortalUtil . escapeRedirect ( redirect ) ;
String portletId = ( String ) portletRequest . getAttribute ( WebKeys . PORTLET_ID ) ;
if ( Validator . isNotNull ( redirect ) ) {
actionResponse . sendRedirect ( redirect ) ;
}
}
try {
LayoutTypePortlet layoutTypePortlet = themeDisplay . getLayoutTypePortlet ( ) ;
protected boolean isDisplaySuccessMessage ( PortletRequest portletRequest ) throws SystemException {
if ( layoutTypePortlet . hasPortletId ( portletId ) ) {
return true ;
}
} catch ( PortalException pe ) {
if ( _log . isDebugEnabled ( ) ) {
_log . debug ( pe , pe ) ;
}
}
if ( ! SessionErrors . isEmpty ( portletRequest ) ) {
return false ;
}
Portlet portlet = PortletLocalServiceUtil . getPortletById ( themeDisplay . getCompanyId ( ) , portletId ) ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) portletRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
if ( portlet . isAddDefaultResource ( ) ) {
return true ;
}
Layout layout = themeDisplay . getLayout ( ) ;
return false ;
}
if ( layout . isTypeControlPanel ( ) ) {
return true ;
}
protected void addSuccessMessage ( ActionRequest actionRequest , ActionResponse actionResponse ) {
String portletId = ( String ) portletRequest . getAttribute ( WebKeys . PORTLET_ID ) ;
PortletConfig portletConfig = ( PortletConfig ) actionRequest
. getAttribute ( JavaConstants . JAVAX_PORTLET_CONFIG ) ;
try {
LayoutTypePortlet layoutTypePortlet = themeDisplay . getLayoutTypePortlet ( ) ;
boolean addProcessActionSuccessMessage = GetterUtil . getBoolean (
portletConfig . getInitParameter ( "add-process-action-success-action" ) , true ) ;
if ( layoutTypePortlet . hasPortletId ( portletId ) ) {
return true ;
}
} catch ( PortalException pe ) {
if ( _log . isDebugEnabled ( ) ) {
_log . debug ( pe , pe ) ;
}
}
if ( ! addProcessActionSuccessMessage ) {
return ;
}
Portlet portlet = PortletLocalServiceUtil . getPortletById ( themeDisplay . getCompanyId ( ) , portletId ) ;
String successMessage = ParamUtil . getString ( actionRequest , "successMessage" ) ;
if ( portlet . isAddDefaultResource ( ) ) {
return true ;
}
SessionMessages . add ( actionRequest , "requestProcessed" , successMessage ) ;
}
return false ;
}
protected void setForward ( PortletRequest portletRequest , String forward ) {
protected void addSuccessMessage ( ActionRequest actionRequest , ActionResponse actionResponse ) {
portletRequest . setAttribute ( getForwardKey ( portletRequest ) , forward ) ;
}
PortletConfig portletConfig = ( PortletConfig ) actionRequest . getAttribute ( JavaConstants . JAVAX_PORTLET_CONFIG ) ;
public static String getForwardKey ( PortletRequest portletRequest ) {
boolean addProcessActionSuccessMessage =
GetterUtil . getBoolean ( portletConfig . getInitParameter ( "add-process-action-success-action" ) , true ) ;
String portletId = ( String ) portletRequest . getAttribute ( WebKeys . PORTLET_ID ) ;
if ( ! addProcessActionSuccessMessage ) {
return ;
}
String portletNamespace = PortalUtil . getPortletNamespace ( portletId ) ;
String successMessage = ParamUtil . getString ( actionRequest , "successMessage" ) ;
return portletNamespace . concat ( PORTLET_STRUTS_FORWARD ) ;
}
SessionMessages . add ( actionRequest , "requestProcessed" , successMessage ) ;
}
private final static String PORTLET_STRUTS_FORWARD = "PORTLET_STRUTS_FORWARD" ;
protected void setForward ( PortletRequest portletRequest , String forward ) {
@Override
public String render ( StrutsPortletAction originalStrutsPortletAction , PortletConfig portletConfig ,
RenderRequest renderRequest , RenderResponse renderResponse ) throws Exception {
portletRequest . setAttribute ( getForwardKey ( portletRequest ) , forward ) ;
}
ThemeDisplay themeDisplay = ( ThemeDisplay ) renderRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
public static String getForwardKey ( PortletRequest portletRequest ) {
long workflowTaskId = ParamUtil . getLong ( renderRequest , "workflowTaskId" ) ;
String portletId = ( String ) portletRequest . getAttribute ( WebKeys . PORTLET_ID ) ;
WorkflowTask workflowTask = null ;
String portletNamespace = PortalUtil . getPortletNamespace ( portletId ) ;
if ( workflowTaskId > 0 ) {
workflowTask = WorkflowTaskManagerUtil . getWorkflowTask ( themeDisplay . getCompanyId ( ) ,
workflowTaskId ) ;
}
return portletNamespace . concat ( PORTLET_STRUTS_FORWARD ) ;
}
String valoreTransizioneEsito = getTransitionValue ( workflowTask . getWorkflowInstanceId ( ) ,
"registra-esito" ) ;
String valoreTransizioneAssegna = getTransitionValue ( workflowTask . getWorkflowInstanceId ( ) , "assegna" ) ;
private final static String PORTLET_STRUTS_FORWARD = "PORTLET_STRUTS_FORWARD" ;
renderRequest . setAttribute ( "registra-esito-value" , valoreTransizioneEsito ) ;
renderRequest . setAttribute ( "assegna-value" , valoreTransizioneAssegna ) ;
@Override
public String render ( StrutsPortletAction originalStrutsPortletAction , PortletConfig portletConfig ,
RenderRequest renderRequest , RenderResponse renderResponse ) throws Exception {
// Gestione permessi action button
ControlloPratica controlloPratica = getControlloPratica ( workflowTask . getWorkflowInstanceId ( ) ) ;
ThemeDisplay themeDisplay = ( ThemeDisplay ) renderRequest . getAttribute ( WebKeys . THEME_DISPLAY ) ;
// ADT BUG BO ID=33
renderRequest . setAttribute (
"historyWorkflowEsitiLogs" ,
getHistoryWorkfloLogs ( themeDisplay , workflowTask . getWorkflowInstanceId ( ) , renderRequest ,
controlloPratica ) ) ;
long workflowTaskId = ParamUtil . getLong ( renderRequest , "workflowTaskId" ) ;
long groupIdTerritorio = controlloPratica . getGroupId ( ) ;
Group group = GroupLocalServiceUtil . getGroup ( groupIdTerritorio ) ;
WorkflowTask workflowTask = null ;
User user = themeDisplay . getUser ( ) ;
Organization org = OrganizationLocalServiceUtil . getOrganization ( group . getClassPK ( ) ) ;
if ( workflowTaskId > 0 ) {
workflowTask = WorkflowTaskManagerUtil . getWorkflowTask ( themeDisplay . getCompanyId ( ) , workflowTaskId ) ;
}
boolean canPortosAssegnatore = UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) ,
org . getGroupId ( ) , "portos_assegnatore" ) ;
boolean canPortosApprovatore = UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) ,
org . getGroupId ( ) , "portos_approvatore" ) ;
String valoreTransizioneEsito = getTransitionValue ( workflowTask . getWorkflowInstanceId ( ) , "registra-esito" ) ;
String valoreTransizioneAssegna = getTransitionValue ( workflowTask . getWorkflowInstance Id ( ) , "assegna " ) ;
boolean canPortosIstruttore = UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) ,
org . getGroup Id ( ) , "portos_istruttore " ) ;
renderRequest . setAttribute ( "registra-esito-value" , valoreTransizioneEsito ) ;
renderRequest . setAttribute ( "assegna-value" , valoreTransizioneAssegna ) ;
// Gestione permessi action button
ControlloPratica controlloPratica = getControlloPratica ( workflowTask . getWorkflowInstanceId ( ) ) ;
//ADT BUG BO ID=33
renderRequest . setAttribute ( "historyWorkflowEsitiLogs" , getHistoryWorkfloLogs ( themeDisplay , workflowTask . getWorkflowInstanceId ( ) , renderRequest , controlloPratica ) ) ;
long groupIdTerritorio = controlloPratica . getGroupId ( ) ;
Group group = GroupLocalServiceUtil . getGroup ( groupIdTerritorio ) ;
renderRequest . setAttribute ( "canPortosAssegnatore" , canPortosAssegnatore ) ;
renderRequest . setAttribute ( "canPortosApprovatore" , canPortosApprovatore ) ;
renderRequest . setAttribute ( "canPortosIstruttore" , canPortosIstruttore ) ;
User user = themeDisplay . getUser ( ) ;
Organization org = OrganizationLocalServiceUtil . getOrganization ( group . getClassPK ( ) ) ;
return originalStrutsPortletAction . render ( originalStrutsPortletAction , portletConfig , renderRequest ,
renderResponse ) ;
}
boolean canPortosAssegnatore =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) , org . getGroupId ( ) , "portos_assegnatore" ) ;
boolean canPortosApprovatore =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) , org . getGroupId ( ) , "portos_approvatore" ) ;
private String getTransitionValue ( long taskInstanceId , String transitionName ) throws PortalException ,
SystemException {
ClassLoader classLoaderKaleoLog = ( ClassLoader ) PortletBeanLocatorUtil . locate (
it . tref . liferay . portos . kaleo . service . ClpSerializer . getServletContextName ( ) ,
"portletClassLoader" ) ;
DynamicQuery dqKaleoLog = DynamicQueryFactoryUtil . forClass ( FormLog . class , classLoaderKaleoLog ) ;
dqKaleoLog . add ( RestrictionsFactoryUtil . eq ( "workflowInstanceId" , taskInstanceId ) ) ;
dqKaleoLog . add ( RestrictionsFactoryUtil . eq ( "transitionName" , transitionName ) ) ;
List < FormLog > listaKaleoLog = FormLogLocalServiceUtil . dynamicQuery ( dqKaleoLog ) ;
if ( listaKaleoLog ! = null & & ! listaKaleoLog . isEmpty ( ) ) {
FormLog formLog = listaKaleoLog . get ( 0 ) ;
JSONObject json = JSONFactoryUtil . createJSONObject ( formLog . getFormParameters ( ) ) ;
KaleoInstance kaleoInstance = KaleoInstanceLocalServiceUtil . getKaleoInstance ( taskInstanceId ) ;
ControlloPratica controlloPratica = ControlloPraticaLocalServiceUtil
. getControlloPratica ( kaleoInstance . getClassPK ( ) ) ;
if ( json . has ( "esito" ) ) {
String tipoEsito = "" ;
String appStirng = json . getString ( "esito" ) ;
switch ( appStirng ) {
case "IN" :
tipoEsito = "Richiesta Integrazione" ;
break ;
case "CO" :
if ( AzioniPraticheUtil . isDeposito ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Conforme" ;
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Autorizzata" ;
}
break ;
boolean canPortosIstruttore =
UserGroupRoleLocalServiceUtil . hasUserGroupRole ( user . getUserId ( ) , org . getGroupId ( ) , "portos_istruttore" ) ;
case "NC" :
if ( AzioniPraticheUtil . isDeposito ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Non conforme" ;
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Non autorizzata" ;
}
break ;
renderRequest . setAttribute ( "canPortosAssegnatore" , canPortosAssegnatore ) ;
renderRequest . setAttribute ( "canPortosApprovatore" , canPortosApprovatore ) ;
renderRequest . setAttribute ( "canPortosIstruttore" , canPortosIstruttore ) ;
case "AL" :
tipoEsito = "Annullata" ;
break ;
default :
break ;
}
return tipoEsito ;
return originalStrutsPortletAction . render ( originalStrutsPortletAction , portletConfig , renderRequest , renderResponse ) ;
}
} else if ( json . has ( "istruttore" ) ) {
private String getTransitionValue ( long taskInstanceId , String transitionName ) throws PortalException , SystemException {
String userIdIstruttore = json . getString ( "istruttore" ) ;
User istruttore = UserLocalServiceUtil . fetchUser ( Long . parseLong ( userIdIstruttore ) ) ;
if ( Validator . isNotNull ( istruttore ) ) {
return istruttore . getFullName ( ) ;
}
ClassLoader classLoaderKaleoLog =
( ClassLoader ) PortletBeanLocatorUtil . locate (
it . tref . liferay . portos . kaleo . service . ClpSerializer . getServletContextName ( ) , "portletClassLoader" ) ;
}
DynamicQuery dqKaleoLog = DynamicQueryFactoryUtil . forClass ( FormLog . class , classLoaderKaleoLog ) ;
dqKaleoLog . add ( RestrictionsFactoryUtil . eq ( "workflowInstanceId" , taskInstanceId ) ) ;
dqKaleoLog . add ( RestrictionsFactoryUtil . eq ( "transitionName" , transitionName ) ) ;
}
List < FormLog > listaKaleoLog = FormLogLocalServiceUtil . dynamicQuery ( dqKaleoLog ) ;
if ( listaKaleoLog ! = null & & ! listaKaleoLog . isEmpty ( ) ) {
FormLog formLog = listaKaleoLog . get ( 0 ) ;
JSONObject json = JSONFactoryUtil . createJSONObject ( formLog . getFormParameters ( ) ) ;
return null ;
}
KaleoInstance kaleoInstance = KaleoInstanceLocalServiceUtil . getKaleoInstance ( taskInstanceId ) ;
ControlloPratica controlloPratica =
ControlloPraticaLocalServiceUtil . getControlloPratica ( kaleoInstance . getClassPK ( ) ) ;
private ControlloPratica getControlloPratica ( long taskInstanceId ) throws PortalException , SystemException {
if ( json . has ( "esito" ) ) {
String tipoEsito = "" ;
String appStirng = json . getString ( "esito" ) ;
switch ( appStirng ) {
case "IN" :
tipoEsito = "Richiesta Integrazione" ;
break ;
ClassLoader classLoaderKaleoLog = ( ClassLoader ) PortletBeanLocatorUtil . locate (
it . tref . liferay . portos . kaleo . service . ClpSerializer . getServletContextName ( ) ,
"portletClassLoader" ) ;
case "CO" :
if ( AzioniPraticheUtil . isDeposito ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Conforme" ;
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Autorizzata" ;
}
break ;
KaleoInstance kaleoInstance = KaleoInstanceLocalServiceUtil . getKaleoInstance ( taskInstanceId ) ;
ControlloPratica controlloPratica = ControlloPraticaLocalServiceUtil
. getControlloPratica ( kaleoInstance . getClassPK ( ) ) ;
case "NC" :
if ( AzioniPraticheUtil . isDeposito ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Non conforme" ;
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Non autorizzata" ;
}
break ;
return controlloPratica ;
}
case "AL" :
tipoEsito = "Annullata" ;
break ;
default :
break ;
}
return tipoEsito ;
} else if ( json . has ( "istruttore" ) ) {
String userIdIstruttore = json . getString ( "istruttore" ) ;
User istruttore = UserLocalServiceUtil . fetchUser ( Long . parseLong ( userIdIstruttore ) ) ;
if ( Validator . isNotNull ( istruttore ) ) {
return istruttore . getFullName ( ) ;
}
}
}
return null ;
}
private ControlloPratica getControlloPratica ( long taskInstanceId ) throws PortalException , SystemException {
ClassLoader classLoaderKaleoLog =
( ClassLoader ) PortletBeanLocatorUtil . locate (
it . tref . liferay . portos . kaleo . service . ClpSerializer . getServletContextName ( ) , "portletClassLoader" ) ;
KaleoInstance kaleoInstance = KaleoInstanceLocalServiceUtil . getKaleoInstance ( taskInstanceId ) ;
ControlloPratica controlloPratica =
ControlloPraticaLocalServiceUtil . getControlloPratica ( kaleoInstance . getClassPK ( ) ) ;
return controlloPratica ;
}
/ * *
* ADT BUG BO ID = 33 - implementazione nuovo metodo
*
* @param themeDisplay
* @param workflowInstanceId
* @param renderRequest
* @param controlloPratica
* @return
* /
private Map < Long , String > getHistoryWorkfloLogs ( ThemeDisplay themeDisplay , long workflowInstanceId , RenderRequest renderRequest , ControlloPratica controlloPratica ) {
Map < Long , String > esitiMapByWorkflowLogID = new HashMap < Long , String > ( ) ;
try {
/ * *
* ADT BUG BO ID = 33 - implementazione nuovo metodo
*
* @param themeDisplay
* @param workflowInstanceId
* @param renderRequest
* @param controlloPratica
* @return
* /
private Map < Long , String > getHistoryWorkfloLogs ( ThemeDisplay themeDisplay , long workflowInstanceId ,
RenderRequest renderRequest , ControlloPratica controlloPratica ) {
Map < Long , String > esitiMapByWorkflowLogID = new HashMap < Long , String > ( ) ;
try {
List < Integer > logTypes = new ArrayList < Integer > ( ) ;
logTypes . add ( WorkflowLog . TASK_ASSIGN ) ;
logTypes . add ( WorkflowLog . TASK_COMPLETION ) ;
logTypes . add ( WorkflowLog . TASK_UPDATE ) ;
logTypes . add ( WorkflowLog . TRANSITION ) ;
List < WorkflowLog > workflowLogs = WorkflowLogManagerUtil . getWorkflowLogsByWorkflowInstance ( themeDisplay . getCompanyId ( ) , workflowInstanceId , logTypes , QueryUtil . ALL_POS , QueryUtil . ALL_POS , WorkflowComparatorFactoryUtil . getLogCreateDateComparator ( true ) ) ;
List < WorkflowLog > workflowLogs = WorkflowLogManagerUtil . getWorkflowLogsByWorkflowInstance (
themeDisplay . getCompanyId ( ) , workflowInstanceId , logTypes , QueryUtil . ALL_POS ,
QueryUtil . ALL_POS , WorkflowComparatorFactoryUtil . getLogCreateDateComparator ( true ) ) ;
for ( WorkflowLog workflowLog : workflowLogs ) {
try {
WorkflowTask wfTask = null ;
if ( workflowLog . getWorkflowTaskId ( ) > 0 ) {
wfTask = WorkflowTaskManagerUtil . getWorkflowTask ( themeDisplay . getCompanyId ( ) , workflowLog . getWorkflowTaskId ( ) ) ;
wfTask = WorkflowTaskManagerUtil . getWorkflowTask ( themeDisplay . getCompanyId ( ) ,
workflowLog . getWorkflowTaskId ( ) ) ;
ServiceContext serviceContext = ServiceContextFactory . getInstance ( renderRequest ) ;
FormLog formLog = FormLogLocalServiceUtil . findByC_Task ( serviceContext . getCompanyId ( ) , wfTask . getWorkflowTaskId ( ) ) ;
FormLog formLog = FormLogLocalServiceUtil . findByC_Task ( serviceContext . getCompanyId ( ) ,
wfTask . getWorkflowTaskId ( ) ) ;
if ( formLog ! = null & & Validator . isNotNull ( formLog . getFormParameters ( ) ) ) {
if ( formLog ! = null & & Validator . isNotNull ( formLog . getFormParameters ( ) ) ) {
JSONObject json = JSONFactoryUtil . createJSONObject ( formLog . getFormParameters ( ) ) ;
if ( json . has ( "esito" ) ) {
String tipoEsito = "" ;
@ -530,11 +545,10 @@ public class EditWorkflowTaskAction extends BaseStrutsPortletAction {
break ;
case "CO" :
if ( AzioniPraticheUtil . isDeposito ( controlloPratica
. getIntPraticaId ( ) ) ) {
if ( AzioniPraticheUtil . isDeposito ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Conforme" ;
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica
. getIntPraticaId ( ) ) ) {
. getIntPraticaId ( ) ) ) {
tipoEsito = "Autorizzata" ;
}
break ;
@ -542,7 +556,8 @@ public class EditWorkflowTaskAction extends BaseStrutsPortletAction {
case "NC" :
if ( AzioniPraticheUtil . isDeposito ( controlloPratica . getIntPraticaId ( ) ) ) {
tipoEsito = "Non conforme" ;
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica . getIntPraticaId ( ) ) ) {
} else if ( AzioniPraticheUtil . isAutorizzazione ( controlloPratica
. getIntPraticaId ( ) ) ) {
tipoEsito = "Non autorizzata" ;
}
break ;
@ -555,7 +570,9 @@ public class EditWorkflowTaskAction extends BaseStrutsPortletAction {
break ;
}
//_log.info("WorkflowLogId="+ workflowLog.getWorkflowLogId() + " "+ tipoEsito);
// _log.info("WorkflowLogId="+
// workflowLog.getWorkflowLogId() + " "+
// tipoEsito);
esitiMapByWorkflowLogID . put ( workflowLog . getWorkflowLogId ( ) , tipoEsito ) ;
}
}
@ -575,26 +592,31 @@ public class EditWorkflowTaskAction extends BaseStrutsPortletAction {
return esitiMapByWorkflowLogID ;
}
/ * *
* ADT : check congruenza WF - presenza dell ' istruttore
*
*
* @param transitionName
* @param workflowTaskId
* /
/ * *
* ADT : check congruenza WF - presenza dell ' istruttore
*
*
* @param transitionName
* @param workflowTaskId
* /
private void checkPresenzaIstruttore ( String transitionName , long workflowTaskId ) {
if ( transitionName . equalsIgnoreCase ( "registra-esito" ) ) {
try {
KaleoTaskInstanceToken kaleoTaskInstanceToken = KaleoTaskInstanceTokenLocalServiceUtil . getKaleoTaskInstanceToken ( workflowTaskId ) ;
ControlloPratica controlloPratica = getControlloPratica ( kaleoTaskInstanceToken . getKaleoInstanceId ( ) ) ;
Map < String , Serializable > wfParameters = it . tref . liferay . portos . bo . util . WorkflowUtil . getFormParameters ( controlloPratica ) ;
KaleoTaskInstanceToken kaleoTaskInstanceToken = KaleoTaskInstanceTokenLocalServiceUtil
. getKaleoTaskInstanceToken ( workflowTaskId ) ;
ControlloPratica controlloPratica = getControlloPratica ( kaleoTaskInstanceToken
. getKaleoInstanceId ( ) ) ;
Map < String , Serializable > wfParameters = it . tref . liferay . portos . bo . util . WorkflowUtil
. getFormParameters ( controlloPratica ) ;
String istruttore = ( String ) wfParameters . get ( "istruttore" ) ;
_log . info ( "checkPresenzaIstruttore - istruttore presente sul workflow= " + istruttore + " - ControlloPraticaId = " + controlloPratica . getControlloPraticaId ( ) ) ;
_log . info ( "checkPresenzaIstruttore - istruttore presente sul workflow= " + istruttore
+ " - ControlloPraticaId = " + controlloPratica . getControlloPraticaId ( ) ) ;
if ( istruttore = = null ) {
_log . info ( "checkPresenzaIstruttore - rilevata incongrueza WF - istruttore non presente per controlloPratica = " + controlloPratica . getControlloPraticaId ( ) ) ;
long istruttoreId = IntPraticaLocalServiceUtil . getIntPratica ( controlloPratica . getIntPraticaId ( ) ) . getStatusByUserId ( ) ;
_log . info ( "checkPresenzaIstruttore - rilevata incongrueza WF - istruttore non presente per controlloPratica = "
+ controlloPratica . getControlloPraticaId ( ) ) ;
long istruttoreId = IntPraticaLocalServiceUtil . getIntPratica (
controlloPratica . getIntPraticaId ( ) ) . getStatusByUserId ( ) ;
if ( istruttoreId > 0 ) {
String jsonFormParameters = null ;
Map < String , Serializable > parametri = new HashMap < String , Serializable > ( ) ;
@ -605,15 +627,19 @@ public class EditWorkflowTaskAction extends BaseStrutsPortletAction {
ServiceContext serviceContext = new ServiceContext ( ) ;
serviceContext . setCompanyId ( controlloPratica . getCompanyId ( ) ) ;
serviceContext . setUserId ( controlloPratica . getUserId ( ) ) ;
FormLogLocalServiceUtil . addFormLog ( kaleoTaskInstanceToken . getKaleoInstanceId ( ) , 0l , "cambio-istruttore" , jsonFormParameters , serviceContext ) ;
_log . info ( "checkPresenzaIstruttore correttamente eseguito - ControlloPraticaId = " + controlloPratica . getControlloPraticaId ( ) ) ;
} else {
_log . info ( "checkPresenzaIstruttore KO - istruttore non calcolato - ControlloPraticaId = " + controlloPratica . getControlloPraticaId ( ) ) ;
FormLogLocalServiceUtil . addFormLog ( kaleoTaskInstanceToken . getKaleoInstanceId ( ) , 0l ,
"cambio-istruttore" , jsonFormParameters , serviceContext ) ;
_log . info ( "checkPresenzaIstruttore correttamente eseguito - ControlloPraticaId = "
+ controlloPratica . getControlloPraticaId ( ) ) ;
} else {
_log . info ( "checkPresenzaIstruttore KO - istruttore non calcolato - ControlloPraticaId = "
+ controlloPratica . getControlloPraticaId ( ) ) ;
}
}
} catch ( Exception e ) {
_log . error ( "checkPresenzaIstruttore KO per workflowTaskId = " + workflowTaskId + " [" + e . getMessage ( ) + " , " + e . getCause ( ) + "]" ) ;
_log . error ( "checkPresenzaIstruttore KO per workflowTaskId = " + workflowTaskId + " ["
+ e . getMessage ( ) + " , " + e . getCause ( ) + "]" ) ;
}
}
}