static ObjectSchema convertSalesforceGlobalObjectJsonToSchema(final JsonNode payload) { final Set<Object> allSchemas = new HashSet<>(); for (final JsonNode sobject : payload) { // generate SObject schema from description final ObjectSchema sobjectSchema = new ObjectSchema(); sobjectSchema.setId(JsonUtils.DEFAULT_ID_PREFIX + ":" + sobject.get("name").asText()); sobjectSchema.setTitle(sobject.get("label").asText()); allSchemas.add(sobjectSchema); } final ObjectSchema schema = new ObjectSchema(); schema.setOneOf(allSchemas); return schema; }
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)); }); }
@Test public void shouldAdaptObjectMetadataForSchema() { final Map<String, Object> properties = new HashMap<>(); properties.put("sObjectName", "SimpleObject"); final SyndesisMetadata<ObjectSchema> metadata = adapter.adapt(properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build()); assertThat(metadata.inputSchema).isSameAs(metadata.outputSchema); final Object oneOf = payload.getOneOf().iterator().next(); assertThat(metadata.inputSchema).isSameAs(oneOf); assertThat(metadata.inputSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4); }
ObjectSchema simpleObjectSchema(final String name, final String label) { final ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setId(JsonUtils.DEFAULT_ID_PREFIX + ":" + name); objectSchema.setTitle(label); return objectSchema; }
@Test public void shouldAdaptObjectMetadataForSchema() { final Map<String, Object> properties = new HashMap<>(); properties.put("sObjectName", "SimpleObject"); final SyndesisMetadata<ObjectSchema> metadata = adapter.adapt(null, properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build()); assertThat(metadata.inputSchema).isSameAs(metadata.outputSchema); final Object oneOf = payload.getOneOf().iterator().next(); assertThat(metadata.inputSchema).isSameAs(oneOf); assertThat(metadata.inputSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4); }
public SalesforceCreateSObjectComponent() { super("salesforce-create-sobject", SalesforceCreateSObjectComponent.class.getName()); setAfterProducer( exchange -> { // map json response back to CreateSObjectResult POJO ObjectMapper mapper = JsonUtils.createObjectMapper(); if (!exchange.isFailed()) { Message out = exchange.getOut(); CreateSObjectResult result = mapper.readValue(out.getBody(String.class), CreateSObjectResult.class); out.setBody(result); } }); }
static ObjectSchema adaptSchema(final ObjectSchema schema) { schema.set$schema(JsonUtils.SCHEMA4); return schema; }