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; }
@Override public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) { ObjectSchema s = schemaProvider.objectSchema(); schema = s; // if we don't already have a recursive visitor context, create one if (visitorContext == null) { visitorContext = new VisitorContext(); } // give each object schema a reference id and keep track of the ones we've seen String schemaUri = visitorContext.addSeenSchemaUri(convertedType); if (schemaUri != null) { s.setId(schemaUri); } return visitorFactory.objectFormatVisitor(provider, s, visitorContext); }
@Override public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) { ObjectSchema s = schemaProvider.objectSchema(); schema = s; // if we don't already have a recursive visitor context, create one if (visitorContext == null) { visitorContext = new VisitorContext(); } // give each object schema a reference id and keep track of the ones we've seen String schemaUri = visitorContext.addSeenSchemaUri(convertedType); if (schemaUri != null) { s.setId(schemaUri); } return visitorFactory.objectFormatVisitor(provider, s, visitorContext); }
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; } }
public SalesforceMetadataRetrievalTest() { final Map<String, JsonSchema> objectProperties = new HashMap<>(); objectProperties.put("simpleProperty", new StringSchema()); objectProperties.put("anotherProperty", new NumberSchema()); final StringSchema uniqueProperty1 = new StringSchema(); uniqueProperty1.setDescription("idLookup,autoNumber"); uniqueProperty1.setTitle("Unique property 1"); final StringSchema uniqueProperty2 = new StringSchema(); uniqueProperty2.setDescription("calculated,idLookup"); uniqueProperty2.setTitle("Unique property 2"); objectProperties.put("uniqueProperty1", uniqueProperty1); objectProperties.put("uniqueProperty2", uniqueProperty2); final ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setId("urn:jsonschema:org:apache:camel:component:salesforce:dto:SimpleObject"); objectSchema.setProperties(objectProperties); payload = new ObjectSchema(); payload.setOneOf(Collections.singleton(objectSchema)); }