@Test public void shouldAdaptObjectMetadataForProperties() { final Map<String, Object> properties = new HashMap<>(); properties.put("sObjectName", "SimpleObject"); properties.put("sObjectIdName", null); final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build()); assertThat(metadata.getProperties()).containsKey("sObjectIdName"); final List<PropertyPair> values = metadata.getProperties().get("sObjectIdName"); assertThat(values).containsOnly(new PropertyPair("uniqueProperty1", "Unique property 1"), new PropertyPair("uniqueProperty2", "Unique property 2")); }
@Override protected SyndesisMetadata adapt(final CamelContext context, final String componentId, final 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(SalesforceMetadataRetrieval::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataRetrieval::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(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { try { final String objectName = ConnectorOptions.extractOption(properties, SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); final String specification = io.syndesis.common.util.json.JsonUtils.writer().writeValueAsString(inputOutputSchema); return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build(), new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build()); } catch (final JsonProcessingException e) { throw new IllegalStateException(e); } } return new SyndesisMetadata(enrichedProperties, null, null); }
SalesforceMetadataRetrieval extends ComponentMetadataRetrieval { @Override protected SyndesisMetadata adapt(final CamelContext context, final String componentId, final 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(SalesforceMetadataRetrieval::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataRetrieval::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(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { try { final String objectName = ConnectorOptions.extractOption(properties, SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); final String specification = io.syndesis.common.util.json.JsonUtils.writer().writeValueAsString(inputOutputSchema); return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build(), new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build()); } catch (final JsonProcessingException e) { throw new IllegalStateException(e); } } return new SyndesisMetadata(enrichedProperties, null, null); } }
SalesforceMetadataRetrieval extends ComponentMetadataRetrieval { @Override protected SyndesisMetadata adapt(final CamelContext context, final String componentId, final 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(SalesforceMetadataRetrieval::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataRetrieval::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(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { try { final String objectName = ConnectorOptions.extractOption(properties, SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); final String specification = io.syndesis.common.util.json.JsonUtils.writer().writeValueAsString(inputOutputSchema); return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build(), new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build()); } catch (final JsonProcessingException e) { throw new IllegalStateException(e); } } return new SyndesisMetadata(enrichedProperties, null, null); }  }
SalesforceMetadataRetrieval extends ComponentMetadataRetrieval { @Override protected SyndesisMetadata adapt(final CamelContext context, final String componentId, final 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(SalesforceMetadataRetrieval::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataRetrieval::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(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { try { final String objectName = ConnectorOptions.extractOption(properties, SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); final String specification = io.syndesis.common.util.json.JsonUtils.writer().writeValueAsString(inputOutputSchema); return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build(), new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build()); } catch (final JsonProcessingException e) { throw new IllegalStateException(e); } } return new SyndesisMetadata(enrichedProperties, null, null); }  @Override RuntimeException handle(final Exception e); }
SalesforceMetadataRetrieval extends ComponentMetadataRetrieval { @Override protected SyndesisMetadata adapt(final CamelContext context, final String componentId, final 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(SalesforceMetadataRetrieval::isObjectSchema) .map(ObjectSchema.class::cast).collect(Collectors.toSet()); } final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>(); enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, schemasToConsider.stream() .map(SalesforceMetadataRetrieval::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(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList())); } if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) { try { final String objectName = ConnectorOptions.extractOption(properties, SalesforceEndpointConfig.SOBJECT_NAME); final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName); final String specification = io.syndesis.common.util.json.JsonUtils.writer().writeValueAsString(inputOutputSchema); return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build(), new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA) .type(inputOutputSchema.getTitle()) .name(SALESFORCE + objectName) .description(SALESFORCE + objectName) .specification(specification).build()); } catch (final JsonProcessingException e) { throw new IllegalStateException(e); } } return new SyndesisMetadata(enrichedProperties, null, null); }  @Override RuntimeException handle(final Exception e); static final String SALESFORCE; }