Reorganizng code

This commit is contained in:
Luca Frosini 2023-02-06 17:04:25 +01:00
parent 879cf9b81f
commit 833a69d8d5
3 changed files with 17 additions and 28 deletions

View File

@ -15,7 +15,7 @@ public class ISModelRegistrationProvider implements RegistrationProvider {
static { static {
packages = new HashSet<>(); packages = new HashSet<>();
for(AccessType accessType : RegistrationProvider.getAccessTypes()) { for(AccessType accessType : AccessType.getModelTypes()) {
Class<Element> clz = accessType.getTypeClass(); Class<Element> clz = accessType.getTypeClass();
packages.add(clz.getPackage()); packages.add(clz.getPackage());
} }

View File

@ -1,10 +1,6 @@
package org.gcube.informationsystem.discovery; package org.gcube.informationsystem.discovery;
import java.util.Collection; 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. * Any model requires to register the defined types.
@ -28,14 +24,4 @@ public interface RegistrationProvider {
*/ */
public Collection<Package> getPackagesToRegister(); public Collection<Package> getPackagesToRegister();
public static Set<AccessType> getAccessTypes() {
Set<AccessType> 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;
}
} }

View File

@ -1,7 +1,9 @@
package org.gcube.informationsystem.discovery.knowledge; package org.gcube.informationsystem.discovery.knowledge;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.AccessType;
@ -17,20 +19,25 @@ import org.gcube.informationsystem.tree.Tree;
*/ */
public class ModelKnowledge { public class ModelKnowledge {
protected RegistrationProvider registrationProvider;
protected Map<AccessType, Tree<Class<Element>>> trees; protected Map<AccessType, Tree<Class<Element>>> trees;
protected Map<AccessType, Discovery<? extends Element>> discoveries; protected Map<AccessType, Discovery<? extends Element>> discoveries;
public ModelKnowledge(RegistrationProvider registrationProvider) { public ModelKnowledge() {
this.registrationProvider = registrationProvider;
this.trees = new HashMap<>(); this.trees = new HashMap<>();
this.discoveries = new HashMap<>(); this.discoveries = new HashMap<>();
} }
public void createKnowledge() throws Exception { public void createKnowledge() throws Exception {
Set<AccessType> modelTypes = RegistrationProvider.getAccessTypes(); AccessType[] modelTypes = AccessType.getModelTypes();
Set<Package> allPackages = new HashSet<>();
ServiceLoader<? extends RegistrationProvider> registrationProviders = ServiceLoader
.load(RegistrationProvider.class);
for(RegistrationProvider rp : registrationProviders) {
allPackages.addAll(rp.getPackagesToRegister());
}
for(AccessType accessType : modelTypes) { for(AccessType accessType : modelTypes) {
Class<Element> clz = accessType.getTypeClass(); Class<Element> clz = accessType.getTypeClass();
@ -41,22 +48,18 @@ public class ModelKnowledge {
Discovery<? extends Element> discovery = new Discovery<>(clz); Discovery<? extends Element> discovery = new Discovery<>(clz);
discoveries.put(accessType, discovery); discoveries.put(accessType, discovery);
discovery.addPackages(allPackages);
discovery.addPackages(registrationProvider.getPackagesToRegister());
discovery.addDiscoveredElementActions(new ElementMappingAction()); discovery.addDiscoveredElementActions(new ElementMappingAction());
discovery.addDiscoveredElementActions(aetta); discovery.addDiscoveredElementActions(aetta);
discovery.discover(); discovery.discover();
} }
} }
public Map<AccessType, Tree<Class<Element>>> getTrees() { public Tree<Class<Element>> getTree(AccessType accessType) {
return trees; return trees.get(accessType);
} }
public void setTrees(Map<AccessType, Tree<Class<Element>>> trees) {
this.trees = trees;
}
} }