simplified code using functionalities added in is-model
This commit is contained in:
parent
237667ab0c
commit
631b2cef57
|
@ -36,7 +36,7 @@ public class ModelKnowledgeGenerator extends DocumentationGenerator {
|
|||
public ModelKnowledgeGenerator(RegistrationProvider rp) throws Exception {
|
||||
super();
|
||||
this.rp = rp;
|
||||
this.modelKnowledge = Knowledge.getInstance().getModelKnowledges(rp);
|
||||
this.modelKnowledge = Knowledge.getInstance().getModelKnowledge(rp);
|
||||
this.splittedFiles = false;
|
||||
this.desiredFileName = rp.getModelName().toLowerCase().replaceAll(" ", FILENAME_SEPARATOR);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,9 @@ package org.gcube.informationsystem.utils.documentation;
|
|||
|
||||
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.Knowledge;
|
||||
import org.gcube.informationsystem.discovery.knowledge.ModelKnowledge;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.utils.documentation.generator.ModelKnowledgeGenerator;
|
||||
import org.gcube.informationsystem.utils.documentation.model.Documentation;
|
||||
import org.junit.Test;
|
||||
|
@ -29,22 +25,7 @@ public class GenerateTest {
|
|||
ServiceLoader<? extends RegistrationProvider> registrationProviders = ServiceLoader
|
||||
.load(RegistrationProvider.class);
|
||||
for(RegistrationProvider rp : registrationProviders) {
|
||||
logger.info("-------- Analising Discovery for model '{}'", rp.getModelName());
|
||||
|
||||
ModelKnowledge modelKnowledge = Knowledge.getInstance().getModelKnowledges(rp);
|
||||
ResultAnaliser ra = new ResultAnaliser(rp);
|
||||
modelKnowledge.addDiscoveredElementActions(ra);
|
||||
|
||||
logger.info("-------- Analising Trees for model '{}'", rp.getModelName());
|
||||
|
||||
AccessType[] accessTypes = AccessType.getModelTypes();
|
||||
for(AccessType accessType : accessTypes) {
|
||||
logger.info(" ------------- Analising Tree of '{}' for model '{}'", accessType.getName() ,rp.getModelName());
|
||||
|
||||
Tree<Class<Element>> tree = modelKnowledge.getClassesTree(accessType);
|
||||
tree.elaborate(ra);
|
||||
}
|
||||
|
||||
Knowledge.getInstance().validateModelKnowledge(rp);
|
||||
logger.info("ALL TEST PASSED FOR '{}'", rp.getModelName());
|
||||
|
||||
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.utils.documentation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
|
||||
import org.gcube.informationsystem.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.tree.Node;
|
||||
import org.gcube.informationsystem.tree.NodeElaborator;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ResultAnaliser implements DiscoveredElementAction<Element>, NodeElaborator<Class<Element>> {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(ResultAnaliser.class);
|
||||
|
||||
protected RegistrationProvider rp;
|
||||
protected Collection<Package> packages;
|
||||
protected List<Class<Element>> baseTypes;
|
||||
|
||||
public ResultAnaliser(RegistrationProvider rp) {
|
||||
this.rp = rp;
|
||||
this.packages = rp.getPackagesToRegister();
|
||||
this.baseTypes = new ArrayList<>();
|
||||
AccessType[] accessTypes = AccessType.getModelTypes();
|
||||
for(AccessType accessType : accessTypes) {
|
||||
this.baseTypes.add(accessType.getTypeClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analizeElement(Class<Element> e) throws Exception {
|
||||
String typeName = TypeMapper.getType(e);
|
||||
if(baseTypes.contains(e)) {
|
||||
logger.info("- Type {} is the root type", typeName);
|
||||
return;
|
||||
}
|
||||
|
||||
if(packages.contains(e.getPackage())) {
|
||||
logger.info(" - Type {} belongs to {} as expected", typeName, rp.getModelName());
|
||||
}else {
|
||||
logger.error(" - Type {} DOES NOT belong to {} as expected. This is very strange and should not occurr.", typeName, rp.getModelName());
|
||||
throw new Exception("Type " + typeName + " DOES NOT belong to " + rp.getModelName() +" as expected. This is very strange and should not occurr.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elaborate(Node<Class<Element>> node, int level) throws Exception {
|
||||
Class<Element> e = node.getNodeElement();
|
||||
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < level; ++i) {
|
||||
stringBuffer.append(Node.INDENTATION);
|
||||
}
|
||||
|
||||
String typeName = TypeMapper.getType(e);
|
||||
if(node.getTree().getRoot().getNodeElement() == e) {
|
||||
logger.info("{}- Type {} is the root type", stringBuffer.toString(), typeName);
|
||||
return;
|
||||
}
|
||||
|
||||
if(packages.contains(e.getPackage())) {
|
||||
logger.info("{}- Type {} belongs to {} as expected", stringBuffer.toString(), typeName, rp.getModelName());
|
||||
}else {
|
||||
logger.error("{}- Type {} DOES NOT belong to {} as expected. This is very strange and should not occurr.", stringBuffer.toString(), typeName, rp.getModelName());
|
||||
throw new Exception("Type " + typeName + " DOES NOT belong to " + rp.getModelName() +" as expected. This is very strange and should not occurr.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue