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");
}
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");
}
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);
}
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);
}
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;
}
Aggregations