FMDependencyProviderImpl.java
8.51 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
/*
* 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
* 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.transferobjects.AssetInfo;
import com.adobe.aem.formsndocuments.util.FMConstants;
import com.adobe.aem.formsndocuments.util.FMUtils;
import com.adobe.aemforms.fm.exception.FormsMgrException;
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 java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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 FMDependencyProviderImpl
implements DependencyProvider {
private static final Logger logger = LoggerFactory.getLogger(FMDependencyProviderImpl.class);
@Reference
private FormsFoundationUtils formsFoundationUtils;
@Reference
private FormsRelationService formsRelationService;
@Reference
private ResourceResolverFactory resourceResolverFactory;
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());
Set<AssetInfo> assetInfoSet = this.formsRelationService.getDependentParentFMAssets(resolver, assetId);
this.processDependentParentAssets(assetInfoSet, parentDeps);
}
catch (FormsFoundationException e) {
throw e;
}
catch (FormsMgrException e) {
throw new FormsFoundationException(e.getMessage(), (Throwable)e);
}
catch (Exception e) {
throw new FormsFoundationException((Throwable)e);
}
return parentDeps;
}
public boolean hasParentDependencies(String assetId) throws FormsFoundationException {
boolean hasParentDeps;
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());
hasParentDeps = this.formsRelationService.hasDependentParentFMAssets(resolver, assetId);
}
catch (FormsFoundationException e) {
throw e;
}
catch (FormsMgrException e) {
throw new FormsFoundationException(e.getMessage(), (Throwable)e);
}
catch (Exception e) {
throw new FormsFoundationException((Throwable)e);
}
return hasParentDeps;
}
public Map<FormsAssetType, Set<String>> getDDEReferences(String dataDictionaryID, List<String> ddeReferenceNames) throws FormsFoundationException {
try {
if (dataDictionaryID == null || dataDictionaryID.isEmpty() || ddeReferenceNames == null || ddeReferenceNames.size() == 0) {
Object[] obj = null;
throw new FormsFoundationException("AEM-FF-002", obj);
}
HashMap<FormsAssetType, Set<String>> parentDeps = new HashMap<FormsAssetType, Set<String>>();
Set<AssetInfo> assetInfoSet = this.formsRelationService.getDDEReferences(dataDictionaryID, ddeReferenceNames);
this.processDependentParentAssets(assetInfoSet, parentDeps);
return parentDeps;
}
catch (FormsFoundationException e) {
throw e;
}
catch (FormsMgrException e) {
throw new FormsFoundationException(e.getMessage(), (Throwable)e);
}
catch (Exception e) {
throw new FormsFoundationException((Throwable)e);
}
}
public boolean hasDDEReferences(String dataDictionaryID, List<String> ddeReferenceNames) throws FormsFoundationException {
try {
if (dataDictionaryID == null || dataDictionaryID.isEmpty() || ddeReferenceNames == null || ddeReferenceNames.size() == 0) {
Object[] obj = null;
throw new FormsFoundationException("AEM-FF-002", obj);
}
return this.formsRelationService.hasDDEReferences(dataDictionaryID, ddeReferenceNames);
}
catch (FormsFoundationException e) {
throw e;
}
catch (FormsMgrException e) {
throw new FormsFoundationException(e.getMessage(), (Throwable)e);
}
catch (Exception e) {
throw new FormsFoundationException((Throwable)e);
}
}
private void processDependentParentAssets(Set<AssetInfo> assetInfoSet, Map<FormsAssetType, Set<String>> parentDeps) throws FormsMgrException {
if (assetInfoSet == null) {
logger.debug("assetInfoSet should not be null in processDependentParentAssets() in FMDependencyProviderImpl");
return;
}
for (AssetInfo assetInfo : assetInfoSet) {
Resource resource = assetInfo.getResource();
if (resource == null) continue;
String path = resource.getPath();
FormsAssetType assetType = FMUtils.getFormsFoundationAssetType(assetInfo.getType());
this.addAssetToDependenciesList(parentDeps, assetType, path);
}
}
private void addAssetToDependenciesList(Map<FormsAssetType, Set<String>> dependenciesMap, FormsAssetType assetType, String path) {
if (path == null || path.isEmpty()) {
logger.error("empty path cannot be added in addAssetToDependenciesList() in FMDependencyProviderImpl");
return;
}
if (assetType == null) {
logger.error("assetType cannot be null in addAssetToDependenciesList() in FMDependencyProviderImpl");
return;
}
if (!dependenciesMap.containsKey((Object)assetType)) {
dependenciesMap.put(assetType, new HashSet());
}
dependenciesMap.get((Object)assetType).add(path);
}
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;
}
}
}