Search in sources :

Example 6 with ObjectSchema

use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.

the class JsonSchemaInspectorTest method shouldCollectPathsFromJsonSchema.

@Test
public void shouldCollectPathsFromJsonSchema() throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectSchema schema = mapper.readValue(JsonSchemaInspectorTest.class.getResourceAsStream("/salesforce.Contact.jsonschema"), ObjectSchema.class);
    final ArrayList<String> paths = new ArrayList<>();
    JsonSchemaInspector.fetchPaths(null, paths, schema.getProperties());
    assertThat(paths).contains("Id", "IsDeleted", "MasterRecordId", "AccountId", "LastName", "FirstName", "OtherAddress.latitude", "MailingAddress.city");
}
Also used : ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with ObjectSchema

use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.

the class SalesforceMetadataRetrieval method isObjectSchema.

static boolean isObjectSchema(final Object obj) {
    final ObjectSchema schema = (ObjectSchema) obj;
    final String id = schema.getId();
    return !id.contains(":QueryRecords");
}
Also used : ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)

Example 8 with ObjectSchema

use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.

the class SalesforceMetadataRetrieval method adapt.

@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 = (String) properties.get(SalesforceEndpointConfig.SOBJECT_NAME);
            final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName);
            final String specification = Json.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);
}
Also used : PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) MetaData(org.apache.camel.component.extension.MetaDataExtension.MetaData) HashMap(java.util.HashMap) ComponentMetadataRetrieval(io.syndesis.connector.support.verifier.api.ComponentMetadataRetrieval) HashSet(java.util.HashSet) SimpleTypeSchema(com.fasterxml.jackson.module.jsonSchema.types.SimpleTypeSchema) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonUtils(org.apache.camel.component.salesforce.api.utils.JsonUtils) CamelContext(org.apache.camel.CamelContext) DataShape(io.syndesis.common.model.DataShape) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) List(java.util.List) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Entry(java.util.Map.Entry) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) Collections(java.util.Collections) Json(io.syndesis.common.util.Json) HashMap(java.util.HashMap) DataShape(io.syndesis.common.model.DataShape) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 9 with ObjectSchema

use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.

the class SalesforceMetadataRetrievalTest method shouldAdaptObjectMetadataForSchema.

@Test
public void shouldAdaptObjectMetadataForSchema() throws IOException {
    final Map<String, Object> properties = new HashMap<>();
    properties.put("sObjectName", "SimpleObject");
    final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());
    assertThat(metadata.inputShape).isSameAs(metadata.inputShape);
    final Object oneOf = payload.getOneOf().iterator().next();
    final ObjectSchema inSchema = Json.reader().forType(ObjectSchema.class).readValue(metadata.inputShape.getSpecification());
    assertThat(inSchema).isEqualTo(oneOf);
    assertThat(inSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4);
}
Also used : SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with ObjectSchema

use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.

the class SalesforceMetadataRetrievalTest method simpleObjectSchema.

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;
}
Also used : ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)

Aggregations

ObjectSchema (com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)11 SyndesisMetadata (io.syndesis.connector.support.verifier.api.SyndesisMetadata)5 PropertyPair (io.syndesis.connector.support.verifier.api.PropertyPair)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 JsonSchema (com.fasterxml.jackson.module.jsonSchema.JsonSchema)3 DataShape (io.syndesis.common.model.DataShape)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleTypeSchema (com.fasterxml.jackson.module.jsonSchema.types.SimpleTypeSchema)1 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)1 Json (io.syndesis.common.util.Json)1 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)1 SqlParam (io.syndesis.connector.sql.common.SqlParam)1 SqlStatementMetaData (io.syndesis.connector.sql.common.SqlStatementMetaData)1