Refactored
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@141497 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1078b43fcf
commit
098bf95122
|
@ -11,6 +11,7 @@ import org.gcube.informationsystem.model.entity.Resource;
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
import org.gcube.informationsystem.model.relation.Relation;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.rest.AccessType;
|
||||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||||
import org.gcube.informationsystem.types.TypeBinder;
|
import org.gcube.informationsystem.types.TypeBinder;
|
||||||
|
@ -39,11 +40,11 @@ public class SchemaActionImpl implements SchemaAction {
|
||||||
String json = TypeBinder.serializeType(r);
|
String json = TypeBinder.serializeType(r);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
if (ConsistsOf.class.isAssignableFrom(r)) {
|
if (ConsistsOf.class.isAssignableFrom(r)) {
|
||||||
schemaManagement.registerConsistsOfSchema(json);
|
schemaManagement.create(json, AccessType.CONSISTS_OF);
|
||||||
} else if(IsRelatedTo.class.isAssignableFrom(r)){
|
} else if(IsRelatedTo.class.isAssignableFrom(r)){
|
||||||
schemaManagement.registerIsRelatedToSchema(json);
|
schemaManagement.create(json, AccessType.IS_RELATED_TO);
|
||||||
} else {
|
} else {
|
||||||
schemaManagement.registerRelationSchema(json);
|
schemaManagement.create(json, AccessType.RELATION);
|
||||||
}
|
}
|
||||||
} catch(Exception ex){
|
} catch(Exception ex){
|
||||||
logger.error("Error creating schema for {} type {} : {}", Relation.NAME, r.getSimpleName(), ex.getMessage());
|
logger.error("Error creating schema for {} type {} : {}", Relation.NAME, r.getSimpleName(), ex.getMessage());
|
||||||
|
@ -57,11 +58,11 @@ public class SchemaActionImpl implements SchemaAction {
|
||||||
String json = TypeBinder.serializeType(e);
|
String json = TypeBinder.serializeType(e);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
if (Facet.class.isAssignableFrom(e)) {
|
if (Facet.class.isAssignableFrom(e)) {
|
||||||
schemaManagement.createFacetSchema(json);
|
schemaManagement.create(json, AccessType.FACET);
|
||||||
} else if(Resource.class.isAssignableFrom(e)){
|
} else if(Resource.class.isAssignableFrom(e)){
|
||||||
schemaManagement.registerResourceSchema(json);
|
schemaManagement.create(json, AccessType.RESOURCE);
|
||||||
} else {
|
} else {
|
||||||
schemaManagement.createEntitySchema(json);
|
schemaManagement.create(json, AccessType.ENTITY);
|
||||||
}
|
}
|
||||||
} catch(Exception ex){
|
} catch(Exception ex){
|
||||||
logger.error("Error creating schema for {} type {} : {}", Entity.NAME, e.getSimpleName(), ex.getMessage());
|
logger.error("Error creating schema for {} type {} : {}", Entity.NAME, e.getSimpleName(), ex.getMessage());
|
||||||
|
@ -74,7 +75,7 @@ public class SchemaActionImpl implements SchemaAction {
|
||||||
try {
|
try {
|
||||||
String json = TypeBinder.serializeType(e);
|
String json = TypeBinder.serializeType(e);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
schemaManagement.registerEmbeddedTypeSchema(json);
|
schemaManagement.create(json, AccessType.EMBEDDED);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error("Error creating schema for {} type {} : {}",
|
logger.error("Error creating schema for {} type {} : {}",
|
||||||
Embedded.NAME, e.getSimpleName(),
|
Embedded.NAME, e.getSimpleName(),
|
||||||
|
|
|
@ -35,8 +35,6 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(EntityManagement.class);
|
.getLogger(EntityManagement.class);
|
||||||
|
|
||||||
protected Vertex element;
|
|
||||||
|
|
||||||
protected EntityManagement(Class<E> entityClass) {
|
protected EntityManagement(Class<E> entityClass) {
|
||||||
super(entityClass);
|
super(entityClass);
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,6 @@ public abstract class RelationManagement<R extends Relation> extends ERManagemen
|
||||||
|
|
||||||
protected final Class<? extends Entity> targetEntityClass;
|
protected final Class<? extends Entity> targetEntityClass;
|
||||||
|
|
||||||
protected Edge element;
|
|
||||||
|
|
||||||
protected RelationManagement(Class<R> relationClass) {
|
protected RelationManagement(Class<R> relationClass) {
|
||||||
super(relationClass);
|
super(relationClass);
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,10 @@ public class Access {
|
||||||
|
|
||||||
public static final String ID_PATH_PARAM = "id";
|
public static final String ID_PATH_PARAM = "id";
|
||||||
public static final String TYPE_PATH_PARAM = "type";
|
public static final String TYPE_PATH_PARAM = "type";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It includeSubtypesows to query Entities and Relations in the current Context.<br />
|
* It includeSubtypesows to query Entities and Relations in the current
|
||||||
|
* Context.<br />
|
||||||
* It accepts idempotent query only.. <br />
|
* It accepts idempotent query only.. <br />
|
||||||
* <br />
|
* <br />
|
||||||
* For query syntax please refer to<br />
|
* For query syntax please refer to<br />
|
||||||
|
@ -76,52 +76,54 @@ public class Access {
|
||||||
return queryManager.query(query, limit, fetchPlan);
|
return queryManager.query(query, limit, fetchPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public static ERManagement getERManagement(AccessType querableType) throws ResourceRegistryException {
|
public static ERManagement getERManagement(AccessType querableType)
|
||||||
|
throws ResourceRegistryException {
|
||||||
switch (querableType) {
|
switch (querableType) {
|
||||||
case FACET:
|
case FACET:
|
||||||
return new FacetManagement();
|
return new FacetManagement();
|
||||||
|
|
||||||
case RESOURCE:
|
case RESOURCE:
|
||||||
return new ResourceManagement();
|
return new ResourceManagement();
|
||||||
|
|
||||||
case IS_RELATED_TO:
|
case IS_RELATED_TO:
|
||||||
return new IsRelatedToManagement();
|
return new IsRelatedToManagement();
|
||||||
|
|
||||||
case CONSISTS_OF:
|
case CONSISTS_OF:
|
||||||
return new ConsistsOfManagement();
|
return new ConsistsOfManagement();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ResourceRegistryException(String.format("%s is not querable", querableType.toString()));
|
throw new ResourceRegistryException(String.format(
|
||||||
|
"%s is not querable", querableType.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* e.g. GET /resource-registry/access/instance/{E-R}/4d28077b-566d-4132-b073-f4edaf61dcb9
|
* e.g. GET
|
||||||
|
* /resource-registry/access/instance/{E-R}/4d28077b-566d-4132-b073-
|
||||||
|
* f4edaf61dcb9
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM +"}"
|
@Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}"
|
||||||
+ "/{" + ID_PATH_PARAM + "}")
|
+ "/{" + ID_PATH_PARAM + "}")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getInstance(
|
public String getInstance(
|
||||||
@PathParam(ID_PATH_PARAM) String type,
|
@PathParam(TYPE_PATH_PARAM) String type,
|
||||||
@PathParam(ID_PATH_PARAM) String facetId)
|
@PathParam(ID_PATH_PARAM) String id)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
logger.info("Requested Facet with id {}", facetId);
|
logger.info("Requested {} with id {}", type, id);
|
||||||
|
|
||||||
AccessType querableType = null;
|
AccessType querableType = null;
|
||||||
try {
|
try {
|
||||||
querableType = AccessType.valueOf(type);
|
querableType = AccessType.valueOf(type);
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
String error = String.format("%s is not querable", type);
|
String error = String.format("%s is not querable", type);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
ERManagement erManagement = getERManagement(querableType);
|
ERManagement erManagement = getERManagement(querableType);
|
||||||
erManagement.setUUID(UUID.fromString(facetId));
|
erManagement.setUUID(UUID.fromString(id));
|
||||||
return erManagement.read();
|
return erManagement.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,195 +131,49 @@ public class Access {
|
||||||
* e.g. GET /resource-registry/access/instances/{E-R}?polymorphic=true
|
* e.g. GET /resource-registry/access/instances/{E-R}?polymorphic=true
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path(AccessPath.INSTANCE_PATH_PART + "s/" + "{" + TYPE_PATH_PARAM +"}"
|
@Path(AccessPath.INSTANCE_PATH_PART + "s/" + "{" + TYPE_PATH_PARAM + "}")
|
||||||
+ "/{" + ID_PATH_PARAM + "}")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getInstances(
|
public String getInstances(
|
||||||
@PathParam(ID_PATH_PARAM) String type,
|
@PathParam(TYPE_PATH_PARAM) String type,
|
||||||
@PathParam(ID_PATH_PARAM) String facetId)
|
@QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic)
|
||||||
throws FacetNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ResourceRegistryException {
|
||||||
logger.info("Requested Facet with id {}", facetId);
|
logger.info("Requested {} ({}={}) instances", type, AccessPath.POLYMORPHIC_PARAM, polymorphic);
|
||||||
AccessType querableType = null;
|
AccessType querableType = null;
|
||||||
try {
|
try {
|
||||||
querableType = AccessType.valueOf(type);
|
querableType = AccessType.valueOf(type);
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
String error = String.format("%s is not querable", type);
|
String error = String.format("%s is not querable", type);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* e.g. GET /resource-registry/access/schema/Facet/ContactFacet?
|
* e.g. GET /resource-registry/access/schema/{E-R}/ContactFacet?
|
||||||
* includeSubtypes=true&
|
* polymorphic=true
|
||||||
* includeSchema=true
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path(AccessPath.SCHEMA_PATH_PART + "/{"
|
@Path(AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||||
+ TYPE_PATH_PARAM + "}")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getSchema(@PathParam(TYPE_PATH_PARAM) String type,
|
public String getSchema(
|
||||||
@QueryParam(AccessPath.INCLUDE_SUBTYPES_PARAM) Boolean includeSubtypes,
|
@PathParam(TYPE_PATH_PARAM) String type,
|
||||||
@QueryParam(AccessPath.INCLUDE_SCHEMA_PARAM) Boolean includeSchema)
|
@QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic)
|
||||||
throws SchemaNotFoundException, SchemaException {
|
throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
|
||||||
logger.info("Requested Facet Schema for type {}", type);
|
logger.info("Requested Schema for type {}", type);
|
||||||
|
|
||||||
|
AccessType accessType = null;
|
||||||
|
try {
|
||||||
|
accessType = AccessType.valueOf(type);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String error = String.format("Cannot get %s schema", type);
|
||||||
|
throw new ResourceRegistryException(error);
|
||||||
|
}
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
|
return schemaManagement.read(type, accessType, polymorphic);
|
||||||
// TODO
|
|
||||||
|
|
||||||
return schemaManagement.readFacetSchema(type, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/facet/instance/
|
|
||||||
// * 4d28077b-566d-4132-b073-f4edaf61dcb9
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART
|
|
||||||
// + "/{" + ID_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getFacet(@PathParam(ID_PATH_PARAM) String facetId)
|
|
||||||
// throws FacetNotFoundException, ResourceRegistryException {
|
|
||||||
// logger.info("Requested Facet with id {}", facetId);
|
|
||||||
// FacetManagement facetManagement = new FacetManagement();
|
|
||||||
// facetManagement.setUUID(UUID.fromString(facetId));
|
|
||||||
// return facetManagement.read();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/facet/schema/ContactFacet?
|
|
||||||
// * includeSubtypes=true&
|
|
||||||
// * includeSchema=true
|
|
||||||
// *
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{"
|
|
||||||
// + TYPE_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getFacetSchema(@PathParam(TYPE_PATH_PARAM) String facetType,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SUBTYPES_PARAM) Boolean includeSubtypes,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SCHEMA_PARAM) Boolean includeSchema)
|
|
||||||
// throws SchemaNotFoundException, SchemaException {
|
|
||||||
// logger.info("Requested Facet Schema for type {}", facetType);
|
|
||||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
// return schemaManagement.readFacetSchema(facetType, includeSubtypes,
|
|
||||||
// includeSchema);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/resource/instance/
|
|
||||||
// * cc132a2c-d0b0-45a8-92fa-7451f6a44b6d
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART
|
|
||||||
// + "/{" + ID_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getResource(@PathParam(ID_PATH_PARAM) String resourceId)
|
|
||||||
// throws ResourceNotFoundException, ResourceRegistryException {
|
|
||||||
// logger.info("Requested Resource with id {}", resourceId);
|
|
||||||
// ResourceManagement resourceManagement = new ResourceManagement();
|
|
||||||
// resourceManagement.setUUID(UUID.fromString(resourceId));
|
|
||||||
// return resourceManagement.read();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/resource/schema/HostingNode?
|
|
||||||
// * includeSubtypes=true&
|
|
||||||
// * includeSchema=true
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART
|
|
||||||
// + "/{" + TYPE_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getResourceSchema(
|
|
||||||
// @PathParam(TYPE_PATH_PARAM) String resourceType,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SUBTYPES_PARAM) Boolean includeSubtypes,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SCHEMA_PARAM) Boolean includeSchema)
|
|
||||||
// throws SchemaNotFoundException, SchemaException {
|
|
||||||
// logger.info("Requested Resource Schema for type {}", resourceType);
|
|
||||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
// return schemaManagement.getResourceSchema(resourceType,
|
|
||||||
// includeSubtypes, includeSchema);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/embedded/schema/Embedded?
|
|
||||||
// * includeSubtypes=true&
|
|
||||||
// * includeSchema=true
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.EMBEDDED_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART
|
|
||||||
// + "/{" + TYPE_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getEmbeddedSchema(
|
|
||||||
// @PathParam(TYPE_PATH_PARAM) String embeddedType,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SUBTYPES_PARAM) Boolean includeSubtypes,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SCHEMA_PARAM) Boolean includeSchema)
|
|
||||||
// throws SchemaNotFoundException, SchemaException {
|
|
||||||
// if (includeSchema == null) {
|
|
||||||
// includeSchema = false;
|
|
||||||
// }
|
|
||||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
// return schemaManagement.getEmbeddedTypeSchema(embeddedType,
|
|
||||||
// includeSubtypes, includeSchema);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/consistsOf/schema/HasContact?
|
|
||||||
// * includeSubtypes=true&
|
|
||||||
// * includeSchema=true
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.CONSISTS_OF_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART
|
|
||||||
// + "/{" + TYPE_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getConsistsOfSchema(
|
|
||||||
// @PathParam(TYPE_PATH_PARAM) String consistsOfType,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SUBTYPES_PARAM) Boolean includeSubtypes,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SCHEMA_PARAM) Boolean includeSchema)
|
|
||||||
// throws SchemaNotFoundException, SchemaException {
|
|
||||||
// if (includeSchema == null) {
|
|
||||||
// includeSchema = false;
|
|
||||||
// }
|
|
||||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
// return schemaManagement.getConsistsOfSchema(consistsOfType,
|
|
||||||
// includeSubtypes, includeSchema);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * e.g. GET /resource-registry/access/isRelatedTo/schema/HasContact?
|
|
||||||
// * includeSubtypes=true&
|
|
||||||
// * includeSchema=true
|
|
||||||
// */
|
|
||||||
// @GET
|
|
||||||
// @Path(AccessPath.IS_RELATED_TO_PATH_PART + "/"
|
|
||||||
// + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// public String getIsRelatedToSchema(
|
|
||||||
// @PathParam(TYPE_PATH_PARAM) String isRelatedToType,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SUBTYPES_PARAM) Boolean includeSubtypes,
|
|
||||||
// @QueryParam(AccessPath.INCLUDE_SCHEMA_PARAM) Boolean includeSchema)
|
|
||||||
// throws SchemaNotFoundException, SchemaException {
|
|
||||||
// if (includeSchema == null) {
|
|
||||||
// includeSchema = false;
|
|
||||||
// }
|
|
||||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
// return schemaManagement.getIsRelatedToSchema(isRelatedToType,
|
|
||||||
// includeSubtypes, includeSchema);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,10 +3,13 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.rest;
|
package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.embedded.Embedded;
|
||||||
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.model.entity.Entity;
|
import org.gcube.informationsystem.model.entity.Entity;
|
||||||
import org.gcube.informationsystem.model.entity.Facet;
|
import org.gcube.informationsystem.model.entity.Facet;
|
||||||
import org.gcube.informationsystem.model.entity.Resource;
|
import org.gcube.informationsystem.model.entity.Resource;
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
|
import org.gcube.informationsystem.model.relation.IsParentOf;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
import org.gcube.informationsystem.model.relation.Relation;
|
||||||
|
|
||||||
|
@ -17,18 +20,25 @@ import org.gcube.informationsystem.model.relation.Relation;
|
||||||
*/
|
*/
|
||||||
public enum AccessType {
|
public enum AccessType {
|
||||||
|
|
||||||
ENTITY(Entity.NAME),
|
EMBEDDED(Embedded.class, Embedded.NAME),
|
||||||
RESOURCE(Resource.NAME),
|
CONTEXT(Context.class, Context.NAME),
|
||||||
FACET(Facet.NAME),
|
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME),
|
||||||
|
|
||||||
|
ENTITY(Entity.class, Entity.NAME),
|
||||||
|
RESOURCE(Resource.class, Resource.NAME),
|
||||||
|
FACET(Facet.class, Facet.NAME),
|
||||||
|
|
||||||
RELATION(Relation.NAME),
|
RELATION(Relation.class, Relation.NAME),
|
||||||
IS_RELATED_TO(IsRelatedTo.NAME),
|
IS_RELATED_TO(IsRelatedTo.class, IsRelatedTo.NAME),
|
||||||
CONSISTS_OF(ConsistsOf.NAME);
|
CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME);
|
||||||
|
|
||||||
|
|
||||||
|
private final Class<?> clz;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String lowerCaseFirstCharacter;
|
private final String lowerCaseFirstCharacter;
|
||||||
|
|
||||||
AccessType(String name){
|
AccessType(Class<?> clz, String name){
|
||||||
|
this.clz = clz;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.lowerCaseFirstCharacter = name.substring(0, 1).toLowerCase() + name.substring(1);
|
this.lowerCaseFirstCharacter = name.substring(0, 1).toLowerCase() + name.substring(1);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +47,14 @@ public enum AccessType {
|
||||||
return lowerCaseFirstCharacter;
|
return lowerCaseFirstCharacter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class<?> getTypeClass(){
|
||||||
|
return clz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return name;
|
return name;
|
||||||
|
|
|
@ -4,14 +4,11 @@ import javax.ws.rs.ApplicationPath;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.embedded.Embedded;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.model.entity.Facet;
|
|
||||||
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.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
||||||
|
@ -23,116 +20,171 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
* @author Lucio Lelii (ISTI - CNR)
|
* @author Lucio Lelii (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
|
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
|
||||||
public class SchemaManager {
|
public class SchemaManager {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SchemaManager.class);
|
private static Logger logger = LoggerFactory.getLogger(SchemaManager.class);
|
||||||
|
public static final String TYPE_PATH_PARAM = "type";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* e.g. PUT /resource-registry/schema/embedded
|
* e.g. PUT /resource-registry/schema/{E-R}
|
||||||
*
|
*
|
||||||
* BODY: {...}
|
* BODY: {...}
|
||||||
*
|
*
|
||||||
* ?schema={...}
|
* @param type
|
||||||
*
|
* @param json
|
||||||
* @param jsonSchema
|
|
||||||
* @return
|
* @return
|
||||||
* @throws SchemaException
|
* @throws SchemaException
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path(SchemaPath.EMBEDDED_PATH_PART)
|
@Path("{" + TYPE_PATH_PARAM + "}")
|
||||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String registerEmbeddedTypeSchema(String jsonSchema)
|
public String create(
|
||||||
throws SchemaException {
|
@PathParam(TYPE_PATH_PARAM) String type,
|
||||||
logger.trace("Requested {} registration with schema {}", Embedded.NAME,
|
String json)
|
||||||
jsonSchema);
|
throws SchemaException, ResourceRegistryException {
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
logger.trace("Requested {} registration with schema {}", type, json);
|
||||||
return schemaManagement.registerEmbeddedTypeSchema(jsonSchema);
|
|
||||||
}
|
AccessType accessType = null;
|
||||||
|
try {
|
||||||
|
accessType = AccessType.valueOf(type);
|
||||||
|
switch (accessType) {
|
||||||
|
case EMBEDDED:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FACET:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RESOURCE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IS_RELATED_TO:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONSISTS_OF:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Exception();
|
||||||
|
|
||||||
/**
|
}
|
||||||
* e.g. PUT /resource-registry/schema/facet
|
} catch (Exception e) {
|
||||||
*
|
String error = String.format("Cannot register %s schema", type);
|
||||||
* BODY: {...}
|
throw new ResourceRegistryException(error);
|
||||||
*
|
}
|
||||||
* @param jsonSchema
|
|
||||||
* @return
|
|
||||||
* @throws SchemaException
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path(SchemaPath.FACET_PATH_PART)
|
|
||||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public String registerFacetSchema(String jsonSchema) throws SchemaException {
|
|
||||||
logger.trace("Requested {} registration with schema {}", Facet.NAME,
|
|
||||||
jsonSchema);
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
return schemaManagement.createFacetSchema(jsonSchema);
|
return schemaManagement.create(json, accessType);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* e.g. PUT /resource-registry/schema/resource
|
|
||||||
*
|
|
||||||
* BODY: {...}
|
|
||||||
*
|
|
||||||
* @param jsonSchema
|
|
||||||
* @param jsonSchema
|
|
||||||
* @return
|
|
||||||
* @throws SchemaException
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path(SchemaPath.RESOURCE_PATH_PART)
|
|
||||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public String registerResourceSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
logger.trace("Requested {} registration with schema {}", Resource.NAME,
|
|
||||||
jsonSchema);
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
return schemaManagement.registerResourceSchema(jsonSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* e.g. PUT /resource-registry/schema/consistsOf
|
|
||||||
*
|
|
||||||
* BODY: {...}
|
|
||||||
*
|
|
||||||
* @param jsonSchema
|
|
||||||
* @return
|
|
||||||
* @throws SchemaException
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path(SchemaPath.CONSISTS_OF_PATH_PART)
|
|
||||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public String registerConsistOfSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
logger.trace("Requested {} registration with schema {} ",
|
|
||||||
ConsistsOf.NAME, jsonSchema);
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
return schemaManagement.registerConsistsOfSchema(jsonSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* e.g. PUT /resource-registry/schema/isRelatedTo
|
|
||||||
*
|
|
||||||
* BODY: {...}
|
|
||||||
*
|
|
||||||
* @param jsonSchema
|
|
||||||
* @return
|
|
||||||
* @throws SchemaException
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path(SchemaPath.IS_RELATED_TO_PATH_PART)
|
|
||||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public String registerIsRelatedToSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
logger.trace("Requested {} registration with schema {} ",
|
|
||||||
IsRelatedTo.NAME, jsonSchema);
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
|
||||||
return schemaManagement.registerIsRelatedToSchema(jsonSchema);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * e.g. PUT /resource-registry/schema/embedded
|
||||||
|
// *
|
||||||
|
// * BODY: {...}
|
||||||
|
// *
|
||||||
|
// * @param json
|
||||||
|
// * @return
|
||||||
|
// * @throws SchemaException
|
||||||
|
// */
|
||||||
|
// @PUT
|
||||||
|
// @Path(SchemaPath.EMBEDDED_PATH_PART)
|
||||||
|
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||||
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
|
// public String registerEmbeddedTypeSchema(String json)
|
||||||
|
// throws SchemaException {
|
||||||
|
// logger.trace("Requested {} registration with schema {}", Embedded.NAME,
|
||||||
|
// json);
|
||||||
|
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
|
// return schemaManagement.create(json, AccessType.EMBEDDED);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * e.g. PUT /resource-registry/schema/facet
|
||||||
|
// *
|
||||||
|
// * BODY: {...}
|
||||||
|
// *
|
||||||
|
// * @param json
|
||||||
|
// * @return
|
||||||
|
// * @throws SchemaException
|
||||||
|
// */
|
||||||
|
// @PUT
|
||||||
|
// @Path(SchemaPath.FACET_PATH_PART)
|
||||||
|
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||||
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
|
// public String registerFacetSchema(String json) throws SchemaException {
|
||||||
|
// logger.trace("Requested {} registration with schema {}", Facet.NAME,
|
||||||
|
// json);
|
||||||
|
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
|
// return schemaManagement.create(json, AccessType.FACET);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * e.g. PUT /resource-registry/schema/resource
|
||||||
|
// *
|
||||||
|
// * BODY: {...}
|
||||||
|
// *
|
||||||
|
// * @param jsonSchema
|
||||||
|
// * @return
|
||||||
|
// * @throws SchemaException
|
||||||
|
// */
|
||||||
|
// @PUT
|
||||||
|
// @Path(SchemaPath.RESOURCE_PATH_PART)
|
||||||
|
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||||
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
|
// public String registerResourceSchema(String json)
|
||||||
|
// throws SchemaException {
|
||||||
|
// logger.trace("Requested {} registration with schema {}", Resource.NAME,
|
||||||
|
// json);
|
||||||
|
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
|
// return schemaManagement.create(json, AccessType.RESOURCE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * e.g. PUT /resource-registry/schema/consistsOf
|
||||||
|
// *
|
||||||
|
// * BODY: {...}
|
||||||
|
// *
|
||||||
|
// * @param jsonSchema
|
||||||
|
// * @return
|
||||||
|
// * @throws SchemaException
|
||||||
|
// */
|
||||||
|
// @PUT
|
||||||
|
// @Path(SchemaPath.CONSISTS_OF_PATH_PART)
|
||||||
|
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||||
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
|
// public String registerConsistsOfSchema(String json)
|
||||||
|
// throws SchemaException {
|
||||||
|
// logger.trace("Requested {} registration with schema {} ",
|
||||||
|
// ConsistsOf.NAME, json);
|
||||||
|
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
|
// return schemaManagement.create(json, AccessType.CONSISTS_OF);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * e.g. PUT /resource-registry/schema/isRelatedTo
|
||||||
|
// *
|
||||||
|
// * BODY: {...}
|
||||||
|
// *
|
||||||
|
// * @param jsonSchema
|
||||||
|
// * @return
|
||||||
|
// * @throws SchemaException
|
||||||
|
// */
|
||||||
|
// @PUT
|
||||||
|
// @Path(SchemaPath.IS_RELATED_TO_PATH_PART)
|
||||||
|
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||||
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
|
// public String registerIsRelatedToSchema(String json)
|
||||||
|
// throws SchemaException {
|
||||||
|
// logger.trace("Requested {} registration with schema {} ",
|
||||||
|
// IsRelatedTo.NAME, json);
|
||||||
|
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
|
// return schemaManagement.create(json, AccessType.IS_RELATED_TO);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.rest.AccessType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -12,16 +13,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
||||||
*/
|
*/
|
||||||
public interface SchemaManagement {
|
public interface SchemaManagement {
|
||||||
|
|
||||||
|
public String create(String json, AccessType accessType) throws SchemaException;
|
||||||
|
|
||||||
|
public String read(String type, AccessType accessType, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException;
|
||||||
|
|
||||||
|
public String update(String type, AccessType accessType, String json) throws SchemaNotFoundException, SchemaException;
|
||||||
|
|
||||||
|
public String delete(String type, AccessType accessType) throws SchemaNotFoundException;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public String create(String json) throws SchemaException;
|
|
||||||
|
|
||||||
public String read(String type, boolean includeSubtypes, boolean includeSchema) throws SchemaNotFoundException, SchemaException;
|
|
||||||
|
|
||||||
public String update(String type, String json) throws SchemaNotFoundException, SchemaException;
|
|
||||||
|
|
||||||
public String delete(String type) throws SchemaNotFoundException;
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String createEntitySchema(String jsonSchema) throws SchemaException;
|
public String createEntitySchema(String jsonSchema) throws SchemaException;
|
||||||
|
|
||||||
public String readEntitySchema(String entityType, boolean includeSubtypes, boolean includeSchema) throws SchemaNotFoundException, SchemaException;
|
public String readEntitySchema(String entityType, boolean includeSubtypes, boolean includeSchema) throws SchemaNotFoundException, SchemaException;
|
||||||
|
@ -83,5 +83,6 @@ public interface SchemaManagement {
|
||||||
public String updateIsRelatedToSchema(String isRelatedToType, String jsonSchema) throws SchemaNotFoundException, SchemaException;
|
public String updateIsRelatedToSchema(String isRelatedToType, String jsonSchema) throws SchemaNotFoundException, SchemaException;
|
||||||
|
|
||||||
public String deleteIsRelatedToSchema(String isRelatedToType) throws SchemaException;
|
public String deleteIsRelatedToSchema(String isRelatedToType) throws SchemaException;
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,20 +8,15 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONArray;
|
|
||||||
import org.codehaus.jettison.json.JSONException;
|
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
|
||||||
import org.gcube.informationsystem.model.embedded.Embedded;
|
import org.gcube.informationsystem.model.embedded.Embedded;
|
||||||
import org.gcube.informationsystem.model.entity.Entity;
|
import org.gcube.informationsystem.model.entity.Entity;
|
||||||
import org.gcube.informationsystem.model.entity.Facet;
|
|
||||||
import org.gcube.informationsystem.model.entity.Resource;
|
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.model.relation.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.rest.AccessType;
|
||||||
import org.gcube.informationsystem.types.TypeBinder;
|
import org.gcube.informationsystem.types.TypeBinder;
|
||||||
import org.gcube.informationsystem.types.TypeBinder.Property;
|
import org.gcube.informationsystem.types.TypeBinder.Property;
|
||||||
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
||||||
|
@ -29,7 +24,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
|
||||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
|
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
|
||||||
|
@ -55,11 +49,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(SchemaManagementImpl.class);
|
.getLogger(SchemaManagementImpl.class);
|
||||||
|
|
||||||
protected static OClass getEntityOClass(OrientBaseGraph orientBaseGraph,
|
protected static OClass getOClass(OSchema oSchema, String type) throws SchemaException {
|
||||||
String entityType) throws SchemaException {
|
return oSchema.getClass(type);
|
||||||
OMetadata oMetadata = orientBaseGraph.getRawGraph().getMetadata();
|
|
||||||
OSchema oSchema = oMetadata.getSchema();
|
|
||||||
return oSchema.getClass(entityType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OClass getTypeSchema(OrientBaseGraph orientBaseGraph,
|
public static OClass getTypeSchema(OrientBaseGraph orientBaseGraph,
|
||||||
|
@ -114,7 +105,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
protected static TypeDefinition getTypeDefinition(OClass oClass)
|
protected static TypeDefinition getTypeDefinition(OClass oClass)
|
||||||
throws SchemaException {
|
throws SchemaException {
|
||||||
String json = serializeOClass(oClass);
|
ODocument oDocument = ((OClassImpl) oClass).toStream();
|
||||||
|
String json = oDocument.toJSON();
|
||||||
try {
|
try {
|
||||||
return TypeBinder.deserializeTypeDefinition(json);
|
return TypeBinder.deserializeTypeDefinition(json);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -127,32 +119,17 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TypeDefinition typeDefinition = getTypeDefinition(oClass);
|
TypeDefinition typeDefinition = getTypeDefinition(oClass);
|
||||||
return TypeBinder.serializeType(typeDefinition);
|
return TypeBinder.serializeTypeDefinition(typeDefinition);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SchemaException(e);
|
throw new SchemaException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static JSONObject serializeOClassAsJSON(OClass oClass)
|
|
||||||
throws SchemaException {
|
|
||||||
String json = serializeOClass(oClass);
|
|
||||||
try {
|
|
||||||
return new JSONObject(json);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
throw new SchemaException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static String serializeOClass(OClass oClass) {
|
|
||||||
ODocument oDocument = ((OClassImpl) oClass).toStream();
|
|
||||||
return oDocument.toJSON();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<OClass> getSuperclassesAndCheckCompliancy(
|
protected List<OClass> getSuperclassesAndCheckCompliancy(
|
||||||
OrientGraphNoTx orientGraphNoTx, TypeDefinition typeDefinition,
|
OrientGraphNoTx orientGraphNoTx, TypeDefinition typeDefinition,
|
||||||
String baseType) throws SchemaException {
|
String baseType) throws SchemaException {
|
||||||
|
|
||||||
Set<String> superClasses = typeDefinition.getSuperclasses();
|
Set<String> superClasses = typeDefinition.getSuperClasses();
|
||||||
if (baseType != null) {
|
if (baseType != null) {
|
||||||
if (superClasses == null || superClasses.size() == 0) {
|
if (superClasses == null || superClasses.size() == 0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
@ -162,9 +139,12 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
||||||
|
OSchema oSchema = oMetadata.getSchema();
|
||||||
|
|
||||||
List<OClass> oSuperclasses = new ArrayList<>();
|
List<OClass> oSuperclasses = new ArrayList<>();
|
||||||
for (String superClass : superClasses) {
|
for (String superClass : superClasses) {
|
||||||
OClass oSuperClass = getEntityOClass(orientGraphNoTx, superClass);
|
OClass oSuperClass = getOClass(oSchema, superClass);
|
||||||
if (baseType != null) {
|
if (baseType != null) {
|
||||||
if (typeDefinition.getName().compareTo(baseType) != 0) {
|
if (typeDefinition.getName().compareTo(baseType) != 0) {
|
||||||
if (!oSuperClass.isSubClassOf(baseType)) {
|
if (!oSuperClass.isSubClassOf(baseType)) {
|
||||||
|
@ -181,17 +161,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
return oSuperclasses;
|
return oSuperclasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getTypeSchemaAsString(String type, String baseType)
|
protected String registerTypeSchema(String jsonSchema, AccessType baseType)
|
||||||
throws SchemaNotFoundException {
|
|
||||||
try {
|
|
||||||
OClass oClass = getTypeSchema(type, baseType);
|
|
||||||
return serializeOClass(oClass);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new SchemaNotFoundException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String registerTypeSchema(String jsonSchema, Class<?> baseType)
|
|
||||||
throws SchemaException {
|
throws SchemaException {
|
||||||
|
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
|
@ -201,7 +171,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = null;
|
OrientGraphNoTx orientGraphNoTx = null;
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to register {} {}", baseType.getSimpleName(),
|
logger.info("Trying to register {} {}", baseType.getName(),
|
||||||
jsonSchema);
|
jsonSchema);
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
@ -209,26 +179,26 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
TypeDefinition.class);
|
TypeDefinition.class);
|
||||||
|
|
||||||
orientGraphNoTx = orientGraphFactory.getNoTx();
|
orientGraphNoTx = orientGraphFactory.getNoTx();
|
||||||
|
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
||||||
|
OSchema oSchema = oMetadata.getSchema();
|
||||||
|
|
||||||
|
|
||||||
OClass oClass = null;
|
OClass oClass = null;
|
||||||
|
|
||||||
if (Entity.class.isAssignableFrom(baseType)) {
|
if (Entity.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
oClass = orientGraphNoTx.createVertexType(typeDefinition
|
oClass = orientGraphNoTx.createVertexType(typeDefinition
|
||||||
.getName());
|
.getName());
|
||||||
} else if (Relation.class.isAssignableFrom(baseType)) {
|
} else if (Relation.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
oClass = orientGraphNoTx.createEdgeType(typeDefinition
|
oClass = orientGraphNoTx.createEdgeType(typeDefinition
|
||||||
.getName());
|
.getName());
|
||||||
} else if (Embedded.class.isAssignableFrom(baseType)) {
|
} else if (Embedded.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraphNoTx
|
|
||||||
.getRawGraph();
|
|
||||||
OMetadata oMetadata = oDatabaseDocumentTx.getMetadata();
|
|
||||||
OSchema oSchema = oMetadata.getSchema();
|
|
||||||
oClass = oSchema.createClass(typeDefinition.getName());
|
oClass = oSchema.createClass(typeDefinition.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
oClass.setDescription(typeDefinition.getDescription());
|
oClass.setDescription(typeDefinition.getDescription());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
oClass.setAbstract(typeDefinition.isAbstractType());
|
oClass.setAbstract(typeDefinition.isAbstract());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Unable to set the Vertex Type {} as abstract. This is an OrientDB <= 2.2.12 bug. The Type will be created as it is not abstarct.",
|
"Unable to set the Vertex Type {} as abstract. This is an OrientDB <= 2.2.12 bug. The Type will be created as it is not abstarct.",
|
||||||
|
@ -238,11 +208,11 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
if (typeDefinition.getName().compareTo(Embedded.NAME) != 0) {
|
if (typeDefinition.getName().compareTo(Embedded.NAME) != 0) {
|
||||||
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
|
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
|
||||||
orientGraphNoTx, typeDefinition,
|
orientGraphNoTx, typeDefinition,
|
||||||
baseType.getSimpleName());
|
baseType.getName());
|
||||||
oClass.setSuperClasses(oSuperclasses);
|
oClass.setSuperClasses(oSuperclasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Resource.class.isAssignableFrom(baseType)) {
|
if (Resource.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||||
Set<Property> properties = typeDefinition.getProperties();
|
Set<Property> properties = typeDefinition.getProperties();
|
||||||
if (properties != null && properties.size() > 0) {
|
if (properties != null && properties.size() > 0) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -264,9 +234,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
op.setNotNull(false);
|
op.setNotNull(false);
|
||||||
|
|
||||||
op.setReadonly(property.isReadonly());
|
op.setReadonly(property.isReadonly());
|
||||||
op.setRegexp(property.getRegexpr());
|
op.setRegexp(property.getRegexp());
|
||||||
if (property.getLinkedClass() != null) {
|
if (property.getLinkedClass() != null) {
|
||||||
OClass linkedClass = getEntityOClass(orientGraphNoTx,
|
OClass linkedClass = getOClass(oSchema,
|
||||||
property.getLinkedClass());
|
property.getLinkedClass());
|
||||||
if (linkedClass == null) {
|
if (linkedClass == null) {
|
||||||
logger.trace("class {} not found in schema",
|
logger.trace("class {} not found in schema",
|
||||||
|
@ -289,16 +259,15 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OClass toBeSerializedOClass = oClass;
|
OClass toBeSerializedOClass = oClass;
|
||||||
if (oClass instanceof OrientElementType) {
|
if (oClass instanceof OrientElementType) {
|
||||||
toBeSerializedOClass = getEntityOClass(orientGraphNoTx,
|
toBeSerializedOClass = getOClass(oSchema, typeDefinition.getName());
|
||||||
typeDefinition.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String ret = serializeOClass(toBeSerializedOClass);
|
String ret = getTypeDefinitionAsString(toBeSerializedOClass);
|
||||||
logger.info("{} type registered successfully: {}",
|
logger.info("{} type registered successfully: {}",
|
||||||
baseType.getSimpleName(), jsonSchema);
|
baseType.getName(), jsonSchema);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -310,8 +279,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getSchema(String type, String baseType,
|
protected String getSchema(String type, AccessType baseType,
|
||||||
boolean includeSubtypes, boolean includeSchema)
|
boolean includeSubtypes)
|
||||||
throws SchemaNotFoundException, SchemaException {
|
throws SchemaNotFoundException, SchemaException {
|
||||||
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
OrientGraphFactory orientGraphFactory = SecurityContextMapper
|
||||||
.getSecurityContextFactory(
|
.getSecurityContextFactory(
|
||||||
|
@ -324,31 +293,18 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
|
|
||||||
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
||||||
OSchema oSchema = oMetadata.getSchema();
|
OSchema oSchema = oMetadata.getSchema();
|
||||||
OClass baseOClass = getTypeSchema(oSchema, type, baseType);
|
OClass baseOClass = getTypeSchema(oSchema, type, baseType.getName());
|
||||||
|
|
||||||
String ret = null;
|
|
||||||
if (includeSubtypes) {
|
List<TypeDefinition> typeDefinitions = new ArrayList<>();
|
||||||
JSONArray jsonArray = new JSONArray();
|
Collection<OClass> oClasses = oSchema.getClasses();
|
||||||
Collection<OClass> oClasses = oSchema.getClasses();
|
for (OClass oClass : oClasses) {
|
||||||
for (OClass oClass : oClasses) {
|
if (oClass.isSubClassOf(baseOClass)) {
|
||||||
if (oClass.isSubClassOf(baseOClass)) {
|
typeDefinitions.add(getTypeDefinition(oClass));
|
||||||
if (includeSchema) {
|
|
||||||
jsonArray.put(getTypeDefinitionAsString(oClass));
|
|
||||||
} else {
|
|
||||||
jsonArray.put(oClass.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = jsonArray.toString();
|
|
||||||
} else {
|
|
||||||
if (includeSchema) {
|
|
||||||
ret = getTypeDefinitionAsString(baseOClass);
|
|
||||||
} else {
|
|
||||||
ret = baseOClass.getName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return TypeBinder.serializeTypeDefinitions(typeDefinitions);
|
||||||
} catch (SchemaException e) {
|
} catch (SchemaException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -360,184 +316,28 @@ public class SchemaManagementImpl implements SchemaManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String createEntitySchema(String jsonSchema) throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, Entity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String readEntitySchema(String entityType, boolean includeSubtypes,
|
|
||||||
boolean includeSchema) throws SchemaNotFoundException,
|
|
||||||
SchemaException {
|
|
||||||
return getSchema(entityType, Entity.NAME, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateEntitySchema(String entityType, String jsonSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteEntitySchema(String entityType)
|
|
||||||
throws SchemaNotFoundException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String createFacetSchema(String jsonSchema) throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, Facet.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String readFacetSchema(String facetType, boolean includeSubtypes,
|
|
||||||
boolean includeSchema) throws SchemaNotFoundException,
|
|
||||||
SchemaException {
|
|
||||||
return getSchema(facetType, Facet.NAME, includeSubtypes, includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateFacetSchema(String facetType, String jsonSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteFacetSchema(String facetType)
|
|
||||||
throws SchemaNotFoundException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String registerResourceSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, Resource.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getResourceSchema(String resourceType,
|
|
||||||
boolean includeSubtypes, boolean includeSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
return getSchema(resourceType, Resource.NAME, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateResourceSchema(String resourceType, String jsonSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteResourceSchema(String resourceType)
|
|
||||||
throws SchemaNotFoundException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String registerEmbeddedTypeSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, Embedded.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getEmbeddedTypeSchema(String embeddedType,
|
|
||||||
boolean includeSubtypes, boolean includeSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
return getSchema(embeddedType, Embedded.NAME, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateEmbeddedTypeSchema(String embeddedType,
|
|
||||||
String jsonSchema) throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteEmbeddedTypeSchema(String embeddedType)
|
|
||||||
throws SchemaNotFoundException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String registerRelationSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, Relation.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRelationSchema(String relationType,
|
|
||||||
boolean includeSubtypes, boolean includeSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
return getSchema(relationType, Relation.NAME, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateRelationSchema(String relationType, String jsonSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteRelationSchema(String relationType)
|
|
||||||
throws SchemaNotFoundException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String registerConsistsOfSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, ConsistsOf.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getConsistsOfSchema(String consistsOfType,
|
|
||||||
boolean includeSubtypes, boolean includeSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
return getSchema(consistsOfType, ConsistsOf.NAME, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateConsistsOfSchema(String consistsOfType,
|
|
||||||
String jsonSchema) throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteConsistsOfSchema(String consistsOfType)
|
|
||||||
throws SchemaNotFoundException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String registerIsRelatedToSchema(String jsonSchema)
|
|
||||||
throws SchemaException {
|
|
||||||
return registerTypeSchema(jsonSchema, IsRelatedTo.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIsRelatedToSchema(String isRelatedToType,
|
|
||||||
boolean includeSubtypes, boolean includeSchema)
|
|
||||||
throws SchemaNotFoundException, SchemaException {
|
|
||||||
return getSchema(isRelatedToType, IsRelatedTo.NAME, includeSubtypes,
|
|
||||||
includeSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String updateIsRelatedToSchema(String isRelatedToType,
|
|
||||||
String jsonSchema) throws SchemaNotFoundException, SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deleteIsRelatedToSchema(String isRelatedToType)
|
|
||||||
throws SchemaException {
|
|
||||||
throw new UnsupportedOperationException("Not Yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String create(String jsonSchema, AccessType accessType) throws SchemaException {
|
||||||
|
return registerTypeSchema(jsonSchema, accessType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String read(String entityType, AccessType accessType, boolean includeSubtypes) throws SchemaNotFoundException,
|
||||||
|
SchemaException {
|
||||||
|
return getSchema(entityType, accessType, includeSubtypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String update(String entityType, AccessType accessType, String jsonSchema)
|
||||||
|
throws SchemaNotFoundException, SchemaException {
|
||||||
|
throw new UnsupportedOperationException("Not Yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String delete(String entityType, AccessType accessType)
|
||||||
|
throws SchemaNotFoundException {
|
||||||
|
throw new UnsupportedOperationException("Not Yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,7 @@ import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
import org.gcube.informationsystem.model.relation.Relation;
|
||||||
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
|
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
|
||||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
import org.gcube.informationsystem.resourceregistry.rest.AccessType;
|
||||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
|
||||||
import org.gcube.informationsystem.types.TypeBinder;
|
import org.gcube.informationsystem.types.TypeBinder;
|
||||||
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -33,108 +32,112 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
*/
|
*/
|
||||||
public class SchemaManagementImplTest {
|
public class SchemaManagementImplTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SchemaManagementImplTest.class);
|
private static Logger logger = LoggerFactory
|
||||||
|
.getLogger(SchemaManagementImplTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerEmbeddedTypeSchema() throws Exception{
|
public void registerEmbeddedTypeSchema() throws Exception {
|
||||||
Class<?> clz = Header.class;
|
Class<?> clz = Header.class;
|
||||||
String json = TypeBinder.serializeType(clz);
|
String json = TypeBinder.serializeType(clz);
|
||||||
logger.trace(json);
|
logger.debug(json);
|
||||||
//new SchemaManagementImpl().registerEmbeddedTypeSchema(json);
|
//new SchemaManagementImpl().create(json, AccessType.EMBEDDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEmbeddedTypeSchema() throws Exception{
|
public void getEmbeddedTypeSchema() throws Exception {
|
||||||
String json = new SchemaManagementImpl().getEmbeddedTypeSchema(AccessPolicy.NAME, false, true);
|
String json = new SchemaManagementImpl().read(Embedded.NAME,
|
||||||
logger.trace(json);
|
AccessType.EMBEDDED, false);
|
||||||
|
logger.debug(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerFacetSchema() throws Exception{
|
public void registerFacetSchema() throws Exception {
|
||||||
Class<?> clz = ContactFacet.class;
|
Class<?> clz = ContactFacet.class;
|
||||||
String json = TypeBinder.serializeType(clz);
|
String json = TypeBinder.serializeType(clz);
|
||||||
logger.trace(json);
|
TypeBinder.deserializeTypeDefinition(json);
|
||||||
//new SchemaManagementImpl().registerFacetSchema(json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFacetSchema() throws Exception{
|
public void getFacetSchema() throws Exception {
|
||||||
String json = new SchemaManagementImpl().readFacetSchema(ContactFacet.NAME, false, true);
|
String json = new SchemaManagementImpl().read(ContactFacet.NAME,
|
||||||
|
AccessType.FACET, false);
|
||||||
logger.info(json);
|
logger.info(json);
|
||||||
TypeDefinition typeDefinition = TypeBinder.deserializeTypeDefinition(json);
|
List<TypeDefinition> typeDefinitions = TypeBinder.deserializeTypeDefinitions(json);
|
||||||
logger.info(typeDefinition.toString());
|
logger.info("{}", typeDefinitions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerEntityTypeSchema() throws Exception{
|
public void registerEntityTypeSchema() throws Exception {
|
||||||
Class<?> clz = Entity.class;
|
Class<?> clz = Entity.class;
|
||||||
String json = TypeBinder.serializeType(clz);
|
String json = TypeBinder.serializeType(clz);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
//new SchemaManagementImpl().registerEntitySchema(json);
|
// new SchemaManagementImpl().registerEntitySchema(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerResourceSchema() throws Exception{
|
public void registerResourceSchema() throws Exception {
|
||||||
Class<?> clz = Actor.class;
|
Class<?> clz = Resource.class;
|
||||||
String json = TypeBinder.serializeType(clz);
|
String json = TypeBinder.serializeType(clz);
|
||||||
logger.trace(json);
|
logger.info(json);
|
||||||
//new SchemaManagementImpl().registerFacetSchema(json);
|
// new SchemaManagementImpl().registerFacetSchema(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceSchema() throws Exception{
|
public void getResourceSchema() throws Exception {
|
||||||
String json = new SchemaManagementImpl().getResourceSchema(Actor.NAME, false, true);
|
String json = new SchemaManagementImpl().read(Actor.NAME,
|
||||||
|
AccessType.RESOURCE, false);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerRelation() throws Exception{
|
public void registerRelation() throws Exception {
|
||||||
Class<?> clz = Hosts.class;
|
Class<?> clz = Hosts.class;
|
||||||
String json = TypeBinder.serializeType(clz);
|
String json = TypeBinder.serializeType(clz);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
//new SchemaManagementImpl().registerFacetSchema(json);
|
// new SchemaManagementImpl().registerFacetSchema(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getList() throws Exception{
|
public void getList() throws Exception {
|
||||||
logger.debug("\n\n\n");
|
logger.debug("\n\n\n");
|
||||||
|
|
||||||
boolean includeSubTypes = true;
|
boolean includeSubTypes = true;
|
||||||
boolean includeSchema = true;
|
|
||||||
|
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||||
String list = schemaManagement.getEmbeddedTypeSchema(Embedded.NAME, includeSubTypes, includeSchema);
|
String list = schemaManagement.read(Embedded.NAME, AccessType.EMBEDDED,
|
||||||
|
includeSubTypes);
|
||||||
logger.debug("{} list : {}", Embedded.NAME, list);
|
logger.debug("{} list : {}", Embedded.NAME, list);
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
List<TypeDefinition> typeDefinitions = mapper.readValue(list, new TypeReference<List<TypeDefinition>>(){});
|
List<TypeDefinition> typeDefinitions = mapper.readValue(list,
|
||||||
|
new TypeReference<List<TypeDefinition>>() {
|
||||||
|
});
|
||||||
logger.debug("{}", typeDefinitions);
|
logger.debug("{}", typeDefinitions);
|
||||||
|
|
||||||
|
list = schemaManagement.read(Entity.NAME, AccessType.ENTITY,
|
||||||
|
includeSubTypes);
|
||||||
list = schemaManagement.readEntitySchema(Entity.NAME, includeSubTypes, includeSchema);
|
|
||||||
logger.debug("{} list : {}", Entity.NAME, list);
|
logger.debug("{} list : {}", Entity.NAME, list);
|
||||||
|
|
||||||
list = schemaManagement.getResourceSchema(Resource.NAME, includeSubTypes, includeSchema);
|
list = schemaManagement.read(Resource.NAME, AccessType.RESOURCE,
|
||||||
|
includeSubTypes);
|
||||||
logger.debug("{} list : {}", Resource.NAME, list);
|
logger.debug("{} list : {}", Resource.NAME, list);
|
||||||
|
|
||||||
list = schemaManagement.readFacetSchema(Facet.NAME, includeSubTypes, includeSchema);
|
list = schemaManagement.read(Facet.NAME, AccessType.FACET,
|
||||||
|
includeSubTypes);
|
||||||
logger.debug("{} list : {}", Facet.NAME, list);
|
logger.debug("{} list : {}", Facet.NAME, list);
|
||||||
|
|
||||||
|
list = schemaManagement.read(Relation.NAME, AccessType.RELATION,
|
||||||
|
includeSubTypes);
|
||||||
list = schemaManagement.getRelationSchema(Relation.NAME, includeSubTypes, includeSchema);
|
|
||||||
logger.debug("{} list : {}", Relation.NAME, list);
|
logger.debug("{} list : {}", Relation.NAME, list);
|
||||||
|
|
||||||
list = schemaManagement.getConsistsOfSchema(ConsistsOf.NAME, includeSubTypes, includeSchema);
|
list = schemaManagement.read(ConsistsOf.NAME, AccessType.CONSISTS_OF,
|
||||||
|
includeSubTypes);
|
||||||
logger.debug("{} list : {}", ConsistsOf.NAME, list);
|
logger.debug("{} list : {}", ConsistsOf.NAME, list);
|
||||||
|
|
||||||
list = schemaManagement.getIsRelatedToSchema(IsRelatedTo.NAME, includeSubTypes, includeSchema);
|
list = schemaManagement.read(IsRelatedTo.NAME,
|
||||||
|
AccessType.IS_RELATED_TO, includeSubTypes);
|
||||||
logger.debug("{} list : {}", IsRelatedTo.NAME, list);
|
logger.debug("{} list : {}", IsRelatedTo.NAME, list);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,7 @@
|
||||||
|
|
||||||
<logger name="org.gcube" level="INFO" />
|
<logger name="org.gcube" level="INFO" />
|
||||||
<logger name="org.gcube.informationsystem" level="DEBUG" />
|
<logger name="org.gcube.informationsystem" level="DEBUG" />
|
||||||
<logger name="org.gcube.informationsystem.resourceregistry" level="DEBUG" />
|
|
||||||
<logger name="org.gcube.informationsystem.resourceregistry.context" level="DEBUG" />
|
|
||||||
<logger name="org.gcube.informationsystem.impl.utils.discovery" level="ERROR" />
|
|
||||||
|
|
||||||
<root level="WARN">
|
<root level="WARN">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
</root>
|
</root>
|
||||||
|
|
Loading…
Reference in New Issue