Renamed Class

This commit is contained in:
Luca Frosini 2021-10-22 10:24:16 +02:00
parent b9d1a43520
commit d2324da565
6 changed files with 71 additions and 73 deletions

View File

@ -6,7 +6,7 @@ import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement; import org.gcube.informationsystem.resourceregistry.types.TypeManagement;
import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.utils.discovery.SchemaAction; import org.gcube.informationsystem.utils.discovery.SchemaAction;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -23,9 +23,9 @@ public class SchemaActionImpl implements SchemaAction {
public <R extends RelationElement<? extends EntityElement,? extends EntityElement>> void manageRelationClass(Class<R> r) public <R extends RelationElement<? extends EntityElement,? extends EntityElement>> void manageRelationClass(Class<R> r)
throws Exception { throws Exception {
try { try {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeAndTypeName(r); typeManagement.setTypeAndTypeName(r);
schemaManagement.create(); typeManagement.create();
} catch(SchemaAlreadyPresentException sape) { } catch(SchemaAlreadyPresentException sape) {
logger.warn("{} already exists. It will be ignored", TypeMapper.getType(r)); logger.warn("{} already exists. It will be ignored", TypeMapper.getType(r));
} catch(Exception ex) { } catch(Exception ex) {
@ -37,9 +37,9 @@ public class SchemaActionImpl implements SchemaAction {
@Override @Override
public <E extends EntityElement> void manageEntityClass(Class<E> e) throws Exception { public <E extends EntityElement> void manageEntityClass(Class<E> e) throws Exception {
try { try {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeAndTypeName(e); typeManagement.setTypeAndTypeName(e);
schemaManagement.create(); typeManagement.create();
} catch(SchemaAlreadyPresentException sape) { } catch(SchemaAlreadyPresentException sape) {
logger.warn("{} already exists. It will be ignored", TypeMapper.getType(e)); logger.warn("{} already exists. It will be ignored", TypeMapper.getType(e));
} catch(Exception ex) { } catch(Exception ex) {
@ -51,12 +51,12 @@ public class SchemaActionImpl implements SchemaAction {
@Override @Override
public <P extends PropertyElement> void managePropertyClass(Class<P> p) throws Exception { public <P extends PropertyElement> void managePropertyClass(Class<P> p) throws Exception {
try { try {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeAndTypeName(p); typeManagement.setTypeAndTypeName(p);
if(p.equals(Property.class) || p.equals(Header.class) ) { if(p.equals(Property.class) || p.equals(Header.class) ) {
((SchemaManagement) schemaManagement).setSkipTypeDefinitionCreation(true); ((TypeManagement) typeManagement).setSkipTypeDefinitionCreation(true);
} }
schemaManagement.create(); typeManagement.create();
} catch(SchemaAlreadyPresentException sape) { } catch(SchemaAlreadyPresentException sape) {
logger.warn("{} already exists. It will be ignored", TypeMapper.getType(p)); logger.warn("{} already exists. It will be ignored", TypeMapper.getType(p));
} catch(Exception ex) { } catch(Exception ex) {

View File

@ -39,7 +39,7 @@ import org.gcube.informationsystem.resourceregistry.instances.model.entities.Res
import org.gcube.informationsystem.resourceregistry.query.Query; import org.gcube.informationsystem.resourceregistry.query.Query;
import org.gcube.informationsystem.resourceregistry.query.QueryImpl; import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
import org.gcube.informationsystem.resourceregistry.query.json.JsonQuery; import org.gcube.informationsystem.resourceregistry.query.json.JsonQuery;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement; import org.gcube.informationsystem.resourceregistry.types.TypeManagement;
import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.Type;
@ -102,9 +102,9 @@ public class Access extends BaseRest {
logger.info("Requested Schema for type {}", type); logger.info("Requested Schema for type {}", type);
CalledMethodProvider.instance.set("readType"); CalledMethodProvider.instance.set("readType");
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(type); typeManagement.setTypeName(type);
List<Type> types = schemaManagement.read(polymorphic); List<Type> types = typeManagement.read(polymorphic);
try { try {
return TypeMapper.serializeTypeDefinitions(types); return TypeMapper.serializeTypeDefinitions(types);
}catch (Exception e) { }catch (Exception e) {

View File

@ -22,7 +22,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath; import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement; import org.gcube.informationsystem.resourceregistry.types.TypeManagement;
import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.Type;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -57,7 +57,7 @@ public class TypeManager {
logger.info("Requested {} creation with schema {}", typeName, json); logger.info("Requested {} creation with schema {}", typeName, json);
CalledMethodProvider.instance.set("createType"); CalledMethodProvider.instance.set("createType");
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement schemaManagement = new TypeManagement();
schemaManagement.setTypeName(typeName); schemaManagement.setTypeName(typeName);
schemaManagement.setJson(json); schemaManagement.setJson(json);
String ret = schemaManagement.create(); String ret = schemaManagement.create();
@ -79,7 +79,7 @@ public class TypeManager {
logger.info("Requested Schema for type {}", type); logger.info("Requested Schema for type {}", type);
CalledMethodProvider.instance.set("readType"); CalledMethodProvider.instance.set("readType");
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement schemaManagement = new TypeManagement();
schemaManagement.setTypeName(type); schemaManagement.setTypeName(type);
List<Type> types = schemaManagement.read(polymorphic); List<Type> types = schemaManagement.read(polymorphic);
try { try {

View File

@ -175,7 +175,7 @@ public class CachedType<T extends Type> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private T internalGetType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { private T internalGetType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
if(type==null) { if(type==null) {
ElementManagement<?,?> erManagement = SchemaManagement.getTypeManagement(internalGetOClass()); ElementManagement<?,?> erManagement = TypeManagement.getTypeManagement(internalGetOClass());
String typeString = erManagement.read(); String typeString = erManagement.read();
try { try {
type = (T) TypeMapper.deserializeTypeDefinition(typeString); type = (T) TypeMapper.deserializeTypeDefinition(typeString);

View File

@ -68,9 +68,9 @@ import com.orientechnologies.orient.core.record.OElement;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public class SchemaManagement { public class TypeManagement {
private static Logger logger = LoggerFactory.getLogger(SchemaManagement.class); private static Logger logger = LoggerFactory.getLogger(TypeManagement.class);
protected String typeName; protected String typeName;
protected String json; protected String json;
@ -106,7 +106,7 @@ public class SchemaManagement {
} }
} }
public SchemaManagement() { public TypeManagement() {
this.skipTypeDefinitionCreation = false; this.skipTypeDefinitionCreation = false;
} }

View File

@ -60,9 +60,9 @@ public class SchemaManagementImplTest extends ContextTest {
@Test @Test
public void getPropertyTypeSchema() throws Exception { public void getPropertyTypeSchema() throws Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(Property.NAME); typeManagement.setTypeName(Property.NAME);
List<Type> types = schemaManagement.read(false); List<Type> types = typeManagement.read(false);
String json = TypeMapper.serializeTypeDefinitions(types); String json = TypeMapper.serializeTypeDefinitions(types);
logger.debug(json); logger.debug(json);
} }
@ -86,9 +86,9 @@ public class SchemaManagementImplTest extends ContextTest {
@Test @Test
public void getFacetSchema() throws Exception { public void getFacetSchema() throws Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(ContactFacet.NAME); typeManagement.setTypeName(ContactFacet.NAME);
List<Type> types = schemaManagement.read(false); List<Type> types = typeManagement.read(false);
String json = TypeMapper.serializeTypeDefinitions(types); String json = TypeMapper.serializeTypeDefinitions(types);
logger.info(json); logger.info(json);
List<Type> typeDefinitions = TypeMapper.deserializeTypeDefinitions(json); List<Type> typeDefinitions = TypeMapper.deserializeTypeDefinitions(json);
@ -109,14 +109,13 @@ public class SchemaManagementImplTest extends ContextTest {
Class<? extends Resource> clz = Resource.class; Class<? extends Resource> clz = Resource.class;
String json = TypeMapper.serializeType(clz); String json = TypeMapper.serializeType(clz);
logger.info(json); logger.info(json);
// new SchemaManagementImpl().registerFacetSchema(json);
} }
@Test @Test
public void getResourceSchema() throws Exception { public void getResourceSchema() throws Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(Actor.NAME); typeManagement.setTypeName(Actor.NAME);
List<Type> types = schemaManagement.read(false); List<Type> types = typeManagement.read(false);
String json = TypeMapper.serializeTypeDefinitions(types); String json = TypeMapper.serializeTypeDefinitions(types);
logger.trace(json); logger.trace(json);
} }
@ -126,7 +125,6 @@ public class SchemaManagementImplTest extends ContextTest {
Class<? extends Element> clz = Hosts.class; Class<? extends Element> clz = Hosts.class;
String json = TypeMapper.serializeType(clz); String json = TypeMapper.serializeType(clz);
logger.trace(json); logger.trace(json);
// new SchemaManagementImpl().registerFacetSchema(json);
} }
@Test @Test
@ -135,9 +133,9 @@ public class SchemaManagementImplTest extends ContextTest {
boolean includeSubTypes = true; boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(Resource.NAME); typeManagement.setTypeName(Resource.NAME);
List<Type> types = schemaManagement.read(includeSubTypes); List<Type> types = typeManagement.read(includeSubTypes);
String list = TypeMapper.serializeTypeDefinitions(types); String list = TypeMapper.serializeTypeDefinitions(types);
logger.info("{} list : {}", Resource.NAME, list); logger.info("{} list : {}", Resource.NAME, list);
} }
@ -148,9 +146,9 @@ public class SchemaManagementImplTest extends ContextTest {
boolean includeSubTypes = true; boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(Facet.NAME); typeManagement.setTypeName(Facet.NAME);
List<Type> types = schemaManagement.read(includeSubTypes); List<Type> types = typeManagement.read(includeSubTypes);
String list = TypeMapper.serializeTypeDefinitions(types); String list = TypeMapper.serializeTypeDefinitions(types);
logger.info("{} list : {}", Facet.NAME, list); logger.info("{} list : {}", Facet.NAME, list);
} }
@ -161,9 +159,9 @@ public class SchemaManagementImplTest extends ContextTest {
boolean includeSubTypes = true; boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(ConsistsOf.NAME); typeManagement.setTypeName(ConsistsOf.NAME);
List<Type> types = schemaManagement.read(includeSubTypes); List<Type> types = typeManagement.read(includeSubTypes);
String list = TypeMapper.serializeTypeDefinitions(types); String list = TypeMapper.serializeTypeDefinitions(types);
logger.info("{} list : {}", ConsistsOf.NAME, list); logger.info("{} list : {}", ConsistsOf.NAME, list);
} }
@ -174,9 +172,9 @@ public class SchemaManagementImplTest extends ContextTest {
boolean includeSubTypes = true; boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(IsRelatedTo.NAME); typeManagement.setTypeName(IsRelatedTo.NAME);
List<Type> types = schemaManagement.read(includeSubTypes); List<Type> types = typeManagement.read(includeSubTypes);
String list = TypeMapper.serializeTypeDefinitions(types); String list = TypeMapper.serializeTypeDefinitions(types);
logger.info("{} list : {}", IsRelatedTo.NAME, list); logger.info("{} list : {}", IsRelatedTo.NAME, list);
@ -189,28 +187,28 @@ public class SchemaManagementImplTest extends ContextTest {
boolean includeSubTypes = true; boolean includeSubTypes = true;
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
try { try {
schemaManagement.setTypeName(PropertyElement.NAME); typeManagement.setTypeName(PropertyElement.NAME);
schemaManagement.read(includeSubTypes); typeManagement.read(includeSubTypes);
throw new Exception("Should not be allowed to get " + PropertyElement.NAME + " schema"); throw new Exception("Should not be allowed to get " + PropertyElement.NAME + " schema");
} catch (SchemaException e) { } catch (SchemaException e) {
} }
try { try {
schemaManagement = new SchemaManagement(); typeManagement = new TypeManagement();
schemaManagement.setTypeName(Entity.NAME); typeManagement.setTypeName(Entity.NAME);
schemaManagement.read(includeSubTypes); typeManagement.read(includeSubTypes);
throw new Exception("Should not be allowed to get " + Entity.NAME + " schema"); throw new Exception("Should not be allowed to get " + Entity.NAME + " schema");
} catch (SchemaException e) { } catch (SchemaException e) {
} }
try { try {
schemaManagement = new SchemaManagement(); typeManagement = new TypeManagement();
schemaManagement.setTypeName(Relation.NAME); typeManagement.setTypeName(Relation.NAME);
schemaManagement.read(includeSubTypes); typeManagement.read(includeSubTypes);
throw new Exception("Should not be allowed to get " + Relation.NAME + " schema"); throw new Exception("Should not be allowed to get " + Relation.NAME + " schema");
} catch (SchemaException e) { } catch (SchemaException e) {
@ -221,19 +219,19 @@ public class SchemaManagementImplTest extends ContextTest {
protected String create(Class<? extends Element> clz) protected String create(Class<? extends Element> clz)
throws SchemaAlreadyPresentException, SchemaException, Exception { throws SchemaAlreadyPresentException, SchemaException, Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeAndTypeName(clz); typeManagement.setTypeAndTypeName(clz);
String ret = schemaManagement.create(); String ret = typeManagement.create();
logger.debug(ret); logger.debug(ret);
return ret; return ret;
} }
protected String update(Class<? extends Element> clz, boolean skipVersionCheckOnUpdate) protected String update(Class<? extends Element> clz, boolean skipVersionCheckOnUpdate)
throws SchemaAlreadyPresentException, SchemaException, SchemaNotFoundException, Exception { throws SchemaAlreadyPresentException, SchemaException, SchemaNotFoundException, Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeAndTypeName(clz); typeManagement.setTypeAndTypeName(clz);
schemaManagement.setSkipVersionCheckOnUpdate(skipVersionCheckOnUpdate); typeManagement.setSkipVersionCheckOnUpdate(skipVersionCheckOnUpdate);
String ret = schemaManagement.update(); String ret = typeManagement.update();
logger.debug(ret); logger.debug(ret);
return ret; return ret;
} }
@ -305,12 +303,12 @@ public class SchemaManagementImplTest extends ContextTest {
@Test @Test
public void deleteTestFacetType() throws Exception { public void deleteTestFacetType() throws Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
String typeName = TestFacet.NAME; String typeName = TestFacet.NAME;
schemaManagement.setTypeName(typeName); typeManagement.setTypeName(typeName);
try { try {
logger.info("Going to delete {}", typeName); logger.info("Going to delete {}", typeName);
schemaManagement.delete(AccessType.FACET); typeManagement.delete(AccessType.FACET);
logger.info("Deleted {}", typeName); logger.info("Deleted {}", typeName);
} catch (SchemaNotFoundException e) { } catch (SchemaNotFoundException e) {
// The test has been failed before creating the type // The test has been failed before creating the type
@ -322,12 +320,12 @@ public class SchemaManagementImplTest extends ContextTest {
@Test @Test
public void createUpdateDeleteFacetType() throws Exception { public void createUpdateDeleteFacetType() throws Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
String typeName = TestFacet.NAME; String typeName = TestFacet.NAME;
schemaManagement.setTypeName(typeName); typeManagement.setTypeName(typeName);
try { try {
logger.info("Going to delete {}", typeName); logger.info("Going to delete {}", typeName);
schemaManagement.delete(AccessType.FACET); typeManagement.delete(AccessType.FACET);
logger.info("Deleted {}", typeName); logger.info("Deleted {}", typeName);
} catch (SchemaNotFoundException e) { } catch (SchemaNotFoundException e) {
// Removing the test type in case of a previous failure on test occurred // Removing the test type in case of a previous failure on test occurred
@ -368,12 +366,12 @@ public class SchemaManagementImplTest extends ContextTest {
} catch (Exception e) { } catch (Exception e) {
throw e; throw e;
} finally { } finally {
schemaManagement = new SchemaManagement(); typeManagement = new TypeManagement();
typeName = TestFacet.NAME; typeName = TestFacet.NAME;
schemaManagement.setTypeName(typeName); typeManagement.setTypeName(typeName);
try { try {
logger.info("Going to delete {}", typeName); logger.info("Going to delete {}", typeName);
schemaManagement.delete(AccessType.FACET); typeManagement.delete(AccessType.FACET);
logger.info("Deleted {}", typeName); logger.info("Deleted {}", typeName);
} catch (SchemaNotFoundException e) { } catch (SchemaNotFoundException e) {
// The test has been failed before creating the type // The test has been failed before creating the type
@ -386,8 +384,8 @@ public class SchemaManagementImplTest extends ContextTest {
@Test(expected=SchemaNotFoundException.class) @Test(expected=SchemaNotFoundException.class)
public void deleteFacetType() throws Exception { public void deleteFacetType() throws Exception {
SchemaManagement schemaManagement = new SchemaManagement(); TypeManagement typeManagement = new TypeManagement();
schemaManagement.setTypeName(TestFacet.NAME); typeManagement.setTypeName(TestFacet.NAME);
schemaManagement.delete(AccessType.FACET); typeManagement.delete(AccessType.FACET);
} }
} }