2014年3月4日 星期二

Kaleo Workflow integration custom portlet

先在自己portlet  建立一個service.xml  以下的欄位可供參考,
建立好後即可build-service。
紅色文字部分是參考到database的 WorkflowInstanceLink 資料表


service.xml


<column name="resourcePrimKey" type="long"></column>
<column name="version" type="int"></column>
<column name="title" type="String"></column>
<column name="content" type="String"></column>
<column name="description" type="String"></column>
<column name="priority" type="int"></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>

<!-- Order -->

<order by="desc">
<order-column name="modifiedDate" />
</order>
<finder name="R_S" return-type="Collection">
<finder-column name="resourcePrimKey"></finder-column>
<finder-column name="status"></finder-column>
</finder>
<reference package-path="com.liferay.portal" entity="WorkflowInstanceLink"></reference>

=====================================================================

接下來 在 Liferay-portlet.xml 中,加入紅色部分<workflow-handler> 的tag,中間包夾的是workflowHandler的JAVA類別路徑。
請自行創建  class  並extends BaseWorkflowHandler ,並orverride 三個 abstract method。


Liferay-portlet.xml

<portlet>
<portlet-name>WorkflowCustom</portlet-name>
<icon>/icon.png</icon>
<workflow-handler>com.xxx.xxx.portlet.ArticleWorkflowHandler</workflow-handler>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<css-class-wrapper>WorkflowCustom-portlet</css-class-wrapper>
</portlet>


您需要擴展com.liferay.portal.kernel.workflow.BaseWorkflowHandler


public class ArticleWorkflowHandler extends BaseWorkflowHandler {

public static final String CLASS_NAME = Demo.class.getName();
@Override
public String getClassName() {
// TODO Auto-generated method stub
return CLASS_NAME;
}

@Override
public String getType(Locale locale) {
// TODO Auto-generated method stub
return LanguageUtil.get(locale, "model.resource." + CLASS_NAME);
}

@Override
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 DemoLocalServiceUtil.updateStatus(userId, resourcePrimKey,status, serviceContext);
}

}
====================================================================

Now you need to implement one method called updateStatus() in you LocalServiceImpl class. which will return object of your model class.


public class DemoLocalServiceImpl extends DemoLocalServiceBaseImpl
{
  public Demo updateStatus(long userId, long resourcePrimKey, int status,ServiceContext serviceContext)   
  {
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    // Article
    Demo dempObj = null;
    dempObj.setStatus(status);
    dempObj.setStatusByUserId(user.getUserId());
    dempObj.setStatusByUserName(user.getFullName());
    dempObj.setStatusDate(serviceContext.getModifiedDate(now));
    demoPersistence.update(dempObj, false);
    if (status != WorkflowConstants.STATUS_APPROVED)
    {
      return dempObj;
    }
    return dempObj;
  }
}
=================================================================================


Now Deploy service and portlet you will find out your asset in control panel as showing below .now you can apply any definition on that.





 
資料來源參考
http://liferayzone.wordpress.com/2013/11/29/kaleo-workflow-configuration-for-custom-portlet-in-liferay-6-1/
http://stackoverflow.com/questions/17853340/kaleo-workflow-in-custom-portlet
http://stackoverflow.com/questions/9511344/how-to-integrate-kaleo-workflow-in-custom-portlet
http://www.cignex.com/articles/applying-advanced-workflow-custom-assets-liferay-6

沒有留言:

張貼留言