use of com.twinsoft.convertigo.beans.core.StepSource in project convertigo by convertigo.
the class ShowStepInPickerAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
if (treeObject != null) {
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject selectedDbo = ((DatabaseObjectTreeObject) treeObject).getObject();
if (selectedDbo != null) {
StepSourceEvent event = null;
if (showSource) {
if (selectedDbo instanceof Step) {
Step step = (Step) selectedDbo;
Set<StepSource> sources = step.getSources();
if (!sources.isEmpty()) {
event = new StepSourceEvent(sources.iterator().next());
} else {
throw new Exception("No Source defined");
}
}
} else {
event = new StepSourceEvent(selectedDbo);
}
if (event != null) {
SourcePickerView spv = ConvertigoPlugin.getDefault().getSourcePickerView();
if (spv == null) {
spv = (SourcePickerView) getActivePage().showView("com.twinsoft.convertigo.eclipse.views.sourcepicker.SourcePickerView");
}
if (spv != null) {
spv.sourceSelected(event);
}
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to show object in Picker!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.StepSource in project convertigo by convertigo.
the class StepVariable method getSourceValue.
public Object getSourceValue() throws EngineException {
Object value = null;
if (sourceDefinition.size() != 0 && parent != null) {
StepSource source = new StepSource((Step) parent, sourceDefinition);
value = source.getContextOutputNodes();
}
return value;
}
use of com.twinsoft.convertigo.beans.core.StepSource in project convertigo by convertigo.
the class PushNotificationStep method PushToAPNS.
//
// seems like total size of Payload cannot exceed 256 bytes.
//
protected void PushToAPNS(Context javascriptContext, Scriptable scope, List<Parameters> dictionary) throws EngineException, Exception {
Engine.logBeans.debug("Push notification, Notifying IOS devices");
evaluate(javascriptContext, scope, this.clientCertificate, "clientCertificate", false);
sClientCertificate = evaluated instanceof Undefined ? "" : evaluated.toString();
sClientCertificate = getAbsoluteFilePath(sClientCertificate);
evaluate(javascriptContext, scope, this.certificatePassword, "certificatePassword", false);
sCertificatePassword = evaluated instanceof Undefined ? "" : evaluated.toString();
evaluate(javascriptContext, scope, this.useProductionAPNS, "ProductionCertificate", false);
String sUseProductionCertificate = evaluated instanceof Undefined ? "" : evaluated.toString();
boolean bUseProductionCertificate = "true".equalsIgnoreCase(sUseProductionCertificate);
// get Token List
StepSource tokens = getTokenSource();
NodeList list;
list = tokens.inError() ? null : tokens.getContextOutputNodes();
if (list != null) {
ArrayList<String> devicesList = new ArrayList<String>();
for (int i = 0; i < list.getLength(); i++) {
String token = getNodeValue(list.item(i));
if (token.startsWith("apns:")) {
devicesList.add(token.substring(5));
Engine.logBeans.trace("Push notification, iOS device " + token.substring(5) + " will be notified");
}
}
if (devicesList.isEmpty()) {
Engine.logBeans.debug("Push notification, no iOS devices in the list");
return;
} else {
Engine.logBeans.debug("Push notification, " + devicesList.size() + " iOS devices in the list. Sending to the " + (bUseProductionCertificate ? "production" : "development") + " APNS server");
}
try {
// Submit the push to JavaPN library...
PushedNotifications pn;
if (dictionary.size() > 1) {
/* Build a blank payload to customize */
PushNotificationPayload payload = PushNotificationPayload.complex();
for (int i = 0; i < dictionary.size(); i++) {
// if plugin specified, check it and skip accordingly
if ((dictionary.get(i).plug.length() != 0) && !(dictionary.get(i).plug.equalsIgnoreCase("aps") || dictionary.get(i).plug.equalsIgnoreCase("all"))) {
continue;
}
String value = dictionary.get(i).value;
if (dictionary.get(i).name.equalsIgnoreCase("alert")) {
payload.addAlert(value);
} else if (dictionary.get(i).name.equalsIgnoreCase("badge")) {
payload.addBadge(Integer.parseInt(value, 10));
} else if (dictionary.get(i).name.equalsIgnoreCase("sound")) {
payload.addSound(value);
} else {
if (dictionary.get(i).type.equalsIgnoreCase("int")) {
payload.addCustomDictionary(dictionary.get(i).name, Integer.parseInt(value, 10));
} else {
payload.addCustomDictionary(dictionary.get(i).name, value);
}
}
}
pn = Push.payload(payload, sClientCertificate, sCertificatePassword, bUseProductionCertificate, devicesList);
} else {
if (apnsNotificationType == ApnsNotificationType.Message) {
pn = Push.alert(dictionary.get(0).value, sClientCertificate, sCertificatePassword, bUseProductionCertificate, devicesList);
} else if (apnsNotificationType == ApnsNotificationType.Badge) {
// mod jmc 07/10/2015
pn = Push.badge(Integer.parseInt(dictionary.get(0).value, 10), sClientCertificate, sCertificatePassword, bUseProductionCertificate, devicesList);
} else {
pn = Push.sound(dictionary.get(0).value, sClientCertificate, sCertificatePassword, bUseProductionCertificate, devicesList);
}
}
// Analyze the responses..
for (PushedNotification notification : pn) {
if (!notification.isSuccessful()) {
String invalidToken = notification.getDevice().getToken();
/* Find out more about what the problem was */
Exception theProblem = notification.getException();
/* If the problem was an error-response packet returned by Apple, get it */
ResponsePacket theErrorResponse = notification.getResponse();
if (theErrorResponse != null)
saveErrorForOutput("aps", invalidToken, "" + theErrorResponse.getIdentifier(), "", theErrorResponse.getMessage());
else
saveErrorForOutput("aps", invalidToken, "", "", theProblem.getMessage());
}
}
} catch (KeystoreException e) {
errorMessage = e.toString();
Engine.logBeans.error("Push notification, IOS keystore exception : " + errorMessage);
} catch (CommunicationException e) {
/* A critical communication error occurred while trying to contact Apple servers */
errorMessage = e.toString();
Engine.logBeans.error("Push notification, IOS communication exception : " + errorMessage);
} catch (Exception e) {
errorMessage = "Push notification, IOS device exception: " + e.toString();
Engine.logBeans.error(errorMessage);
}
}
}
use of com.twinsoft.convertigo.beans.core.StepSource in project convertigo by convertigo.
the class PushNotificationStep method PushToGCM.
protected void PushToGCM(Context javascriptContext, Scriptable scope, List<Parameters> dictionary) throws EngineException, Exception {
Engine.logBeans.debug("Push notification, Notifying Android devices");
try {
if (dictionary == null) {
Engine.logBeans.debug("Push notification, dictionary empty");
return;
}
evaluate(javascriptContext, scope, this.GCMApiKey, "gcmapikey", false);
sGCMApiKey = evaluated instanceof Undefined ? "" : evaluated.toString();
Sender sender = new Sender(sGCMApiKey);
// get Token List
StepSource tokens = getTokenSource();
NodeList list;
list = tokens.inError() ? null : tokens.getContextOutputNodes();
if (list != null) {
ArrayList<String> devicesList = new ArrayList<String>();
for (int i = 0; i < list.getLength(); i++) {
String token = getNodeValue(list.item(i));
if (token.startsWith("gcm:")) {
devicesList.add(token.substring(4));
Engine.logBeans.trace("Push notification, Android device " + token.substring(4) + " will be notified");
}
}
if (devicesList.isEmpty()) {
Engine.logBeans.debug("Push notification, device list empty");
return;
}
// use this line to send message with payload data
Message.Builder builder = new Message.Builder().collapseKey("1").timeToLive(AndroidTimeToLive).delayWhileIdle(true);
// add all dictionary entries in turn
for (int i = 0; i < dictionary.size(); i++) {
// if plugin specified, check it and skip accordingly
if ((dictionary.get(i).plug.length() != 0) && !(dictionary.get(i).plug.equalsIgnoreCase("gcm") || dictionary.get(i).plug.equalsIgnoreCase("all")))
continue;
// if only one dictionary entry, hardcode key as "message"
if (dictionary.size() == 1) {
builder.addData("message", dictionary.get(i).value);
break;
}
builder.addData(dictionary.get(i).name, dictionary.get(i).value);
}
Message message = builder.build();
// Use this for multicast messages
MulticastResult multicastResult;
try {
multicastResult = sender.send(message, devicesList, NB_RETRIES);
} catch (IOException e) {
errorMessage = "Push notification, error posting Android messages " + e.toString();
Engine.logBeans.debug(errorMessage);
return;
}
if (multicastResult.getResults() != null) {
Engine.logBeans.debug("Push notification, Android devices notified: " + multicastResult.toString());
List<Result> results = multicastResult.getResults();
for (int i = 0; i < devicesList.size(); i++) {
Result result = results.get(i);
String regId = devicesList.get(i);
String messageId = result.getMessageId();
String canonicalRegId = result.getCanonicalRegistrationId();
if (messageId != null) {
Engine.logBeans.info("Push notification, succesfully sent message to device: " + regId + "; messageId = " + messageId);
canonicalRegId = result.getCanonicalRegistrationId();
if (canonicalRegId != null) {
saveErrorForOutput("gcm", regId, messageId, canonicalRegId, "Device registered more than once");
// same device has more than on registration id: update it
Engine.logBeans.info("Push notification, warning, same device has more than on registration canonicalRegId " + canonicalRegId);
}
} else {
String error = result.getErrorCodeName();
if (error.equals(com.google.android.gcm.server.Constants.ERROR_NOT_REGISTERED)) {
saveErrorForOutput("gcm", regId, messageId, canonicalRegId, "Application removed from device");
// application has been removed from device - unregister it
Engine.logBeans.info("Push notification, unregistered device: " + regId);
} else {
saveErrorForOutput("gcm", regId, "", canonicalRegId, error);
Engine.logBeans.debug("Push notification, error sending message to '" + regId + "': " + error);
}
}
}
} else {
errorMessage = "Push notification, Android device error: " + multicastResult.getFailure();
Engine.logBeans.error(errorMessage);
}
}
} catch (Exception e) {
errorMessage = "Push notification, Android device exception: " + e;
Engine.logBeans.error(errorMessage);
}
}
use of com.twinsoft.convertigo.beans.core.StepSource in project convertigo by convertigo.
the class PushNotificationStep method stepExecute.
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
errorList = new JSONArray();
// get Source data as a string to payload
StepSource stepSource = getSource();
NodeList list = stepSource.inError() ? null : stepSource.getContextOutputNodes();
if (list != null) {
List<Parameters> dictionary = new ArrayList<PushNotificationStep.Parameters>();
NodeList childNodes = list.item(0).getChildNodes();
if (childNodes.getLength() > 0)
enumAllStrings(list.item(0), dictionary);
else
dictionary.add(new PushNotificationStep.Parameters(list.item(0).getParentNode().getNodeName(), ((Element) list.item(0).getParentNode()).getAttribute("plugin"), "string", list.item(0).getNodeValue()));
try {
PushToAPNS(javascriptContext, scope, dictionary);
PushToGCM(javascriptContext, scope, dictionary);
} catch (EngineException e) {
errorMessage = e.toString();
throw e;
} catch (Exception e) {
errorMessage = e.getClass().getSimpleName() + " during push notification";
throw new EngineException(e.getClass().getSimpleName() + " during push notification", e);
}
}
if (super.stepExecute(javascriptContext, scope)) {
return true;
}
}
return false;
}
Aggregations