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

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

Introduction

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

Prototype

public static <T> WorkflowHandler<T> getWorkflowHandler(String className) 

Source Link

Usage

From source file:au.com.permeance.liferay.util.startup.StartupListener.java

License:Open Source License

protected static synchronized void applicationStart() {
    if (!applicationStarted) {
        applicationStarted = true;//from ww w . j a v  a 2  s . c  o m
        _log.info("Starting up Web Content Workflow Configuration Portlet");
        oldWorkflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(JournalArticle.class.getName());
        WorkflowHandlerRegistryUtil.register(newWorkflowHandler);
    }
}

From source file:com.liferay.document.library.web.internal.portlet.configuration.icon.EditFolderPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    try {// w w w .j  a  v a2s  .c o  m
        long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

        Folder folder = ActionUtil.getFolder(portletRequest);

        if (folder == null) {
            if (!WorkflowEngineManagerUtil.isDeployed()
                    || (WorkflowHandlerRegistryUtil.getWorkflowHandler(DLFileEntry.class.getName()) == null)) {

                return false;
            }
        } else {
            folderId = folder.getFolderId();
        }

        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        return DLFolderPermission.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(),
                folderId, ActionKeys.UPDATE);
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.document.library.workflow.WorkflowHandlerInvocationCounter.java

License:Open Source License

public WorkflowHandlerInvocationCounter(String className) {
    WorkflowHandler<T> workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);

    _counts = new HashMap<>();

    WorkflowHandler<T> delegateWorkflowHandler = _createInvocationCounterWorkflowHandler(workflowHandler);

    _workflowHandlerReplacer = new WorkflowHandlerReplacer<>(className, delegateWorkflowHandler);
}

From source file:com.liferay.document.library.workflow.WorkflowHandlerReplacer.java

License:Open Source License

public WorkflowHandlerReplacer(String className, WorkflowHandler<T> replacementWorkflowHandler) {

    _originalWorkflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);
    _replacementWorkflowHandler = replacementWorkflowHandler;

    WorkflowHandlerRegistryUtil.unregister(_originalWorkflowHandler);
    WorkflowHandlerRegistryUtil.register(_replacementWorkflowHandler);
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormAdminDisplayContext.java

License:Open Source License

public boolean isDDLRecordWorkflowHandlerDeployed() {
    if (!_workflowEngineManager.isDeployed()) {
        return false;
    }//from   ww w .j a va  2 s  .  co  m

    WorkflowHandler<DDLRecord> ddlRecordWorkflowHandler = WorkflowHandlerRegistryUtil
            .getWorkflowHandler(DDLRecord.class.getName());

    if (ddlRecordWorkflowHandler != null) {
        return true;
    }

    return false;
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.display.context.DDMFormAdminDisplayContext.java

License:Open Source License

public boolean isFormInstanceRecordWorkflowHandlerDeployed() {
    if (!_workflowEngineManager.isDeployed()) {
        return false;
    }/* www . j  av a2s .co  m*/

    WorkflowHandler<DDMFormInstanceRecord> formInstanceRecordWorkflowHandler = WorkflowHandlerRegistryUtil
            .getWorkflowHandler(DDMFormInstanceRecord.class.getName());

    if (formInstanceRecordWorkflowHandler != null) {
        return true;
    }

    return false;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Copies the web content article matching the group, article ID, and
 * version. This method creates a new article, extracting all the values
 * from the old one and updating its article ID.
 *
 * @param  userId the primary key of the web content article's creator/owner
 * @param  groupId the primary key of the web content article's group
 * @param  oldArticleId the primary key of the old web content article
 * @param  newArticleId the primary key of the new web content article
 * @param  autoArticleId whether to auto-generate the web content article ID
 * @param  version the web content article's version
 * @return the new web content article/*  w w w.j  av a2 s.c  om*/
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle copyArticle(long userId, long groupId, String oldArticleId, String newArticleId,
        boolean autoArticleId, double version) throws PortalException {

    // Article

    User user = userLocalService.getUser(userId);
    oldArticleId = StringUtil.toUpperCase(StringUtil.trim(oldArticleId));
    newArticleId = StringUtil.toUpperCase(StringUtil.trim(newArticleId));

    JournalArticle oldArticle = journalArticlePersistence.findByG_A_V(groupId, oldArticleId, version);

    if (autoArticleId) {
        newArticleId = String.valueOf(counterLocalService.increment());
    } else {
        validate(newArticleId);

        if (journalArticlePersistence.countByG_A(groupId, newArticleId) > 0) {

            StringBundler sb = new StringBundler(5);

            sb.append("{groupId=");
            sb.append(groupId);
            sb.append(", articleId=");
            sb.append(newArticleId);
            sb.append("}");

            throw new DuplicateArticleIdException(sb.toString());
        }
    }

    long id = counterLocalService.increment();

    long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId, newArticleId);

    JournalArticle newArticle = journalArticlePersistence.create(id);

    newArticle.setResourcePrimKey(resourcePrimKey);
    newArticle.setGroupId(groupId);
    newArticle.setCompanyId(user.getCompanyId());
    newArticle.setUserId(user.getUserId());
    newArticle.setUserName(user.getFullName());
    newArticle.setFolderId(oldArticle.getFolderId());
    newArticle.setTreePath(oldArticle.getTreePath());
    newArticle.setArticleId(newArticleId);
    newArticle.setVersion(JournalArticleConstants.VERSION_DEFAULT);
    newArticle.setUrlTitle(getUniqueUrlTitle(id, groupId, newArticleId, oldArticle.getTitleCurrentValue()));

    try {
        copyArticleImages(oldArticle, newArticle);
    } catch (Exception e) {
        newArticle.setContent(oldArticle.getContent());
    }

    newArticle.setDDMStructureKey(oldArticle.getDDMStructureKey());
    newArticle.setDDMTemplateKey(oldArticle.getDDMTemplateKey());
    newArticle.setDefaultLanguageId(oldArticle.getDefaultLanguageId());
    newArticle.setLayoutUuid(oldArticle.getLayoutUuid());
    newArticle.setDisplayDate(oldArticle.getDisplayDate());
    newArticle.setExpirationDate(oldArticle.getExpirationDate());
    newArticle.setReviewDate(oldArticle.getReviewDate());
    newArticle.setIndexable(oldArticle.isIndexable());
    newArticle.setSmallImage(oldArticle.isSmallImage());
    newArticle.setSmallImageId(counterLocalService.increment());
    newArticle.setSmallImageURL(oldArticle.getSmallImageURL());

    WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil
            .getWorkflowHandler(JournalArticle.class.getName());

    WorkflowDefinitionLink workflowDefinitionLink = workflowHandler
            .getWorkflowDefinitionLink(oldArticle.getCompanyId(), oldArticle.getGroupId(), oldArticle.getId());

    if (oldArticle.isPending() || (workflowDefinitionLink != null)) {
        newArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
    } else {
        newArticle.setStatus(oldArticle.getStatus());
    }

    ExpandoBridgeUtil.copyExpandoBridgeAttributes(oldArticle.getExpandoBridge(), newArticle.getExpandoBridge());

    journalArticlePersistence.update(newArticle);

    // Article localization

    String urlTitle = JournalUtil.getUrlTitle(id, oldArticle.getUrlTitle());

    int uniqueUrlTitleCount = _getUniqueUrlTitleCount(groupId, newArticleId, urlTitle);

    Map<Locale, String> newTitleMap = oldArticle.getTitleMap();

    for (Locale locale : newTitleMap.keySet()) {
        StringBundler sb = new StringBundler(5);

        sb.append(newTitleMap.get(locale));
        sb.append(StringPool.SPACE);
        sb.append(LanguageUtil.get(locale, "duplicate"));
        sb.append(StringPool.SPACE);
        sb.append(uniqueUrlTitleCount);

        newTitleMap.put(locale, sb.toString());
    }

    _addArticleLocalizedFields(newArticle.getCompanyId(), newArticle.getId(), newTitleMap,
            oldArticle.getDescriptionMap());

    // Resources

    addArticleResources(newArticle, true, true);

    // Small image

    if (oldArticle.isSmallImage()) {
        Image image = imageLocalService.fetchImage(oldArticle.getSmallImageId());

        if (image != null) {
            byte[] smallImageBytes = image.getTextObj();

            imageLocalService.updateImage(newArticle.getSmallImageId(), smallImageBytes);
        }
    }

    // Asset

    long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());
    String[] assetTagNames = assetTagLocalService.getTagNames(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());

    AssetEntry oldAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());

    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(oldAssetEntry.getEntryId(), false);

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    updateAsset(userId, newArticle, assetCategoryIds, assetTagNames, assetLinkEntryIds,
            oldAssetEntry.getPriority());

    // Dynamic data mapping

    updateDDMLinks(id, groupId, oldArticle.getDDMStructureKey(), oldArticle.getDDMTemplateKey(), true);

    return newArticle;
}

