Adding documenation generation
This commit is contained in:
parent
401745d7dc
commit
45d5a3a131
|
@ -4,7 +4,7 @@ import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interfaces is an helper to identify elements of the model
|
* This interfaces is an helper to identify elements of the model
|
||||||
* i.e. REsource, Facet, IsRelatedTo, ConsistsOf
|
* i.e. Resource, Facet, IsRelatedTo, ConsistsOf
|
||||||
*
|
*
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package org.gcube.informationsystem.utils.discovery;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
|
|
||||||
|
public class Discovery {
|
||||||
|
|
||||||
|
public static void discover(SchemaAction schemaAction) throws Exception {
|
||||||
|
List<Package> packages = new ArrayList<Package>();
|
||||||
|
|
||||||
|
Class<Type> tdClz = Type.class;
|
||||||
|
packages.add(tdClz.getPackage());
|
||||||
|
|
||||||
|
AccessType[] accessTypes = AccessType.values();
|
||||||
|
for(AccessType accessType : accessTypes) {
|
||||||
|
Class<Element> clz = accessType.getTypeClass();
|
||||||
|
packages.add(clz.getPackage());
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
|
||||||
|
.load(RegistrationProvider.class);
|
||||||
|
for(RegistrationProvider registrationProvider : regsitrationProviders) {
|
||||||
|
packages.addAll(registrationProvider.getPackagesToRegister());
|
||||||
|
}
|
||||||
|
|
||||||
|
ElementSpecilizationDiscovery.manageISM(schemaAction , packages);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.gcube.informationsystem.utils.documentation;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
|
import org.gcube.informationsystem.utils.discovery.Discovery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class DocumentationGenerator {
|
||||||
|
|
||||||
|
protected File baseDirectory;
|
||||||
|
|
||||||
|
public DocumentationGenerator(File baseDirectory) {
|
||||||
|
this.baseDirectory = baseDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generatePropertySection(Type type) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() throws Exception {
|
||||||
|
|
||||||
|
DocumentationSchemaAction schemaAction = new DocumentationSchemaAction();
|
||||||
|
Discovery.discover(schemaAction);
|
||||||
|
|
||||||
|
Map<String, Type> propertyElements = schemaAction.getPropertyElement();
|
||||||
|
Set<String> propertyNames = propertyElements.keySet();
|
||||||
|
for(String name : propertyNames) {
|
||||||
|
Type type = propertyElements.get(name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Type> relationElements = schemaAction.getRelationElements();
|
||||||
|
Set<String> relationNames = relationElements.keySet();
|
||||||
|
for(String name : relationNames) {
|
||||||
|
Type type = propertyElements.get(name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Type> entityElements = schemaAction.getEntityElement();
|
||||||
|
Set<String> entityNames = entityElements.keySet();
|
||||||
|
for(String name : entityNames) {
|
||||||
|
Type type = propertyElements.get(name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package org.gcube.informationsystem.utils.documentation;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
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.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 Package packageToInclude;
|
||||||
|
|
||||||
|
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(Package pkg) {
|
||||||
|
this();
|
||||||
|
this.packageToInclude = pkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(packageToInclude!=null && !r.getPackage().getName().startsWith(packageToInclude.getName())) {
|
||||||
|
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(packageToInclude!=null && !p.getPackage().getName().startsWith(packageToInclude.getName())) {
|
||||||
|
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(packageToInclude!=null && !e.getPackage().getName().startsWith(packageToInclude.getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Type type = TypeMapper.createTypeDefinition(e);
|
||||||
|
String name = type.getName();
|
||||||
|
logger.debug("Found {} {}", EntityElement.NAME, name);
|
||||||
|
entityElements.put(name,type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.gcube.informationsystem.utils.documentation.rst;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class Section {
|
||||||
|
|
||||||
|
public enum SectionType {
|
||||||
|
HEADING_1(true, "*"),
|
||||||
|
HEADING_2(false, "="),
|
||||||
|
HEADING_3(false, "_"),
|
||||||
|
HEADING_4(false, "^");
|
||||||
|
|
||||||
|
boolean both;
|
||||||
|
String separator;
|
||||||
|
|
||||||
|
private SectionType(boolean both, String separator) {
|
||||||
|
this.both = both;
|
||||||
|
this.separator = separator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected StringBuffer getSectionSeparation(String separator, int lenght) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
for(int i=0; i<lenght; i++) {
|
||||||
|
stringBuffer.append(separator);
|
||||||
|
}
|
||||||
|
return stringBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringBuffer generateSection(SectionType sectionType, String sectionTitle) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
int lenght = sectionTitle.length();
|
||||||
|
if(sectionType.both) {
|
||||||
|
stringBuffer.append(getSectionSeparation(sectionType.separator, lenght));
|
||||||
|
}
|
||||||
|
stringBuffer.append(sectionTitle);
|
||||||
|
stringBuffer.append(getSectionSeparation(sectionType.separator, lenght));
|
||||||
|
return stringBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.informationsystem.utils.documentation.table;
|
package org.gcube.informationsystem.utils.documentation.rst.table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.informationsystem.utils.documentation.table;
|
package org.gcube.informationsystem.utils.documentation.rst.table;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.informationsystem.utils.documentation.table;
|
package org.gcube.informationsystem.utils.documentation.rst.table;
|
||||||
|
|
||||||
public enum RowType {
|
public enum RowType {
|
||||||
HEADING(Table.ROW_SEPARATOR_HEADING),
|
HEADING(Table.ROW_SEPARATOR_HEADING),
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.informationsystem.utils.documentation.table;
|
package org.gcube.informationsystem.utils.documentation.rst.table;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -12,7 +12,6 @@ public class Table {
|
||||||
public static final String ROW_SEPARATOR = "-";
|
public static final String ROW_SEPARATOR = "-";
|
||||||
public static final String ROW_SEPARATOR_HEADING = "=";
|
public static final String ROW_SEPARATOR_HEADING = "=";
|
||||||
|
|
||||||
|
|
||||||
private List<Row> rows;
|
private List<Row> rows;
|
||||||
private List<Integer> maxSizePerCell;
|
private List<Integer> maxSizePerCell;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.gcube.informationsystem.utils.discovery.documentation.table;
|
package org.gcube.informationsystem.utils.discovery.documentation.table;
|
||||||
|
|
||||||
import org.gcube.informationsystem.utils.documentation.table.Cell;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
|
||||||
import org.gcube.informationsystem.utils.documentation.table.Row;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
|
||||||
import org.gcube.informationsystem.utils.documentation.table.RowType;
|
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
|
||||||
import org.gcube.informationsystem.utils.documentation.table.Table;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
Loading…
Reference in New Issue