Search code examples
javaliferayliferay-6

Cannot view asset in workflow liferay


I created a portlet with workflow on liferay portal CE 6.2.0 and added single approver workflow to it after deployment. It works successfully and i can view notification, assign to someone and approve it or reject. But when I click on view button it says "asset not found" enter image description here


I couldn't figure out what I missed. I have the following in my code.

In LocalServiceImpl

assetEntryLocalService.updateEntry(userId, timesheet.getGroupId(),
                date, date, Timesheet.class.getName(),
                timesheet.getPrimaryKey(), timesheet.getUuid(), 0,
                serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames(), true, null, null, null,
                null, ContentTypes.TEXT_HTML, timesheet.getProject(),
                timesheet.getTaskType(), timesheet.getProject() + " : "
                        + timesheet.getTaskType(), null, 0, 0, 0, false);

In AssetRenderer

public String render(RenderRequest request, RenderResponse response,
        String template) throws Exception {
    if (template.equals("full_content")) {
        request.setAttribute("TIMESHEET_ENTRY", _timesheet);
        return "/html/" + template + ".jsp";
    } else {
        return null;
    }
}

In AssetRendererFactory

public AssetRenderer getAssetRenderer(long classPK, int type)
        throws PortalException, SystemException {
    Timesheet timesheet = TimesheetLocalServiceUtil.getTimesheet(classPK);
    return new TimesheetAssetRenderer(timesheet);
}

Is there anything wrong in what I am doing?

I had added the following in my portlet.xml

        <asset-renderer-factory>com.timesheet.asset.TimesheetAssetRendererFactory</asset-renderer-factory>

Is it some other function that i need to override?

I found that the error is thrown from liferay-portal / portal-web / docroot / html / portlet / asset_publisher / view_content.jsp at the below given code point

if (!assetEntry.isVisible() &&
            (assetRenderer.getAssetRendererType() == AssetRendererFactory.TYPE_LATEST_APPROVED)) {

            throw new NoSuchModelException();
    }

Here I could find that even if I set visible to true in my updateEntry method call, it is being set to false. I dont know what to do for this. Where is the problem happening?


Solution

  • (porting my comment as an Answer:)

    AssetEntry belongs to the Liferay's architecture that uses the Service builder ORM implementation. If you open the Liferay source and search for any [SOME_MODEL_CLASS]LocalServiceImpl Class, you can see the update-type functions are following this pattern:

        SOME_MODEL_CLASS obj = sOME_MODEL_CLASSPersistence.findByPrimaryKey(longId);
        obj.setSomeProperty(someValue);
        sOME_MODEL_CLASSPersistence.update(obj, false);
    

    Notice that in the end, they are calling the persistence.update, which will eventually store that change in your database.

    As a rule, when updating a Liferay Object's value, make sure to call SOME_MODEL_CLASSLocalServiceUtil.update() function. For Example, in the following code, I'm trying to update a user's Facebook id:

    Contact cnt =  user.getContact();
    cnt.setFacebookSn(facebookId);
    ContactLocalServiceUtil.updateContact(cnt);
    UserLocalServiceUtil.updateUser(user);