1
22
23 package com.liferay.portal.webdav;
24
25 import com.liferay.portal.kernel.dao.orm.QueryUtil;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.model.Company;
28 import com.liferay.portal.model.Group;
29 import com.liferay.portal.service.CompanyLocalServiceUtil;
30 import com.liferay.portal.service.GroupLocalServiceUtil;
31
32 import java.util.ArrayList;
33 import java.util.LinkedHashMap;
34 import java.util.List;
35
36
41 public class CompanyWebDAVStorageImpl extends BaseWebDAVStorageImpl {
42
43 public Resource getResource(WebDAVRequest webDavRequest)
44 throws WebDAVException {
45
46 String path = getRootPath() + webDavRequest.getPath();
47
48 return new BaseResourceImpl(
49 path, StringPool.BLANK, WebDAVUtil.getWebId(path));
50 }
51
52 public List<Resource> getResources(WebDAVRequest webDavRequest)
53 throws WebDAVException {
54
55 try {
56 LinkedHashMap<String, Object> groupParams =
57 new LinkedHashMap<String, Object>();
58
59 groupParams.put("usersGroups", new Long(webDavRequest.getUserId()));
60
61 List<Resource> resources = new ArrayList<Resource>();
62
63 List<Group> groups = GroupLocalServiceUtil.search(
64 webDavRequest.getCompanyId(), null, null, groupParams,
65 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
66
67 for (Group group : groups) {
68 Resource resource = getResource(group);
69
70 resources.add(resource);
71 }
72
73 Group group = GroupLocalServiceUtil.getUserGroup(
74 webDavRequest.getCompanyId(), webDavRequest.getUserId());
75
76 Resource resource = getResource(group);
77
78 resources.add(resource);
79
80 return resources;
81 }
82 catch (Exception e) {
83 throw new WebDAVException(e);
84 }
85 }
86
87 protected Resource getResource(Group group) throws WebDAVException {
88 try {
89 Company company = CompanyLocalServiceUtil.getCompanyById(
90 group.getCompanyId());
91
92 String webId = company.getWebId();
93
94 String parentPath = getRootPath() + StringPool.SLASH + webId;
95
96 String name = group.getFriendlyURL();
97
98 name = name.substring(1, name.length());
99
100 return new BaseResourceImpl(parentPath, name, name);
101 }
102 catch (Exception e) {
103 throw new WebDAVException(e);
104 }
105 }
106
107 }