From source file:com.liferay.portlet.workflowinstances.action.EditWorkflowInstanceAction.java

License:Open Source License

protected void deleteInstance(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long workflowInstanceId = ParamUtil.getLong(actionRequest, "workflowInstanceId");

    WorkflowInstance workflowInstance = WorkflowInstanceManagerUtil
            .getWorkflowInstance(themeDisplay.getCompanyId(), workflowInstanceId);

    Map<String, Serializable> workflowContext = workflowInstance.getWorkflowContext();

    long companyId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
    long groupId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_GROUP_ID));
    String className = GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME));
    long classPK = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

    WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);

    workflowHandler.updateStatus(WorkflowConstants.STATUS_DRAFT, workflowContext);

    WorkflowInstanceLinkLocalServiceUtil.deleteWorkflowInstanceLink(companyId, groupId, className, classPK);
}

From source file:jorgediazest.util.model.ModelImpl.java

License:Open Source License

public WorkflowHandler getWorkflowHandler() {
    return WorkflowHandlerRegistryUtil.getWorkflowHandler(getClassName());
}

From source file:se.gothiaforum.actorarticle.service.TestActorArticleService.java

License:Open Source License

@Test
public void test3() throws Exception {

    JournalArticle journalArticle3 = new JournalArticleImpl();

    journalArticle3.setUserId(33333);/*from  w  ww. j a v a  2  s . c om*/
    journalArticle3.setCompanyId(44444);
    journalArticle3.setType("hehehj");
    journalArticle3.setGroupId(4331);

    journalArticle3.setPrimaryKey(1234);

    WorkflowHandlerRegistryUtil workflowHandlerRegistryUtil = new WorkflowHandlerRegistryUtil();

    WorkflowHandlerRegistry workflowHandlerRegistry = PowerMockito.mock(WorkflowHandlerRegistry.class);

    workflowHandlerRegistryUtil.setWorkflowHandlerRegistry(workflowHandlerRegistry);

    WorkflowHandler workflowHandler = PowerMockito.mock(WorkflowHandler.class);

    PowerMockito.when(WorkflowHandlerRegistryUtil.getWorkflowHandler(Mockito.anyString()))
            .thenReturn(workflowHandler);

    ServiceContext serviceContext = Mockito.mock(ServiceContext.class);

    actorsService.sendActors(10, journalArticle3, 100, serviceContext);

    Mockito.verify(workflowHandler).startWorkflowInstance(Mockito.anyLong(), Mockito.anyLong(),
            Mockito.anyLong(), Mockito.anyLong(), Mockito.isNotNull(), Mockito.anyMap());

}