SitesDependencyProviderImpl.java
8.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
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
217
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.forms.foundation.provider.DependencyProvider
* com.adobe.forms.foundation.service.FormsAssetType
* com.adobe.forms.foundation.service.FormsFoundationException
* com.adobe.forms.foundation.service.util.FormsFoundationUtils
* com.day.cq.search.Predicate
* com.day.cq.search.PredicateGroup
* com.day.cq.search.Query
* com.day.cq.search.QueryBuilder
* com.day.cq.search.result.SearchResult
* javax.jcr.Node
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aem.formsndocuments.service.impl;
import com.adobe.aem.formsndocuments.service.FormsRelationService;
import com.adobe.aem.formsndocuments.util.FMUtils;
import com.adobe.forms.foundation.provider.DependencyProvider;
import com.adobe.forms.foundation.service.FormsAssetType;
import com.adobe.forms.foundation.service.FormsFoundationException;
import com.adobe.forms.foundation.service.util.FormsFoundationUtils;
import com.day.cq.search.Predicate;
import com.day.cq.search.PredicateGroup;
import com.day.cq.search.Query;
import com.day.cq.search.QueryBuilder;
import com.day.cq.search.result.SearchResult;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service
public class SitesDependencyProviderImpl
implements DependencyProvider {
private static final Logger logger = LoggerFactory.getLogger(SitesDependencyProviderImpl.class);
@Reference
private FormsFoundationUtils formsFoundationUtils;
@Reference
private FormsRelationService formsRelationService;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference(referenceInterface=QueryBuilder.class)
private QueryBuilder queryBuilder;
public Map<FormsAssetType, Set<String>> getImmediateParentDependencies(String assetId) throws FormsFoundationException {
HashMap<FormsAssetType, Set<String>> parentDeps = new HashMap<FormsAssetType, Set<String>>();
try {
if (assetId == null || assetId.isEmpty()) {
Object[] obj = null;
throw new FormsFoundationException("AEM-FF-002", obj);
}
ResourceResolver resolver = FMUtils.getResourceResolver(this.resourceResolverFactory, this.formsFoundationUtils.getCurrentSession());
SearchResult result = this.searchDependentParentAssets(assetId);
if (result != null) {
HashSet<String> referringPages = new HashSet<String>();
Iterator iter = result.getNodes();
while (iter.hasNext()) {
String nodePath = ((Node)iter.next()).getPath();
Resource cqPageResouce = FMUtils.getClosestNodeUpInHierarchy(resolver, nodePath, "jcr:primaryType", "cq:Page", true);
if (cqPageResouce == null) continue;
referringPages.add(cqPageResouce.getPath());
}
parentDeps.put(FormsAssetType.CQ_PAGE, referringPages);
}
}
catch (FormsFoundationException e) {
throw e;
}
catch (Exception e) {
throw new FormsFoundationException((Throwable)e);
}
return parentDeps;
}
public boolean hasParentDependencies(String assetId) throws FormsFoundationException {
try {
if (assetId == null || assetId.isEmpty()) {
Object[] obj = null;
throw new FormsFoundationException("AEM-FF-002", obj);
}
SearchResult result = this.searchDependentParentAssets(assetId);
if (result != null && result.getTotalMatches() > 0) {
return true;
}
}
catch (FormsFoundationException e) {
throw e;
}
catch (Exception e) {
throw new FormsFoundationException((Throwable)e);
}
return false;
}
public Map<FormsAssetType, Set<String>> getDDEReferences(String dataDictionaryID, List<String> ddeReferenceNames) throws FormsFoundationException {
return new HashMap<FormsAssetType, Set<String>>();
}
public boolean hasDDEReferences(String dataDictionaryID, List<String> ddeReferenceNames) throws FormsFoundationException {
return false;
}
private SearchResult searchDependentParentAssets(String path) throws FormsFoundationException {
logger.debug("Enter : searchDependentParentAssets for asset : " + path);
if (path.startsWith("/content/forms/af")) {
path = FMUtils.getAssetPathFromPage(path);
}
PredicateGroup predicateGroup = new PredicateGroup();
predicateGroup.setAllRequired(true);
Predicate typePredicate = new Predicate("type");
typePredicate.set("type", "nt:unstructured");
Predicate pathPredicate = new Predicate("path");
pathPredicate.set("path", "/content");
pathPredicate.set("exact", "false");
PredicateGroup refPredicateGroup = new PredicateGroup();
FormsAssetType assetType = this.formsFoundationUtils.getAssetType(path);
switch (assetType) {
case ADAPTIVE_DOCUMENT:
case ADAPTIVE_FORM: {
refPredicateGroup.setAllRequired(true);
Predicate refPredicate = this.getPropertyPredicate("sling:resourceType", "fd/af/components/aemform");
refPredicateGroup.add(refPredicate);
refPredicate = this.getPropertyPredicate("formRef", path);
refPredicateGroup.add(refPredicate);
break;
}
case THEME: {
return null;
}
default: {
return null;
}
}
predicateGroup.add(typePredicate);
predicateGroup.add(pathPredicate);
predicateGroup.add((Predicate)refPredicateGroup);
Query query = this.queryBuilder.createQuery(predicateGroup, this.formsFoundationUtils.getCurrentSession());
SearchResult result = query.getResult();
logger.debug("Query execution time (ms) " + result.getExecutionTimeMillis());
logger.debug("Exit : searchParentDependentAssets for asset : " + path);
return result;
}
private Predicate getPropertyPredicate(String propertyPath, String propertyVal) {
Predicate refPredicate = new Predicate("property");
refPredicate.set("property", propertyPath);
refPredicate.set("operation", "equals");
refPredicate.set("value", propertyVal);
return refPredicate;
}
protected void bindFormsFoundationUtils(FormsFoundationUtils formsFoundationUtils) {
this.formsFoundationUtils = formsFoundationUtils;
}
protected void unbindFormsFoundationUtils(FormsFoundationUtils formsFoundationUtils) {
if (this.formsFoundationUtils == formsFoundationUtils) {
this.formsFoundationUtils = null;
}
}
protected void bindFormsRelationService(FormsRelationService formsRelationService) {
this.formsRelationService = formsRelationService;
}
protected void unbindFormsRelationService(FormsRelationService formsRelationService) {
if (this.formsRelationService == formsRelationService) {
this.formsRelationService = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindQueryBuilder(QueryBuilder queryBuilder) {
this.queryBuilder = queryBuilder;
}
protected void unbindQueryBuilder(QueryBuilder queryBuilder) {
if (this.queryBuilder == queryBuilder) {
this.queryBuilder = null;
}
}
}