1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.mirage.aop;
24  
25  import com.sun.saw.Workflow;
26  import com.sun.saw.WorkflowException;
27  import com.sun.saw.WorkflowFactory;
28  
29  import java.util.Properties;
30  
31  import org.aspectj.lang.ProceedingJoinPoint;
32  
33  /**
34   * <a href="JournalArticleLocalServiceAdvice.java.html"><b><i>View Source</i>
35   * </b></a>
36   *
37   * @author Joshna Reddy
38   * @author Raymond Augé
39   *
40   */
41  public class JournalArticleLocalServiceAdvice extends BaseMirageAdvice {
42  
43      protected Object doInvoke(ProceedingJoinPoint proceedingJoinPoint)
44          throws Throwable {
45  
46          String methodName = proceedingJoinPoint.getSignature().getName();
47          Object[] arguments = proceedingJoinPoint.getArgs();
48  
49          if (methodName.equals("addArticle") ||
50              methodName.equals("deleteArticle") ||
51              methodName.equals("getArticle") ||
52              methodName.equals("getLatestArticle") ||
53              methodName.equals("updateArticle")||
54              methodName.equals("updateContent")) {
55  
56              ContentInvoker contentInvoker = new ContentInvoker(
57                  proceedingJoinPoint);
58  
59              if (methodName.equals("addArticle")) {
60                  contentService.createContent(contentInvoker);
61              }
62              else if (methodName.equals("deleteArticle")) {
63                  contentService.deleteContent(contentInvoker);
64              }
65              else if (methodName.equals("getArticle") ||
66                       methodName.equals("getLatestArticle")) {
67  
68                  contentService.getContent(contentInvoker, null);
69              }
70              else if (methodName.equals("updateArticle")) {
71                  contentService.updateContent(contentInvoker);
72              }
73              else if (methodName.equals("updateContent")) {
74                  contentService.updateContent(contentInvoker, null);
75              }
76  
77              return contentInvoker.getReturnValue();
78          }
79          else if (methodName.equals("approveArticle") ||
80                   methodName.equals("expireArticle")) {
81  
82              WorkflowInvoker workflowInvoker = new WorkflowInvoker(
83                  proceedingJoinPoint);
84  
85              if (methodName.equals("approveArticle")) {
86                  workflowService.updateWorkflowComplete(workflowInvoker);
87              }
88              else if (methodName.equals("expireArticle")) {
89                  workflowService.updateWorkflowContentRejected(workflowInvoker);
90              }
91  
92              return workflowInvoker.getReturnValue();
93          }
94          else if (methodName.equals("getArticles") ||
95                   methodName.equals("getArticlesBySmallImageId")||
96                   methodName.equals("getArticlesCount") ||
97                   methodName.equals("getDisplayArticle") ||
98                   methodName.equals("getStructureArticles") ||
99                   methodName.equals("getStructureArticlesCount") ||
100                  methodName.equals("getTemplateArticles") ||
101                  methodName.equals("getTemplateArticlesCount") ||
102                  methodName.equals("searchCount") ||
103                  (methodName.equals("search") && (arguments.length > 6))) {
104 
105             SearchCriteriaInvoker searchCriteriaInvoker =
106                 new SearchCriteriaInvoker(proceedingJoinPoint);
107 
108             if (methodName.equals("getArticles") ||
109                 methodName.equals("getArticlesBySmallImageId") ||
110                 methodName.equals("getDisplayArticle")||
111                 methodName.equals("getTemplateArticles")||
112                 methodName.equals("search")) {
113 
114                 contentService.searchContents(searchCriteriaInvoker);
115             }
116             else if (methodName.equals("getStructureArticles")) {
117                 contentService.searchContentsByType(
118                     null, searchCriteriaInvoker);
119             }
120             else if (methodName.equals("getArticlesCount") ||
121                      methodName.equals("searchCount")||
122                      methodName.equals("getTemplateArticlesCount")) {
123 
124                 contentService.contentSearchCount(searchCriteriaInvoker);
125             }
126             else if (methodName.equals("getStructureArticlesCount")) {
127                 contentService.contentSearchCount(null,searchCriteriaInvoker);
128             }
129 
130             return searchCriteriaInvoker.getReturnValue();
131         }
132         else {
133             return proceedingJoinPoint.proceed();
134         }
135     }
136 
137     protected Workflow getWorkflow() throws WorkflowException {
138         Properties properties = new Properties();
139 
140         properties.setProperty(
141             "sawworkflowimplclass", "com.sun.saw.impls.osworkflow.OSWorkflow");
142 
143         WorkflowFactory workflowFactory = WorkflowFactory.getInstance();
144 
145         return workflowFactory.getWorkflowInstance(properties);
146     }
147 
148 }