Improving solution
This commit is contained in:
parent
8a6f0f916f
commit
03859306e8
|
@ -0,0 +1,57 @@
|
|||
package org.gcube.informationsystem.utils.documentation.knowledge;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
||||
public class FacetKnowledge {
|
||||
|
||||
private static FacetKnowledge singleton;
|
||||
|
||||
public static FacetKnowledge getInstace() {
|
||||
if(FacetKnowledge.singleton==null) {
|
||||
FacetKnowledge.singleton = new FacetKnowledge();
|
||||
}
|
||||
return FacetKnowledge.singleton;
|
||||
}
|
||||
|
||||
protected Map<String, Set<LinkedEntity>> map;
|
||||
|
||||
private FacetKnowledge(){
|
||||
this.map = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
protected void add(String typeName, LinkedEntity linkedEntity) {
|
||||
Set<LinkedEntity> list = map.get(typeName);
|
||||
if(list==null) {
|
||||
list = new TreeSet<>();
|
||||
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(Collection<LinkedEntity> linkedEntities) {
|
||||
for(LinkedEntity le : linkedEntities) {
|
||||
add(le);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<LinkedEntity> getUsage(String typeName){
|
||||
Set<LinkedEntity> list = map.get(typeName);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +1,34 @@
|
|||
package org.gcube.informationsystem.utils.documentation.knowledge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
||||
public class Knowledge {
|
||||
public class ResourceKnowledge {
|
||||
|
||||
private static Knowledge singleton;
|
||||
private static ResourceKnowledge singleton;
|
||||
|
||||
public static Knowledge getInstace() {
|
||||
if(Knowledge.singleton==null) {
|
||||
Knowledge.singleton = new Knowledge();
|
||||
public static ResourceKnowledge getInstace() {
|
||||
if(ResourceKnowledge.singleton==null) {
|
||||
ResourceKnowledge.singleton = new ResourceKnowledge();
|
||||
}
|
||||
return Knowledge.singleton;
|
||||
return ResourceKnowledge.singleton;
|
||||
}
|
||||
|
||||
protected Map<String, List<LinkedEntity>> map;
|
||||
protected Map<String, Set<LinkedEntity>> map;
|
||||
|
||||
private Knowledge(){
|
||||
private ResourceKnowledge(){
|
||||
this.map = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
protected void add(String typeName, LinkedEntity linkedEntity) {
|
||||
List<LinkedEntity> list = map.get(typeName);
|
||||
Set<LinkedEntity> list = map.get(typeName);
|
||||
if(list==null) {
|
||||
list = new ArrayList<>();
|
||||
list = new TreeSet<>();
|
||||
map.put(typeName, list);
|
||||
}
|
||||
list.add(linkedEntity);
|
||||
|
@ -48,8 +49,8 @@ public class Knowledge {
|
|||
}
|
||||
}
|
||||
|
||||
public List<LinkedEntity> getUsage(String typeName){
|
||||
List<LinkedEntity> list = map.get(typeName);
|
||||
public Set<LinkedEntity> getUsage(String typeName){
|
||||
Set<LinkedEntity> list = map.get(typeName);
|
||||
return list;
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.informationsystem.utils.documentation.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -153,40 +154,45 @@ public abstract class DocumentationGenerator {
|
|||
return row;
|
||||
}
|
||||
|
||||
protected Table addLinkedEntities(Table table, List<LinkedEntity> entities) {
|
||||
if(entities!=null) {
|
||||
for(LinkedEntity entity : entities) {
|
||||
protected Row getLinkedEntityrow(LinkedEntity linkedEntity) {
|
||||
Row row = new Row(RowType.NORMAL);
|
||||
Cell source = new Cell();
|
||||
source.setText(entity.getSource());
|
||||
source.setText(linkedEntity.getSource());
|
||||
row.appendCell(source);
|
||||
|
||||
Cell relation = new Cell();
|
||||
relation.setText(entity.getRelation());
|
||||
relation.setText(linkedEntity.getRelation());
|
||||
row.appendCell(relation);
|
||||
|
||||
Cell multiplicity = new Cell();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Integer min = entity.getMin();
|
||||
Integer min = linkedEntity.getMin();
|
||||
buffer.append(min==null? "0" : min.toString());
|
||||
buffer.append("..");
|
||||
Integer max = entity.getMax();
|
||||
Integer max = linkedEntity.getMax();
|
||||
buffer.append(max==null? "n" : max.toString());
|
||||
multiplicity.setText(buffer.toString());
|
||||
row.appendCell(multiplicity);
|
||||
|
||||
Cell target = new Cell();
|
||||
target.setText(entity.getTarget());
|
||||
target.setText(linkedEntity.getTarget());
|
||||
row.appendCell(target);
|
||||
|
||||
Cell description = new Cell();
|
||||
description.setText(entity.getDescription());
|
||||
description.setText(linkedEntity.getDescription());
|
||||
row.appendCell(description);
|
||||
|
||||
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
|
||||
row.appendCell(description);
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
protected Table addLinkedEntities(Table table, Collection<LinkedEntity> entities) {
|
||||
if(entities!=null) {
|
||||
for(LinkedEntity entity : entities) {
|
||||
Row row = getLinkedEntityrow(entity);
|
||||
table.appendRow(row);
|
||||
}
|
||||
}
|
||||
|
@ -267,6 +273,29 @@ public abstract class DocumentationGenerator {
|
|||
return addCellSpanToRow(row, content, cellSpan);
|
||||
}
|
||||
|
||||
protected Table addPropertyRows(Table table, Set<PropertyDefinition> properties) {
|
||||
table.appendRow(getPropertyFieldsBoldRow());
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* E.g. GCubeProperty extends Property
|
||||
*/
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
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.knowledge.FacetKnowledge;
|
||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||
|
||||
/**
|
||||
|
@ -24,32 +22,14 @@ public class FacetDocumentationGenerator extends EntityDocumentationGenerator {
|
|||
protected Table getTable() {
|
||||
Table table = new Table();
|
||||
table.appendRow(getEntityHeadingRow());
|
||||
table.appendRow(getPropertyFieldsBoldRow());
|
||||
Set<PropertyDefinition> properties = type.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());
|
||||
}
|
||||
table = addPropertyRows(table, properties);
|
||||
|
||||
table.appendRow(getKnownUsageBoldRow());
|
||||
table.appendRow(getSourceTargetBoldRow());
|
||||
|
||||
Knowledge k = Knowledge.getInstace();
|
||||
List<LinkedEntity> usage = k.getUsage(type.getName());
|
||||
FacetKnowledge fk = FacetKnowledge.getInstace();
|
||||
Set<LinkedEntity> usage = fk.getUsage(type.getName());
|
||||
addLinkedEntities(table, usage);
|
||||
|
||||
return table;
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package org.gcube.informationsystem.utils.documentation.model.entities;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.utils.documentation.knowledge.Knowledge;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.utils.documentation.knowledge.FacetKnowledge;
|
||||
import org.gcube.informationsystem.utils.documentation.knowledge.ResourceKnowledge;
|
||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||
|
||||
/**
|
||||
|
@ -14,9 +18,10 @@ public class ResourceDocumentationGenerator extends EntityDocumentationGenerator
|
|||
public ResourceDocumentationGenerator(Type type) {
|
||||
super(type,AccessType.RESOURCE);
|
||||
ResourceType rt = (ResourceType) type;
|
||||
Knowledge k = Knowledge.getInstace();
|
||||
k.addAll(rt.getFacets());
|
||||
k.addAll(rt.getResources());
|
||||
FacetKnowledge fk = FacetKnowledge.getInstace();
|
||||
fk.addAll(rt.getFacets());
|
||||
ResourceKnowledge rk = ResourceKnowledge.getInstace();
|
||||
rk.addAll(rt.getResources());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,9 +30,13 @@ public class ResourceDocumentationGenerator extends EntityDocumentationGenerator
|
|||
table.appendRow(getSourceTargetHeadingRow());
|
||||
table.appendRow(getRowCellSpan("**Facets**", requiredNumberOfColumns));
|
||||
ResourceType resourceType = (ResourceType) type;
|
||||
addLinkedEntities(table, resourceType.getFacets());
|
||||
FacetKnowledge fk = FacetKnowledge.getInstace();
|
||||
Set<LinkedEntity> facets = fk.getUsage(resourceType.getName());
|
||||
addLinkedEntities(table, facets);
|
||||
table.appendRow(getRowCellSpan("**Relations**", requiredNumberOfColumns));
|
||||
addLinkedEntities(table, resourceType.getResources());
|
||||
ResourceKnowledge rk = ResourceKnowledge.getInstace();
|
||||
Set<LinkedEntity> resources = rk.getUsage(resourceType.getName());
|
||||
addLinkedEntities(table, resources);
|
||||
return table;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.gcube.informationsystem.utils.documentation.model.relations;
|
||||
|
||||
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.utils.documentation.knowledge.FacetKnowledge;
|
||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||
|
||||
/**
|
||||
|
@ -15,8 +19,13 @@ public class ConsistsOfDocumentationGenerator extends RelationDocumentationGener
|
|||
|
||||
@Override
|
||||
protected Table getTable() {
|
||||
Table table = new Table();
|
||||
table.appendRow(getPropertyFieldsHeadingRow());
|
||||
Table table = super.getTable();
|
||||
|
||||
table.appendRow(getKnownUsageBoldRow());
|
||||
FacetKnowledge fk = FacetKnowledge.getInstace();
|
||||
Set<LinkedEntity> facets = fk.getUsage(type.getName());
|
||||
addLinkedEntities(table, facets);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.gcube.informationsystem.utils.documentation.model.relations;
|
||||
|
||||
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.utils.documentation.knowledge.ResourceKnowledge;
|
||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||
|
||||
/**
|
||||
|
@ -15,8 +19,13 @@ public class IsRelatedToDocumentationGenerator extends RelationDocumentationGene
|
|||
|
||||
@Override
|
||||
protected Table getTable() {
|
||||
Table table = new Table();
|
||||
table.appendRow(getPropertyFieldsHeadingRow());
|
||||
Table table = super.getTable();
|
||||
|
||||
table.appendRow(getKnownUsageBoldRow());
|
||||
ResourceKnowledge rk = ResourceKnowledge.getInstace();
|
||||
Set<LinkedEntity> resources = rk.getUsage(type.getName());
|
||||
addLinkedEntities(table, resources);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
package org.gcube.informationsystem.utils.documentation.model.relations;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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.types.reference.entities.EntityType;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationType;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -24,10 +32,47 @@ public class RelationDocumentationGenerator extends DocumentationGenerator {
|
|||
super(type, requiredType, superClassToBeExcluded);
|
||||
}
|
||||
|
||||
protected Row getTypeDefinitionRow(RelationType<? extends EntityType, ? extends EntityType> relationType) {
|
||||
Row row = new Row(RowType.NORMAL);
|
||||
Cell source = new Cell();
|
||||
source.setText(relationType.getSource().getName());
|
||||
row.appendCell(source);
|
||||
|
||||
Cell relation = new Cell();
|
||||
relation.setText(relationType.getName());
|
||||
row.appendCell(relation);
|
||||
|
||||
Cell multiplicity = new Cell();
|
||||
multiplicity.setText("0..n");
|
||||
row.appendCell(multiplicity);
|
||||
|
||||
Cell target = new Cell();
|
||||
target.setText(relationType.getTarget().getName());
|
||||
row.appendCell(target);
|
||||
|
||||
Cell description = new Cell();
|
||||
description.setText(relationType.getDescription());
|
||||
row.appendCell(description);
|
||||
|
||||
for(int i=row.getCells().size(); i<requiredNumberOfColumns; i++) {
|
||||
row.appendCell(description);
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Table getTable() {
|
||||
Table table = new Table();
|
||||
table.appendRow(getPropertyFieldsHeadingRow());
|
||||
table.appendRow(getSourceTargetHeadingRow());
|
||||
|
||||
table.appendRow(getRowCellSpan("**Definition**", requiredNumberOfColumns));
|
||||
@SuppressWarnings("unchecked")
|
||||
RelationType<? extends EntityType, ? extends EntityType> relationType = (RelationType<? extends EntityType, ? extends EntityType>) type;
|
||||
table.appendRow(getTypeDefinitionRow(relationType));
|
||||
|
||||
Set<PropertyDefinition> properties = type.getProperties();
|
||||
table = addPropertyRows(table, properties);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue