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.portlet.tasks.model.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.language.LanguageUtil;
28  import com.liferay.portal.model.Group;
29  import com.liferay.portal.service.GroupLocalServiceUtil;
30  import com.liferay.portlet.tasks.model.TasksProposal;
31  import com.liferay.portlet.tasks.model.TasksReview;
32  import com.liferay.portlet.tasks.service.TasksReviewLocalServiceUtil;
33  
34  import java.util.List;
35  import java.util.Locale;
36  
37  /**
38   * <a href="TasksProposalImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   *
42   */
43  public class TasksProposalImpl
44      extends TasksProposalModelImpl implements TasksProposal {
45  
46      public TasksProposalImpl() {
47      }
48  
49      public String getStatus(Locale locale)
50          throws PortalException, SystemException {
51  
52          String status = null;
53          int stage = 1;
54  
55          Group group = GroupLocalServiceUtil.getGroup(getGroupId());
56  
57          int stages = group.getWorkflowStages();
58  
59          for (; stage <= stages; stage++) {
60              status = getStatus(stage);
61  
62              if (status.equals(_STATUS_APPROVED)) {
63              }
64              else if (status.equals(_STATUS_PENDING) ||
65                       status.equals(_STATUS_REJECTED)) {
66  
67                  break;
68              }
69              else if ((status.equals(_STATUS_UNASSIGNED)) &&
70                       (stage > 1)) {
71              }
72              else if (stage == 0) {
73                  break;
74              }
75  
76              if (stage == stages) {
77                  break;
78              }
79          }
80  
81          return LanguageUtil.format(
82              getCompanyId(), locale, status, String.valueOf(stage + 1));
83      }
84  
85      protected String getStatus(int stage) throws SystemException {
86          List<TasksReview> reviews = TasksReviewLocalServiceUtil.getReviews(
87              getProposalId(), stage);
88  
89          if (reviews.size() <= 0) {
90              return _STATUS_UNASSIGNED;
91          }
92  
93          List<TasksReview> completedReviews =
94              TasksReviewLocalServiceUtil.getReviews(
95                  getProposalId(), stage, true);
96  
97          if (completedReviews.size() < reviews.size()) {
98              return _STATUS_PENDING;
99          }
100 
101         List<TasksReview> completedRejectedReviews =
102             TasksReviewLocalServiceUtil.getReviews(
103                 getProposalId(), stage, true, true);
104 
105         if (completedRejectedReviews.size() > 0) {
106             return _STATUS_REJECTED;
107         }
108         else {
109             return _STATUS_APPROVED;
110         }
111     }
112 
113     private static final String _STATUS_APPROVED = "stage-x-review-approved";
114 
115     private static final String _STATUS_PENDING = "stage-x-pending-review";
116 
117     private static final String _STATUS_REJECTED = "stage-x-review-rejected";
118 
119     private static final String _STATUS_UNASSIGNED =
120         "stage-x-review-unassigned";
121 
122 }