Improved doc generation

This commit is contained in:
Luca Frosini 2023-01-20 16:44:56 +01:00
parent 82f2c26b3e
commit 8a6f0f916f
13 changed files with 524 additions and 234 deletions

View File

@ -1,9 +1,5 @@
package org.gcube.informationsystem.utils.documentation;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -16,21 +12,16 @@ import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.discovery.ElementSpecilizationDiscovery;
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DocGenerator {
public class ClassesDiscoveryGenerator {
private static final Logger logger = LoggerFactory.getLogger(DocGenerator.class);
protected TypeListGenerator typeListGenerator;
protected File baseDirectory;
public DocGenerator(File baseDirectory) {
this.baseDirectory = baseDirectory;
public ClassesDiscoveryGenerator() {
}
protected List<Package> getPackages(){
@ -62,60 +53,30 @@ public class DocGenerator {
generate(pkgs.toArray(new Package[pkgs.size()]));
}
protected File getFile(ModelTypes cm) throws IOException {
String fileName = cm.getFilename();
File file = new File(fileName);
if(cm.requiresNewFile()) {
if(file.exists()) {
file.delete();
}
}
if(!file.exists()) {
logger.info("Goign to create {}", file.getAbsolutePath());
file.createNewFile();
}
return file;
}
protected <E extends Element> void generateAllOfType(ModelTypes cm, Package[] packages) throws Exception {
ElementSpecilizationDiscovery<E> discovery = new ElementSpecilizationDiscovery<>(cm.getAccessType().getTypeClass());
protected <E extends Element> void discover(AccessType at, Package[] packages) throws Exception {
ElementSpecilizationDiscovery<E> discovery = new ElementSpecilizationDiscovery<>(at.getTypeClass());
if(Objects.nonNull(packages)) {
Arrays.stream(packages).forEach(p -> discovery.addPackage(p));
}
discovery.discover();
File f = getFile(cm);
for(Class<? extends E> clz : discovery.getDiscovered()) {
Type type = TypeMapper.createTypeDefinition(clz);
DocumentationGenerator dgInstance = cm.getDocumentationGeneratorInstance(type);
StringBuffer sb = dgInstance.generateSection();
Files.write(f.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
typeListGenerator.addType(type);
}
}
protected void generateSingle(ModelTypes cm) throws Exception {
File f = getFile(cm);
Class<? extends Element> clz = cm.getAccessType().getTypeClass();
Type type = TypeMapper.createTypeDefinition(clz);
DocumentationGenerator dgInstance = cm.getDocumentationGeneratorInstance(type);
StringBuffer sb = dgInstance.generateSection();
Files.write(f.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
}
protected void generate(Package[] packages) throws Exception {
for(ModelTypes cm : ModelTypes.values()) {
if(cm.discover()) {
generateAllOfType(cm, packages);
}else {
generateSingle(cm);
}
typeListGenerator = new TypeListGenerator();
AccessType[] types = new AccessType[] {
AccessType.PROPERTY,
AccessType.RESOURCE, AccessType.FACET,
AccessType.CONSISTS_OF, AccessType.IS_RELATED_TO};
for(AccessType at : types) {
discover(at, packages);
}
typeListGenerator.generate();
}
}

View File

@ -1,72 +0,0 @@
package org.gcube.informationsystem.utils.documentation;
import java.lang.reflect.Constructor;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.entities.EntityDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.entities.FacetDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.entities.ResourceDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.properties.PropertyDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.relations.ConsistsOfDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.relations.IsRelatedToDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.relations.RelationDocumentationGenerator;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public enum ModelTypes {
PROPERTY(AccessType.PROPERTY, PropertyDocumentationGenerator.class, true, ModelTypes.PROPERTIES_FILENAME, true),
ENTITY(AccessType.ENTITY, EntityDocumentationGenerator.class, false, ModelTypes.ENTITIES_FILENAME, true),
RESOURCE(AccessType.RESOURCE, ResourceDocumentationGenerator.class, true, ModelTypes.ENTITIES_FILENAME, false),
FACET(AccessType.FACET, FacetDocumentationGenerator.class, true, ModelTypes.ENTITIES_FILENAME, false),
RELATION(AccessType.RELATION, RelationDocumentationGenerator.class, false, ModelTypes.RELATIONS_FILENAME, true),
IS_RELATED_TO(AccessType.IS_RELATED_TO, IsRelatedToDocumentationGenerator.class, true, ModelTypes.RELATIONS_FILENAME, false),
CONSISTS_OF(AccessType.CONSISTS_OF, ConsistsOfDocumentationGenerator.class, true, ModelTypes.RELATIONS_FILENAME, false);
public static final String PROPERTIES_FILENAME = "properties.rst";
public static final String ENTITIES_FILENAME = "entities.rst";
public static final String RELATIONS_FILENAME = "relations.rst";
private final AccessType accessType;
private final Class<? extends DocumentationGenerator> dgClz;
private final boolean discover;
private final String filename;
private final boolean newFile;
ModelTypes(AccessType accessType, Class<? extends DocumentationGenerator> dgClz, boolean discover, String filename, boolean newFile) {
this.accessType = accessType;
this.dgClz = dgClz;
this.discover = discover;
this.filename = filename;
this.newFile = newFile;
}
public AccessType getAccessType() {
return accessType;
}
public Class<? extends DocumentationGenerator> getDocumentationGeneratorClz() {
return dgClz;
}
public DocumentationGenerator getDocumentationGeneratorInstance(Type type) throws Exception {
Constructor<? extends DocumentationGenerator> constructor = dgClz.getConstructor(Type.class);
return constructor.newInstance(type);
}
public boolean discover() {
return discover;
}
public String getFilename() {
return filename;
}
public boolean requiresNewFile() {
return newFile;
}
}

View File

@ -0,0 +1,221 @@
package org.gcube.informationsystem.utils.documentation;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.entities.EntityDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.entities.FacetDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.entities.ResourceDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.properties.PropertyDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.relations.ConsistsOfDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.relations.IsRelatedToDocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.model.relations.RelationDocumentationGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeListGenerator {
private static final Logger logger = LoggerFactory.getLogger(TypeListGenerator.class);
public static final String PROPERTIES_FILENAME = "properties.rst";
public static final String ENTITIES_FILENAME = "entities.rst";
public static final String RELATIONS_FILENAME = "relations.rst";
protected List<PropertyType<Property>> propertyTypes;
protected List<ResourceType> resourceTypes;
protected List<FacetType> facetTypes;
protected List<IsRelatedToType> isRelatedToTypes;
protected List<ConsistsOfType> consistsOfTypes;
public TypeListGenerator() {
this.propertyTypes = new ArrayList<>();
this.resourceTypes = new ArrayList<>();
this.facetTypes = new ArrayList<>();
this.isRelatedToTypes = new ArrayList<>();
this.consistsOfTypes = new ArrayList<>();
}
public List<ResourceType> getResourceTypes() {
return resourceTypes;
}
public void setResourceTypes(List<ResourceType> resources) {
this.resourceTypes = resources;
}
public List<FacetType> getFacetTypes() {
return facetTypes;
}
public void setFacetTypes(List<FacetType> facets) {
this.facetTypes = facets;
}
public List<IsRelatedToType> getIsRelatedToTypes() {
return isRelatedToTypes;
}
public void setIsRelatedToTypes(List<IsRelatedToType> isRelatedToTypes) {
this.isRelatedToTypes = isRelatedToTypes;
}
public List<ConsistsOfType> getConsistsOfTypes() {
return consistsOfTypes;
}
public void setConsistsOfTypes(List<ConsistsOfType> consistsOfTypes) {
this.consistsOfTypes = consistsOfTypes;
}
public void addType(Type type) {
switch (type.getAccessType()) {
case PROPERTY:
@SuppressWarnings("unchecked")
PropertyType<Property> p = (PropertyType<Property>) type;
propertyTypes.add(p);
break;
case RESOURCE:
ResourceType r = (ResourceType) type;
resourceTypes.add(r);
break;
case FACET:
FacetType f = (FacetType) type;
facetTypes.add(f);
break;
case IS_RELATED_TO:
IsRelatedToType irt = (IsRelatedToType) type;
isRelatedToTypes.add(irt);
break;
case CONSISTS_OF:
ConsistsOfType co = (ConsistsOfType) type;
consistsOfTypes.add(co);
break;
default:
break;
}
}
protected File getFile(String fileName, boolean newFile) throws IOException {
File file = new File(fileName);
if(file.exists() && newFile) {
file.delete();
}
if(!file.exists()) {
logger.info("Going to create {}", file.getAbsolutePath());
file.createNewFile();
}
return file;
}
public void checkList(List<? extends Type> list) throws Exception {
Type first = list.get(0);
AccessType accessType = first.getAccessType();
if(Objects.isNull(list) || list.size()==0) {
throw new Exception("Please add all " + accessType.getName() + " types before starting generation");
}
}
protected DocumentationGenerator getDocumentationGeneratorInstance(Class<? extends DocumentationGenerator> clz, Type type) throws Exception {
Constructor<? extends DocumentationGenerator> constructor = clz.getConstructor(Type.class);
return constructor.newInstance(type);
}
public void elaborateList(List<? extends Type> types) throws Exception {
Type first = types.get(0);
AccessType accessType = first.getAccessType();
Class<? extends DocumentationGenerator> clz;
File f;
switch (accessType) {
case PROPERTY:
clz = PropertyDocumentationGenerator.class;
f = getFile(PROPERTIES_FILENAME, true);
break;
case RESOURCE:
clz = ResourceDocumentationGenerator.class;
f = getFile(ENTITIES_FILENAME, false);
break;
case FACET:
clz = FacetDocumentationGenerator.class;
f = getFile(ENTITIES_FILENAME, false);
break;
case IS_RELATED_TO:
clz = IsRelatedToDocumentationGenerator.class;
f = getFile(RELATIONS_FILENAME, false);
break;
case CONSISTS_OF:
clz = ConsistsOfDocumentationGenerator.class;
f = getFile(RELATIONS_FILENAME, false);
break;
default:
throw new Exception("List of types not recognized");
}
for(Type type : types) {
DocumentationGenerator dg = getDocumentationGeneratorInstance(clz, type);
StringBuffer sb = dg.generateSection();
Files.write(f.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
}
}
public void generate() throws Exception {
checkList(propertyTypes);
checkList(resourceTypes);
checkList(facetTypes);
checkList(isRelatedToTypes);
checkList(consistsOfTypes);
elaborateList(propertyTypes);
File f = getFile(ENTITIES_FILENAME, true);
DocumentationGenerator edg = new EntityDocumentationGenerator(TypeMapper.createTypeDefinition(Entity.class));
StringBuffer sb = edg.generateSection();
Files.write(f.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
elaborateList(resourceTypes);
elaborateList(facetTypes);
f = getFile(RELATIONS_FILENAME, true);
DocumentationGenerator rdg = new RelationDocumentationGenerator(TypeMapper.createTypeDefinition(Relation.class));
sb = rdg.generateSection();
Files.write(f.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
elaborateList(isRelatedToTypes);
elaborateList(consistsOfTypes);
}
}

View File

@ -0,0 +1,56 @@
package org.gcube.informationsystem.utils.documentation.knowledge;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
public class Knowledge {
private static Knowledge singleton;
public static Knowledge getInstace() {
if(Knowledge.singleton==null) {
Knowledge.singleton = new Knowledge();
}
return Knowledge.singleton;
}
protected Map<String, List<LinkedEntity>> map;
private Knowledge(){
this.map = new LinkedHashMap<>();
}
protected void add(String typeName, LinkedEntity linkedEntity) {
List<LinkedEntity> list = map.get(typeName);
if(list==null) {
list = new ArrayList<>();
map.put(typeName, list);
}
list.add(linkedEntity);
}
public void add(LinkedEntity linkedEntity) {
String source = linkedEntity.getSource();
add(source, linkedEntity);
String relation = linkedEntity.getRelation();
add(relation, linkedEntity);
String target = linkedEntity.getTarget();
add(target, linkedEntity);
}
public void addAll(List<LinkedEntity> linkedEntities) {
for(LinkedEntity le : linkedEntities) {
add(le);
}
}
public List<LinkedEntity> getUsage(String typeName){
List<LinkedEntity> list = map.get(typeName);
return list;
}
}

View File

@ -1,9 +1,12 @@
package org.gcube.informationsystem.utils.documentation.model;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.documentation.rst.Section;
import org.gcube.informationsystem.utils.documentation.rst.Section.SectionType;
@ -21,15 +24,37 @@ public abstract class DocumentationGenerator {
private static final Logger logger = LoggerFactory.getLogger(DocumentationGenerator.class);
protected final Type type;
protected final String superClassToBeExcluded;
private static final int DEFAULT_NUMBER_OF_COLUMNS = 5;
protected DocumentationGenerator(Type type, String superClassToBeExcluded) {
protected final Type type;
protected final AccessType requiredType;
protected final String superClassToBeExcluded;
protected final int requiredNumberOfColumns;
protected DocumentationGenerator(Type type, AccessType requiredType) {
this(type, requiredType, DEFAULT_NUMBER_OF_COLUMNS, null);
}
protected DocumentationGenerator(Type type, AccessType requiredType, int requiredNumberOfColumns) {
this(type, requiredType, requiredNumberOfColumns, null);
}
protected DocumentationGenerator(Type type, AccessType requiredType, String superClassToBeExcluded) {
this(type, requiredType, DEFAULT_NUMBER_OF_COLUMNS, superClassToBeExcluded);
}
protected DocumentationGenerator(Type type, AccessType requiredType, int requiredNumberOfColumns, String superClassToBeExcluded) {
this.type = type;
this.requiredType = requiredType;
AccessType accessType = type.getAccessType();
if(accessType!=requiredType) {
throw new RuntimeException(type.getName() + " is not a " + requiredType.getName() + " type");
}
this.requiredNumberOfColumns = requiredNumberOfColumns;
this.superClassToBeExcluded = superClassToBeExcluded;
}
protected Row getPropertiesBoldRow() {
protected Row getPropertyFieldsBoldRow() {
Row row = new Row(RowType.NORMAL);
Cell name = new Cell();
name.setText("**Name**");
@ -43,11 +68,14 @@ public abstract class DocumentationGenerator {
Cell description = new Cell();
description.setText("**Description**");
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
return row;
}
protected Row getPropertiesHeadingRow() {
protected Row getPropertyFieldsHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell name = new Cell();
name.setText("Name");
@ -61,9 +89,110 @@ public abstract class DocumentationGenerator {
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
return row;
}
protected Row getSourceTargetBoldRow() {
Row row = new Row(RowType.NORMAL);
Cell source = new Cell();
source.setText("**Source**");
row.appendCell(source);
Cell relation = new Cell();
relation.setText("**Relation**");
row.appendCell(relation);
Cell multiplicity = new Cell();
multiplicity.setText("**Multiplicity**");
row.appendCell(multiplicity);
Cell target = new Cell();
target.setText("**Target**");
row.appendCell(target);
Cell description = new Cell();
description.setText("**Description**");
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
return row;
}
protected Row getSourceTargetHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell source = new Cell();
source.setText("Source");
row.appendCell(source);
Cell relation = new Cell();
relation.setText("Relation");
row.appendCell(relation);
Cell multiplicity = new Cell();
multiplicity.setText("Multiplicity");
row.appendCell(multiplicity);
Cell target = new Cell();
target.setText("Target");
row.appendCell(target);
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
return row;
}
protected Row getKnownUsageBoldRow() {
Row row = new Row(RowType.NORMAL);
row = addCellSpanToRow(row, "**Known Usage**", requiredNumberOfColumns);
return row;
}
protected Row getPropertiesBoldRow() {
Row row = new Row(RowType.NORMAL);
row = addCellSpanToRow(row, "**Properties**", requiredNumberOfColumns);
return row;
}
protected Table addLinkedEntities(Table table, List<LinkedEntity> entities) {
if(entities!=null) {
for(LinkedEntity entity : entities) {
Row row = new Row(RowType.NORMAL);
Cell source = new Cell();
source.setText(entity.getSource());
row.appendCell(source);
Cell relation = new Cell();
relation.setText(entity.getRelation());
row.appendCell(relation);
Cell multiplicity = new Cell();
StringBuffer buffer = new StringBuffer();
Integer min = entity.getMin();
buffer.append(min==null? "0" : min.toString());
buffer.append("..");
Integer max = entity.getMax();
buffer.append(max==null? "n" : max.toString());
multiplicity.setText(buffer.toString());
row.appendCell(multiplicity);
Cell target = new Cell();
target.setText(entity.getTarget());
row.appendCell(target);
Cell description = new Cell();
description.setText(entity.getDescription());
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
table.appendRow(row);
}
}
return table;
}
protected String getPropertyAttributes(PropertyDefinition propertyDefinition) {
StringBuffer stringBuffer = new StringBuffer();
@ -114,11 +243,14 @@ public abstract class DocumentationGenerator {
Cell description = new Cell();
description.setText(propertyDefinition.getDescription());
row.appendCell(description);
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
row.appendCell(description);
}
return row;
}
protected Row getNoPropertyRow() {
return getRowCellSpan("This type does not define any additional attributes.", 4);
return getRowCellSpan("This type does not define any additional attributes.", requiredNumberOfColumns);
}
protected Row addCellSpanToRow(Row row, String content, int cellSpan) {

View File

@ -1,8 +1,13 @@
package org.gcube.informationsystem.utils.documentation.model.entities;
import java.util.HashSet;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
@ -14,20 +19,56 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class EntityDocumentationGenerator extends DocumentationGenerator {
public EntityDocumentationGenerator(Type type) {
super(type, TypeMapper.getType(EntityElement.class));
super(type, AccessType.ENTITY, 4, TypeMapper.getType(EntityElement.class));
}
protected EntityDocumentationGenerator(Type type, AccessType requiredType) {
super(type, requiredType);
}
protected EntityDocumentationGenerator(Type type, AccessType requiredType, int requiredNumberOfColumns) {
super(type, requiredType, requiredNumberOfColumns);
}
protected EntityDocumentationGenerator(Type type, AccessType requiredType, String superClassToBeExcluded) {
super(type, requiredType, superClassToBeExcluded);
}
protected EntityDocumentationGenerator(Type type, AccessType requiredType, int requiredNumberOfColumns, String superClassToBeExcluded) {
super(type, requiredType, requiredNumberOfColumns, superClassToBeExcluded);
}
protected Row getEntityHeadingRow() {
Row row = new Row(RowType.HEADING);
row = addCellSpanToRow(row, "Properties", 4);
row = addCellSpanToRow(row, "Properties", requiredNumberOfColumns);
return row;
}
@Override
protected Table getTable() {
Type entityElementType = TypeMapper.createTypeDefinition(EntityElement.class);
Table table = new Table();
table.appendRow(getEntityHeadingRow());
table.appendRow(getPropertiesBoldRow());
table.appendRow(getPropertyFieldsBoldRow());
Set<PropertyDefinition> properties = entityElementType.getProperties();
if(properties!=null && properties.size()>0) {
Set<PropertyDefinition> notMandatoryProperties = new HashSet<>();
for(PropertyDefinition propertyDefinition : properties) {
if(propertyDefinition.isMandatory()) {
/*
* Adding Mandatory properties first in the table
*/
table.appendRow(getPropertyRow(propertyDefinition));
}else {
notMandatoryProperties.add(propertyDefinition);
}
}
for(PropertyDefinition propertyDefinition : notMandatoryProperties) {
table.appendRow(getPropertyRow(propertyDefinition));
}
}else {
table.appendRow(getNoPropertyRow());
}
return table;
}

View File

@ -1,10 +1,14 @@
package org.gcube.informationsystem.utils.documentation.model.entities;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.documentation.knowledge.Knowledge;
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
/**
@ -13,14 +17,14 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class FacetDocumentationGenerator extends EntityDocumentationGenerator {
public FacetDocumentationGenerator(Type type) {
super(type);
super(type, AccessType.FACET);
}
@Override
protected Table getTable() {
Table table = new Table();
table.appendRow(getEntityHeadingRow());
table.appendRow(getPropertiesBoldRow());
table.appendRow(getPropertyFieldsBoldRow());
Set<PropertyDefinition> properties = type.getProperties();
if(properties!=null && properties.size()>0) {
Set<PropertyDefinition> notMandatoryProperties = new HashSet<>();
@ -40,6 +44,14 @@ public class FacetDocumentationGenerator extends EntityDocumentationGenerator {
}else {
table.appendRow(getNoPropertyRow());
}
table.appendRow(getKnownUsageBoldRow());
table.appendRow(getSourceTargetBoldRow());
Knowledge k = Knowledge.getInstace();
List<LinkedEntity> usage = k.getUsage(type.getName());
addLinkedEntities(table, usage);
return table;
}

View File

@ -1,9 +1,9 @@
package org.gcube.informationsystem.utils.documentation.model.entities;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.utils.documentation.knowledge.Knowledge;
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
/**
@ -12,32 +12,23 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class ResourceDocumentationGenerator extends EntityDocumentationGenerator {
public ResourceDocumentationGenerator(Type type) {
super(type);
super(type,AccessType.RESOURCE);
ResourceType rt = (ResourceType) type;
Knowledge k = Knowledge.getInstace();
k.addAll(rt.getFacets());
k.addAll(rt.getResources());
}
protected Row getHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell name = new Cell();
name.setText("Name");
row.appendCell(name);
Cell type = new Cell();
type.setText("Type");
row.appendCell(type);
Cell attributes = new Cell();
attributes.setText("Attributes");
row.appendCell(attributes);
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
return row;
}
@Override
protected Table getTable() {
Table table = new Table();
table.appendRow(getHeadingRow());
table.appendRow(getSourceTargetHeadingRow());
table.appendRow(getRowCellSpan("**Facets**", requiredNumberOfColumns));
ResourceType resourceType = (ResourceType) type;
addLinkedEntities(table, resourceType.getFacets());
table.appendRow(getRowCellSpan("**Relations**", requiredNumberOfColumns));
addLinkedEntities(table, resourceType.getResources());
return table;
}
}

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.utils.documentation.model.properties;
import java.util.HashSet;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
@ -16,14 +17,14 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class PropertyDocumentationGenerator extends DocumentationGenerator {
public PropertyDocumentationGenerator(Type type) {
super(type, TypeMapper.getType(PropertyElement.class));
super(type, AccessType.PROPERTY, 4, TypeMapper.getType(PropertyElement.class));
}
@Override
protected Table getTable() {
Table table = new Table();
table.appendRow(getPropertiesHeadingRow());
table.appendRow(getPropertyFieldsHeadingRow());
Set<PropertyDefinition> properties = type.getProperties();
if(properties!=null && properties.size()>0) {
Set<PropertyDefinition> notMandatoryProperties = new HashSet<>();

View File

@ -1,9 +1,7 @@
package org.gcube.informationsystem.utils.documentation.model.relations;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
/**
@ -12,30 +10,13 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class ConsistsOfDocumentationGenerator extends RelationDocumentationGenerator {
public ConsistsOfDocumentationGenerator(Type type) {
super(type);
}
protected Row getHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell name = new Cell();
name.setText("Name");
row.appendCell(name);
Cell type = new Cell();
type.setText("Type");
row.appendCell(type);
Cell attributes = new Cell();
attributes.setText("Attributes");
row.appendCell(attributes);
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
return row;
super(type, AccessType.CONSISTS_OF);
}
@Override
protected Table getTable() {
Table table = new Table();
table.appendRow(getHeadingRow());
table.appendRow(getPropertyFieldsHeadingRow());
return table;
}

View File

@ -1,9 +1,7 @@
package org.gcube.informationsystem.utils.documentation.model.relations;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
/**
@ -12,30 +10,13 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class IsRelatedToDocumentationGenerator extends RelationDocumentationGenerator {
public IsRelatedToDocumentationGenerator(Type type) {
super(type);
}
protected Row getHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell name = new Cell();
name.setText("Name");
row.appendCell(name);
Cell type = new Cell();
type.setText("Type");
row.appendCell(type);
Cell attributes = new Cell();
attributes.setText("Attributes");
row.appendCell(attributes);
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
return row;
super(type, AccessType.IS_RELATED_TO);
}
@Override
protected Table getTable() {
Table table = new Table();
table.appendRow(getHeadingRow());
table.appendRow(getPropertyFieldsHeadingRow());
return table;
}

View File

@ -1,12 +1,10 @@
package org.gcube.informationsystem.utils.documentation.model.relations;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
/**
@ -15,30 +13,22 @@ import org.gcube.informationsystem.utils.documentation.rst.table.Table;
public class RelationDocumentationGenerator extends DocumentationGenerator {
public RelationDocumentationGenerator(Type type) {
super(type, TypeMapper.getType(RelationElement.class));
super(type, AccessType.RELATION, TypeMapper.getType(RelationElement.class));
}
protected Row getHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell name = new Cell();
name.setText("Name");
row.appendCell(name);
Cell type = new Cell();
type.setText("Type");
row.appendCell(type);
Cell attributes = new Cell();
attributes.setText("Attributes");
row.appendCell(attributes);
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
return row;
protected RelationDocumentationGenerator(Type type, AccessType requiredType) {
super(type, requiredType);
}
protected RelationDocumentationGenerator(Type type, AccessType requiredType, String superClassToBeExcluded) {
super(type, requiredType, superClassToBeExcluded);
}
@Override
protected Table getTable() {
Table table = new Table();
table.appendRow(getHeadingRow());
table.appendRow(getPropertyFieldsHeadingRow());
return table;
}

View File

@ -1,8 +1,5 @@
package org.gcube.informationsystem.utils.documentation;
import java.io.File;
import java.net.URL;
import org.junit.Test;
/**
@ -12,9 +9,7 @@ public class GenerateTest {
@Test
public void testDocGeneration() throws Exception {
URL jsonFileURL = this.getClass().getClassLoader().getResource("logback-test.xml");
File file = new File(jsonFileURL.toURI());
DocGenerator documentationGenerator = new DocGenerator(file.getParentFile());
ClassesDiscoveryGenerator documentationGenerator = new ClassesDiscoveryGenerator();
documentationGenerator.generate();
}
}