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
42 public class CompanyWebDAVStorageImpl extends BaseWebDAVStorageImpl {
43
44 public Resource getResource(WebDAVRequest webDavRequest)
45 throws WebDAVException {
46
47 String path = getRootPath() + webDavRequest.getPath();
48
49 return new BaseResourceImpl(
50 path, StringPool.BLANK, WebDAVUtil.getWebId(path));
51 }
52
53 public List<Resource> getResources(WebDAVRequest webDavRequest)
54 throws WebDAVException {
55
56 try {
57 LinkedHashMap<String, Object> groupParams =
58 new LinkedHashMap<String, Object>();
59
60 groupParams.put("usersGroups", new Long(webDavRequest.getUserId()));
61
62 List<Resource> resources = new ArrayList<Resource>();
63
64 List<Group> groups = GroupLocalServiceUtil.search(
65 webDavRequest.getCompanyId(), null, null, groupParams,
66 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
67
68 for (Group group : groups) {
69 Resource resource = getResource(group);
70
71 resources.add(resource);
72 }
73
74 Group group = GroupLocalServiceUtil.getUserGroup(
75 webDavRequest.getCompanyId(), webDavRequest.getUserId());
76
77 Resource resource = getResource(group);
78
79 resources.add(resource);
80
81 return resources;
82 }
83 catch (Exception e) {
84 throw new WebDAVException(e);
85 }
86 }
87
88 protected Resource getResource(Group group) throws WebDAVException {
89 try {
90 Company company = CompanyLocalServiceUtil.getCompanyById(
91 group.getCompanyId());
92
93 String webId = company.getWebId();
94
95 String parentPath = getRootPath() + StringPool.SLASH + webId;
96
97 String name = group.getFriendlyURL();
98
99 name = name.substring(1, name.length());
100
101 return new BaseResourceImpl(parentPath, name, name);
102 }
103 catch (Exception e) {
104 throw new WebDAVException(e);
105 }
106 }
107
108 }