BaseFMServlet.java
35.3 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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.forms.foundation.service.FormsDependencyManager
* com.adobe.forms.foundation.service.FormsFoundationException
* com.day.cq.commons.jcr.JcrUtil
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* javax.jcr.ValueFactory
* javax.servlet.Servlet
* org.apache.commons.codec.binary.Base64
* org.apache.commons.io.IOUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.request.RequestParameter
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aem.formsndocuments.servlet;
import com.adobe.aem.formsndocuments.publish.PublishService;
import com.adobe.aem.formsndocuments.service.FMCRUDService;
import com.adobe.aem.formsndocuments.service.FormsRelationService;
import com.adobe.aem.formsndocuments.transferobjects.AssetInfo;
import com.adobe.aem.formsndocuments.util.FMUtils;
import com.adobe.aem.formsndocuments.util.SettingsHolder;
import com.adobe.aem.formsndocuments.util.ThumbnailUtil;
import com.adobe.aemforms.fm.exception.FormsMgrException;
import com.adobe.forms.foundation.service.FormsDependencyManager;
import com.adobe.forms.foundation.service.FormsFoundationException;
import com.day.cq.commons.jcr.JcrUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.servlet.Servlet;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, immediate=1, label="BaseFormsManagementServlet", description="BaseFormsManagementServlet")
@Service(value={Servlet.class})
@Properties(value={@org.apache.felix.scr.annotations.Property(name="sling.servlet.extensions", value={"json"}), @org.apache.felix.scr.annotations.Property(name="sling.servlet.resourceTypes", value={"fd/fm/baseManageServlet"}), @org.apache.felix.scr.annotations.Property(name="sling.servlet.methods", value={"POST"})})
public class BaseFMServlet
extends SlingAllMethodsServlet {
private static final long serialVersionUID = -1;
@Reference(referenceInterface=PublishService.class)
private PublishService publishService;
@Reference(referenceInterface=FMCRUDService.class)
private FMCRUDService fmCRUDService;
@Reference(referenceInterface=FormsRelationService.class)
private FormsRelationService formsRelationService;
@Reference
private FormsDependencyManager formsDependencyManager;
private static final String IMAGE = "image";
private static final String IMAGE_BASE64_ENCODED = "base64image";
private final String FUNC_LITERAL = "func";
private final String NODEPATH_LITERAL = "nodePath";
private final String ASSETPATH_LITERAL = "assetPath";
private final String ERROR_CODE_LITERAL = "code";
private final String ERROR_TYPE_LITERAL = "type";
private final String ERROR_TITLE_LITERAL = "title";
private final String ERROR_UNRESOLVED_MESSAGE_LITERAL = "unresolvedMessage";
private final String ERROR_DESCRIPTION_LITERAL = "description";
private final String ERROR_MESSAGE_ARGS_LITERAL = "messageArgs";
private final String ERROR_ROOTCAUSE_LITERAL = "rootCause";
private final String ERROR_EXTENDEDDATA_LITERAL = "extendedData";
private final String PUBLISH_LITERAL = "activate";
private final String DEACTIVATE_LITERAL = "deactivate";
private final String GET_RELATED_ASSET_TO_PUBLISH = "getRelatedAssetsToPublish";
private final String DELETEASSET_LITERAL = "deleteAsset";
private final String EXCEPTION_ERRORTYPE = "error";
private final String EXCEPTION_ERRORCODE = "ALC-FMG-001-001";
private final String UPLOAD_SAMPLE_DATA = "uploadSampleData";
private final String IS_IE = "isIE";
private final String SAMPLEDATA_LITERAL = "sampleData";
private final String CREATE_FORMSET = "createFormset";
private final String CREATE_FRAGMENT_FROM_PANEL = "createFragmentFromPanel";
private final String UPDATE_FORMSET = "updateFormset";
private final String GET_FORMS_IN_A_FORMSET = "getFormsInAFormset";
private final String GET_DEPENDENT_PARENT_FM_ASSETS = "getDependentParentFMAssets";
private final String HAS_DEPENDENT_PARENT_ASSETS = "hasDependentParentAssets";
private final String GET_ALL_RELATED_CHILD_ASSETS = "getAllRelatedChildAssets";
private final String GENERATE_FORMSET_THUMBNAIL = "generateFormsetThumbnail";
private final String GENERATE_THUMBNAIL = "generateThumbnail";
private final String GET_FIRST_LEVEL_RELATED_CHILD_ASSETS = "getFirstLevelRelatedChildAssets";
private final String CREATE_THEME = "createTheme";
private final String CHECK_NODE_EXIST = "checkNodeExist";
private final String MOVE_NODE = "moveNode";
private final String PASTE_THEME = "pasteTheme";
private final String CLEAN_UP_FORMS = "cleanUpForms";
private final Logger log = LoggerFactory.getLogger(BaseFMServlet.class);
protected void activate(ComponentContext componentContext) throws RepositoryException {
this.log.info("Activated: FormsManagementServlet started");
}
protected void deactivate(ComponentContext context) {
this.log.info("Deactivated: FormsManagementServlet stopped");
}
public void doPost(SlingHttpServletRequest req, SlingHttpServletResponse resp) {
this.requestHandler(req, resp);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void requestHandler(SlingHttpServletRequest req, SlingHttpServletResponse resp) {
try {
resp.setContentType("application/json;charset=utf-8");
String func = req.getParameter("func");
if (func != null) {
if (func.equals("activate")) {
this.publishAssets(req, resp);
} else if (func.equals("deactivate")) {
this.deactivateAssets(req, resp);
} else if (func.equals("getRelatedAssetsToPublish")) {
this.getRelatedAssetsToPublish(req, resp);
} else if (func.equals("getAllRelatedChildAssets")) {
this.getAllRelatedChildAssets(req, resp);
} else if (func.equals("uploadSampleData")) {
this.uploadSampleData(req, resp);
} else if (func.equals("deleteAsset")) {
this.deleteAsset(req, resp);
} else if (func.equals("createFormset")) {
this.createFormset(req, resp);
} else if (func.equals("createFragmentFromPanel")) {
this.createFragmentFromPanel(req, resp);
} else if (func.equals("getFormsInAFormset")) {
this.getFormsInAFormset(req, resp);
} else if (func.equals("getDependentParentFMAssets")) {
this.getDependentParentFMAssets(req, resp);
} else if (func.equals("hasDependentParentAssets")) {
this.hasDependentParentAssets(req, resp);
} else if (func.equals("updateFormset")) {
this.updateFormset(req, resp);
} else if (func.equals("generateFormsetThumbnail")) {
this.generateFormsetThumbnail(req, resp);
} else if (func.equals("generateThumbnail")) {
this.generateThumbnail(req, resp);
} else if (func.equals("getFirstLevelRelatedChildAssets")) {
this.getFirstLevelRelatedChildAssets(req, resp);
} else if (func.equals("createTheme")) {
this.createTheme(req, resp);
} else if (func.equals("checkNodeExist")) {
this.checkNodeExist(req, resp);
} else if (func.equals("moveNode")) {
this.moveNode(req, resp);
} else if (func.equals("pasteTheme")) {
this.pasteTheme(req, resp);
} else if (func.equals("cleanUpForms")) {
this.cleanUpForms(req, resp);
}
}
}
catch (Exception e) {
PrintWriter writer = null;
try {
writer = resp.getWriter();
this.log.error("Error in Servlet Request: " + e.getMessage(), (Throwable)e);
JSONObject errorJson = new JSONObject();
String code = "ALC-FMG-001-001";
String cause = null;
String message = e.getMessage();
String unresolvedMessage = null;
ArrayList<String> messageArgs = null;
if (e.getCause() != null) {
cause = e.getCause().toString();
}
if (cause == null) {
cause = e.toString();
}
if (message == null) {
message = cause;
}
if (e instanceof FormsMgrException) {
FormsMgrException fme = (FormsMgrException)e;
if (fme.getCode() != null && !fme.getCode().isEmpty()) {
code = fme.getCode();
message = fme.getMessage();
unresolvedMessage = fme.getUnresolvedMessage();
}
if (fme.getMessageArgs() != null && fme.getMessageArgs().length > 0) {
messageArgs = new ArrayList<String>();
for (Object arg : fme.getMessageArgs()) {
if (arg == null || arg instanceof String) {
messageArgs.add((String)arg);
continue;
}
messageArgs.add(arg.toString());
}
}
}
errorJson.put("code", (Object)code);
errorJson.put("type", (Object)"error");
errorJson.put("title", (Object)message);
errorJson.put("description", (Object)message);
errorJson.put("unresolvedMessage", (Object)unresolvedMessage);
errorJson.put("messageArgs", messageArgs);
errorJson.put("rootCause", (Object)e.toString());
errorJson.append("extendedData", (Object)null);
writer.write(errorJson.toString());
}
catch (Exception ex) {
this.log.error("Error in Servlet Request catch block: " + ex.getMessage(), (Throwable)ex);
}
finally {
if (writer != null) {
writer.close();
}
}
}
}
private void publishAssets(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException, IOException, JSONException {
Session session = (Session)req.getResourceResolver().adaptTo(Session.class);
String nodePath = req.getParameter("nodePath");
if (nodePath == null || nodePath.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", nodePath});
}
String[] nodePaths = nodePath.split("\\|");
ArrayList<String> nodePathList = new ArrayList<String>(Arrays.asList(nodePaths));
this.publishService.publish(session, nodePathList);
FMUtils.writeRequestStatusSuccess(resp, false);
}
private void deactivateAssets(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException, IOException, JSONException {
Session session = (Session)req.getResourceResolver().adaptTo(Session.class);
String nodePath = req.getParameter("nodePath");
if (nodePath == null || nodePath.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", nodePath});
}
String[] nodePaths = nodePath.split("\\|");
ArrayList<String> nodePathList = new ArrayList<String>(Arrays.asList(nodePaths));
this.publishService.deactivate(session, nodePathList);
FMUtils.writeRequestStatusSuccess(resp, false);
}
private void getRelatedAssetsToPublish(SlingHttpServletRequest request, SlingHttpServletResponse response) throws FormsMgrException {
PrintWriter writer = null;
try {
ResourceResolver resourceResolver = request.getResourceResolver();
String path = request.getParameter("nodePath");
if (path == null || path.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", path});
}
writer = response.getWriter();
Set<AssetInfo> toBePublishedAssets = this.publishService.getRelatedAssetsToPublish(resourceResolver, path);
writer.print(FMUtils.convertSetOfFormInfoToJSONObject(toBePublishedAssets).toString());
}
catch (Exception e) {
throw new FormsMgrException(e);
}
finally {
if (writer != null) {
writer.close();
}
}
}
private void getAllRelatedChildAssets(SlingHttpServletRequest request, SlingHttpServletResponse response) throws FormsMgrException {
PrintWriter writer = null;
try {
ResourceResolver resourceResolver = request.getResourceResolver();
String path = request.getParameter("nodePath");
if (path == null || path.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", path});
}
writer = response.getWriter();
HashSet<AssetInfo> allRelatedChildAssets = new HashSet<AssetInfo>();
this.formsRelationService.getAllRelatedChildAssets(resourceResolver, path, allRelatedChildAssets);
writer.print(FMUtils.convertSetOfFormInfoToJSONObject(allRelatedChildAssets).toString());
}
catch (Exception e) {
throw new FormsMgrException(e);
}
finally {
if (writer != null) {
writer.close();
}
}
}
private void getFirstLevelRelatedChildAssets(SlingHttpServletRequest request, SlingHttpServletResponse response) throws FormsMgrException {
PrintWriter writer = null;
try {
ResourceResolver resourceResolver = request.getResourceResolver();
String path = request.getParameter("nodePath");
if (path == null || path.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", path});
}
writer = response.getWriter();
HashSet<AssetInfo> allRelatedChildAssets = new HashSet<AssetInfo>();
this.formsRelationService.getFirstLevelRelatedChildAssets(resourceResolver, path, allRelatedChildAssets);
writer.print(FMUtils.convertSetOfFormInfoToJSONObject(allRelatedChildAssets).toString());
}
catch (Exception e) {
throw new FormsMgrException(e);
}
finally {
if (writer != null) {
writer.close();
}
}
}
private void uploadSampleData(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException, IOException, JSONException {
block8 : {
try {
ResourceResolver resourceResolver = req.getResourceResolver();
Session session = (Session)resourceResolver.adaptTo(Session.class);
String nodePath = req.getParameter("nodePath");
Boolean isIE = Boolean.valueOf(req.getParameter("isIE"));
InputStream inputStream = null;
if (FMUtils.isGuide(session, nodePath) || FMUtils.isXDPForm(session, nodePath) || FMUtils.isPDFForm(session, nodePath) || FMUtils.isFormset(session, nodePath) || FMUtils.isAFFragment(session, nodePath) || FMUtils.isAdaptiveDocument(session, nodePath)) {
RequestParameter param = req.getRequestParameter("sampleData");
if (param != null) {
inputStream = param.getInputStream();
}
if (inputStream != null) {
String fileId = this.storeSampleData(inputStream, session);
PrintWriter writer = resp.getWriter();
JSONObject previewObject = new JSONObject();
fileId = "crx://" + fileId;
previewObject.put("sampleDataId", (Object)fileId);
if (isIE.booleanValue()) {
resp.setContentType("text/html;charset=utf-8");
writer.write("<textarea>");
}
writer.write(previewObject.toString());
if (isIE.booleanValue()) {
writer.write("</textarea>");
}
writer.close();
} else {
this.log.error("No Input Data");
}
break block8;
}
Object[] args = new Object[]{"Form", nodePath};
throw new FormsMgrException("No valid {0} object exists at path : {1}.", args);
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
}
private String storeSampleData(InputStream instream, Session session) throws FormsMgrException {
try {
String rootPath = "/content/dam/formsanddocuments";
long time = System.nanoTime();
String fileId = "" + time;
String fileName = "tempArchive_" + fileId;
String tempStoragePath = rootPath + "/" + "temp_archive_storage";
String tempArchiveLocation = tempStoragePath + "/" + fileName;
int i = 0;
while (session.nodeExists(tempArchiveLocation)) {
fileId = "" + i++ + time;
fileName = "tempArchive_" + fileId;
tempArchiveLocation = tempStoragePath + "/" + fileName;
}
Node tempNode = null;
if (!session.nodeExists(tempStoragePath)) {
Node rootNode = session.getNode(rootPath);
tempNode = rootNode.addNode("temp_archive_storage");
} else {
tempNode = session.getNode(tempStoragePath);
}
Node tempArchiveNode = tempNode.addNode(fileName, "{http://www.jcp.org/jcr/nt/1.0}file");
ValueFactory valFactory = session.getValueFactory();
Binary binary = valFactory.createBinary(instream);
Node contentNode = tempArchiveNode.addNode("jcr:content", "{http://www.jcp.org/jcr/nt/1.0}resource");
contentNode.addMixin("{http://www.jcp.org/jcr/mix/1.0}mimeType");
contentNode.setProperty("jcr:data", binary);
contentNode.setProperty("jcr:mimeType", ".xml");
session.save();
return tempArchiveLocation;
}
catch (RepositoryException e) {
throw new FormsMgrException((Throwable)e);
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
private void deleteAsset(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException {
String assetPath = req.getParameter("assetPath");
try {
if (!SettingsHolder.getInstance().getLcInstance().booleanValue()) {
ResourceResolver resourceResolver = req.getResourceResolver();
Session session = (Session)resourceResolver.adaptTo(Session.class);
this.fmCRUDService.deleteCRXResource(session, assetPath);
} else {
this.log.error("In case of LC setup, delete API of FormsManagementServlet should be invoked.");
}
FMUtils.writeRequestStatusSuccess(resp, false);
}
catch (Exception e) {
throw FMUtils.getFormsMgrException(e);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void createFragmentFromPanel(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
JSONObject fragmentJson = new JSONObject(req.getParameter("assetJson"));
String affPath = this.fmCRUDService.createFragmentFromPanel(req.getResourceResolver(), fragmentJson);
PrintWriter writer = null;
try {
JSONObject respJson = new JSONObject();
respJson.put("fragmentPath", (Object)affPath);
writer = resp.getWriter();
writer.write(respJson.toString());
}
finally {
if (writer != null) {
writer.close();
}
}
}
private void createFormset(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
JSONObject formsetJSON = new JSONObject(req.getParameter("assetJson"));
this.fmCRUDService.createFormset(req.getResourceResolver(), formsetJSON);
FMUtils.writeRequestStatusSuccess(resp, false);
}
private void updateFormset(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
JSONObject formsetJSON = new JSONObject(req.getParameter("assetJson"));
this.fmCRUDService.updateFormset(req.getResourceResolver(), formsetJSON);
FMUtils.writeRequestStatusSuccess(resp, false);
}
private void generateFormsetThumbnail(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
String formsetPath = req.getParameter("nodePath");
this.fmCRUDService.generateFormsetThumbnail(req.getResourceResolver(), formsetPath);
FMUtils.writeRequestStatusSuccess(resp, false);
}
private void getFormsInAFormset(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException {
block7 : {
String assetPath = req.getParameter("assetPath");
Session session = (Session)req.getResourceResolver().adaptTo(Session.class);
try {
if (assetPath != null && session.nodeExists(assetPath)) {
JSONObject respJson = new JSONObject();
JSONArray formsArray = new JSONArray();
Node formsetNode = session.getNode(assetPath);
if (formsetNode.hasProperty("jcr:content/related/forms/sling:members/sling:resources")) {
Value[] forms;
for (Value value : forms = formsetNode.getProperty("jcr:content/related/forms/sling:members/sling:resources").getValues()) {
String formPath = value.getString();
String title = "";
if (!session.nodeExists(formPath)) continue;
Node formNode = session.getNode(formPath);
if (formNode.hasProperty("jcr:content/metadata/title")) {
title = FMUtils.getMetadataNode(formNode, false).getProperty("title").getString();
}
if (title.isEmpty()) {
title = formNode.getName();
}
JSONObject formObject = new JSONObject();
formObject.put("path", (Object)formPath);
formObject.put("title", (Object)title);
formsArray.put((Object)formObject);
}
}
respJson.put("referencedForms", (Object)formsArray);
resp.getWriter().write(respJson.toString());
resp.getWriter().close();
break block7;
}
Object[] args = new Object[]{assetPath};
throw new FormsMgrException("AEM-FMG-700-002", args);
}
catch (Exception e) {
throw new FormsMgrException(e);
}
}
}
private void getDependentParentFMAssets(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException {
PrintWriter writer = null;
try {
ResourceResolver resourceResolver = req.getResourceResolver();
String path = req.getParameter("nodePath");
if (path == null || path.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", path});
}
writer = resp.getWriter();
Set<AssetInfo> dependentParentAssets = this.formsRelationService.getDependentParentFMAssets(resourceResolver, path);
writer.print(FMUtils.convertSetOfFormInfoToJSONObject(dependentParentAssets).toString());
}
catch (Exception e) {
throw new FormsMgrException(e);
}
finally {
if (writer != null) {
writer.close();
}
}
}
private void hasDependentParentAssets(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException {
PrintWriter writer = null;
try {
String path = req.getParameter("nodePath");
if (path == null || path.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", path});
}
writer = resp.getWriter();
boolean response = this.formsDependencyManager.hasParentDependencies(path);
JSONObject relatedAssetsJson = new JSONObject();
relatedAssetsJson.put("hasDependentParentAssets", response);
writer.write(relatedAssetsJson.toString());
}
catch (FormsFoundationException e) {
throw new FormsMgrException(e.getMessage(), (Throwable)e);
}
catch (Exception e) {
throw new FormsMgrException(e);
}
finally {
if (writer != null) {
writer.close();
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void generateThumbnail(SlingHttpServletRequest req, SlingHttpServletResponse resp) {
InputStream is = null;
try {
ResourceResolver resourceResolver = req.getResourceResolver();
String path = req.getParameter("nodePath");
if (path == null || path.length() == 0) {
throw new FormsMgrException("AEM-FMG-700-001", new String[]{"nodePath", path});
}
Resource resource = resourceResolver.getResource(path);
RequestParameter image = req.getRequestParameter("image");
RequestParameter imageBase64Encoded = req.getRequestParameter("base64image");
Boolean isIE = Boolean.valueOf(req.getParameter("isIE"));
if (resource != null && (image != null && image.getInputStream() != null || imageBase64Encoded != null)) {
if (image != null && image.getInputStream() != null) {
is = image.getInputStream();
} else if (imageBase64Encoded != null) {
String base64EncodeString = imageBase64Encoded.getString();
byte[] decodedArray = Base64.decodeBase64((String)base64EncodeString);
is = new ByteArrayInputStream(decodedArray);
}
ThumbnailUtil.addThumbnailToAsset(resource, is);
resourceResolver.commit();
}
FMUtils.writeRequestStatusSuccess(resp, isIE);
}
catch (Exception e) {
this.log.error("Error while creating new rendition", (Throwable)e);
}
finally {
IOUtils.closeQuietly((InputStream)is);
}
}
private void createTheme(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
JSONObject themeJson = new JSONObject(req.getParameter("assetJson"));
this.fmCRUDService.createTheme(req.getResourceResolver(), themeJson);
FMUtils.writeRequestStatusSuccess(resp, false);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void checkNodeExist(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
String nodePath = req.getParameter("path");
boolean isNodeExist = this.fmCRUDService.checkNodeExist(req.getResourceResolver(), nodePath);
PrintWriter writer = null;
try {
JSONObject respJson = new JSONObject();
respJson.put("NODE_EXIST", isNodeExist);
writer = resp.getWriter();
writer.write(respJson.toString());
}
finally {
if (writer != null) {
writer.close();
}
}
}
private void moveNode(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws Exception {
String sourceLocation = req.getParameter("sourceLocation");
String destinationLocation = req.getParameter("destinationLocation");
FMUtils.moveNode(req.getResourceResolver(), sourceLocation, destinationLocation);
FMUtils.writeRequestStatusSuccess(resp, false);
}
private void cleanUpForms(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException, IOException, JSONException {
try {
String[] formPaths = req.getParameterValues("formPaths");
ResourceResolver resourceResolver = req.getResourceResolver();
Session session = (Session)resourceResolver.adaptTo(Session.class);
for (String formPath : formPaths) {
if (formPath != null) {
if ((formPath = formPath.trim()).startsWith("/content/dam/formsanddocuments")) {
this.fmCRUDService.cleanUpReviewInfo(session, formPath);
this.fmCRUDService.cleanUpAnalyticsInfo(session, formPath);
this.fmCRUDService.cleanUpFormABTestingInfo(session, formPath);
} else if (formPath.startsWith("/content/forms/af")) {
this.fmCRUDService.cleanUpFormPageABTestingInfo(session, formPath);
}
}
session.save();
}
FMUtils.writeRequestStatusSuccess(resp, false);
}
catch (RepositoryException e) {
throw FMUtils.getFormsMgrException((Exception)e);
}
}
private void pasteTheme(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws FormsMgrException {
String themeSrcPath = req.getParameter("srcPath").trim();
String themeDestPath = req.getParameter("destPath").trim();
String destParentPath = req.getParameter("destParentPath").trim();
ResourceResolver resourceResolver = req.getResourceResolver();
Session session = (Session)resourceResolver.adaptTo(Session.class);
try {
if (session.nodeExists(themeSrcPath) && session.nodeExists(themeDestPath)) {
Node themeSrcNode = session.getNode(themeSrcPath);
Node themeDestNode = session.getNode(themeDestPath);
String clientlibRefPath = FMUtils.getClientlibPath(themeSrcNode);
Node srcClientLib = session.getNode(clientlibRefPath);
String destClientLibParentPath = destParentPath.replace("/content/dam/formsanddocuments-themes", "/etc/clientlibs/fd/themes");
Node destClientLibParentNode = JcrUtil.createPath((String)destClientLibParentPath, (String)"nt:folder", (String)"nt:folder", (Session)session, (boolean)false);
Node destClientLibNode = JcrUtil.copy((Node)srcClientLib, (Node)destClientLibParentNode, (String)themeDestNode.getName());
String destCategoryName = FMUtils.getCategoryNameFromClientLibPath(destClientLibParentPath + "/" + themeDestNode.getName());
destClientLibNode.setProperty("categories", new String[]{destCategoryName});
Node metadataNode = themeDestNode.getNode("jcr:content/metadata");
metadataNode.setProperty("clientlibCategory", destCategoryName);
metadataNode.setProperty("clientlibRef", destClientLibParentPath);
this.fmCRUDService.cleanUpForm(session, themeDestPath);
session.save();
}
FMUtils.writeRequestStatusSuccess(resp, false);
}
catch (Exception e) {
throw FMUtils.getFormsMgrException(e);
}
}
protected void bindPublishService(PublishService publishService) {
this.publishService = publishService;
}
protected void unbindPublishService(PublishService publishService) {
if (this.publishService == publishService) {
this.publishService = null;
}
}
protected void bindFmCRUDService(FMCRUDService fMCRUDService) {
this.fmCRUDService = fMCRUDService;
}
protected void unbindFmCRUDService(FMCRUDService fMCRUDService) {
if (this.fmCRUDService == fMCRUDService) {
this.fmCRUDService = null;
}
}
protected void bindFormsRelationService(FormsRelationService formsRelationService) {
this.formsRelationService = formsRelationService;
}
protected void unbindFormsRelationService(FormsRelationService formsRelationService) {
if (this.formsRelationService == formsRelationService) {
this.formsRelationService = null;
}
}
protected void bindFormsDependencyManager(FormsDependencyManager formsDependencyManager) {
this.formsDependencyManager = formsDependencyManager;
}
protected void unbindFormsDependencyManager(FormsDependencyManager formsDependencyManager) {
if (this.formsDependencyManager == formsDependencyManager) {
this.formsDependencyManager = null;
}
}
}