ProjectImpl.java
7.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.projects.api.Project
* com.adobe.cq.projects.api.ProjectException
* com.adobe.cq.projects.api.ProjectLink
* com.adobe.cq.projects.api.ProjectMember
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.wcm.api.Template
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.commons.lang3.StringUtils
* org.apache.jackrabbit.commons.JcrUtils
* org.apache.sling.adapter.annotations.Adaptable
* org.apache.sling.adapter.annotations.Adapter
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ResourceWrapper
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.projects.impl;
import com.adobe.cq.projects.api.Project;
import com.adobe.cq.projects.api.ProjectException;
import com.adobe.cq.projects.api.ProjectLink;
import com.adobe.cq.projects.api.ProjectMember;
import com.adobe.cq.projects.impl.ProjectLinkImpl;
import com.adobe.cq.projects.impl.team.Team;
import com.adobe.cq.projects.impl.team.TeamException;
import com.adobe.cq.projects.impl.team.TeamManager;
import com.adobe.cq.projects.impl.util.ProjectUtils;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.wcm.api.Template;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adapter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ResourceWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Adaptable(adaptableClass=Project.class, adapters={@Adapter(value={Resource.class, Template.class})})
public class ProjectImpl
extends ResourceWrapper
implements Project {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectImpl.class);
private TeamManager teamManager;
public ProjectImpl(Resource resource, TeamManager teamManager) {
super(resource);
this.teamManager = teamManager;
}
public void setTeamManager(TeamManager teamManager) {
this.teamManager = teamManager;
}
public TeamManager getTeamManager() {
return this.teamManager;
}
public ProjectLink addLink(String name, String target) {
try {
if (StringUtils.isBlank((CharSequence)name)) {
name = "link";
}
Resource linksFolder = this.getLinksFolderResource();
String newName = JcrUtil.createValidName((String)name).replaceAll("-", "");
Node linkNode = JcrUtils.getOrCreateUniqueByPath((Node)((Node)linksFolder.adaptTo(Node.class)), (String)newName, (String)"nt:unstructured");
linkNode.setProperty("sling:resourceType", "cq/gui/components/projects/admin/card/linkcard");
linkNode.setProperty("suffix", target);
return new ProjectLinkImpl(this, this.getResourceResolver().getResource(linkNode.getPath()));
}
catch (RepositoryException e) {
throw new ProjectException("Failed to add link", (Throwable)e);
}
}
private Resource getLinksFolderResource() {
return this.getChild("jcr:content/links");
}
public Iterable<ProjectLink> getLinks() {
ArrayList<ProjectLink> result = new ArrayList<ProjectLink>();
Resource linksFolder = this.getLinksFolderResource();
if (linksFolder != null && !ResourceUtil.isNonExistingResource((Resource)linksFolder)) {
Iterable links = linksFolder.getChildren();
for (Resource link : links) {
result.add(new ProjectLinkImpl(this, link));
}
}
return result;
}
public Collection<ProjectMember> updateMembers(List<String> userIds, List<String> roleIds) {
try {
String path = this.getPath();
if (!this.teamManager.canApplyTeam(path)) {
LOGGER.warn("User {} does not have permission to update the team members for project {}", (Object)this.teamManager.getUserId(), (Object)this.getPath());
throw new ProjectException("Unable to update team members for project " + this.getPath());
}
return this.teamManager.updateRoleGroups(this, userIds, roleIds);
}
catch (TeamException te) {
throw new ProjectException("Failed to update project members", (Throwable)te);
}
}
public void setProjectCover(String mimeType, InputStream thumbnailStream) {
Resource content = this.getChild("jcr:content");
ProjectUtils.setCoverImage(content, this, mimeType, thumbnailStream, "cover");
}
public Resource getProjectCover() {
return ProjectUtils.getCoverImage((Resource)this);
}
public Set<ProjectMember> getMembers() {
Team team = this.getTeam();
LinkedHashSet<ProjectMember> members = new LinkedHashSet<ProjectMember>();
if (team != null) {
members.addAll(team.getMembers().values());
}
return members;
}
public Resource getAssetFolder() {
String damFolderPath = ProjectUtils.getProjectProperty((Resource)this, "damFolderPath", String.class);
return this.getResourceResolver().resolve(damFolderPath);
}
public String getTitle() {
return ProjectUtils.getProjectProperty((Resource)this, "jcr:title", String.class);
}
public void setTitle(String title) {
try {
ProjectUtils.setProjectProperty((Resource)this, "jcr:title", title);
}
catch (RepositoryException e) {
throw new ProjectException("Unable to update the project's title", (Throwable)e);
}
}
public String getDescription() {
return ProjectUtils.getProjectProperty((Resource)this, "jcr:description", String.class);
}
public void setDescription(String description) {
try {
ProjectUtils.setProjectProperty((Resource)this, "jcr:description", description);
}
catch (RepositoryException e) {
throw new ProjectException("Unable to update the project's description", (Throwable)e);
}
}
private Team getTeam() {
try {
return this.teamManager.getTeam(this);
}
catch (TeamException e) {
throw new ProjectException("Failed to retrieve project team", (Throwable)e);
}
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (Resource.class == type) {
return (AdapterType)this.getResource();
}
if (Template.class == type) {
Resource templateResource;
String template = ProjectUtils.getProjectProperty((Resource)this, "cq:template", String.class);
if (StringUtils.isNotEmpty((CharSequence)template) && (templateResource = this.getResourceResolver().getResource(template)) != null) {
return (AdapterType)templateResource.adaptTo(Template.class);
}
return null;
}
return (AdapterType)super.adaptTo(type);
}
public void setActive(boolean active) {
try {
ProjectUtils.setProjectProperty((Resource)this, "active", active);
}
catch (RepositoryException e) {
throw new ProjectException("Unable to update the project's active state", (Throwable)e);
}
}
public boolean isActive() {
Boolean active = ProjectUtils.getProjectProperty((Resource)this, "active", Boolean.class);
if (active == null) {
return false;
}
return active;
}
}