Liferay provide default workflow for inbuild portlets but we can use our custom portlets also.
So, I here for you to implement workflow in our custom portlets and make assist of the activity.
Add entity in portlet service.xml regarding your workflow portlet as shown :
<entity name="XXWorkflow" local-service="true" remote-service="false">
<!-- PK fields -->
<column name="workflowId" type="long" primary="true" />
<!-- Foreign key columns -->
<column name="XXd" type="long" />
<column name="companyId" type="long" />
<column name="groupId" type="long" />
<column name="userId" type="long"/>
<!-- Workflow fields -->
<!-- Resource -->
<column name="resourcePrimKey" type="long"></column>
<column name="title" type="String"></column>
<column name="status" type="int"></column>
<column name="statusByUserId" type="long"></column>
<column name="statusByUserName" type="String"></column>
<column name="statusDate" type="Date"></column>
<!-- Finder methods -->
<finder name="ResourcePrimKey" return-type="RfpWorkflow">
<finder-column name="resourcePrimKey"></finder-column>
</finder>
<finder name="Status" return-type="Collection">
<finder-column name="status"></finder-column>
</finder>
<finder name="R_S" return-type="RfpWorkflow">
<finder-column name="resourcePrimKey"></finder-column>
<finder-column name="status"></finder-column>
</finder>
<!-- end of workflow columns and finders -->
<finder return-type="Collection" name="XXId">
<finder-column name="XXId"></finder-column>
</finder>
<reference package-path="com.liferay.portal" entity="WorkflowInstanceLink"></reference>
<reference package-path="com.liferay.portlet.asset" entity="AssetEntry"></reference>
<reference package-path="com.liferay.portlet.social" entity="SocialActivity"></reference>
</entity>
JSP file:-
submit button action url = "processAction"
Put below code in your controller
public void processAction(ActionRequest request, ActionResponse response)
throws Exception {
//do your required stuff
workflowInitiation(request,response,XX.getXXId(),XX.getXXName());
}
public void workflowInitiation(ActionRequest actionRequest,
ActionResponse actionResponse,long XXId,String XXName) throws IOException, PortletException {
// TODO Auto-generated method stub
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
System.out.println("Title : " + XXName);
XXWorkflowImpl xxWorkflow = new XXWorkflowImpl();
XXWorkflow.setTitle(xxName);
XXWorkflow.setxxId(xxpId);
XXWorkflow.setCompanyId(themeDisplay.getCompanyId());
XXWorkflow.setGroupId(themeDisplay.getScopeGroupId());
ThemeDisplay themeDisplay1 = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
ServiceContext serviceContext;
try {
serviceContext = ServiceContextFactory.getInstance(XXPortlet.class.getName(), actionRequest);
XXWorkflowLocalServiceUtil.addXXWorkflow(XXWorkflow,serviceContext, themeDisplay1.getUserId());
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
Create hanlder Class as below :
public class XXWorkflowHandler extends BaseWorkflowHandler {
public static final String CLASS_NAME = XXWorkflow.class.getName();
public String getClassName() {
return CLASS_NAME;
}
public String getType(Locale locale) {
return LanguageUtil.get(locale, "model.resource." + CLASS_NAME);
}
public Object updateStatus(int status,Map<String, Serializable> workflowContext) throws PortalException,
SystemException {
long userId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
long resourcePrimKey = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext");
return RfpWorkflowLocalServiceUtil.updateStatus(userId, resourcePrimKey,status, serviceContext);
}
}
Add below tag in your liferay-portlet.xml after portlet-name
<workflow-handler>com.xx.RFPWorkflowHandler</workflow-handler>
0 Comment(s)