Skip to content

Commit

Permalink
Added QueryObjects trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Drobiazko committed Oct 17, 2016
1 parent 8b49dbe commit 7aa14e6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
29 changes: 17 additions & 12 deletions component.json
Expand Up @@ -15,16 +15,6 @@
},
"credentials" : {
"fields":{
"prodEnv" : {
"label":"Environment",
"viewClass":"SelectView",
"required":true,
"model":{
"test":"Sandbox",
"login":"Production"
},
"prompt":"Select environment"
},
"oauth":{
"label":"Authentication",
"viewClass":"OAuthFieldView",
Expand All @@ -34,11 +24,26 @@
"oauth2":{
"client_id":"{{SALESFORCE_KEY}}",
"client_secret":"{{SALESFORCE_SECRET}}",
"auth_uri":"https://{{prodEnv}}.salesforce.com/services/oauth2/authorize",
"token_uri":"https://{{prodEnv}}.salesforce.com/services/oauth2/token"
"auth_uri":"https://login.salesforce.com/services/oauth2/authorize",
"token_uri":"https://login.salesforce.com/services/oauth2/token"
}
},
"triggers":{
"queryObjects": {
"title": "SOQL Query",
"main":"io.elastic.salesforce.triggers.QueryObjects",
"type":"polling",
"metadata": {
"out": {}
},
"fields": {
"query": {
"label": "SOQL Query",
"required": true,
"viewClass": "TextAreaView"
}
}
},
"newAccount":{
"title":"New Account",
"main":"io.elastic.salesforce.triggers.GetAccounts",
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/io/elastic/salesforce/triggers/QueryObjects.java
@@ -0,0 +1,47 @@
package io.elastic.salesforce.triggers;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.elastic.api.EventEmitter;
import io.elastic.api.ExecutionParameters;
import io.elastic.api.Message;
import io.elastic.salesforce.AbstractSalesforceComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class QueryObjects extends AbstractSalesforceComponent {

public static final Logger logger = LoggerFactory.getLogger(QueryObjects.class);

/**
* Creates a component instance with the given {@link EventEmitter}.
*
* @param eventEmitter emitter to emit events
*/
public QueryObjects(EventEmitter eventEmitter) {
super(eventEmitter);
}

@Override
public void execute(final ExecutionParameters parameters) {

final JsonObject configuration = parameters.getConfiguration();

logger.info(configuration.toString());

final JsonElement query = configuration.get("query");
final String queryString = query.getAsString();

logger.info("About to query objects: {}", queryString);

final JsonObject body = queryObjects(configuration, queryString);

final Message response
= new Message.Builder().body(body).build();

getEventEmitter().emitData(response);

logger.info("Finished execution");

}
}

0 comments on commit 7aa14e6

Please sign in to comment.