1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.workflow;
16  
17  import com.liferay.portal.kernel.workflow.RequiredWorkflowDefinitionException;
18  import com.liferay.portal.service.WorkflowDefinitionLinkLocalServiceUtil;
19  
20  import org.aspectj.lang.ProceedingJoinPoint;
21  
22  /**
23   * <a href="WorkflowLinkAdvice.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class WorkflowLinkAdvice {
28  
29      public Object invoke(ProceedingJoinPoint proceedingJoinPoint)
30          throws Throwable {
31  
32          String methodName = proceedingJoinPoint.getSignature().getName();
33          Object[] arguments = proceedingJoinPoint.getArgs();
34  
35          if (methodName.equals(_UPDATE_ACTIVE)) {
36              long companyId = (Long)arguments[0];
37              String name = (String)arguments[2];
38              int version = (Integer)arguments[3];
39              boolean active = (Boolean)arguments[4];
40  
41              if (!active) {
42                  int workflowDefinitionLinksCount =
43                      WorkflowDefinitionLinkLocalServiceUtil.
44                          getWorkflowDefinitionLinksCount(
45                              companyId, name, version);
46  
47                  if (workflowDefinitionLinksCount >= 1) {
48                      throw new RequiredWorkflowDefinitionException();
49                  }
50              }
51          }
52  
53          return proceedingJoinPoint.proceed();
54      }
55  
56      private static final String _UPDATE_ACTIVE = "updateActive";
57  
58  }