diff --git a/src/main/java/org/gcube/informationsystem/discovery/ISModelRegistrationProvider.java b/src/main/java/org/gcube/informationsystem/discovery/ISModelRegistrationProvider.java index 7a1050d..c2d6400 100644 --- a/src/main/java/org/gcube/informationsystem/discovery/ISModelRegistrationProvider.java +++ b/src/main/java/org/gcube/informationsystem/discovery/ISModelRegistrationProvider.java @@ -15,7 +15,7 @@ public class ISModelRegistrationProvider implements RegistrationProvider { static { packages = new HashSet<>(); - for(AccessType accessType : RegistrationProvider.getAccessTypes()) { + for(AccessType accessType : AccessType.getModelTypes()) { Class clz = accessType.getTypeClass(); packages.add(clz.getPackage()); } diff --git a/src/main/java/org/gcube/informationsystem/discovery/RegistrationProvider.java b/src/main/java/org/gcube/informationsystem/discovery/RegistrationProvider.java index 15fa77b..41cb96d 100644 --- a/src/main/java/org/gcube/informationsystem/discovery/RegistrationProvider.java +++ b/src/main/java/org/gcube/informationsystem/discovery/RegistrationProvider.java @@ -1,10 +1,6 @@ package org.gcube.informationsystem.discovery; import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Set; - -import org.gcube.informationsystem.base.reference.AccessType; /** * Any model requires to register the defined types. @@ -28,14 +24,4 @@ public interface RegistrationProvider { */ public Collection getPackagesToRegister(); - - public static Set getAccessTypes() { - Set accessTypes = new LinkedHashSet<>(); - accessTypes.add(AccessType.PROPERTY); - accessTypes.add(AccessType.RESOURCE); - accessTypes.add(AccessType.FACET); - accessTypes.add(AccessType.IS_RELATED_TO); - accessTypes.add(AccessType.CONSISTS_OF); - return accessTypes; - } } diff --git a/src/main/java/org/gcube/informationsystem/discovery/knowledge/ModelKnowledge.java b/src/main/java/org/gcube/informationsystem/discovery/knowledge/ModelKnowledge.java index 88696a2..fe63c35 100644 --- a/src/main/java/org/gcube/informationsystem/discovery/knowledge/ModelKnowledge.java +++ b/src/main/java/org/gcube/informationsystem/discovery/knowledge/ModelKnowledge.java @@ -1,7 +1,9 @@ package org.gcube.informationsystem.discovery.knowledge; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.ServiceLoader; import java.util.Set; import org.gcube.informationsystem.base.reference.AccessType; @@ -17,20 +19,25 @@ import org.gcube.informationsystem.tree.Tree; */ public class ModelKnowledge { - protected RegistrationProvider registrationProvider; - protected Map>> trees; + protected Map> discoveries; - public ModelKnowledge(RegistrationProvider registrationProvider) { - this.registrationProvider = registrationProvider; + public ModelKnowledge() { this.trees = new HashMap<>(); this.discoveries = new HashMap<>(); } public void createKnowledge() throws Exception { - Set modelTypes = RegistrationProvider.getAccessTypes(); + AccessType[] modelTypes = AccessType.getModelTypes(); + + Set allPackages = new HashSet<>(); + ServiceLoader registrationProviders = ServiceLoader + .load(RegistrationProvider.class); + for(RegistrationProvider rp : registrationProviders) { + allPackages.addAll(rp.getPackagesToRegister()); + } for(AccessType accessType : modelTypes) { Class clz = accessType.getTypeClass(); @@ -41,22 +48,18 @@ public class ModelKnowledge { Discovery discovery = new Discovery<>(clz); discoveries.put(accessType, discovery); - - discovery.addPackages(registrationProvider.getPackagesToRegister()); + discovery.addPackages(allPackages); discovery.addDiscoveredElementActions(new ElementMappingAction()); discovery.addDiscoveredElementActions(aetta); discovery.discover(); + } } - public Map>> getTrees() { - return trees; + public Tree> getTree(AccessType accessType) { + return trees.get(accessType); } - public void setTrees(Map>> trees) { - this.trees = trees; - } - }