Refs #5706: Improve IS Entity/Relation scanning on IS-Model library to support multiple inheritance
Task-Url: https://support.d4science.org/issues/5706 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/resource-registry-database-creator@160631 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6bc3bbba6b
commit
2b51b7e1ea
|
@ -1,21 +1,12 @@
|
|||
package org.gcube.informationsystem.resourceregistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.informationsystem.impl.utils.discovery.SchemaAction;
|
||||
import org.gcube.informationsystem.model.ISManageable;
|
||||
import org.gcube.informationsystem.model.discovery.ISMDiscovery;
|
||||
import org.gcube.informationsystem.model.embedded.Embedded;
|
||||
import org.gcube.informationsystem.model.embedded.ValueSchema;
|
||||
import org.gcube.informationsystem.model.entity.Entity;
|
||||
import org.gcube.informationsystem.model.relation.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.SchemaActionImpl;
|
||||
import org.jgrapht.graph.DefaultEdge;
|
||||
import org.jgrapht.traverse.BreadthFirstIterator;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -24,72 +15,44 @@ public class DataBaseCreator {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ISMDiscovery.class);
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Test
|
||||
public <ISM extends ISManageable> void createDatabase() throws Exception{
|
||||
public void createDatabase() throws Exception{
|
||||
String db = DatabaseEnvironment.DB_URI;
|
||||
logger.debug("Created DB {}", db);
|
||||
|
||||
List<Class<ISM>> isManageables= new ArrayList<>();
|
||||
isManageables.add((Class<ISM>) Embedded.class);
|
||||
isManageables.add((Class<ISM>) Entity.class);
|
||||
isManageables.add((Class<ISM>) Relation.class);
|
||||
|
||||
SchemaAction schemaAction = new SchemaActionImpl();
|
||||
|
||||
for(Class<ISM> ism : isManageables){
|
||||
ISMDiscovery<ISM> ismDiscovery = new ISMDiscovery<>(ism);
|
||||
ismDiscovery.discover();
|
||||
BreadthFirstIterator<Class<ISM>, DefaultEdge> breadthFirstIterator = new BreadthFirstIterator<>(ismDiscovery.getGraph());
|
||||
|
||||
List<Class<ISM>> toRetry = new ArrayList<>();
|
||||
while(breadthFirstIterator.hasNext()){
|
||||
Class<ISM> clz = breadthFirstIterator.next();
|
||||
manageClass(schemaAction, ism, clz, toRetry);
|
||||
|
||||
List<Class<ISM>> nested = new ArrayList<>();
|
||||
for(Class<ISM> c : toRetry){
|
||||
manageClass(schemaAction, ism, c, nested);
|
||||
}
|
||||
toRetry = nested;
|
||||
|
||||
if(clz==Embedded.class){
|
||||
schemaAction.manageEmbeddedClass(ValueSchema.class);
|
||||
}
|
||||
}
|
||||
|
||||
for(Class<ISM> c : toRetry){
|
||||
manageClass(schemaAction, ism, c, null);
|
||||
}
|
||||
|
||||
}
|
||||
logger.info("Created DB {}", db);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected <ISM extends ISManageable> void manageClass(SchemaAction schemaAction, Class<ISM> ism, Class<ISM> clz, List<Class<ISM>> toRetry) throws Exception{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void createTypes() throws Exception {
|
||||
|
||||
try {
|
||||
SchemaAction schemaAction = new SchemaActionImpl();
|
||||
|
||||
if(ism==Embedded.class){
|
||||
schemaAction.manageEmbeddedClass((Class<Embedded>) clz);
|
||||
}
|
||||
|
||||
if(ism==Entity.class){
|
||||
schemaAction.manageEntityClass((Class<Entity>) clz);
|
||||
}
|
||||
|
||||
if(ism==Relation.class){
|
||||
schemaAction.manageRelationClass((Class<Relation>) clz);
|
||||
}
|
||||
} catch (SchemaNotFoundException e) {
|
||||
if(toRetry!=null){
|
||||
toRetry.add(clz);
|
||||
}
|
||||
} catch (SchemaAlreadyPresentException e) {
|
||||
logger.error("{}", e.getMessage());
|
||||
}catch (Exception e) {
|
||||
throw e;
|
||||
ISMDiscovery<Embedded> embeddedDiscovery = new ISMDiscovery<>(Embedded.class);
|
||||
embeddedDiscovery.discover();
|
||||
|
||||
for(Class<Embedded> embedded : embeddedDiscovery.getDiscovered()) {
|
||||
logger.info("Going to create : {}", embedded);
|
||||
schemaAction.manageEmbeddedClass(embedded);
|
||||
}
|
||||
|
||||
ISMDiscovery<Entity> entityDiscovery = new ISMDiscovery<>(Entity.class);
|
||||
entityDiscovery.discover();
|
||||
|
||||
for(Class<Entity> entity : entityDiscovery.getDiscovered()) {
|
||||
logger.info("Going to create : {}", entity);
|
||||
schemaAction.manageEntityClass(entity);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ISMDiscovery<Relation> relationDiscovery = new ISMDiscovery<>(Relation.class);
|
||||
relationDiscovery.discover();
|
||||
|
||||
for(@SuppressWarnings("rawtypes") Class<Relation> relation : relationDiscovery.getDiscovered()) {
|
||||
logger.info("Going to create : {}", relation);
|
||||
schemaAction.manageRelationClass(relation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue