Refactoring
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@133181 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b8ea84e731
commit
fb8fbd44c6
|
@ -3,9 +3,6 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.impl.utils.discovery.ERDiscovery;
|
||||
import org.gcube.informationsystem.model.embedded.Embedded;
|
||||
import org.gcube.informationsystem.model.entity.Entity;
|
||||
|
@ -38,18 +35,6 @@ public class DatabaseIntializator {
|
|||
|
||||
private static final String O_RESTRICTED_CLASS = "ORestricted";
|
||||
|
||||
|
||||
|
||||
private static Set<Package> packages;
|
||||
|
||||
public static void addPackage(Package p){
|
||||
packages.add(p);
|
||||
}
|
||||
|
||||
static {
|
||||
packages = new HashSet<>();
|
||||
}
|
||||
|
||||
public static boolean initGraphDB() throws Exception {
|
||||
|
||||
logger.trace("Connecting to {} as {} to create new DB", DatabaseEnvironment.URI_DB, DatabaseEnvironment.USERNAME);
|
||||
|
@ -110,6 +95,7 @@ public class DatabaseIntializator {
|
|||
ERDiscovery.addPackage(Embedded.class.getPackage());
|
||||
ERDiscovery.addPackage(Entity.class.getPackage());
|
||||
ERDiscovery.addPackage(Relation.class.getPackage());
|
||||
|
||||
ERDiscovery erDiscovery = new ERDiscovery();
|
||||
erDiscovery.discoverERTypes();
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.informationsystem.model.entity.Resource;
|
|||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.relation.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.impl.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -25,6 +26,12 @@ public class EntityRegistrationAction implements ERAction {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(EntityRegistrationAction.class);
|
||||
|
||||
protected SchemaManagement schemaManagement;
|
||||
|
||||
public EntityRegistrationAction(){
|
||||
this.schemaManagement = new SchemaManagementImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Relation<? extends Entity, ? extends Entity>> void manageRelationClass(
|
||||
Class<R> r) throws Exception {
|
||||
|
@ -32,11 +39,11 @@ public class EntityRegistrationAction implements ERAction {
|
|||
String json = TypeBinder.serializeType(r);
|
||||
logger.trace(json);
|
||||
if (ConsistsOf.class.isAssignableFrom(r)) {
|
||||
new SchemaManagementImpl().registerConsistOfSchema(json);
|
||||
schemaManagement.registerConsistOfSchema(json);
|
||||
} else if(IsRelatedTo.class.isAssignableFrom(r)){
|
||||
new SchemaManagementImpl().registerRelatedToSchema(json);
|
||||
schemaManagement.registerRelatedToSchema(json);
|
||||
} else {
|
||||
new SchemaManagementImpl().registerRelationSchema(json);
|
||||
schemaManagement.registerRelationSchema(json);
|
||||
}
|
||||
} catch(Exception ex){
|
||||
logger.error("Error creating schema for {} type {} : {}", Relation.NAME, r.getClass().getSimpleName(), ex.getMessage());
|
||||
|
@ -50,11 +57,11 @@ public class EntityRegistrationAction implements ERAction {
|
|||
String json = TypeBinder.serializeType(e);
|
||||
logger.trace(json);
|
||||
if (Facet.class.isAssignableFrom(e)) {
|
||||
new SchemaManagementImpl().registerFacetSchema(json);
|
||||
schemaManagement.registerFacetSchema(json);
|
||||
} else if(Resource.class.isAssignableFrom(e)){
|
||||
new SchemaManagementImpl().registerResourceSchema(json);
|
||||
schemaManagement.registerResourceSchema(json);
|
||||
} else {
|
||||
new SchemaManagementImpl().registerEntitySchema(json);
|
||||
schemaManagement.registerEntitySchema(json);
|
||||
}
|
||||
} catch(Exception ex){
|
||||
logger.error("Error creating schema for {} type {} : {}", Entity.NAME, e.getClass().getSimpleName(), ex.getMessage());
|
||||
|
@ -71,7 +78,7 @@ public class EntityRegistrationAction implements ERAction {
|
|||
try{
|
||||
String json = TypeBinder.serializeType(e);
|
||||
logger.trace(json);
|
||||
new SchemaManagementImpl().registerEmbeddedTypeSchema(json);
|
||||
schemaManagement.registerEmbeddedTypeSchema(json);
|
||||
} catch(Exception ex){
|
||||
logger.error("Error creating schema for {} type {} : {}", Embedded.NAME, e.getClass().getSimpleName(), ex.getMessage());
|
||||
throw ex;
|
||||
|
|
|
@ -3,14 +3,10 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.resources.impl;
|
||||
|
||||
import org.gcube.informationsystem.model.entity.facet.ContactFacet;
|
||||
import org.gcube.informationsystem.model.entity.resource.Service;
|
||||
import org.gcube.informationsystem.model.relation.isrelatedto.Runs;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseIntializator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -42,9 +38,6 @@ public class ContextManagementImplTest {
|
|||
|
||||
public ContextManagementImplTest(){
|
||||
contextManagementImpl = new ContextManagementImpl();
|
||||
DatabaseIntializator.addPackage(Service.class.getPackage());
|
||||
DatabaseIntializator.addPackage(Runs.class.getPackage());
|
||||
DatabaseIntializator.addPackage(ContactFacet.class.getPackage());
|
||||
}
|
||||
|
||||
public static final String CTX_NAME_A = "A";
|
||||
|
|
Loading…
Reference in New Issue