Added model validation on request
This commit is contained in:
parent
57f38b273f
commit
6fd730edb1
|
@ -4,13 +4,20 @@ import java.util.LinkedHashMap;
|
|||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Knowledge {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(Knowledge.class);
|
||||
|
||||
private static Knowledge instance;
|
||||
|
||||
public static Knowledge getInstance() throws Exception {
|
||||
|
@ -31,6 +38,7 @@ public class Knowledge {
|
|||
|
||||
protected ModelKnowledge allKnowledge;
|
||||
protected Map<String, ModelKnowledge> modelKnowledges;
|
||||
protected Map<String, RegistrationProvider> registrationProviders;
|
||||
|
||||
private Knowledge() {
|
||||
}
|
||||
|
@ -39,23 +47,47 @@ public class Knowledge {
|
|||
return allKnowledge;
|
||||
}
|
||||
|
||||
public ModelKnowledge getModelKnowledges(RegistrationProvider rp) {
|
||||
public ModelKnowledge getModelKnowledge(RegistrationProvider rp) {
|
||||
return modelKnowledges.get(rp.getModelName());
|
||||
}
|
||||
|
||||
public ModelKnowledge getModelKnowledges(String modelName) {
|
||||
public ModelKnowledge getModelKnowledge(String modelName) {
|
||||
return modelKnowledges.get(modelName);
|
||||
}
|
||||
|
||||
public void validateModelKnowledge(RegistrationProvider rp) throws Exception {
|
||||
ModelKnowledge modelKnowledge = getModelKnowledge(rp);
|
||||
|
||||
logger.trace("Going to analise discovered types for model '{}'", rp.getModelName());
|
||||
ModelKnowledgeValidator ra = new ModelKnowledgeValidator(rp);
|
||||
modelKnowledge.addDiscoveredElementActions(ra);
|
||||
|
||||
AccessType[] accessTypes = AccessType.getModelTypes();
|
||||
for(AccessType accessType : accessTypes) {
|
||||
logger.trace("Going to analise tree of '{}' type for model '{}'", accessType.getName(), rp.getModelName());
|
||||
Tree<Class<Element>> tree = modelKnowledge.getClassesTree(accessType);
|
||||
tree.elaborate(ra);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateModelKnowledge(String modelName) throws Exception {
|
||||
RegistrationProvider rp = registrationProviders.get(modelName);
|
||||
validateModelKnowledge(rp);
|
||||
}
|
||||
|
||||
public void discover() throws Exception {
|
||||
|
||||
allKnowledge = new ModelKnowledge();
|
||||
modelKnowledges = new LinkedHashMap<>();
|
||||
registrationProviders = new LinkedHashMap<>();
|
||||
|
||||
ServiceLoader<? extends RegistrationProvider> registrationProviders = ServiceLoader
|
||||
ServiceLoader<? extends RegistrationProvider> providers = ServiceLoader
|
||||
.load(RegistrationProvider.class);
|
||||
|
||||
for(RegistrationProvider rp : registrationProviders) {
|
||||
for(RegistrationProvider rp : providers) {
|
||||
|
||||
registrationProviders.put(rp.getModelName(), rp);
|
||||
|
||||
ModelKnowledge modelKnowledge = new ModelKnowledge();
|
||||
modelKnowledges.put(rp.getModelName(), modelKnowledge);
|
||||
modelKnowledge.addRegistrationProvider(rp);
|
||||
|
|
Loading…
Reference in New Issue