Reorganized discovery and usage knowledge
This commit is contained in:
parent
7a68609de3
commit
d7d609bbf8
|
@ -8,6 +8,8 @@ import java.util.Collection;
|
|||
* returning the list of packages containing the interfaces
|
||||
* representing the model.
|
||||
*
|
||||
* Any registration provider MUST have a constructor with no arguments
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface RegistrationProvider {
|
||||
|
|
|
@ -3,9 +3,13 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.discovery.knowledge;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -21,6 +25,19 @@ public class AddElementToTreeAction implements DiscoveredElementAction<Element>
|
|||
@Override
|
||||
public void analizeElement(Class<Element> e) throws Exception {
|
||||
tree.addNode(e);
|
||||
Type type = TypeMapper.createTypeDefinition(e);
|
||||
createUsageKnowledge(type);
|
||||
}
|
||||
|
||||
protected void createUsageKnowledge(Type type) {
|
||||
if (type.getAccessType() != AccessType.RESOURCE) {
|
||||
return;
|
||||
}
|
||||
ResourceType rt = (ResourceType) type;
|
||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
fk.addAll(rt.getFacets());
|
||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
||||
rk.addAll(rt.getResources());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,31 +12,46 @@ import org.gcube.informationsystem.discovery.Discovery;
|
|||
import org.gcube.informationsystem.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.serialization.ElementMappingAction;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.knowledge.AddTypeToTreeAction;
|
||||
import org.gcube.informationsystem.types.knowledge.TypeInformation;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ModelKnowledge {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ModelKnowledge.class);
|
||||
|
||||
protected boolean created;
|
||||
|
||||
public static ModelKnowledge getInstance() {
|
||||
return new ModelKnowledge();
|
||||
}
|
||||
|
||||
protected Map<AccessType, Tree<Class<Element>>> trees;
|
||||
protected Map<AccessType, Tree<Type>> typeTrees;
|
||||
protected Map<AccessType, Discovery<? extends Element>> discoveries;
|
||||
|
||||
protected ModelKnowledge() {
|
||||
this.trees = new HashMap<>();
|
||||
this.typeTrees = new HashMap<>();
|
||||
this.discoveries = new HashMap<>();
|
||||
this.created = false;
|
||||
}
|
||||
|
||||
public void createKnowledge() throws Exception {
|
||||
public synchronized void createKnowledge(boolean force) throws Exception {
|
||||
if(force) {
|
||||
this.created = false;
|
||||
logger.info("Going to force Knowledge recreation");
|
||||
}
|
||||
|
||||
createKnowledge();
|
||||
}
|
||||
|
||||
public synchronized void createKnowledge() throws Exception {
|
||||
|
||||
if(created) {
|
||||
logger.trace("Knowledge has been already created.");
|
||||
return;
|
||||
}
|
||||
|
||||
AccessType[] modelTypes = AccessType.getModelTypes();
|
||||
|
||||
|
@ -48,7 +63,6 @@ public class ModelKnowledge {
|
|||
}
|
||||
|
||||
ClassInformation classInformation = new ClassInformation();
|
||||
TypeInformation typeInformation = new TypeInformation();
|
||||
|
||||
for(AccessType accessType : modelTypes) {
|
||||
|
||||
|
@ -57,31 +71,22 @@ public class ModelKnowledge {
|
|||
trees.put(accessType, tree);
|
||||
AddElementToTreeAction aetta = new AddElementToTreeAction(tree);
|
||||
|
||||
Type type = TypeMapper.createTypeDefinition(clz);
|
||||
Tree<Type> typeTree = new Tree<>(type, typeInformation);
|
||||
typeTrees.put(accessType, typeTree);
|
||||
AddTypeToTreeAction attta = new AddTypeToTreeAction(typeTree);
|
||||
|
||||
|
||||
Discovery<? extends Element> discovery = new Discovery<>(clz);
|
||||
discoveries.put(accessType, discovery);
|
||||
discovery.addPackages(allPackages);
|
||||
discovery.addDiscoveredElementActions(new ElementMappingAction());
|
||||
discovery.addDiscoveredElementActions(aetta);
|
||||
discovery.addDiscoveredElementActions(attta);
|
||||
|
||||
discovery.discover();
|
||||
|
||||
}
|
||||
|
||||
this.created = true;
|
||||
|
||||
}
|
||||
|
||||
public Tree<Class<Element>> getClassesTree(AccessType accessType) {
|
||||
public synchronized Tree<Class<Element>> getClassesTree(AccessType accessType) {
|
||||
return trees.get(accessType);
|
||||
}
|
||||
|
||||
public Tree<Type> getTypesTree(AccessType accessType) {
|
||||
return typeTrees.get(accessType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.types.knowledge;
|
||||
package org.gcube.informationsystem.discovery.knowledge;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.types.knowledge;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class AddTypeToTreeAction implements DiscoveredElementAction<Element> {
|
||||
|
||||
protected Tree<Type> tree;
|
||||
|
||||
public AddTypeToTreeAction(Tree<Type> tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analizeElement(Class<Element> e) throws Exception {
|
||||
Type type = TypeMapper.createTypeDefinition(e);
|
||||
tree.addNode(type);
|
||||
createUsageKnowledge(type);
|
||||
}
|
||||
|
||||
|
||||
protected void createUsageKnowledge(Type type) {
|
||||
if (type.getAccessType() != AccessType.RESOURCE) {
|
||||
return;
|
||||
}
|
||||
ResourceType rt = (ResourceType) type;
|
||||
UsageKnowledge fk = UsageKnowledge.getFacetKnowledge();
|
||||
fk.addAll(rt.getFacets());
|
||||
UsageKnowledge rk = UsageKnowledge.getResourceKnowledge();
|
||||
rk.addAll(rt.getResources());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package org.gcube.informationsystem.types.knowledge;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.tree.NodeInformation;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class TypeInformation implements NodeInformation<Type> {
|
||||
|
||||
@Override
|
||||
public String getIdentifier(Type type) {
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getParentIdentifiers(Type root, Type type) {
|
||||
if(getIdentifier(type).compareTo(getIdentifier(root))==0) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return type.getSuperClasses();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue