1
22
23 package com.liferay.portal.webdav;
24
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.model.Group;
27 import com.liferay.portal.model.User;
28 import com.liferay.portal.service.GroupLocalServiceUtil;
29 import com.liferay.portal.service.UserLocalServiceUtil;
30 import com.liferay.util.dao.hibernate.QueryUtil;
31
32 import java.util.ArrayList;
33 import java.util.Iterator;
34 import java.util.LinkedHashMap;
35 import java.util.List;
36
37
43 public abstract class BaseWebDAVStorageImpl implements WebDAVStorage {
44
45 public String getRootPath() {
46 return _rootPath;
47 }
48
49 public void setRootPath(String rootPath) {
50 _rootPath = rootPath;
51 }
52
53 public List getCommunities(WebDAVRequest webDavReq)
54 throws WebDAVException {
55
56 try {
57 LinkedHashMap groupParams = new LinkedHashMap();
58
59 groupParams.put("usersGroups", new Long(webDavReq.getUserId()));
60
61 List communities = new ArrayList();
62
63 Iterator itr = GroupLocalServiceUtil.search(
64 webDavReq.getCompanyId(), null, null, groupParams,
65 QueryUtil.ALL_POS, QueryUtil.ALL_POS).iterator();
66
67 while (itr.hasNext()) {
68 Group group = (Group)itr.next();
69
70 Resource resource = getResource(group);
71
72 communities.add(resource);
73 }
74
75 Group group = GroupLocalServiceUtil.getUserGroup(
76 webDavReq.getCompanyId(), webDavReq.getUserId());
77
78 Resource resource = getResource(group);
79
80 communities.add(resource);
81
82 return communities;
83 }
84 catch (Exception e) {
85 throw new WebDAVException(e);
86 }
87 }
88
89 public boolean isAvailable(WebDAVRequest webDavReq)
90 throws WebDAVException {
91
92 if (getResource(webDavReq) == null) {
93 return false;
94 }
95 else {
96 return true;
97 }
98 }
99
100 protected Resource getResource(Group group) throws WebDAVException {
101 try {
102 String parentPath =
103 getRootPath() + StringPool.SLASH + group.getCompanyId();
104
105 String name = group.getName();
106
107 if (group.isUser()) {
108 long userId = group.getClassPK();
109
110 User user = UserLocalServiceUtil.getUserById(userId);
111
112 name = user.getFullName();
113 }
114
115 return new BaseResourceImpl(parentPath, group.getGroupId(), name);
116 }
117 catch (Exception e) {
118 throw new WebDAVException(e);
119 }
120 }
121
122 private String _rootPath;
123
124 }