1   /**
2    * Copyright (c) 2000-2008 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));
83      }
84  
85      protected String getStatus(int stage)
86          throws PortalException, SystemException {
87  
88          List<TasksReview> reviews = TasksReviewLocalServiceUtil.getReviews(
89              getProposalId(), stage);
90  
91          if (reviews.size() <= 0) {
92              return _STATUS_UNASSIGNED;
93          }
94  
95          List<TasksReview> completedReviews =
96              TasksReviewLocalServiceUtil.getReviews(
97                  getProposalId(), stage, true);
98  
99          if (completedReviews.size() < reviews.size()) {
100             return _STATUS_PENDING;
101         }
102 
103         List<TasksReview> completedRejectedReviews =
104             TasksReviewLocalServiceUtil.getReviews(
105                 getProposalId(), stage, true, true);
106 
107         if (completedRejectedReviews.size() > 0) {
108             return _STATUS_REJECTED;
109         }
110         else {
111             return _STATUS_APPROVED;
112         }
113     }
114 
115     private static final String _STATUS_APPROVED = "stage-x-review-approved";
116 
117     private static final String _STATUS_PENDING = "stage-x-pending-review";
118 
119     private static final String _STATUS_REJECTED = "stage-x-review-rejected";
120 
121     private static final String _STATUS_UNASSIGNED =
122         "stage-x-review-unassigned";
123 
124 }