CollectionUpdateContentsOperation.java
4.91 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.mobile.platform.MobileResource
* com.adobe.granite.ui.components.HtmlResponse
* com.day.cq.i18n.I18n
* javax.servlet.http.HttpServletRequest
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.request.RequestParameter
* org.apache.sling.api.resource.Resource
* org.apache.sling.servlets.post.Modification
* org.slf4j.Logger
*/
package com.adobe.cq.mobile.dps.impl.operations;
import com.adobe.cq.mobile.dps.DPSCollection;
import com.adobe.cq.mobile.dps.DPSEntity;
import com.adobe.cq.mobile.dps.DPSException;
import com.adobe.cq.mobile.dps.impl.DPSClient;
import com.adobe.cq.mobile.dps.impl.DPSEntityImporter;
import com.adobe.cq.mobile.dps.impl.ImportStatus;
import com.adobe.cq.mobile.dps.impl.operations.MobilePublishAbstractOperation;
import com.adobe.cq.mobile.platform.MobileResource;
import com.adobe.granite.ui.components.HtmlResponse;
import com.day.cq.i18n.I18n;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.servlets.post.Modification;
import org.slf4j.Logger;
@Component(metatype=0, label="Experience Manager Mobile Collection Content Updater")
@Service
@Properties(value={@Property(name="sling.post.operation", value={"dpsapps:updateContents"}), @Property(name="sling.servlet.methods", value={"POST"})})
public class CollectionUpdateContentsOperation
extends MobilePublishAbstractOperation {
public static final String PARAM_COLLECTION_CONTENTS = "contents";
public static final String PARAM_ADD_RATHER_THAN_REPLACE = "appendContents";
public static final boolean PARAM_ADD_RATHER_THAN_REPLACE_DEFAULT = false;
@Override
protected void perform(SlingHttpServletRequest request, HtmlResponse response, List<Modification> modifications) {
I18n i18n = new I18n((HttpServletRequest)request);
Resource resource = request.getResource();
String entityURIsCommaSeparated = this.getParameter(request, "contents", null);
boolean appendContents = this.getParameter(request, "appendContents", false);
try {
DPSCollection dpsCollection = this.getDPSCollection(request);
if (dpsCollection != null) {
if (request.getRequestParameter("contents") == null) {
String message = i18n.get("Missing parameter during 'updateContents': {0} for {1}", "a parameter name and a resource path", new Object[]{"contents", resource.getPath()});
throw new DPSException(message);
}
} else {
String message = i18n.get("Invalid collection resource {0}", "resource path", new Object[]{resource.getPath()});
throw new DPSException(message);
}
DPSClient dpsClient = this.getDPSClient(request);
DPSEntityImporter dpsEntityImporter = this.getDPSEntityImporter(request);
List entitiesList = StringUtils.isNotEmpty((CharSequence)entityURIsCommaSeparated) ? Arrays.asList(entityURIsCommaSeparated.split(",")) : new ArrayList();
dpsClient.updateCollectionContents(dpsCollection, entitiesList, appendContents);
dpsEntityImporter.importDPSEntity(dpsCollection);
String redirectTo = this.getRedirect(request);
response.setPath(resource.getPath());
String title = i18n.get("Collection contents updated");
String resourceTitle = ((MobileResource)resource.adaptTo(MobileResource.class)).getTitle();
String message = i18n.get("Collection {0} contents has been updated.", "collection", new Object[]{resourceTitle});
this.generateResponse(response, 200, message, title, redirectTo, i18n.get("Done"));
}
catch (Exception ex) {
String title = i18n.get("Error");
String cause = this.getCauseMessage(ex);
if (StringUtils.isEmpty((CharSequence)cause)) {
cause = ex.getLocalizedMessage();
}
String message = i18n.get("Error updating collection contents: {0}. {1}", "collection path and root cause", new Object[]{resource.getName(), cause});
this.getLogger().error(message, (Throwable)ex);
this.generateError(response, message, title, ex);
}
}
}