Java tutorial
/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.journal.workflow; import com.liferay.dynamic.data.mapping.model.DDMStructure; import com.liferay.dynamic.data.mapping.service.DDMStructureLocalService; import com.liferay.journal.model.JournalArticle; import com.liferay.journal.model.JournalArticleConstants; import com.liferay.journal.model.JournalFolder; import com.liferay.journal.service.JournalArticleLocalService; import com.liferay.journal.service.JournalFolderLocalService; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.model.WorkflowDefinitionLink; import com.liferay.portal.kernel.portlet.PortletProvider; import com.liferay.portal.kernel.portlet.PortletProviderUtil; import com.liferay.portal.kernel.security.permission.ResourceActionsUtil; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.service.WorkflowDefinitionLinkLocalService; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.Portal; import com.liferay.portal.kernel.workflow.BaseWorkflowHandler; import com.liferay.portal.kernel.workflow.WorkflowConstants; import com.liferay.portal.kernel.workflow.WorkflowHandler; import java.io.Serializable; import java.util.Locale; import java.util.Map; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Bruno Farache * @author Marcellus Tavares * @author Juan Fernndez * @author Julio Camarero */ @Component(property = { "model.class.name=com.liferay.journal.model.JournalArticle" }, service = WorkflowHandler.class) public class JournalArticleWorkflowHandler extends BaseWorkflowHandler<JournalArticle> { @Override public String getClassName() { return JournalArticle.class.getName(); } @Override public String getType(Locale locale) { return ResourceActionsUtil.getModelResource(locale, getClassName()); } @Override public WorkflowDefinitionLink getWorkflowDefinitionLink(long companyId, long groupId, long classPK) throws PortalException { JournalArticle article = _journalArticleLocalService.getArticle(classPK); long folderId = _journalFolderLocalService.getInheritedWorkflowFolderId(article.getFolderId()); DDMStructure ddmStructure = _ddmStructureLocalService.getStructure(article.getGroupId(), _portal.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); WorkflowDefinitionLink workflowDefinitionLink = _workflowDefinitionLinkLocalService .fetchWorkflowDefinitionLink(companyId, groupId, JournalFolder.class.getName(), folderId, ddmStructure.getStructureId(), true); if (workflowDefinitionLink == null) { workflowDefinitionLink = _workflowDefinitionLinkLocalService.fetchWorkflowDefinitionLink(companyId, groupId, JournalFolder.class.getName(), folderId, JournalArticleConstants.DDM_STRUCTURE_ID_ALL, true); } return workflowDefinitionLink; } @Override public boolean isVisible() { return _VISIBLE; } @Override public JournalArticle updateStatus(int status, Map<String, Serializable> workflowContext) throws PortalException { long userId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID)); long classPK = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)); JournalArticle article = _journalArticleLocalService.getArticle(classPK); ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext"); String articleURL = _portal.getControlPanelFullURL(serviceContext.getScopeGroupId(), PortletProviderUtil.getPortletId(JournalArticle.class.getName(), PortletProvider.Action.EDIT), null); return _journalArticleLocalService.updateStatus(userId, article, status, articleURL, serviceContext, workflowContext); } @Reference(unbind = "-") protected void setDDMStructureLocalService(DDMStructureLocalService ddmStructureLocalService) { _ddmStructureLocalService = ddmStructureLocalService; } @Reference(unbind = "-") protected void setJournalArticleLocalService(JournalArticleLocalService journalArticleLocalService) { _journalArticleLocalService = journalArticleLocalService; } @Reference(unbind = "-") protected void setJournalFolderLocalService(JournalFolderLocalService journalFolderLocalService) { _journalFolderLocalService = journalFolderLocalService; } @Reference(unbind = "-") protected void setWorkflowDefinitionLinkLocalService( WorkflowDefinitionLinkLocalService workflowDefinitionLinkLocalService) { _workflowDefinitionLinkLocalService = workflowDefinitionLinkLocalService; } private static final boolean _VISIBLE = false; private DDMStructureLocalService _ddmStructureLocalService; private JournalArticleLocalService _journalArticleLocalService; private JournalFolderLocalService _journalFolderLocalService; @Reference private Portal _portal; private WorkflowDefinitionLinkLocalService _workflowDefinitionLinkLocalService; }