Hi all again I hava a custom portlet with a single table in service builder. I want to integrate workflow so that insertion of row in the table should go through kaleo workflow so i didn't found a clear tutorial except that one http://liferayzone.wordpress.com/2013/11/29/kaleo-workflow-configuration-for-custom-portlet-in-liferay-6-1/

to have added custom code but when i run an instert item trought the form it get displayed on on a jsp that list all item inserted. the workflow integration didn't worked an nothing got displayed on My Workflow Task. Before doing this i enabled Workflow for my deployed portlet in the control panel.

here is my service builder entity

<author>Cooder</author>
    <namespace>sem</namespace>
    <entity name="OrganizationType" local-service="true" uuid="true">
        <column name="organizationTypeId" primary="true" type="long"></column>
        <column name="organizationTypeName" type="String"></column>
        <column name="userId" type="long"></column>
        <column name="companyId" type="long"></column>
        <column name="groupId" type="long"></column>
        <column name="createDate" type="Date"></column>
        <column name="modifiedDate" type="Date"></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 by="asc">
            <order-column name="createDate" order-by="desc"></order-column>
        </order>
        <finder name="OrganizationTypeName" return-type="Collection">
            <finder-column name="organizationTypeName"></finder-column>
        </finder>
        <finder name="GroupId" return-type="Collection">
            <finder-column name="groupId"></finder-column>
        </finder>
        <finder name="CompanyId" return-type="Collection">
            <finder-column name="companyId"></finder-column>
        </finder>
        <finder name="G_S" return-type="Collection">
            <finder-column name="groupId"></finder-column>
            <finder-column name="status"></finder-column>
        </finder>
        <reference package-path="com.liferay.portal" entity="User"></reference>
        <reference package-path="com.liferay.portlet.asset" entity="AssetEntry"></reference>
    </entity>

Next is my custum organizationImpl class

public class OrganizationTypeLocalServiceImpl
    extends OrganizationTypeLocalServiceBaseImpl {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never reference this interface directly. Always use {@link cm.egov.cameroon.sem.service.service.OrganizationTypeLocalServiceUtil} to access the organization type local service.
     */

    public OrganizationType addOrganizationType(long userId, String organizationTypeName, ServiceContext serviceContext) throws PortalException, SystemException{
        User user = userPersistence.findByPrimaryKey(userId);
        long organizationTypeId = counterLocalService.increment(OrganizationType.class.getName());
        OrganizationType organizationType = organizationTypePersistence.create(organizationTypeId);
        Date now = new Date();

        organizationType.setGroupId(user.getGroupId());
        organizationType.setCompanyId(user.getCompanyId());
        organizationType.setUserId(user.getUserId());
        organizationType.setStatus(WorkflowConstants.STATUS_DRAFT);
        organizationType.setCreateDate(serviceContext.getCreateDate(now));
        //organizationType.setModifiedDate(serviceContext.getModifiedDate(now));

        organizationType.setOrganizationTypeName(organizationTypeName);

        //super.addOrganizationType(organizationType);
        organizationTypePersistence.update(organizationType, false);

        assetEntryLocalService.updateEntry(
                serviceContext.getUserId(), 
                serviceContext.getScopeGroupId(),
                OrganizationType.class.getName(),
                organizationType.getOrganizationTypeId(),
                serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames());

        WorkflowHandlerRegistryUtil.startWorkflowInstance(
                organizationType.getCompanyId(),
                organizationType.getGroupId(),
                organizationType.getUserId(), 
                OrganizationType.class.getName(),
                organizationType.getPrimaryKey(),
                organizationType, serviceContext);

        /*resourceLocalService.addResources(organizationType.getCompanyId(), 
                organizationType.getGroupId(),
                organizationType.getUserId(),
                OrganizationType.class.getName(),
                organizationType.getOrganizationTypeId(),
                false,
                true,
                true);*/

        return organizationType;
    }

    public OrganizationType updateMyOrganizationType(long userId, long organizationTypeId, String organizationTypeName, ServiceContext serviceContext) throws PortalException, SystemException{

        User user = userPersistence.findByPrimaryKey(userId);
        Date now = new Date();

        OrganizationType orgType = OrganizationTypeLocalServiceUtil.fetchOrganizationType(organizationTypeId);

        orgType.setModifiedDate(serviceContext.getModifiedDate(now));
        orgType.setGroupId(user.getGroupId());
        orgType.setCompanyId(user.getCompanyId());
        orgType.setUserId(user.getUserId());
        orgType.setOrganizationTypeName(organizationTypeName);

        super.updateOrganizationType(orgType);

        return orgType;
    }

    public OrganizationType getOrganizationType(long organizationTypeId) throws PortalException, SystemException{
        return organizationTypePersistence.findByPrimaryKey(organizationTypeId);
    }
    public List<OrganizationType> getOrganizationTypeAll() throws SystemException{
        return organizationTypePersistence.findAll();
    }

    public OrganizationType deleteOrganizationType(OrganizationType organizationType) throws SystemException, PortalException{
        assetEntryLocalService.deleteEntry(OrganizationType.class.getName(), organizationType.getOrganizationTypeId());
        return organizationTypePersistence.remove(organizationType);
    }

    public OrganizationType deleteOrganizationType(long organizationTypeId) throws PortalException, SystemException{
        OrganizationType orgType = organizationTypePersistence.findByPrimaryKey(organizationTypeId);
        return deleteOrganizationType(orgType);
    }

    public OrganizationType updateStatus(
            long userId,
            long resourcePrimKey,
            int status,
            ServiceContext serviceContext) throws SystemException, PortalException{
        User user = UserLocalServiceUtil.getUser(userId);
        OrganizationType orgType = OrganizationTypeLocalServiceUtil.getOrganizationType(resourcePrimKey);
        orgType.setStatus(status);
        orgType.setStatusByUserId(userId);
        orgType.setStatusByUserName(user.getFullName());
        orgType.setStatusDate(serviceContext.getModifiedDate());
        organizationTypePersistence.update(orgType, false);
        if(status == WorkflowConstants.STATUS_APPROVED){
            assetEntryLocalService.updateVisible(OrganizationType.class.getName(), resourcePrimKey, true);
        }
        else{
            assetEntryLocalService.updateVisible(OrganizationType.class.getName(), resourcePrimKey, true);
        }
        return orgType;
    }
}

