1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.sharepoint;
16  
17  import com.liferay.portal.kernel.dao.orm.QueryUtil;
18  import com.liferay.portal.kernel.util.StringBundler;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.model.Group;
21  import com.liferay.portal.model.Organization;
22  import com.liferay.portal.model.User;
23  import com.liferay.portal.service.GroupLocalServiceUtil;
24  import com.liferay.portal.service.OrganizationLocalServiceUtil;
25  import com.liferay.portal.service.UserServiceUtil;
26  
27  import java.util.LinkedHashMap;
28  import java.util.List;
29  
30  /**
31   * <a href="CompanySharepointStorageImpl.java.html"><b><i>View Source</i></b>
32   * </a>
33   *
34   * @author Bruno Farache
35   */
36  public class CompanySharepointStorageImpl extends BaseSharepointStorageImpl {
37  
38      public Tree getFoldersTree(SharepointRequest sharepointRequest)
39          throws Exception {
40  
41          Tree foldersTree = new Tree();
42  
43          LinkedHashMap<String, Object> groupParams =
44              new LinkedHashMap<String, Object>();
45  
46          groupParams.put("usersGroups", new Long(sharepointRequest.getUserId()));
47  
48          List<Group> groups = GroupLocalServiceUtil.search(
49              sharepointRequest.getCompanyId(), null, null, groupParams,
50              QueryUtil.ALL_POS, QueryUtil.ALL_POS);
51  
52          Group userGroup = GroupLocalServiceUtil.getUserGroup(
53              sharepointRequest.getCompanyId(), sharepointRequest.getUserId());
54  
55          groups.add(userGroup);
56  
57          List<Organization> organizations =
58              OrganizationLocalServiceUtil.getUserOrganizations(
59                  sharepointRequest.getUserId(), true);
60  
61          for (Organization organization : organizations) {
62              groups.add(organization.getGroup());
63          }
64  
65          for (Group group : groups) {
66              String path = getGroupPath(group);
67  
68              foldersTree.addChild(getFolderTree(path));
69          }
70  
71          foldersTree.addChild(getFolderTree(StringPool.BLANK));
72  
73          return foldersTree;
74      }
75  
76      protected String getGroupPath(Group group) throws Exception {
77          StringBundler sb = new StringBundler(5);
78  
79          String name = group.getName();
80  
81          long classPK = group.getClassPK();
82  
83          if (group.isUser()) {
84              User user = UserServiceUtil.getUserById(classPK);
85  
86              name = user.getFullName();
87          }
88          else if (group.isOrganization()) {
89              Organization organization =
90                  OrganizationLocalServiceUtil.getOrganization(classPK);
91  
92              name = organization.getName();
93          }
94  
95          sb.append(name);
96          sb.append(StringPool.SPACE);
97          sb.append(StringPool.OPEN_BRACKET);
98          sb.append(group.getGroupId());
99          sb.append(StringPool.CLOSE_BRACKET);
100 
101         return sb.toString();
102     }
103 
104 }