001
014
015 package com.liferay.portal.workflow;
016
017 import com.liferay.portal.kernel.workflow.RequiredWorkflowDefinitionException;
018 import com.liferay.portal.service.WorkflowDefinitionLinkLocalServiceUtil;
019
020 import org.aspectj.lang.ProceedingJoinPoint;
021
022
025 public class WorkflowLinkAdvice {
026
027 public Object invoke(ProceedingJoinPoint proceedingJoinPoint)
028 throws Throwable {
029
030 String methodName = proceedingJoinPoint.getSignature().getName();
031 Object[] arguments = proceedingJoinPoint.getArgs();
032
033 if (methodName.equals(_UPDATE_ACTIVE)) {
034 long companyId = (Long)arguments[0];
035 String name = (String)arguments[2];
036 int version = (Integer)arguments[3];
037 boolean active = (Boolean)arguments[4];
038
039 if (!active) {
040 int workflowDefinitionLinksCount =
041 WorkflowDefinitionLinkLocalServiceUtil.
042 getWorkflowDefinitionLinksCount(
043 companyId, name, version);
044
045 if (workflowDefinitionLinksCount >= 1) {
046 throw new RequiredWorkflowDefinitionException();
047 }
048 }
049 }
050
051 return proceedingJoinPoint.proceed();
052 }
053
054 private static final String _UPDATE_ACTIVE = "updateActive";
055
056 }