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  public class TasksProposalImpl
43      extends TasksProposalModelImpl implements TasksProposal {
44  
45      public TasksProposalImpl() {
46      }
47  
48      public String getStatus(Locale locale)
49          throws PortalException, SystemException {
50  
51          String status = null;
52          int stage = 1;
53  
54          Group group = GroupLocalServiceUtil.getGroup(getGroupId());
55  
56          int stages = group.getWorkflowStages();
57  
58          for (; stage <= stages; stage++) {
59              status = getStatus(stage);
60  
61              if (status.equals(_STATUS_APPROVED)) {
62              }
63              else if (status.equals(_STATUS_PENDING) ||
64                       status.equals(_STATUS_REJECTED)) {
65  
66                  break;
67              }
68              else if ((status.equals(_STATUS_UNASSIGNED)) &&
69                       (stage > 1)) {
70              }
71              else if (stage == 0) {
72                  break;
73              }
74  
75              if (stage == stages) {
76                  break;
77              }
78          }
79  
80          return LanguageUtil.format(
81              getCompanyId(), locale, status, String.valueOf(stage + 1));
82      }
83  
84      protected String getStatus(int stage) throws SystemException {
85          List<TasksReview> reviews = TasksReviewLocalServiceUtil.getReviews(
86              getProposalId(), stage);
87  
88          if (reviews.size() <= 0) {
89              return _STATUS_UNASSIGNED;
90          }
91  
92          List<TasksReview> completedReviews =
93              TasksReviewLocalServiceUtil.getReviews(
94                  getProposalId(), stage, true);
95  
96          if (completedReviews.size() < reviews.size()) {
97              return _STATUS_PENDING;
98          }
99  
100         List<TasksReview> completedRejectedReviews =
101             TasksReviewLocalServiceUtil.getReviews(
102                 getProposalId(), stage, true, true);
103 
104         if (completedRejectedReviews.size() > 0) {
105             return _STATUS_REJECTED;
106         }
107         else {
108             return _STATUS_APPROVED;
109         }
110     }
111 
112     private static final String _STATUS_APPROVED = "stage-x-review-approved";
113 
114     private static final String _STATUS_PENDING = "stage-x-pending-review";
115 
116     private static final String _STATUS_REJECTED = "stage-x-review-rejected";
117 
118     private static final String _STATUS_UNASSIGNED =
119         "stage-x-review-unassigned";
120 
121 }