AbstractFDMSubmitService.java
30 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aem.dermis.api.IFormDataModelManager
* com.adobe.aem.dermis.api.bridge.DataContext
* com.adobe.aem.dermis.api.bridge.IDermisBridge
* com.adobe.aem.dermis.api.bridge.OperationOptions
* com.adobe.aem.dermis.api.bridge.Query
* com.adobe.aem.dermis.model.IProperty
* com.adobe.aem.dermis.model.PropertyType
* com.adobe.aem.dermis.model.value.ITypeValue
* com.adobe.aem.dermis.model.value.IValue
* com.adobe.aem.dermis.model.value.IValueList
* com.adobe.aem.dermis.model.value.IValueMap
* com.adobe.aem.dermis.slingmodel.Attribute
* com.adobe.aem.dermis.slingmodel.Entity
* com.adobe.aem.dermis.slingmodel.EntityOperation
* com.adobe.aem.dermis.slingmodel.FormDataModel
* com.adobe.aem.dermis.util.DermisUtils
* com.adobe.aemds.guide.model.FormSubmitInfo
* com.adobe.aemds.guide.service.GuideException
* com.adobe.aemds.guide.service.GuideModelImporter
* com.adobe.aemds.guide.service.GuideModelTransformer
* com.adobe.aemds.guide.service.IJsonSchemaValidatorParser
* com.adobe.aemds.guide.service.external.FormDataModelService
* com.adobe.aemds.guide.utils.JSONCreationOptions
* com.adobe.forms.common.service.FileAttachmentWrapper
* com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
* com.day.cq.i18n.I18n
* com.fasterxml.jackson.databind.JsonNode
* org.apache.commons.collections.BeanMap
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.addon.fdm.submit;
import com.adobe.aem.dermis.api.IFormDataModelManager;
import com.adobe.aem.dermis.api.bridge.DataContext;
import com.adobe.aem.dermis.api.bridge.IDermisBridge;
import com.adobe.aem.dermis.api.bridge.OperationOptions;
import com.adobe.aem.dermis.api.bridge.Query;
import com.adobe.aem.dermis.model.IProperty;
import com.adobe.aem.dermis.model.PropertyType;
import com.adobe.aem.dermis.model.value.ITypeValue;
import com.adobe.aem.dermis.model.value.IValue;
import com.adobe.aem.dermis.model.value.IValueList;
import com.adobe.aem.dermis.model.value.IValueMap;
import com.adobe.aem.dermis.slingmodel.Attribute;
import com.adobe.aem.dermis.slingmodel.Entity;
import com.adobe.aem.dermis.slingmodel.EntityOperation;
import com.adobe.aem.dermis.slingmodel.FormDataModel;
import com.adobe.aem.dermis.util.DermisUtils;
import com.adobe.aemds.guide.addon.fdm.submit.IFDMSubmit;
import com.adobe.aemds.guide.model.FormSubmitInfo;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideModelImporter;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.service.IJsonSchemaValidatorParser;
import com.adobe.aemds.guide.service.external.FormDataModelService;
import com.adobe.aemds.guide.utils.JSONCreationOptions;
import com.adobe.forms.common.service.FileAttachmentWrapper;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import com.day.cq.i18n.I18n;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.collections.BeanMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, metatype=0)
public abstract class AbstractFDMSubmitService
implements IFDMSubmit {
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
protected IFormDataModelManager formDataModelManager;
@Reference
protected ResourceResolverHelper resourceResolverHelper;
@Reference
protected GuideModelImporter guideModelImporter;
@Reference
protected IJsonSchemaValidatorParser jsonSchemaValidatorParser;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
protected IDermisBridge dermisBridge;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
protected FormDataModelService formDataModelService;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
protected GuideModelTransformer guideModelTransformer;
private final Logger logger;
public AbstractFDMSubmitService() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
public abstract String getServiceName();
@Override
public abstract String getOperationName(FormSubmitInfo var1) throws Exception;
protected String getEntityPath(Resource guideContainerResource) {
ValueMap properties = guideContainerResource.getValueMap();
return (String)properties.get("fdmEntityPath", (Object)"");
}
protected String getEntityId(Resource guideContainerResource) {
String entityIdPath = null;
entityIdPath = this.getEntityPath(guideContainerResource);
if (StringUtils.isNotBlank((CharSequence)entityIdPath)) {
entityIdPath = this.formDataModelService.getFDMEntityId(guideContainerResource.getPath(), entityIdPath);
}
return entityIdPath;
}
@Override
public DataContext getDataContext(FormSubmitInfo formSubmitInfo, int fileAttachmentIndex) {
Map requestParamMap = null;
BeanMap dorMap = null;
BeanMap attachmentMap = null;
if (fileAttachmentIndex > -1) {
FileAttachmentWrapper fileAttachment = (FileAttachmentWrapper)formSubmitInfo.getFileAttachments().get(fileAttachmentIndex);
FileAttachmentWrapper fileAttachmentCopy = new FileAttachmentWrapper(fileAttachment.getFileName(), fileAttachment.getContentType(), fileAttachment.getValue());
fileAttachmentCopy.setUuid(fileAttachment.getUuid());
if (fileAttachmentCopy != null) {
String fileName = fileAttachmentCopy.getFileName();
if (StringUtils.isNotBlank((CharSequence)fileName)) {
if (StringUtils.indexOf((CharSequence)fileName, (CharSequence)"/") != -1) {
fileName = StringUtils.substring((String)fileName, (int)(StringUtils.lastIndexOf((CharSequence)fileName, (CharSequence)"/") + 1));
}
fileAttachmentCopy.setFileName(fileName);
}
attachmentMap = new BeanMap((Object)fileAttachmentCopy);
}
}
if (formSubmitInfo.getDocumentOfRecord() != null) {
dorMap = new BeanMap((Object)formSubmitInfo.getDocumentOfRecord());
}
Map resultMap = DermisUtils.createBinaryAndRequestDataContext((Map)requestParamMap, (Map)attachmentMap, (Map)dorMap);
return new DataContext(resultMap);
}
protected String getFormDataModelPath(Resource guideContainerResource) {
ValueMap properties = guideContainerResource.getValueMap();
String formDataModelPath = (String)properties.get("schemaRef", (Object)"");
return formDataModelPath;
}
protected FormDataModel getFormDataModel(Resource guideContainerResource) throws Exception {
String formDataModelPath = this.getFormDataModelPath(guideContainerResource);
FormDataModel formDataModel = this.formDataModelManager.getFormDataModel(formDataModelPath);
return formDataModel;
}
protected void submitBinaryData(FormSubmitInfo formSubmitInfo, Boolean isDorSubmission, Boolean isAttachmentSubmission, String fileAttachmentValue) throws Exception {
ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
Resource guideContainerResource = resourceResolver.getResource(formSubmitInfo.getFormContainerPath());
String formDataModelPath = this.getFormDataModelPath(guideContainerResource);
if (formSubmitInfo.getFileAttachments().size() > 0 || formSubmitInfo.getDocumentOfRecord() != null) {
FormDataModel formDataModel = this.getFormDataModel(guideContainerResource);
if (formDataModel == null) {
throw new Exception("No form data model associated with AF container " + formSubmitInfo.getFormContainerPath());
}
Entity binaryEntity = this.formDataModelManager.getDefaultBinaryEntity(formDataModelPath);
if (binaryEntity != null) {
String binaryUuid = binaryEntity.getPrimaryKey();
String defaultBinaryOperationId = binaryEntity.getDefaultWriteOperation();
OperationOptions options = new OperationOptions(defaultBinaryOperationId, (JSONObject)null);
if (isAttachmentSubmission.booleanValue() && StringUtils.isNotBlank((CharSequence)fileAttachmentValue)) {
String[] fileNames = StringUtils.split((String)fileAttachmentValue, (String)"\n");
block0 : for (int j = 0; j < fileNames.length; ++j) {
for (int i = 0; i < formSubmitInfo.getFileAttachments().size(); ++i) {
if (!StringUtils.equals((CharSequence)StringUtils.substringAfterLast((String)((FileAttachmentWrapper)formSubmitInfo.getFileAttachments().get(i)).getFileName(), (String)"/"), (CharSequence)fileNames[j])) continue;
Query query = new Query(formDataModelPath, this.getDataContext(formSubmitInfo, i), options);
IValue value = this.dermisBridge.executeOperation(query);
FileAttachmentWrapper fileAttachment = (FileAttachmentWrapper)formSubmitInfo.getFileAttachments().get(i);
this.updateAttachmentUuid(fileAttachment, value, binaryUuid);
continue block0;
}
}
}
if (isDorSubmission.booleanValue()) {
Query query = new Query(formDataModelPath, this.getDataContext(formSubmitInfo, -1), options);
IValue value = this.dermisBridge.executeOperation(query);
this.updateAttachmentUuid(formSubmitInfo.getDocumentOfRecord(), value, binaryUuid);
}
}
}
}
protected Object getDataAsPerBindRef(Object data, String bindRef) throws JSONException {
JSONObject boundData = data instanceof JSONObject && ((JSONObject)data).optJSONObject("afData") != null ? ((JSONObject)data).optJSONObject("afData").optJSONObject("afBoundData").optJSONObject("data") : data;
String[] nameTokens = bindRef.split("/");
JSONObject currentNode = boundData;
int pathTokensSize = nameTokens.length;
if (currentNode != null) {
for (int i = 1; i < pathTokensSize; ++i) {
String newData;
JSONObject newNode;
String pathToken = nameTokens[i];
boolean isLastToken = i == pathTokensSize - 1;
JSONObject jSONObject = newNode = currentNode instanceof JSONObject ? ((JSONObject)currentNode).optJSONObject(pathToken) : null;
if (newNode == null && currentNode instanceof JSONObject && ((JSONObject)currentNode).has(pathToken) && !(((JSONObject)currentNode).opt(pathToken) instanceof JSONArray) && StringUtils.isNotBlank((CharSequence)(newData = ((JSONObject)currentNode).optString(pathToken)))) {
newNode = new JSONObject(newData);
((JSONObject)currentNode).put(pathToken, (Object)newNode);
}
if (newNode == null && !isLastToken) break;
if (isLastToken) {
JSONArray jsonArray;
if (newNode == null && currentNode instanceof JSONObject && (jsonArray = ((JSONObject)currentNode).optJSONArray(pathToken)) != null) {
data = jsonArray;
break;
}
data = newNode;
}
currentNode = newNode;
}
}
return data;
}
protected void updateAttachmentUuid(FileAttachmentWrapper fileAttachment, IValue value, String binaryUUID) {
if (fileAttachment != null && value != null) {
if (value instanceof IValueList) {
value = (IValue)((IValueList)value).get(0);
}
if (value instanceof IValueMap) {
if (StringUtils.isNotBlank((CharSequence)binaryUUID)) {
String id = ((IValueMap)value).get(binaryUUID).toString();
fileAttachment.setUuid(id);
} else {
fileAttachment.setUuid(null);
this.logger.debug("No primary key set for binary model in FDM");
}
} else if (value instanceof ITypeValue) {
String id = ((ITypeValue)value).toString();
fileAttachment.setUuid(id);
}
} else {
this.logger.warn("Error in updating binary uuid in the data");
}
}
protected String convertToJsonSchemaPath(String jsonPath) {
String jsonSchemaPath = jsonPath;
if (StringUtils.isNotBlank((CharSequence)jsonSchemaPath)) {
jsonSchemaPath = StringUtils.replace((String)jsonSchemaPath, (String)"/", (String)"/properties/");
}
return jsonSchemaPath;
}
protected Object updateFormDataWithDorInfo(Object data, FormSubmitInfo formSubmitInfo) throws Exception {
Resource guideContainerResource = this.getAdaptiveFormContainerResource(formSubmitInfo);
String entityToSubmit = this.getEntityPath(guideContainerResource);
String bindRef = this.getDORBindRef(formSubmitInfo);
Object dorData = null;
boolean isBinaryInline = this.checkIfJsonPathIsBinaryFormat(formSubmitInfo, this.convertToJsonSchemaPath(bindRef));
if (!isBinaryInline) {
this.submitBinaryData(formSubmitInfo, true, false, null);
if (formSubmitInfo.getDocumentOfRecord() != null) {
dorData = formSubmitInfo.getDocumentOfRecord().getUuid();
}
} else if (formSubmitInfo.getDocumentOfRecord() != null) {
dorData = formSubmitInfo.getDocumentOfRecord().getValue();
}
if (dorData instanceof String && StringUtils.isNotBlank((CharSequence)dorData.toString()) || dorData instanceof byte[]) {
String relativeDorBindRefToEntity = StringUtils.substringAfter((String)bindRef, (String)entityToSubmit);
String fieldName = StringUtils.substringAfterLast((String)relativeDorBindRefToEntity, (String)"/");
Object parentObject = this.getDataAsPerBindRef(data, StringUtils.substringBeforeLast((String)relativeDorBindRefToEntity, (String)"/"));
if (parentObject != null && parentObject instanceof JSONObject) {
if (dorData instanceof byte[]) {
((JSONObject)parentObject).put(fieldName, (Object)((byte[])dorData));
} else if (dorData instanceof String) {
((JSONObject)parentObject).put(fieldName, (Object)((String)dorData));
}
}
}
return data;
}
protected List getAttachmentFieldBindRef(FormSubmitInfo submitInfo) {
JSONCreationOptions jsonCreationOptions;
ArrayList<E> bindRefs = new ArrayList<E>();
Resource guideContainerResource = this.getAdaptiveFormContainerResource(submitInfo);
JSONObject guideJSON = this.guideModelTransformer.exportGuideJsonObject(guideContainerResource, jsonCreationOptions = new JSONCreationOptions(null, true, true, new Locale("en"), guideContainerResource));
if (guideJSON != null) {
try {
this.walkGuideJson(guideJSON, bindRefs);
}
catch (Exception ex) {
this.logger.error("Unable to get guide json for adaptive form container " + submitInfo.getFormContainerPath() + " in fdm submit service", (Throwable)ex);
}
}
return bindRefs;
}
private void walkGuideJson(JSONObject guideJson, List bindRefs) throws Exception {
Iterator keys = guideJson.keys();
while (keys.hasNext()) {
String bindRef;
String key = (String)keys.next();
Object value = guideJson.get(key);
if (StringUtils.equals((CharSequence)key, (CharSequence)"guideNodeClass") && value instanceof String && StringUtils.equals((CharSequence)value.toString(), (CharSequence)"guideFileUpload") && StringUtils.isNotBlank((CharSequence)(bindRef = guideJson.optString("bindRef")))) {
bindRefs.add(bindRef);
}
if (value instanceof JSONObject) {
this.walkGuideJson((JSONObject)value, bindRefs);
}
if (!(value instanceof JSONArray)) continue;
JSONArray arrayData = (JSONArray)value;
for (int i = 0; i < arrayData.length(); ++i) {
if (!(arrayData.get(i) instanceof JSONObject)) continue;
JSONObject nestedObject = arrayData.optJSONObject(i);
this.walkGuideJson(nestedObject, bindRefs);
}
}
}
protected void updateFormDataWithAttachmentInfo(JSONObject formData, FormSubmitInfo formSubmitInfo) throws Exception {
List attachmentBindRefs = this.getAttachmentFieldBindRef(formSubmitInfo);
for (String bindRef : attachmentBindRefs) {
Object bindRefData = this.getDataAsPerBindRef((Object)formData, bindRef);
Object parentBindRefData = this.getDataAsPerBindRef((Object)formData, StringUtils.substringBeforeLast((String)bindRef, (String)"/"));
String key = StringUtils.substringAfterLast((String)bindRef, (String)"/");
this.checkIfAttachmentExistsAndUpdateIt(parentBindRefData, key, bindRefData, formSubmitInfo, this.convertToJsonSchemaPath(bindRef));
}
}
private void checkIfAttachmentExistsAndUpdateIt(Object parent, String key, Object value, FormSubmitInfo formSubmitInfo, String jsonPath) throws Exception {
String fileAttachmentValue = ((JSONObject)value).optString("fileAttachment");
if (StringUtils.isNotBlank((CharSequence)fileAttachmentValue)) {
Object uuid;
boolean isBinaryInline = this.checkIfJsonPathIsBinaryFormat(formSubmitInfo, jsonPath);
if (!isBinaryInline) {
this.submitBinaryData(formSubmitInfo, false, true, fileAttachmentValue);
}
if (StringUtils.isNotBlank((CharSequence)fileAttachmentValue) && ((uuid = this.getFileAttachmentData(formSubmitInfo, fileAttachmentValue, isBinaryInline)) instanceof String && StringUtils.isNotBlank((CharSequence)uuid.toString()) || uuid instanceof byte[]) && parent instanceof JSONObject) {
((JSONObject)parent).remove(key);
((JSONObject)parent).put(key, uuid);
}
}
}
protected Object getFileAttachmentData(FormSubmitInfo formSubmitInfo, String fileAttachmentValue, boolean getBinary) {
byte[] result = null;
if (!getBinary) {
result = new byte[]("");
}
String[] fileNames = StringUtils.split((String)fileAttachmentValue, (String)"\n");
for (int i = 0; i < fileNames.length; ++i) {
for (FileAttachmentWrapper fileAttachment : formSubmitInfo.getFileAttachments()) {
if (!StringUtils.equals((CharSequence)StringUtils.substringAfterLast((String)fileAttachment.getFileName(), (String)"/"), (CharSequence)fileNames[i])) continue;
if (!getBinary && fileAttachment.getUuid() != null) {
((StringBuilder)result).append(fileAttachment.getUuid());
continue;
}
result = fileAttachment.getValue();
}
if (i == fileNames.length - 1 || getBinary) continue;
result.append("\n");
}
if (!getBinary) {
return result.toString();
}
return result;
}
protected JSONObject getWrappedDataAsPerOperation(Object data, String operationId, FormSubmitInfo formSubmitInfo) throws Exception {
JSONObject wrappedData = new JSONObject();
FormDataModel formDataModel = this.getFormDataModel(this.getAdaptiveFormContainerResource(formSubmitInfo));
String entityToSubmit = this.getEntityId(this.getAdaptiveFormContainerResource(formSubmitInfo));
EntityOperation operation = formDataModel.getOperationByReference(operationId);
if (operation != null && operation.getSchema() != null) {
Attribute argumentsDef = operation.getSchema();
if (operation.hasMultipleArguments()) {
for (IProperty argumentDef : argumentsDef.getProperties()) {
if (PropertyType.OBJECT == argumentDef.getType() && argumentDef.getTypeRef().equals(entityToSubmit)) {
if (data instanceof JSONObject) {
String argumentName = argumentDef.getName();
wrappedData.put(argumentName, data);
break;
}
throw new GuideException("Data to submit is expected of type Object for data model " + entityToSubmit);
}
if (PropertyType.ARRAY != argumentDef.getType() || !argumentDef.getTypeRef().equals(entityToSubmit)) continue;
if (data instanceof JSONArray) {
String argumentName = argumentDef.getName();
wrappedData.put(argumentName, data);
break;
}
throw new GuideException("Data to submit is expected of type Array for data model " + entityToSubmit);
}
}
}
return wrappedData;
}
protected Resource getAdaptiveFormContainerResource(FormSubmitInfo formSubmitInfo) {
ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
return resourceResolver.getResource(formSubmitInfo.getFormContainerPath());
}
protected String getDORBindRef(FormSubmitInfo formSubmitInfo) {
String dorBindRef = null;
ResourceResolver resourceResolver = this.resourceResolverHelper.getResourceResolver();
Resource guideContainerResource = resourceResolver.getResource(formSubmitInfo.getFormContainerPath());
if (guideContainerResource != null) {
dorBindRef = (String)guideContainerResource.getValueMap().get("bindRef", (Object)"");
}
return dorBindRef;
}
public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("FormSubmissionComplete", Boolean.FALSE);
Resource guideContainerResource = this.getAdaptiveFormContainerResource(formSubmitInfo);
try {
String fdmEntityPath = this.getEntityPath(guideContainerResource);
String fdmOperationId = this.getOperationName(formSubmitInfo);
ValueMap properties = guideContainerResource.getValueMap();
String formDataModelPath = (String)properties.get("schemaRef", (Object)"");
Boolean isDorSubmit = Boolean.valueOf((String)properties.get("enableDoRSubmission", (Object)""));
Boolean isAttachmentSubmit = Boolean.valueOf((String)properties.get("enableAttachmentSubmission", (Object)""));
if (StringUtils.isBlank((CharSequence)formDataModelPath)) {
this.logger.warn("There is no FDM associated with the Adaptive Form");
return result;
}
if (StringUtils.isBlank((CharSequence)fdmEntityPath)) {
this.logger.warn("There is no data model configured to submit");
return result;
}
if (StringUtils.isBlank((CharSequence)fdmOperationId)) {
this.logger.warn("No default write operation is configured for the data model to submit");
return result;
}
Object entityData = null;
JSONObject formData = null;
if (formSubmitInfo.getData() != null) {
try {
formData = new JSONObject(formSubmitInfo.getData());
}
catch (JSONException ex) {
this.logger.warn("Incorrect json format of submitted data", (Throwable)ex);
return result;
}
if (formData != null) {
entityData = this.getDataAsPerBindRef((Object)formData, fdmEntityPath);
}
if (entityData == null) {
this.logger.warn("No data found with model " + this.getEntityId(guideContainerResource) + " during FDM submission");
return result;
}
if (isAttachmentSubmit.booleanValue() && formSubmitInfo.getFileAttachments() != null && formSubmitInfo.getFileAttachments().size() > 0) {
this.updateFormDataWithAttachmentInfo(formData, formSubmitInfo);
}
if (isDorSubmit.booleanValue() && formSubmitInfo.getDocumentOfRecord() != null) {
entityData = this.updateFormDataWithDorInfo(entityData, formSubmitInfo);
}
JSONObject wrappedEntityData = this.getWrappedDataAsPerOperation(entityData, fdmOperationId, formSubmitInfo);
OperationOptions options = new OperationOptions(fdmOperationId, wrappedEntityData);
Query query = new Query(formDataModelPath, this.getDataContext(formSubmitInfo, -1), options);
IValue value = this.dermisBridge.executeOperation(query);
result.put("fdmSubmitResult", (Object)value);
}
result.put("FormSubmissionComplete", Boolean.TRUE);
}
catch (Exception ex) {
this.logger.error("Error while using the FDM Submit service", (Throwable)ex);
}
return result;
}
protected boolean checkIfJsonPathIsBinaryFormat(FormSubmitInfo formSubmitInfo, String jsonSchemaPath) throws Exception {
boolean isBinaryFormat = false;
Resource guideContainerResource = this.getAdaptiveFormContainerResource(formSubmitInfo);
JSONObject jsonSchema = this.guideModelImporter.getSchemaJson(guideContainerResource);
JsonNode jsonNode = (JsonNode)this.jsonSchemaValidatorParser.getNodeAtPath((Object)jsonSchema, null, jsonSchemaPath);
String format = null;
if (jsonNode != null) {
if (jsonNode.has("format")) {
format = jsonNode.get("format").asText();
isBinaryFormat = StringUtils.equals((CharSequence)format, (CharSequence)"binary");
} else {
isBinaryFormat = jsonNode.has("media");
}
}
return isBinaryFormat;
}
protected void bindFormDataModelManager(IFormDataModelManager iFormDataModelManager) {
this.formDataModelManager = iFormDataModelManager;
}
protected void unbindFormDataModelManager(IFormDataModelManager iFormDataModelManager) {
if (this.formDataModelManager == iFormDataModelManager) {
this.formDataModelManager = null;
}
}
protected void bindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
this.resourceResolverHelper = resourceResolverHelper;
}
protected void unbindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
if (this.resourceResolverHelper == resourceResolverHelper) {
this.resourceResolverHelper = null;
}
}
protected void bindGuideModelImporter(GuideModelImporter guideModelImporter) {
this.guideModelImporter = guideModelImporter;
}
protected void unbindGuideModelImporter(GuideModelImporter guideModelImporter) {
if (this.guideModelImporter == guideModelImporter) {
this.guideModelImporter = null;
}
}
protected void bindJsonSchemaValidatorParser(IJsonSchemaValidatorParser iJsonSchemaValidatorParser) {
this.jsonSchemaValidatorParser = iJsonSchemaValidatorParser;
}
protected void unbindJsonSchemaValidatorParser(IJsonSchemaValidatorParser iJsonSchemaValidatorParser) {
if (this.jsonSchemaValidatorParser == iJsonSchemaValidatorParser) {
this.jsonSchemaValidatorParser = null;
}
}
protected void bindDermisBridge(IDermisBridge iDermisBridge) {
this.dermisBridge = iDermisBridge;
}
protected void unbindDermisBridge(IDermisBridge iDermisBridge) {
if (this.dermisBridge == iDermisBridge) {
this.dermisBridge = null;
}
}
protected void bindFormDataModelService(FormDataModelService formDataModelService) {
this.formDataModelService = formDataModelService;
}
protected void unbindFormDataModelService(FormDataModelService formDataModelService) {
if (this.formDataModelService == formDataModelService) {
this.formDataModelService = null;
}
}
protected void bindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
this.guideModelTransformer = guideModelTransformer;
}
protected void unbindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
if (this.guideModelTransformer == guideModelTransformer) {
this.guideModelTransformer = null;
}
}
}