Next is my AssetRendererFactory

public class RendererFactoryOrganizationTypeAsset extends BaseAssetRendererFactory{

    @Override
    public AssetRenderer getAssetRenderer(long classPK, int type)
            throws PortalException, SystemException {
        OrganizationType organizationType = OrganizationTypeLocalServiceUtil.getOrganizationType(classPK);
        return new AssetRendererOrganizationType(organizationType);
    }

    @Override
    public String getClassName() {
        return OrganizationType.class.getName();
    }

    @Override
    public String getType() {
        return "article";
    }

}

Next is my AssetRenderer

public class AssetRendererOrganizationType extends BaseAssetRenderer{

    private OrganizationType _organizationType;
    @Override
    public long getClassPK() {
        return _organizationType.getOrganizationTypeId();
    }

    @Override
    public long getGroupId() {
        return _organizationType.getGroupId();
    }

    @Override
    public String getSummary(Locale arg0) {
        return _organizationType.getOrganizationTypeName();
    }

    @Override
    public String getTitle(Locale arg0) {
        return "Organization type context entry";
    }

    @Override
    public long getUserId() {
        return _organizationType.getUserId();
    }

    @Override
    public String getUserName() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getUuid() {
        return _organizationType.getUuid();
    }

    @Override
    public String render(RenderRequest request, RenderResponse response, String template)
            throws Exception {
        if (template.equals(TEMPLATE_FULL_CONTENT)) {
            return "/html/organizationType.jsp";
        }
        else
        {
            return null;
        }
    }

    public AssetRendererOrganizationType(OrganizationType _organizationType) {
        super();
        this._organizationType = _organizationType;
    }

}

Next is my WorkflowHandler

public class WorkflowHandlerOrganizationType extends BaseWorkflowHandler{

    public static final String CLASS_NAME = OrganizationType.class.getName();

    @Override
    public String getClassName() {
        return CLASS_NAME;
    }

    @Override
    public String getType(Locale locale) {
        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 OrganizationTypeLocalServiceUtil.updateStatus(userId, resourcePrimKey, status, serviceContext);
    }

}

finally Here is the piece of liferay-portlet deployment descriptor

<portlet>
        <portlet-name>SearchEngineManager</portlet-name>
        <icon>/icon.png</icon>
        <asset-renderer-factory>sem.RendererFactoryOrganizationTypeAsset</asset-renderer-factory>
        <workflow-handler>sem.WorkflowHandlerOrganizationType</workflow-handler>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>
            /js/main.js
        </footer-portlet-javascript>
        <css-class-wrapper>
            searchenginemanager-portlet
        </css-class-wrapper>
    </portlet>

please help me to figure out what is missing. I'm using MVCPorltet in liferay 6.1 GA3 with Kaleo workflow

Related posts

Recent Viewed