PhoneGapBuildOperation.java
4.98 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.ui.components.HtmlResponse
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.Workflow
* com.adobe.granite.workflow.exec.WorkflowData
* com.adobe.granite.workflow.model.WorkflowModel
* com.day.cq.i18n.I18n
* javax.servlet.http.HttpServletRequest
* 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.api.resource.ResourceResolver
* org.apache.sling.servlets.post.Modification
* org.slf4j.Logger
*/
package com.adobe.cq.mobile.platform.impl.operations;
import com.adobe.cq.mobile.platform.impl.operations.MobileApplicationOperation;
import com.adobe.granite.ui.components.HtmlResponse;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.Workflow;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.model.WorkflowModel;
import com.day.cq.i18n.I18n;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
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.api.resource.ResourceResolver;
import org.apache.sling.servlets.post.Modification;
import org.slf4j.Logger;
@Component(metatype=0, label="Create Mobile Page Operation")
@Service
@Properties(value={@Property(name="sling.post.operation", value={"mobileapps:phoneGapBuild"})})
public class PhoneGapBuildOperation
extends MobileApplicationOperation {
public static final String OPERATION_NAME = "phoneGapBuild";
public static final String PHONE_GAP_BUILD_MODEL = "/etc/workflow/models/phonegap/initiate-phonegap-build/jcr:content/model";
public static final String CQ_APPS_ADMIN_PHONEGAP_BUILD_WFHISTORY = "cq-apps-admin-phonegapbuild-wfhistory";
@Override
protected void perform(SlingHttpServletRequest request, HtmlResponse response, List<Modification> changes) {
I18n i18n = new I18n((HttpServletRequest)request);
Resource appInstance = null;
RequestParameter appInstanceParam = request.getRequestParameter("appInstance");
if (appInstanceParam == null) {
String message = i18n.get("Unable to resolve the mobile app");
String title = i18n.get("Error");
this.generateError(response, message, title);
return;
}
appInstance = request.getResourceResolver().getResource(appInstanceParam.toString());
try {
this.clearContentSyncBuildCache(response, appInstance, false);
}
catch (Exception ex) {
LOGGER.error("Failed to clear content sync cache", (Throwable)ex);
String message = i18n.get("Unable to clear content sync cache. Stopping PhoneGap build process.");
String title = i18n.get("Error");
this.generateError(response, message, title, ex);
return;
}
Workflow wf = this.startBuild(appInstance, i18n, response);
if (wf != null) {
String title = i18n.get("PhoneGap Build");
String message = i18n.get("The PhoneGap Build Process has started");
response.onCreated(wf.getId());
this.generateResponse(response, 201, message, title);
}
}
private Workflow startBuild(Resource appInstance, I18n i18n, HtmlResponse response) {
LOGGER.debug("Starting workflow for phonegap build {}", (Object)appInstance.getPath());
Workflow wf = null;
WorkflowSession wfSession = (WorkflowSession)appInstance.getResourceResolver().adaptTo(WorkflowSession.class);
try {
WorkflowModel modelToStart = wfSession.getModel("/etc/workflow/models/phonegap/initiate-phonegap-build/jcr:content/model");
WorkflowData workflowData = wfSession.newWorkflowData("JCR_PATH", (Object)appInstance.getPath());
HashMap metaData = new HashMap();
wf = wfSession.startWorkflow(modelToStart, workflowData, metaData);
LOGGER.debug("finished executing phonegap build, workflow Id {} ", (Object)wf.getId());
}
catch (WorkflowException ex) {
String title = i18n.get("Error");
String message = i18n.get("Unable to start the PhoneGap build process");
this.generateError(response, message, title, (Throwable)ex);
}
return wf;
}
}