Reorganized code
This commit is contained in:
parent
195a3af39b
commit
e43bb24b2d
|
@ -6,6 +6,8 @@ import java.nio.file.Files;
|
|||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.discovery.knowledge.ModelKnowledge;
|
||||
import org.gcube.informationsystem.discovery.knowledge.UsageKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
|
||||
import org.gcube.informationsystem.utils.documentation.model.entities.EntityDocumentationGenerator;
|
||||
|
@ -25,8 +27,10 @@ public class Generator {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Generator.class);
|
||||
|
||||
protected ModelKnowledge modelKnowledge;
|
||||
|
||||
public Generator() {
|
||||
|
||||
this.modelKnowledge = new ModelKnowledge();
|
||||
}
|
||||
|
||||
public Class<? extends DocumentationGenerator> getDocumentationGeneratorClass(AccessType accessType)
|
||||
|
@ -108,6 +112,10 @@ public class Generator {
|
|||
default:
|
||||
throw new Exception("I'm not developed to manage the " + AccessType.class.getSimpleName() + " " + type.getName());
|
||||
}
|
||||
UsageKnowledge facetKnowledge = modelKnowledge.getUsageKnowledge(AccessType.FACET);
|
||||
dg.setFacetKnowledge(facetKnowledge);
|
||||
UsageKnowledge resourceKnowledge = modelKnowledge.getUsageKnowledge(AccessType.RESOURCE);
|
||||
dg.setResourceKnowledge(resourceKnowledge);
|
||||
return dg;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,11 @@ package org.gcube.informationsystem.utils.documentation.generator;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.ISModelRegistrationProvider;
|
||||
import org.gcube.informationsystem.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.discovery.knowledge.ModelKnowledge;
|
||||
import org.gcube.informationsystem.tree.Node;
|
||||
import org.gcube.informationsystem.tree.NodeElaborator;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
|
@ -29,7 +27,11 @@ public class TreeGenerator extends Generator {
|
|||
public static final String ENTITIES_FILENAME = "entities.rst";
|
||||
public static final String RELATIONS_FILENAME = "relations.rst";
|
||||
|
||||
public TreeGenerator() {
|
||||
protected RegistrationProvider rp;
|
||||
|
||||
public TreeGenerator(RegistrationProvider rp) {
|
||||
super();
|
||||
this.rp = rp;
|
||||
}
|
||||
|
||||
public void elaborateTree(final AccessType at, Tree<Class<Element>> tree, File file, RegistrationProvider rp) throws Exception {
|
||||
|
@ -66,7 +68,6 @@ public class TreeGenerator extends Generator {
|
|||
|
||||
public void generate() throws Exception {
|
||||
|
||||
ModelKnowledge modelKnowledge = ModelKnowledge.getInstance();
|
||||
modelKnowledge.createKnowledge();
|
||||
|
||||
File is = getFile(IS_MODEL_FILENAME, true);
|
||||
|
@ -101,12 +102,8 @@ public class TreeGenerator extends Generator {
|
|||
|
||||
Tree<Class<Element>> tree = modelKnowledge.getClassesTree(at);
|
||||
|
||||
ServiceLoader<? extends RegistrationProvider> registrationProviders = ServiceLoader
|
||||
.load(RegistrationProvider.class);
|
||||
for(RegistrationProvider rp : registrationProviders) {
|
||||
if(!(rp instanceof ISModelRegistrationProvider)) {
|
||||
elaborateTree(at, tree, file, rp);
|
||||
}
|
||||
if(!(rp instanceof ISModelRegistrationProvider)) {
|
||||
elaborateTree(at, tree, file, rp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.discovery.knowledge.UsageKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
|
@ -47,6 +48,25 @@ public abstract class DocumentationGenerator {
|
|||
protected int offsetLevel;
|
||||
protected int level;
|
||||
|
||||
protected UsageKnowledge facetKnowledge;
|
||||
protected UsageKnowledge resourceKnowledge;
|
||||
|
||||
public UsageKnowledge getFacetKnowledge() {
|
||||
return facetKnowledge;
|
||||
}
|
||||
|
||||
public void setFacetKnowledge(UsageKnowledge facetKnowledge) {
|
||||
this.facetKnowledge = facetKnowledge;
|
||||
}
|
||||
|
||||
public UsageKnowledge getResourceKnowledge() {
|
||||
return resourceKnowledge;
|
||||
}
|
||||
|
||||
public void setResourceKnowledge(UsageKnowledge resourceKnowledge) {
|
||||
this.resourceKnowledge = resourceKnowledge;
|
||||
}
|
||||
|
||||
protected DocumentationGenerator(Type type, AccessType requiredType) {
|
||||
this.type = type;
|
||||
this.requiredType = requiredType;
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.informationsystem.utils.documentation.model.entities;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.discovery.knowledge.UsageKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
|
@ -33,8 +32,7 @@ public class FacetDocumentationGenerator extends EntityDocumentationGenerator {
|
|||
table.appendRow(getKnownUsageBoldRow());
|
||||
table.appendRow(getSourceTargetBoldRow());
|
||||
|
||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
Set<LinkedEntity> usage = fk.getUsage(type.getName());
|
||||
Set<LinkedEntity> usage = facetKnowledge.getUsage(type.getName());
|
||||
addLinkedEntities(table, usage, NO_SPECIFIC_KNOWN_USAGE);
|
||||
|
||||
return table;
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.informationsystem.utils.documentation.model.entities;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.discovery.knowledge.UsageKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
@ -34,12 +33,12 @@ public class ResourceDocumentationGenerator extends EntityDocumentationGenerator
|
|||
table.appendRow(getSourceTargetHeadingRow());
|
||||
table.appendRow(getRowCellSpan(FACETS_TABLE_HEADING, requiredNumberOfColumns));
|
||||
ResourceType resourceType = (ResourceType) type;
|
||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
Set<LinkedEntity> facets = fk.getUsage(resourceType.getName());
|
||||
|
||||
Set<LinkedEntity> facets = facetKnowledge.getUsage(resourceType.getName());
|
||||
addLinkedEntities(table, facets, NO_SPECIFIC_FACETS);
|
||||
table.appendRow(getRowCellSpan(RESOURCE_RELATIONS_TABLE_HEADING, requiredNumberOfColumns));
|
||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
||||
Set<LinkedEntity> resources = rk.getUsage(resourceType.getName());
|
||||
|
||||
Set<LinkedEntity> resources = resourceKnowledge.getUsage(resourceType.getName());
|
||||
addLinkedEntities(table, resources, NO_SPECIFIC_RESOURCE_RELATIONS);
|
||||
return table;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.informationsystem.utils.documentation.model.relations;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.discovery.knowledge.UsageKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||
|
@ -28,8 +27,8 @@ public class ConsistsOfDocumentationGenerator extends RelationDocumentationGener
|
|||
|
||||
table.appendRow(getKnownUsageBoldRow());
|
||||
table.appendRow(getSourceTargetBoldRow());
|
||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
Set<LinkedEntity> facets = fk.getUsage(type.getName());
|
||||
|
||||
Set<LinkedEntity> facets = facetKnowledge.getUsage(type.getName());
|
||||
addLinkedEntities(table, facets, NO_SPECIFIC_KNOWN_USAGE);
|
||||
|
||||
return table;
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.gcube.informationsystem.utils.documentation.model.relations;
|
|||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.discovery.knowledge.UsageKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
|
||||
|
@ -28,8 +27,7 @@ public class IsRelatedToDocumentationGenerator extends RelationDocumentationGene
|
|||
|
||||
table.appendRow(getKnownUsageBoldRow());
|
||||
table.appendRow(getSourceTargetBoldRow());
|
||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
||||
Set<LinkedEntity> resources = rk.getUsage(type.getName());
|
||||
Set<LinkedEntity> resources = resourceKnowledge.getUsage(type.getName());
|
||||
addLinkedEntities(table, resources, NO_SPECIFIC_KNOWN_USAGE);
|
||||
|
||||
return table;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.gcube.informationsystem.utils.documentation;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.gcube.informationsystem.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.utils.documentation.generator.TreeGenerator;
|
||||
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
|
||||
import org.junit.Test;
|
||||
|
@ -12,8 +15,12 @@ public class GenerateTest {
|
|||
@Test
|
||||
public void testDocGeneration() throws Exception {
|
||||
DocumentationGenerator.setDefaultOffsetLevel(2);
|
||||
TreeGenerator treeGenerator = new TreeGenerator();
|
||||
treeGenerator.generate();
|
||||
ServiceLoader<? extends RegistrationProvider> registrationProviders = ServiceLoader
|
||||
.load(RegistrationProvider.class);
|
||||
for(RegistrationProvider rp : registrationProviders) {
|
||||
TreeGenerator treeGenerator = new TreeGenerator(rp);
|
||||
treeGenerator.generate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue