package org.gcube.informationsystem.utils.documentation; import java.util.HashMap; import java.util.List; import java.util.Map; import org.gcube.informationsystem.base.reference.entities.EntityElement; import org.gcube.informationsystem.base.reference.properties.PropertyElement; import org.gcube.informationsystem.base.reference.relations.RelationElement; import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.utils.discovery.SchemaAction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class DocumentationSchemaAction implements SchemaAction { private static final Logger logger = LoggerFactory.getLogger(DocumentationSchemaAction.class); protected List packagesToInclude; protected Map relationElements; protected Map propertyElements; protected Map entityElements; public DocumentationSchemaAction() { this.relationElements = new HashMap<>(); this.propertyElements = new HashMap<>(); this.entityElements = new HashMap<>(); } public DocumentationSchemaAction(List pkgs ) { this(); this.packagesToInclude = pkgs; } public Map getRelationElements() { return relationElements; } public Map getPropertyElement() { return propertyElements; } public Map getEntityElement() { return entityElements; } @Override public > void manageRelationClass( Class r) throws Exception { if(r.isAssignableFrom(Type.class)) { return; } if(packagesToInclude!=null) { boolean found = false; for(Package packageToInclude : packagesToInclude) { if(r.getPackage().getName().startsWith(packageToInclude.getName())) { found = true; } } if(!found) { return; } } Type type = TypeMapper.createTypeDefinition(r); String name = type.getName(); logger.debug("Found {} {}", RelationElement.NAME, name); relationElements.put(name, type); } @Override public

void managePropertyClass(Class

p) throws Exception { if(p.isAssignableFrom(Type.class)) { return; } if(packagesToInclude!=null) { boolean found = false; for(Package packageToInclude : packagesToInclude) { if(p.getPackage().getName().startsWith(packageToInclude.getName())) { found = true; } } if(!found) { return; } } Type type = TypeMapper.createTypeDefinition(p); String name = type.getName(); logger.debug("Found {} {}", PropertyElement.NAME, name); propertyElements.put(name, type); } @Override public void manageEntityClass(Class e) throws Exception { if(e.isAssignableFrom(Type.class)) { return; } if(packagesToInclude!=null) { boolean found = false; for(Package packageToInclude : packagesToInclude) { if(e.getPackage().getName().startsWith(packageToInclude.getName())) { found = true; } } if(!found) { return; } } Type type = TypeMapper.createTypeDefinition(e); String name = type.getName(); logger.debug("Found {} {}", EntityElement.NAME, name); entityElements.put(name,type); } }