121 lines
3.3 KiB
Java
121 lines
3.3 KiB
Java
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<Package> packagesToInclude;
|
|
|
|
protected Map<String, Type> relationElements;
|
|
protected Map<String, Type> propertyElements;
|
|
protected Map<String, Type> entityElements;
|
|
|
|
public DocumentationSchemaAction() {
|
|
this.relationElements = new HashMap<>();
|
|
this.propertyElements = new HashMap<>();
|
|
this.entityElements = new HashMap<>();
|
|
}
|
|
|
|
public DocumentationSchemaAction(List<Package> pkgs ) {
|
|
this();
|
|
this.packagesToInclude = pkgs;
|
|
}
|
|
|
|
public Map<String, Type> getRelationElements() {
|
|
return relationElements;
|
|
}
|
|
|
|
public Map<String, Type> getPropertyElement() {
|
|
return propertyElements;
|
|
}
|
|
|
|
public Map<String, Type> getEntityElement() {
|
|
return entityElements;
|
|
}
|
|
|
|
@Override
|
|
public <R extends RelationElement<? extends EntityElement, ? extends EntityElement>> void manageRelationClass(
|
|
Class<R> 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 <P extends PropertyElement> void managePropertyClass(Class<P> 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 <E extends EntityElement> void manageEntityClass(Class<E> 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);
|
|
}
|
|
|
|
}
|