Search in sources :

Example 1 with RelationSchema

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();
        }
    };
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BusinessEntity(org.meveo.model.BusinessEntity) RootRelationSchema(org.meveo.json.schema.RootRelationSchema) ReferenceSchema(org.everit.json.schema.ReferenceSchema) CombinedObjectSchema(org.everit.json.schema.CombinedObjectSchema) RootObjectSchema(org.meveo.json.schema.RootObjectSchema) ObjectSchema(org.everit.json.schema.ObjectSchema) CustomEntityTemplate(org.meveo.model.customEntities.CustomEntityTemplate) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) RootRelationSchema(org.meveo.json.schema.RootRelationSchema) RelationSchema(org.everit.json.schema.RelationSchema) HashMap(java.util.HashMap) Map(java.util.Map) ReferenceViewSchema(org.everit.json.schema.ReferenceViewSchema)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CombinedObjectSchema (org.everit.json.schema.CombinedObjectSchema)1 ObjectSchema (org.everit.json.schema.ObjectSchema)1 ReferenceSchema (org.everit.json.schema.ReferenceSchema)1 ReferenceViewSchema (org.everit.json.schema.ReferenceViewSchema)1 RelationSchema (org.everit.json.schema.RelationSchema)1 RootObjectSchema (org.meveo.json.schema.RootObjectSchema)1 RootRelationSchema (org.meveo.json.schema.RootRelationSchema)1 BusinessEntity (org.meveo.model.BusinessEntity)1 CustomFieldTemplate (org.meveo.model.crm.CustomFieldTemplate)1 CustomEntityTemplate (org.meveo.model.customEntities.CustomEntityTemplate)1