@Override public final String createEndpointUri(final String scheme, final Map<String, String> options) throws URISyntaxException { final String sObjectName = options.get(SalesforceEndpointConfig.SOBJECT_NAME); final String query = "SELECT Id FROM " + sObjectName; final String topicName = topicNameFor(options); options.put("topicName", topicName); options.put(SalesforceEndpointConfig.SOBJECT_QUERY, query); options.remove(SalesforceEndpointConfig.SOBJECT_NAME); final String salesforceComponent = getComponentScheme(); if (!topicName.endsWith("_delete")) { final Enricher enricher = new Enricher( new ConstantExpression(salesforceComponent + ":getSObject?rawPayload=true&sObjectName=" + sObjectName)); enricher.setCamelContext(getCamelContext()); setBeforeConsumer(enricher); } return super.createEndpointUri(scheme, options); }
private static String topicNameFor(final Map<String, String> options) { final String sObjectName = options.get(SalesforceEndpointConfig.SOBJECT_NAME); final String topicSuffix; if (Boolean.valueOf(options.get("notifyForOperationCreate"))) { topicSuffix = "_create"; } else if (Boolean.valueOf(options.get("notifyForOperationUpdate"))) { topicSuffix = "_update"; } else if (Boolean.valueOf(options.get("notifyForOperationDelete"))) { topicSuffix = "_delete"; } else if (Boolean.valueOf(options.get("notifyForOperationUndelete"))) { topicSuffix = "_undelete"; } else { topicSuffix = "_all"; } return TOPIC_PREFIX + sObjectName + topicSuffix; }
public SalesforceUpdateSObjectComponent() { super("salesforce-update-sobject", SalesforceUpdateSObjectComponent.class.getName()); // set sObjectId header setBeforeProducer(exchange -> { // parse input json and extract Id field final ObjectMapper mapper = JsonUtils.createObjectMapper(); final JsonNode node = mapper.readTree(exchange.getIn().getBody(String.class)); final JsonNode sObjectId = node.get("Id"); if (sObjectId == null) { exchange.setException(new SalesforceException("Missing field Id", 404)); } else { exchange.getIn().setHeader(SalesforceEndpointConfig.SOBJECT_ID, sObjectId.asText()); } clearBaseFields((ObjectNode) node); // update input json exchange.getIn().setBody(mapper.writeValueAsString(node)); }); }
@Override public String createEndpointUri(final String scheme, final Map<String, String> options) throws URISyntaxException { final String sObjectName = options.get(SalesforceEndpointConfig.SOBJECT_NAME); final String query = "SELECT Id FROM " + sObjectName; options.put("topicName", topicNameFor(options)); options.put(SalesforceEndpointConfig.SOBJECT_QUERY, query); options.remove(SalesforceEndpointConfig.SOBJECT_NAME); final String salesforceComponent = getComponentName() + "-component"; final Enricher enricher = new Enricher( new ConstantExpression(salesforceComponent + ":getSObject?rawPayload=true&sObjectName=" + sObjectName)); enricher.setCamelContext(getCamelContext()); setBeforeConsumer(enricher); return super.createEndpointUri(scheme, options); }
public PushTopicHelper(SalesforceEndpointConfig config, String topicName, RestClient restClient) { this.config = config; this.topicName = topicName; this.restClient = restClient; this.preApi29 = Double.valueOf(config.getApiVersion()) < 29.0; // validate notify fields right away if (preApi29 && (config.getNotifyForOperationCreate() != null || config.getNotifyForOperationDelete() != null || config.getNotifyForOperationUndelete() != null || config.getNotifyForOperationUpdate() != null)) { throw new IllegalArgumentException("NotifyForOperationCreate, NotifyForOperationDelete" + ", NotifyForOperationUndelete, and NotifyForOperationUpdate" + " are only supported since API version 29.0" + ", instead use NotifyForOperations"); } else if (!preApi29 && config.getNotifyForOperations() != null) { throw new IllegalArgumentException("NotifyForOperations is readonly since API version 29.0" + ", instead use NotifyForOperationCreate, NotifyForOperationDelete" + ", NotifyForOperationUndelete, and NotifyForOperationUpdate"); } }
@Override public SyndesisMetadata<ObjectSchema> adapt(final Map<String, Object> properties, final MetaData metadata) { final ObjectSchema schema = schemaPayload(metadata); Set<ObjectSchema> schemasToConsider; if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { schemasToConsider = Collections.singleton(objectSchemaFrom(schema)); } else { schemasToConsider = schema.getOneOf().stream().filter(SalesforceMetadataAdapter::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataAdapter::nameAndTitlePropertyPairOf).collect(Collectors.toList())); if (isPresent(properties, SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME)) { enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, schemasToConsider.stream() .flatMap(s -> s.getProperties().entrySet().stream()).filter(e -> isIdLookup(e.getValue())) .map(SalesforceMetadataAdapter::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { final String objectName = (String) properties.get(SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); return new SyndesisMetadata<>(enrichedProperties, inputOutputSchema, inputOutputSchema); } return new SyndesisMetadata<>(enrichedProperties, null, null); }
@Override public SyndesisMetadata<ObjectSchema> adapt(String actionId, final Map<String, Object> properties, final MetaData metadata) { final ObjectSchema schema = schemaPayload(metadata); Set<ObjectSchema> schemasToConsider; if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { schemasToConsider = Collections.singleton(objectSchemaFrom(schema)); } else { schemasToConsider = schema.getOneOf().stream().filter(SalesforceMetadataAdapter::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataAdapter::nameAndTitlePropertyPairOf).collect(Collectors.toList())); if (isPresent(properties, SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME)) { enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, schemasToConsider.stream() .flatMap(s -> s.getProperties().entrySet().stream()).filter(e -> isIdLookup(e.getValue())) .map(SalesforceMetadataAdapter::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { final String objectName = (String) properties.get(SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); return new SyndesisMetadata<>(enrichedProperties, inputOutputSchema, inputOutputSchema); } return new SyndesisMetadata<>(enrichedProperties, null, null); }
@Override public void process(final Exchange exchange) throws Exception { // parse input json and extract Id field final Message in = exchange.getIn(); final String body = in.getBody(String.class); if (body == null) { return; } final ObjectNode node = (ObjectNode) MAPPER.readTree(body); final String idPropertyName = determineIdProperty(exchange); final JsonNode idProperty = node.remove(idPropertyName); if (idProperty == null) { exchange.setException( new SalesforceException("Missing option value for Id or " + SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, 404)); return; } final String idValue = idProperty.textValue(); if ("Id".equals(idPropertyName)) { in.setHeader(SalesforceEndpointConfig.SOBJECT_ID, idValue); } else { in.setHeader(SalesforceEndpointConfig.SOBJECT_EXT_ID_VALUE, idValue); } // base fields are not allowed to be updated clearBaseFields(node); // update input json in.setBody(MAPPER.writeValueAsString(node)); }
@Override public String createEndpointUri(final String scheme, final Map<String, String> options) throws URISyntaxException { final String sObjectName = options.get(SalesforceEndpointConfig.SOBJECT_NAME); final String query = "SELECT Id FROM " + sObjectName; options.put("topicName", topicNameFor(options)); options.put(SalesforceEndpointConfig.SOBJECT_QUERY, query); options.remove(SalesforceEndpointConfig.SOBJECT_NAME); return super.createEndpointUri(scheme, options); }
protected CamelSalesforceMojo createMojo() throws IOException { CamelSalesforceMojo mojo = new CamelSalesforceMojo(); mojo.setLog(new SystemStreamLog()); // set login properties setLoginProperties(mojo); // set defaults mojo.version = System.getProperty("apiVersion", SalesforceEndpointConfig.DEFAULT_VERSION); mojo.loginUrl = System.getProperty("loginUrl", SalesforceLoginConfig.DEFAULT_LOGIN_URL); mojo.outputDirectory = new File("target/generated-sources/camel-salesforce"); mojo.packageName = "org.apache.camel.salesforce.dto"; // set code generation properties mojo.includePattern = "(.*__c)|(PushTopic)|(Document)|(Account)"; // remove generated code directory if (mojo.outputDirectory.exists()) { // remove old files for (File file : mojo.outputDirectory.listFiles()) { file.delete(); } mojo.outputDirectory.delete(); } return mojo; }
public AnalyticsApiProcessor(SalesforceEndpoint endpoint) throws SalesforceException { super(endpoint); this.analyticsClient = new DefaultAnalyticsApiClient( (String) endpointConfigMap.get(SalesforceEndpointConfig.API_VERSION), session, httpClient); }
private static String topicNameFor(final Map<String, String> options) { final String sObjectName = options.get(SalesforceEndpointConfig.SOBJECT_NAME); return "syndesis_" + sObjectName + "_delete"; }
protected String topicNameFor(final Map<String, String> options) { final String sObjectName = options.get(SalesforceEndpointConfig.SOBJECT_NAME); return topicPrefix + sObjectName + topicSufix; }
public BulkApiProcessor(SalesforceEndpoint endpoint) throws SalesforceException { super(endpoint); this.bulkClient = new DefaultBulkApiClient( (String) endpointConfigMap.get(SalesforceEndpointConfig.API_VERSION), session, httpClient); }
public SalesforceEndpointConfig getConfig() { return config; }
public void setConfig(SalesforceEndpointConfig config) { this.config = config; }
private String determineIdProperty(final Exchange exchange) throws URISyntaxException { final String uri = exchange.getProperty(Exchange.TO_ENDPOINT, String.class); final Map<String, Object> endpointParameters = URISupport.parseParameters(URI.create(uri)); return (String) endpointParameters.getOrDefault(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, "Id"); }