Example usage for com.liferay.portal.kernel.workflow WorkflowHandlerRegistryUtil startWorkflowInstance

List of usage examples for com.liferay.portal.kernel.workflow WorkflowHandlerRegistryUtil startWorkflowInstance

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowHandlerRegistryUtil startWorkflowInstance.

Prototype

public static <T> void startWorkflowInstance(long companyId, long userId, String className, long classPK,
            T model, ServiceContext serviceContext) throws PortalException 

Source Link

Usage

From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public LMSBook addEntry(long userId, long groupId, long companyId, String bookTitle, String author,
        String description, ServiceContext serviceContext) throws PortalException, SystemException {

    LMSBook lmsBook = null;//from   w  w w .j  a va  2  s  .  c o  m
    long classPK = 0l;

    String userName = userLocalService.getUser(userId).getFullName();
    //lmsBook = super.addLMSBook(lmsBook);

    try {
        classPK = CounterLocalServiceUtil.increment(LMSBook.class.getName());
        lmsBook = LMSBookLocalServiceUtil.createLMSBook(classPK);
        lmsBook.setBookTitle(bookTitle);
        lmsBook.setAuthor(author);
        lmsBook.setCreateDate(new Date());
        lmsBook.setModifiedDate(new Date());
        lmsBook.setCompanyId(companyId);
        lmsBook.setGroupId(groupId);
        lmsBook.setUserId(userId);
        lmsBook.setDescription(description);
        lmsBook.setUserName(userName);
        lmsBook.setStatus(WorkflowConstants.STATUS_DRAFT);
        lmsBook = LMSBookLocalServiceUtil.addLMSBook(lmsBook);

        WorkflowHandlerRegistryUtil.startWorkflowInstance(lmsBook.getCompanyId(), lmsBook.getUserId(),
                LMSBook.class.getName(), lmsBook.getBookId(), lmsBook, serviceContext);
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Resources
    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addEntryResources(lmsBook, userId, groupId, companyId, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(lmsBook, userId, groupId, companyId, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }
    // Asset
    updateAsset(userId, groupId, lmsBook, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());

    // Social Activity
    SocialActivityLocalServiceUtil.addUniqueActivity(userId, groupId, LMSBook.class.getName(), classPK,
            LibraryActivityKeys.ADD_ENTRY, StringPool.BLANK, 0);

    return lmsBook;
}

From source file:com.maximgalushka.service.service.impl.DocumentLocalServiceImpl.java

License:Open Source License

public Document addDocument(Document document, ServiceContext serviceContext) throws SystemException {

    Document newInstance = documentPersistence.create(counterLocalService.increment(Document.class.getName()));
    newInstance.setStatus(WorkflowConstants.STATUS_DRAFT);
    newInstance.setTitle(document.getTitle());
    newInstance.setUserId(document.getUserId());
    newInstance.setCompanyId(document.getCompanyId());
    newInstance.setGroupId(document.getGroupId());
    newInstance.setType(document.getType());

    documentPersistence.update(newInstance, false);

    try {/*w  w  w. j a  v  a 2 s.co m*/
        resourceLocalService.addResources(newInstance.getCompanyId(), newInstance.getGroupId(),
                newInstance.getUserId(), Document.class.getName(), newInstance.getPrimaryKey(), false, true,
                true);

    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        // assetEntryLocalService.addAssetEntry();
        //         assetEntryLocalService.createAssetEntry(entryId)
        assetEntryLocalService.updateEntry(newInstance.getUserId(), newInstance.getGroupId(),
                Document.class.getName(), newInstance.getPrimaryKey(), serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames());
    } catch (PortalException e1) {
        e1.printStackTrace();
    }

    try {
        WorkflowHandlerRegistryUtil.startWorkflowInstance(newInstance.getCompanyId(), newInstance.getUserId(),
                Document.class.getName(), newInstance.getPrimaryKey(), newInstance, serviceContext);

    } catch (PortalException e) {
        e.printStackTrace();
    }

    return document;
}

From source file:com.viapost.stock.service.impl.UserDemandeLocalServiceImpl.java

License:Open Source License

@Override
public UserDemande addUserDemande(final ActionRequest request) throws PortalException, SystemException {
    final UserDemande userDemande = userDemandePersistence
            .create(counterLocalService.increment(UserDemande.class.getName()));

    final ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    final long userId = themeDisplay.getUserId();
    final ServiceContext serviceContext = ServiceContextFactory.getInstance(UserDemande.class.getName(),
            request);//from w  w w  .  j  av  a2 s  .  c  om
    userDemande.setCompanyId(themeDisplay.getCompanyId());
    userDemande.setGroupId(themeDisplay.getScopeGroupId());
    userDemande.setDate(new Date());
    userDemande.setArticle(ParamUtil.getLong(request, "produit"));
    userDemande.setDemandeId(DemandeLocalServiceUtil.findByQuestion(ParamUtil.getString(request, "question")));
    userDemande.setStatus(WorkflowConstants.STATUS_PENDING);
    userDemandePersistence.update(userDemande);

    assetEntryLocalService.updateEntry(userId, userDemande.getGroupId(), UserDemande.class.getName(),
            userDemande.getPrimaryKey(), serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames());

    WorkflowHandlerRegistryUtil.startWorkflowInstance(themeDisplay.getCompanyId(), userId,
            UserDemande.class.getName(), userDemande.getPrimaryKey(), userDemande, serviceContext);

    return userDemande;
}

From source file:org.goodreturn.service.impl.StoryLocalServiceImpl.java

License:Open Source License

/**
 * Creates a new Story and stores it in the database and returns the new Story object.
 * The new story object is based on the 'newStory' Story object.
 * // w ww .j  a  va2 s. c o  m
 * @param newStory - the Story object which the new story will be stored in db.
 * @param userId - the user which this object is associated with.
 * @param serviceContext
 * @return a new Story object based on newStory which is now within the database. 
 */
public Story addStory(Story newStory, long userId, ServiceContext serviceContext)
        throws SystemException, PortalException {

    //Creates the FinalStory and sets all variables.
    Story story = storyPersistence.create(counterLocalService.increment(Story.class.getName()));
    story.setAbacus_Borrower_Loan_Id(newStory.getAbacus_Borrower_Loan_Id());

    story.setStory_Type(newStory.getStory_Type());
    story.setStory_Text(newStory.getStory_Text());
    story.setVideo_Url(newStory.getVideo_Url());
    story.setIs_Good_Enough_For_Marketing(newStory.getIs_Good_Enough_For_Marketing());
    story.setIs_Good_Enough_For_Story(newStory.getIs_Good_Enough_For_Story());

    story.setCompanyId(newStory.getCompanyId());
    story.setGroupId(newStory.getGroupId());
    story.setUserId(userId);

    story.setStatus(WorkflowConstants.STATUS_DRAFT);

    //Updates in the database.
    storyPersistence.update(story, false);

    resourceLocalService.addResources(story.getCompanyId(), story.getGroupId(), userId, Story.class.getName(),
            story.getPrimaryKey(), false, true, true);

    assetEntryLocalService.updateEntry(userId, story.getGroupId(), Story.class.getName(), story.getStory_Id(),
            serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());

    WorkflowHandlerRegistryUtil.startWorkflowInstance(story.getCompanyId(), userId, Story.class.getName(),
            story.getPrimaryKey(), story, serviceContext);

    return story;
}