Improving code
This commit is contained in:
parent
2975b5d613
commit
0529d64606
|
@ -29,10 +29,5 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -71,6 +71,8 @@ public class TreeGenerator extends Generator {
|
||||||
|
|
||||||
protected void writeSectionOnly(Type type, int level) throws Exception {
|
protected void writeSectionOnly(Type type, int level) throws Exception {
|
||||||
DocumentationGenerator dg = getDocumentationGenerator(type);
|
DocumentationGenerator dg = getDocumentationGenerator(type);
|
||||||
|
dg.setFacetKnowledge(tree.getFacetKnowledge());
|
||||||
|
dg.setResourceKnowledge(tree.getResourceKnowledge());
|
||||||
dg.setLevel(level);
|
dg.setLevel(level);
|
||||||
StringBuffer sb = dg.generateSection();
|
StringBuffer sb = dg.generateSection();
|
||||||
Files.write(file.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
|
Files.write(file.toPath(), sb.toString().getBytes(), StandardOpenOption.APPEND);
|
||||||
|
@ -98,19 +100,25 @@ public class TreeGenerator extends Generator {
|
||||||
public void generate() throws Exception {
|
public void generate() throws Exception {
|
||||||
|
|
||||||
File is = getFile(IS_MODEL_FILENAME, true);
|
File is = getFile(IS_MODEL_FILENAME, true);
|
||||||
File file = null;
|
|
||||||
|
|
||||||
|
|
||||||
for(AccessType at : accessTypes) {
|
for(AccessType at : accessTypes) {
|
||||||
Type type = TypeMapper.createTypeDefinition(at.getTypeClass());
|
Type type = TypeMapper.createTypeDefinition(at.getTypeClass());
|
||||||
writeTypeToFile(type, is);
|
writeTypeToFile(type, is);
|
||||||
|
if(at==AccessType.PROPERTY) {
|
||||||
|
for(Class<? extends Property> clz : isModelProperties) {
|
||||||
|
Type t = TypeMapper.createTypeDefinition(clz);
|
||||||
|
writeTypeToFile(t, is, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = null;
|
||||||
|
for(AccessType at : accessTypes) {
|
||||||
switch (at) {
|
switch (at) {
|
||||||
case PROPERTY:
|
case PROPERTY:
|
||||||
file = getFile(PROPERTIES_FILENAME, true);
|
file = getFile(PROPERTIES_FILENAME, true);
|
||||||
for(Class<? extends Property> clz : isModelProperties) {
|
|
||||||
Type t = TypeMapper.createTypeDefinition(clz);
|
|
||||||
writeTypeToFile(t, is, 1);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENTITY:
|
case ENTITY:
|
||||||
|
|
|
@ -17,11 +17,23 @@ public class Tree {
|
||||||
private boolean allowMultipleInheritance;
|
private boolean allowMultipleInheritance;
|
||||||
private HashMap<String, Node> locate = new HashMap<String, Node>();
|
private HashMap<String, Node> locate = new HashMap<String, Node>();
|
||||||
|
|
||||||
|
private UsageKnowledge facetKnowledge;
|
||||||
|
private UsageKnowledge resourceKnowledge;
|
||||||
|
|
||||||
public Tree(Type head) {
|
public Tree(Type head) {
|
||||||
this.root = new Node(head);
|
this.root = new Node(head);
|
||||||
this.locate.put(head.getName(), root);
|
this.locate.put(head.getName(), root);
|
||||||
this.allowMultipleInheritance = false;
|
this.allowMultipleInheritance = false;
|
||||||
|
this.facetKnowledge = new UsageKnowledge();
|
||||||
|
this.resourceKnowledge = new UsageKnowledge();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UsageKnowledge getFacetKnowledge() {
|
||||||
|
return facetKnowledge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UsageKnowledge getResourceKnowledge() {
|
||||||
|
return resourceKnowledge;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAllowMultipleInheritance(boolean allowMultipleInheritance) {
|
public void setAllowMultipleInheritance(boolean allowMultipleInheritance) {
|
||||||
|
@ -33,10 +45,8 @@ public class Tree {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ResourceType rt = (ResourceType) type;
|
ResourceType rt = (ResourceType) type;
|
||||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
facetKnowledge.addAll(rt.getFacets());
|
||||||
fk.addAll(rt.getFacets());
|
resourceKnowledge.addAll(rt.getResources());
|
||||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
|
||||||
rk.addAll(rt.getResources());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNode(Type type) {
|
public void addNode(Type type) {
|
||||||
|
|
|
@ -13,27 +13,9 @@ import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
*/
|
*/
|
||||||
public class UsageKnowledge {
|
public class UsageKnowledge {
|
||||||
|
|
||||||
private static UsageKnowledge facetKnowledge;
|
|
||||||
private static UsageKnowledge resourceKnowledge;
|
|
||||||
|
|
||||||
public static UsageKnowledge getFacetKnowledge() {
|
|
||||||
if(UsageKnowledge.facetKnowledge==null) {
|
|
||||||
UsageKnowledge.facetKnowledge = new UsageKnowledge();
|
|
||||||
}
|
|
||||||
return UsageKnowledge.facetKnowledge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UsageKnowledge getResourceKnowledge() {
|
|
||||||
if(UsageKnowledge.resourceKnowledge==null) {
|
|
||||||
UsageKnowledge.resourceKnowledge = new UsageKnowledge();
|
|
||||||
}
|
|
||||||
return UsageKnowledge.resourceKnowledge;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected Map<String, Set<LinkedEntity>> map;
|
protected Map<String, Set<LinkedEntity>> map;
|
||||||
|
|
||||||
private UsageKnowledge(){
|
public UsageKnowledge(){
|
||||||
this.map = new LinkedHashMap<>();
|
this.map = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||||
|
import org.gcube.informationsystem.utils.documentation.knowledge.UsageKnowledge;
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.Section;
|
import org.gcube.informationsystem.utils.documentation.rst.Section;
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.Section.SectionType;
|
import org.gcube.informationsystem.utils.documentation.rst.Section.SectionType;
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
|
||||||
|
@ -47,6 +48,9 @@ public abstract class DocumentationGenerator {
|
||||||
protected int offsetLevel;
|
protected int offsetLevel;
|
||||||
protected int level;
|
protected int level;
|
||||||
|
|
||||||
|
protected UsageKnowledge facetKnowledge;
|
||||||
|
protected UsageKnowledge resourceKnowledge;
|
||||||
|
|
||||||
protected DocumentationGenerator(Type type, AccessType requiredType) {
|
protected DocumentationGenerator(Type type, AccessType requiredType) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.requiredType = requiredType;
|
this.requiredType = requiredType;
|
||||||
|
@ -57,6 +61,8 @@ public abstract class DocumentationGenerator {
|
||||||
this.requiredNumberOfColumns = DEFAULT_NUMBER_OF_COLUMNS;
|
this.requiredNumberOfColumns = DEFAULT_NUMBER_OF_COLUMNS;
|
||||||
this.superClassToBeExcluded = null;
|
this.superClassToBeExcluded = null;
|
||||||
this.offsetLevel = DocumentationGenerator.defaultOffsetLevel;
|
this.offsetLevel = DocumentationGenerator.defaultOffsetLevel;
|
||||||
|
this.facetKnowledge = new UsageKnowledge();
|
||||||
|
this.resourceKnowledge = new UsageKnowledge();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(int level) {
|
public void setLevel(int level) {
|
||||||
|
@ -66,6 +72,15 @@ public abstract class DocumentationGenerator {
|
||||||
public void setOffsetLevel(int offsetLevel) {
|
public void setOffsetLevel(int offsetLevel) {
|
||||||
this.offsetLevel = offsetLevel;
|
this.offsetLevel = offsetLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFacetKnowledge(UsageKnowledge facetKnowledge) {
|
||||||
|
this.facetKnowledge = facetKnowledge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceKnowledge(UsageKnowledge resourceKnowledge) {
|
||||||
|
this.resourceKnowledge = resourceKnowledge;
|
||||||
|
}
|
||||||
|
|
||||||
protected Row getPropertyFieldsBoldRow() {
|
protected Row getPropertyFieldsBoldRow() {
|
||||||
Row row = new Row(RowType.NORMAL);
|
Row row = new Row(RowType.NORMAL);
|
||||||
Cell name = new Cell();
|
Cell name = new Cell();
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||||
import org.gcube.informationsystem.utils.documentation.knowledge.UsageKnowledge;
|
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +32,7 @@ public class FacetDocumentationGenerator extends EntityDocumentationGenerator {
|
||||||
table.appendRow(getKnownUsageBoldRow());
|
table.appendRow(getKnownUsageBoldRow());
|
||||||
table.appendRow(getSourceTargetBoldRow());
|
table.appendRow(getSourceTargetBoldRow());
|
||||||
|
|
||||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
Set<LinkedEntity> usage = facetKnowledge.getUsage(type.getName());
|
||||||
Set<LinkedEntity> usage = fk.getUsage(type.getName());
|
|
||||||
addLinkedEntities(table, usage, NO_SPECIFIC_KNOWN_USAGE);
|
addLinkedEntities(table, usage, NO_SPECIFIC_KNOWN_USAGE);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
import org.gcube.informationsystem.utils.documentation.knowledge.UsageKnowledge;
|
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,12 +33,10 @@ public class ResourceDocumentationGenerator extends EntityDocumentationGenerator
|
||||||
table.appendRow(getSourceTargetHeadingRow());
|
table.appendRow(getSourceTargetHeadingRow());
|
||||||
table.appendRow(getRowCellSpan(FACETS_TABLE_HEADING, requiredNumberOfColumns));
|
table.appendRow(getRowCellSpan(FACETS_TABLE_HEADING, requiredNumberOfColumns));
|
||||||
ResourceType resourceType = (ResourceType) type;
|
ResourceType resourceType = (ResourceType) type;
|
||||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
Set<LinkedEntity> facets = facetKnowledge.getUsage(resourceType.getName());
|
||||||
Set<LinkedEntity> facets = fk.getUsage(resourceType.getName());
|
|
||||||
addLinkedEntities(table, facets, NO_SPECIFIC_FACETS);
|
addLinkedEntities(table, facets, NO_SPECIFIC_FACETS);
|
||||||
table.appendRow(getRowCellSpan(RESOURCE_RELATIONS_TABLE_HEADING, requiredNumberOfColumns));
|
table.appendRow(getRowCellSpan(RESOURCE_RELATIONS_TABLE_HEADING, requiredNumberOfColumns));
|
||||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
Set<LinkedEntity> resources = resourceKnowledge.getUsage(resourceType.getName());
|
||||||
Set<LinkedEntity> resources = rk.getUsage(resourceType.getName());
|
|
||||||
addLinkedEntities(table, resources, NO_SPECIFIC_RESOURCE_RELATIONS);
|
addLinkedEntities(table, resources, NO_SPECIFIC_RESOURCE_RELATIONS);
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Set;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
import org.gcube.informationsystem.utils.documentation.knowledge.UsageKnowledge;
|
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,8 +27,7 @@ public class ConsistsOfDocumentationGenerator extends RelationDocumentationGener
|
||||||
|
|
||||||
table.appendRow(getKnownUsageBoldRow());
|
table.appendRow(getKnownUsageBoldRow());
|
||||||
table.appendRow(getSourceTargetBoldRow());
|
table.appendRow(getSourceTargetBoldRow());
|
||||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
Set<LinkedEntity> facets = facetKnowledge.getUsage(type.getName());
|
||||||
Set<LinkedEntity> facets = fk.getUsage(type.getName());
|
|
||||||
addLinkedEntities(table, facets, NO_SPECIFIC_KNOWN_USAGE);
|
addLinkedEntities(table, facets, NO_SPECIFIC_KNOWN_USAGE);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Set;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
import org.gcube.informationsystem.utils.documentation.knowledge.UsageKnowledge;
|
|
||||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,8 +27,7 @@ public class IsRelatedToDocumentationGenerator extends RelationDocumentationGene
|
||||||
|
|
||||||
table.appendRow(getKnownUsageBoldRow());
|
table.appendRow(getKnownUsageBoldRow());
|
||||||
table.appendRow(getSourceTargetBoldRow());
|
table.appendRow(getSourceTargetBoldRow());
|
||||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
Set<LinkedEntity> resources = resourceKnowledge.getUsage(type.getName());
|
||||||
Set<LinkedEntity> resources = rk.getUsage(type.getName());
|
|
||||||
addLinkedEntities(table, resources, NO_SPECIFIC_KNOWN_USAGE);
|
addLinkedEntities(table, resources, NO_SPECIFIC_KNOWN_USAGE);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
|
|
Loading…
Reference in New Issue