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.social;
24  
25  import com.liferay.portal.kernel.json.JSONFactoryUtil;
26  import com.liferay.portal.kernel.json.JSONObject;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.portal.theme.ThemeDisplay;
30  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
31  import com.liferay.portlet.social.model.SocialActivity;
32  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
33  import com.liferay.portlet.tasks.model.TasksProposal;
34  import com.liferay.portlet.tasks.service.TasksProposalLocalServiceUtil;
35  
36  /**
37   * <a href="TasksActivityInterpreter.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Raymond Augé
40   *
41   */
42  public class TasksActivityInterpreter extends BaseSocialActivityInterpreter {
43  
44      public String[] getClassNames() {
45          return _CLASS_NAMES;
46      }
47  
48      protected SocialActivityFeedEntry doInterpret(
49              SocialActivity activity, ThemeDisplay themeDisplay)
50          throws Exception {
51  
52          String creatorUserName = getUserName(
53              activity.getUserId(), themeDisplay);
54          String receiverUserName = getUserName(
55              activity.getReceiverUserId(), themeDisplay);
56  
57          int activityType = activity.getType();
58  
59          JSONObject extraData = null;
60  
61          if (Validator.isNotNull(activity.getExtraData())) {
62              extraData = JSONFactoryUtil.createJSONObject(
63                  activity.getExtraData());
64          }
65  
66          // Title
67  
68          String title = StringPool.BLANK;
69  
70          if (activityType == TasksActivityKeys.ADD_PROPOSAL) {
71              title = themeDisplay.translate(
72                  "activity-tasks-add-proposal", creatorUserName);
73          }
74          else if (activityType == TasksActivityKeys.ASSIGN_PROPOSAL) {
75              title = themeDisplay.translate(
76                  "activity-tasks-assign-proposal",
77                  new Object[] {creatorUserName, receiverUserName});
78          }
79          else if (activityType == TasksActivityKeys.REVIEW_PROPOSAL) {
80              title = themeDisplay.translate(
81                  "activity-tasks-review-proposal",
82                  new Object[] {creatorUserName, receiverUserName});
83          }
84  
85          // Body
86  
87          TasksProposal proposal = TasksProposalLocalServiceUtil.getProposal(
88              activity.getClassPK());
89  
90          StringBuilder sb = new StringBuilder();
91  
92          sb.append("<b>");
93          sb.append(proposal.getName());
94          sb.append("</b> (");
95          sb.append(
96              themeDisplay.translate(
97                  "model.resource." + proposal.getClassName()));
98          sb.append(")<br />");
99          sb.append(themeDisplay.translate("description"));
100         sb.append(": ");
101         sb.append(proposal.getDescription());
102 
103         if (activityType != TasksActivityKeys.ADD_PROPOSAL) {
104             int stage = extraData.getInt("stage");
105             boolean completed = extraData.getBoolean("completed");
106             boolean rejected = extraData.getBoolean("rejected");
107 
108             sb.append("<br />");
109             sb.append(themeDisplay.translate("stage"));
110             sb.append(": ");
111             sb.append(stage);
112             sb.append("<br />");
113             sb.append(themeDisplay.translate("status"));
114             sb.append(": ");
115 
116             if (completed && rejected) {
117                 sb.append(themeDisplay.translate("rejected"));
118             }
119             else if (completed && !rejected) {
120                 sb.append(themeDisplay.translate("approved"));
121             }
122             else {
123                 sb.append(themeDisplay.translate("awaiting-approval"));
124             }
125         }
126 
127         String body = sb.toString();
128 
129         return new SocialActivityFeedEntry(title, body);
130     }
131 
132     private static final String[] _CLASS_NAMES = new String[] {
133         TasksProposal.class.getName()
134     };
135 
136 }