LaunchImpl.java
6.66 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchException
* com.adobe.cq.launches.api.LaunchSource
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.Template
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.cq.wcm.launches.impl;
import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.launches.api.LaunchException;
import com.adobe.cq.launches.api.LaunchSource;
import com.adobe.cq.wcm.launches.impl.LaunchSourceImpl;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.Template;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public class LaunchImpl
implements Launch {
private final Resource resource;
private final Resource contentRes;
private final ResourceResolver resolver;
private final ValueMap props;
private final ValueMap contentProps;
private List<LaunchSource> launchSources = null;
LaunchImpl(Resource r) throws LaunchException {
if (r == null) {
throw new LaunchException("Cannot instantiate launch. Resource cannot be null.");
}
if (r.isResourceType("wcm/launches/components/launch")) {
this.contentRes = r;
this.resource = r.getParent();
} else {
this.contentRes = r.getChild("jcr:content");
if (this.contentRes == null) {
throw new LaunchException("Cannot instantiate launch. Resource has no jcr:content child node.");
}
if (!this.contentRes.isResourceType("wcm/launches/components/launch")) {
throw new LaunchException("Cannot instantiate launch. Invalid resource type for [" + this.contentRes.getPath() + "].");
}
this.resource = r;
}
this.resolver = this.resource.getResourceResolver();
this.props = (ValueMap)this.resource.adaptTo(ValueMap.class);
this.contentProps = (ValueMap)this.contentRes.adaptTo(ValueMap.class);
if (this.getRootResource() == null) {
throw new LaunchException("Cannot instantiate launch. Root resource cannot be null.");
}
}
public Resource getResource() {
return this.resource;
}
public Resource getRootResource() {
Resource sourceRootRes = this.getSourceRootResource();
if (sourceRootRes != null) {
return this.resource.getChild(sourceRootRes.getPath().substring(1));
}
return null;
}
public Resource getSourceRootResource() {
String sourceRootResPath = (String)this.contentProps.get("sourceRootResource", String.class);
return sourceRootResPath != null ? this.resolver.getResource(sourceRootResPath) : null;
}
public String getTitle() {
return (String)this.contentProps.get("jcr:title", String.class);
}
public Calendar getLiveDate() {
return (Calendar)this.contentProps.get("liveDate", Calendar.class);
}
public boolean isProductionReady() {
return (Boolean)this.contentProps.get("isProductionReady", (Object)false);
}
public boolean isLiveCopy() {
return (Boolean)this.contentProps.get("isLiveCopy", (Object)false);
}
public boolean isDeep() {
return (Boolean)this.contentProps.get("isDeep", (Object)false);
}
public Calendar getCreated() {
return (Calendar)this.props.get("jcr:created", Calendar.class);
}
public String getCreatedBy() {
return (String)this.props.get("jcr:createdBy", String.class);
}
public Calendar getModified() {
return (Calendar)this.contentProps.get("cq:lastModified", (Object)this.getCreated());
}
public String getModifiedBy() {
return (String)this.contentProps.get("cq:lastModifiedBy", (Object)this.getCreatedBy());
}
public Calendar getLastPromoted() {
return (Calendar)this.contentProps.get("lastPromoted", Calendar.class);
}
public String getLastPromotedBy() {
return (String)this.contentProps.get("lastPromotedBy", String.class);
}
public boolean containsResource(Resource productionResource) {
Resource r;
Page p;
if (productionResource == null) {
return false;
}
try {
r = LaunchUtils.getLaunchResource(this, productionResource);
}
catch (LaunchException e) {
return false;
}
if (r != null && (p = (Page)r.adaptTo(Page.class)) != null) {
Template t = p.getTemplate();
return t == null || !"/libs/launches/templates/outofscope".equals(t.getPath());
}
return false;
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
public int compareTo(Launch launch) {
int c;
if (launch == null) {
return 1;
}
if (this.getLiveDate() != null) {
if (launch.getLiveDate() == null) return 1;
c = this.getLiveDate().compareTo(launch.getLiveDate());
if (c != 0) {
return c;
}
} else if (launch.getLiveDate() != null) {
return -1;
}
if ((c = this.getCreated().compareTo(launch.getCreated())) == 0) return this.getResource().getPath().compareTo(launch.getResource().getPath());
return c;
}
public List<LaunchSource> getLaunchSources() {
if (this.launchSources == null) {
Iterable childList;
this.launchSources = new ArrayList<LaunchSource>();
Resource parentResource = this.contentRes.getChild("sources");
if (parentResource != null && (childList = parentResource.getChildren()) != null) {
for (Resource child : childList) {
ValueMap valueMap = (ValueMap)child.adaptTo(ValueMap.class);
String strPath = (String)valueMap.get("sourceRootResource", String.class);
Resource childResource = this.resolver.getResource(strPath);
boolean childIsDeep = (Boolean)valueMap.get("isDeep", (Object)false);
this.launchSources.add(new LaunchSourceImpl(childResource, childIsDeep));
}
}
}
if (this.launchSources.size() == 0) {
this.launchSources.add(new LaunchSourceImpl(this.getSourceRootResource(), this.isDeep()));
}
return this.launchSources;
}
}