001
014
015 package com.liferay.portlet.tasks.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.language.LanguageUtil;
020 import com.liferay.portal.model.Group;
021 import com.liferay.portal.service.GroupLocalServiceUtil;
022 import com.liferay.portlet.tasks.model.TasksProposal;
023 import com.liferay.portlet.tasks.model.TasksReview;
024 import com.liferay.portlet.tasks.service.TasksReviewLocalServiceUtil;
025
026 import java.util.List;
027 import java.util.Locale;
028
029
032 public class TasksProposalImpl
033 extends TasksProposalModelImpl implements TasksProposal {
034
035 public TasksProposalImpl() {
036 }
037
038 public String getStatus(Locale locale)
039 throws PortalException, SystemException {
040
041 String status = null;
042 int stage = 1;
043
044 Group group = GroupLocalServiceUtil.getGroup(getGroupId());
045
046 int stages = group.getWorkflowStages();
047
048 for (; stage <= stages; stage++) {
049 status = getStatus(stage);
050
051 if (status.equals(_STATUS_APPROVED)) {
052 }
053 else if (status.equals(_STATUS_PENDING) ||
054 status.equals(_STATUS_REJECTED)) {
055
056 break;
057 }
058 else if ((status.equals(_STATUS_UNASSIGNED)) &&
059 (stage > 1)) {
060 }
061 else if (stage == 0) {
062 break;
063 }
064
065 if (stage == stages) {
066 break;
067 }
068 }
069
070 return LanguageUtil.format(locale, status, String.valueOf(stage + 1));
071 }
072
073 protected String getStatus(int stage) throws SystemException {
074 List<TasksReview> reviews = TasksReviewLocalServiceUtil.getReviews(
075 getProposalId(), stage);
076
077 if (reviews.size() <= 0) {
078 return _STATUS_UNASSIGNED;
079 }
080
081 List<TasksReview> completedReviews =
082 TasksReviewLocalServiceUtil.getReviews(
083 getProposalId(), stage, true);
084
085 if (completedReviews.size() < reviews.size()) {
086 return _STATUS_PENDING;
087 }
088
089 List<TasksReview> completedRejectedReviews =
090 TasksReviewLocalServiceUtil.getReviews(
091 getProposalId(), stage, true, true);
092
093 if (completedRejectedReviews.size() > 0) {
094 return _STATUS_REJECTED;
095 }
096 else {
097 return _STATUS_APPROVED;
098 }
099 }
100
101 private static final String _STATUS_APPROVED = "stage-x-review-approved";
102
103 private static final String _STATUS_PENDING = "stage-x-pending-review";
104
105 private static final String _STATUS_REJECTED = "stage-x-review-rejected";
106
107 private static final String _STATUS_UNASSIGNED =
108 "stage-x-review-unassigned";
109
110 }