Kalkidan Chekol
Kalkidan Chekol

Reputation: 39

My workflow Tasks in liferay is empty every time

I am implementing custom portlet with kaleo workflow in liferay 6.2 when I save data, I can see status=1 which is pending. but then nothing show up in My Workflow Tasks, as pending or as complete.

I have two users, The first one(let us say x) is admin who tries to add data, the other(let us say y) has content reviewer role so that he can approve the workflow.

what am I missing: bellow is my code for my Workflow Handler class:

public class BookWorkflowHandler extends BaseWorkflowHandler{

    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 {
        System.out.println("statu while updating in workflow handler"+status);
        long userId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
        long resourcePrimKey = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
        ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext");
        System.out.println("statu while updating in workflow handler"+status);
        return BookLocalServiceUtil.updateStatus(userId, resourcePrimKey, status, serviceContext);

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

and here is my BookLocalSeviceImpl:

public class BookLocalServiceImpl extends BookLocalServiceBaseImpl {

    @SuppressWarnings("deprecation")
    public Book addBook(Book newBook, long userId,
            ServiceContext serviceContext)
                    throws SystemException, PortalException {
        Book book =
                bookPersistence.create(
                        counterLocalService.increment(Book.class.getName()));
        book.setCompanyId(newBook.getCompanyId());
        System.out.println("********group id********"+newBook.getGroupId());
        book.setGroupId(serviceContext.getScopeGroupId());
        book.setUserId(serviceContext.getUserId());
        book.setTitle(newBook.getTitle());
        book.setAuthor(newBook.getAuthor());
        book.setStatus(1);
        bookPersistence.update(book, false);

        assetEntryLocalService.updateEntry(
                userId, book.getGroupId(), Book.class.getName(),
                book.getBookId(), serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames());
        book.setStatus(WorkflowConstants.STATUS_DRAFT);
        System.out.println("status while adding "+book.getStatus());
        WorkflowHandlerRegistryUtil.startWorkflowInstance(
                book.getCompanyId(), book.getGroupId(), userId,
                Book.class.getName(), book.getPrimaryKey(), book,
                serviceContext);

        return book;
    }

    @Override
    public Book updateStatus(long userId, long resourcePrimKey, int status, ServiceContext serviceContext)throws PortalException, SystemException {
            User user = userLocalService.getUser(userId);
            Book book = getBook(resourcePrimKey);
            book.setStatusByUserId(userId);
            book.setStatusByUserName(user.getFullName());
            book.setStatusDate(serviceContext.getModifiedDate());
            bookPersistence.update(book, false);
            System.out.println("status in updateStatus localService******"+status);
    if (status == WorkflowConstants.STATUS_APPROVED) {
        System.out.println("workflow approved");
        assetEntryLocalService.updateVisible(
                Book.class.getName(), resourcePrimKey, true);
    }
    else if(status==1) {
        System.out.println("workflow pending");
        assetEntryLocalService.updateVisible(
                Book.class.getName(), resourcePrimKey, false);
    }
    return book;
}


}

Thanks in advance!

Upvotes: 2

Views: 817

Answers (1)

Russ Bohl
Russ Bohl

Reputation: 211

I don't know exactly what's wrong, but I can help with some troubleshooting/code optimization tips:

  1. Don't set the int "status" value yourself. Let Liferay do it. In the LocalServiceImpl add method, instead of book.setStatus(1); call book.setStatus(WorkflowConstants.STATUS_DRAFT);, which is actually the int value '2'.

  2. In the LocalServiceImpl updateStatusmethod, just set the visibility to false for ALL assets that are not APPROVED, so instead of your else if statement, use

    else {

       assetEntryLocalService.updateVisible(Book.class.getName(),
          resourcePrimKey, false);
    }
    
  3. Neither step 1 or 2 is likely to solve your problem though. Are you using the Single Approver Definition that comes with Liferay, or a different definition? If different, can you paste the definition here? I'd want to make sure that the proper roles are assigned to the review task. I'd also test the workflow with another entity to see if it's working properly.

  4. The Liferay Developer Network (https://dev.liferay.com), the official site for Liferay Development Documentation, has a Learning Path on Enabling entities for workflow, that you might want to look at for code comparison purposes. https://dev.liferay.com/develop/learning-paths/mvc/-/knowledge_base/6-2/approving-content-with-workflow

Upvotes: 1

Related Questions