1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class IGActivityInterpreter 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          PermissionChecker permissionChecker =
53              themeDisplay.getPermissionChecker();
54  
55          IGImage image = IGImageLocalServiceUtil.getIGImage(
56              activity.getClassPK());
57  
58          if (!IGImagePermission.contains(
59                  permissionChecker, image, ActionKeys.VIEW)) {
60  
61              return null;
62          }
63  
64          String groupName = StringPool.BLANK;
65  
66          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
67              groupName = getGroupName(activity.getGroupId(), themeDisplay);
68          }
69  
70          String creatorUserName = getUserName(
71              activity.getUserId(), themeDisplay);
72  
73          int activityType = activity.getType();
74  
75          // Link
76  
77          String link =
78              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
79                  "/image_gallery/find_image?imageId=" + image.getImageId();
80  
81          // Title
82  
83          String titlePattern = null;
84  
85          if (activityType == IGActivityKeys.ADD_IMAGE) {
86              titlePattern = "activity-image-gallery-add-image";
87          }
88          else if (activityType == IGActivityKeys.UPDATE_IMAGE) {
89              titlePattern = "activity-image-gallery-update-image";
90          }
91  
92          if (Validator.isNotNull(groupName)) {
93              titlePattern += "-in";
94          }
95  
96          String imageName = wrapLink(link, cleanContent(image.getName()));
97  
98          Object[] titleArguments = new Object[] {
99              groupName, creatorUserName, imageName
100         };
101 
102         String title = themeDisplay.translate(titlePattern, titleArguments);
103 
104         // Body
105 
106         String folderLink =
107             themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
108                 "/image_gallery/find_folder?folderId=" + image.getFolderId();
109 
110         String body = wrapLink(folderLink, "go-to-folder", themeDisplay);
111 
112         return new SocialActivityFeedEntry(link, title, body);
113     }
114 
115     private static final String[] _CLASS_NAMES = new String[] {
116         IGImage.class.getName()
117     };
118 
119 }