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.imagegallery.social;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.security.permission.ActionKeys;
28  import com.liferay.portal.security.permission.PermissionChecker;
29  import com.liferay.portal.theme.ThemeDisplay;
30  import com.liferay.portlet.imagegallery.model.IGImage;
31  import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
32  import com.liferay.portlet.imagegallery.service.permission.IGImagePermission;
33  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
34  import com.liferay.portlet.social.model.SocialActivity;
35  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
36  
37  /**
38   * <a href="IGActivityInterpreter.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Ryan Park
41   *
42   */
43  public class IGActivityInterpreter extends BaseSocialActivityInterpreter {
44  
45      public String[] getClassNames() {
46          return _CLASS_NAMES;
47      }
48  
49      protected SocialActivityFeedEntry doInterpret(
50              SocialActivity activity, ThemeDisplay themeDisplay)
51          throws Exception {
52  
53          PermissionChecker permissionChecker =
54              themeDisplay.getPermissionChecker();
55  
56          IGImage image = IGImageLocalServiceUtil.getIGImage(
57              activity.getClassPK());
58  
59          if (!IGImagePermission.contains(
60                  permissionChecker, image, ActionKeys.VIEW)) {
61  
62              return null;
63          }
64  
65          String groupName = StringPool.BLANK;
66  
67          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
68              groupName = getGroupName(activity.getGroupId(), themeDisplay);
69          }
70  
71          String creatorUserName = getUserName(
72              activity.getUserId(), themeDisplay);
73  
74          int activityType = activity.getType();
75  
76          // Link
77  
78          String link =
79              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
80                  "/image_gallery/find_image?imageId=" + image.getImageId();
81  
82          // Title
83  
84          String titlePattern = null;
85  
86          if (activityType == IGActivityKeys.ADD_IMAGE) {
87              titlePattern = "activity-image-gallery-add-image";
88          }
89          else if (activityType == IGActivityKeys.UPDATE_IMAGE) {
90              titlePattern = "activity-image-gallery-update-image";
91          }
92  
93          if (Validator.isNotNull(groupName)) {
94              titlePattern += "-in";
95          }
96  
97          String imageName = wrapLink(link, cleanContent(image.getName()));
98  
99          Object[] titleArguments = new Object[] {
100             groupName, creatorUserName, imageName
101         };
102 
103         String title = themeDisplay.translate(titlePattern, titleArguments);
104 
105         // Body
106 
107         String folderLink =
108             themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
109                 "/image_gallery/find_folder?folderId=" + image.getFolderId();
110 
111         String body = wrapLink(folderLink, "go-to-folder", themeDisplay);
112 
113         return new SocialActivityFeedEntry(link, title, body);
114     }
115 
116     private static final String[] _CLASS_NAMES = new String[] {
117         IGImage.class.getName()
118     };
119 
120 }