AbstractNotificationOperation.java
6.67 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.ui.components.HtmlResponse
* com.day.cq.i18n.I18n
* javax.jcr.RepositoryException
* javax.servlet.http.HttpServletRequest
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONException
* org.apache.sling.servlets.post.Modification
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceReference
* org.osgi.service.component.ComponentContext
*/
package com.adobe.cq.mobile.notifications.impl.operations;
import com.adobe.cq.mobile.notifications.impl.exceptions.NotificationException;
import com.adobe.cq.mobile.notifications.impl.services.NotificationService;
import com.adobe.cq.mobile.platform.MobileResource;
import com.adobe.cq.mobile.platform.impl.operations.MobileAbstractOperation;
import com.adobe.cq.mobile.platform.impl.operations.MobileOperationException;
import com.adobe.cq.mobile.platform.impl.utils.MobileUtil;
import com.adobe.granite.ui.components.HtmlResponse;
import com.day.cq.i18n.I18n;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
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.JSONException;
import org.apache.sling.servlets.post.Modification;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
public abstract class AbstractNotificationOperation
extends MobileAbstractOperation {
public static final String PARAM_APP_INSTANCE = "appInstance";
public static final String RESPONSE_TITLE = "Service Response";
private ComponentContext context;
protected I18n i18n;
@Override
protected void perform(SlingHttpServletRequest request, HtmlResponse response, List<Modification> changes) {
String message;
String title;
this.i18n = new I18n((HttpServletRequest)request);
String appInstanceParam = request.getParameter("appInstance");
if (StringUtils.isBlank((String)appInstanceParam)) {
String message2 = this.i18n.get("Missing required parameter {0}", null, new Object[]{"appInstance"});
String title2 = this.i18n.get("Error");
this.generateError(response, message2, title2);
return;
}
Resource appInstance = request.getResourceResolver().getResource(appInstanceParam);
MobileResource mobileResource = (MobileResource)appInstance.adaptTo(MobileResource.class);
ValueMap properties = null;
NotificationService notificationService = null;
try {
MobileResource shellInstance = MobileUtil.getAppInstance(mobileResource);
properties = shellInstance.getProperties();
String pushServiceId = (String)properties.get("rps/pushServiceId", String.class);
if (pushServiceId == null) {
String msg = "No push notification service Id found. It is possible the notification config is invalid or points to a non-existent resource.";
String message3 = this.i18n.get(msg, null);
String title3 = this.i18n.get("Error");
this.generateError(response, message3, title3, new MobileOperationException(msg));
return;
}
String filter = "(cq.mobile.apps.notification.service=" + pushServiceId + ")";
ServiceReference[] refs = this.context.getBundleContext().getServiceReferences(NotificationService.class.getName(), filter);
if (refs == null || refs.length == 0) {
String msg = "No push notification service has been registered for the type '" + pushServiceId + "'";
String message4 = this.i18n.get(msg, null);
String title4 = this.i18n.get("Error");
this.generateError(response, message4, title4, new MobileOperationException(msg));
return;
}
ServiceReference ref = refs[0];
notificationService = (NotificationService)this.context.getBundleContext().getService(ref);
}
catch (Throwable e) {
message = this.i18n.get("The server is unable to process your request.");
title = this.i18n.get("Error");
this.generateError(response, message, title, e);
}
try {
this.performOperation(request, response, mobileResource, notificationService);
}
catch (JSONException e) {
message = this.i18n.get("Exception creating JSON data.");
title = this.i18n.get("Error");
this.generateError(response, message, title, (Throwable)e);
}
catch (NotificationException e) {
message = this.i18n.get(e.getMessage());
title = this.i18n.get("Error");
Object pushNotificationConfigObj = null;
if (properties != null) {
pushNotificationConfigObj = properties.get((Object)"notificationConfig");
}
Integer exCode = e.getStatusCode();
if (pushNotificationConfigObj == null || exCode != 1200 && !notificationService.getConfigRelatedErrorMessages().contains(e.getMessage())) {
this.generateError(response, message, title, e);
}
String url = pushNotificationConfigObj.toString().trim();
while (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
this.generateError(response, message, title, e, url + ".html", this.i18n.get("Edit Configuration"));
}
}
protected void activate(ComponentContext context) throws RepositoryException {
this.context = context;
}
protected abstract void performOperation(SlingHttpServletRequest var1, HtmlResponse var2, MobileResource var3, NotificationService var4) throws NotificationException, JSONException;
protected boolean verifyMobileResourceType(HtmlResponse response, MobileResource mobileResource, String type) {
if (mobileResource == null || !mobileResource.isA(type)) {
String message = this.i18n.get("Internal Error trying to resolve application type: {0}", null, new Object[]{type});
String title = this.i18n.get("Error");
this.generateError(response, message, title);
return false;
}
return true;
}
}