use of org.everit.json.schema.RelationSchema in project meveo by meveo-org.
the class JSONSchemaGenerator method processorOf.
private CustomTemplateProcessor processorOf(CustomRelationshipTemplate relationshipTemplate) {
return new CustomTemplateProcessor() {
@Override
String code() {
return relationshipTemplate.getCode();
}
@Override
Map<String, CustomFieldTemplate> fields() {
return cache.getCustomFieldTemplates(relationshipTemplate.getAppliesTo());
}
@Override
CustomTemplateProcessor parentTemplate() {
return null;
}
@Override
ObjectSchema.Builder createJsonSchemaBuilder(String schemaLocation, Set<String> allRefs) {
RelationSchema.Builder result = RelationSchema.builder().requiresRelation(true).id(relationshipTemplate.getCode()).title(relationshipTemplate.getName()).description(relationshipTemplate.getDescription()).storages(buildDBStorageType(relationshipTemplate.getAvailableStorages())).schemaLocation(schemaLocation);
CustomEntityTemplate node;
node = relationshipTemplate.getStartNode();
if (node != null) {
result.source(createReference(node));
allRefs.add(node.getCode());
}
node = relationshipTemplate.getEndNode();
if (node != null) {
result.target(createReference(node));
allRefs.add(node.getCode());
}
return result;
}
@Override
ObjectSchema.Builder toRootJsonSchema(ObjectSchema original, Map<String, Schema> dependencies) {
RootRelationSchema.Builder builder = RootRelationSchema.builder().copyOf((RelationSchema) original).specificationVersion(JSON_SCHEMA_VERSION);
dependencies.forEach(builder::addDefinition);
return builder;
}
private ReferenceSchema createReference(CustomEntityTemplate node) {
ReferenceSchema.Builder r = ReferenceSchema.builder().refValue(DEFINITIONS_PREFIX + node.getCode());
return r.build();
}
@SuppressWarnings("unused")
private ReferenceViewSchema createReference_obsolete(CustomEntityTemplate node, String nodeKeys) {
List<String> actualKeys;
if (nodeKeys != null) {
actualKeys = Arrays.asList(nodeKeys.split(","));
} else {
actualKeys = processorOf(node).fields().values().stream().filter(CustomFieldTemplate::isUnique).map(BusinessEntity::getCode).collect(Collectors.toList());
}
ReferenceViewSchema.Builder r = ReferenceViewSchema.builder().refValue(DEFINITIONS_PREFIX + node.getCode());
actualKeys.forEach(p -> r.addRefProperty(p.trim()));
return r.build();
}
};
}
Aggregations