Fixed Relations names

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@141322 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-12-21 15:28:16 +00:00
parent 7c4625c2d9
commit 45e11a3806
5 changed files with 271 additions and 52 deletions

View File

@ -39,9 +39,9 @@ public class EntityRegistrationAction implements ERAction {
String json = TypeBinder.serializeType(r);
logger.trace(json);
if (ConsistsOf.class.isAssignableFrom(r)) {
schemaManagement.registerConsistOfSchema(json);
schemaManagement.registerConsistsOfSchema(json);
} else if(IsRelatedTo.class.isAssignableFrom(r)){
schemaManagement.registerRelatedToSchema(json);
schemaManagement.registerIsRelatedToSchema(json);
} else {
schemaManagement.registerRelationSchema(json);
}

View File

@ -7,6 +7,11 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.gcube.informationsystem.model.embedded.Embedded;
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.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
@ -21,7 +26,6 @@ import org.slf4j.LoggerFactory;
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
public class SchemaManager {
private static Logger logger = LoggerFactory.getLogger(SchemaManager.class);
protected SchemaManagement schemaManager = new SchemaManagementImpl();
@ -32,16 +36,19 @@ public class SchemaManager {
* BODY: {...}
*
* ?schema={...}
*
* @param jsonSchema
* @return
* @throws SchemaException
*/
@PUT
@Path(SchemaPath.EMBEDDED_PATH_PART)
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String registerEmbeddedTypeSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested Embedded registration with schema {}",jsonSchema);
public String registerEmbeddedTypeSchema(String jsonSchema)
throws SchemaException {
logger.trace("Requested {} registration with schema {}", Embedded.NAME,
jsonSchema);
return schemaManager.registerEmbeddedTypeSchema(jsonSchema);
}
@ -56,10 +63,11 @@ public class SchemaManager {
*/
@PUT
@Path(SchemaPath.FACET_PATH_PART)
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String registerFacetSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested Facet registration with schema {}",jsonSchema);
logger.trace("Requested {} registration with schema {}", Facet.NAME,
jsonSchema);
return schemaManager.registerFacetSchema(jsonSchema);
}
@ -75,15 +83,17 @@ public class SchemaManager {
*/
@PUT
@Path(SchemaPath.RESOURCE_PATH_PART)
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String registerResourceSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested Resource registration with schema {}",jsonSchema);
public String registerResourceSchema(String jsonSchema)
throws SchemaException {
logger.trace("Requested {} registration with schema {}", Resource.NAME,
jsonSchema);
return schemaManager.registerResourceSchema(jsonSchema);
}
/**
* e.g. PUT /resource-registry/schema/consistOf
* e.g. PUT /resource-registry/schema/consistsOf
*
* BODY: {...}
*
@ -92,16 +102,18 @@ public class SchemaManager {
* @throws SchemaException
*/
@PUT
@Path(SchemaPath.CONSIST_OF_PATH_PART)
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@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 ConsistOf registration with schema {} ",jsonSchema);
return schemaManager.registerConsistOfSchema(jsonSchema);
public String registerConsistOfSchema(String jsonSchema)
throws SchemaException {
logger.trace("Requested {} registration with schema {} ",
ConsistsOf.NAME, jsonSchema);
return schemaManager.registerConsistsOfSchema(jsonSchema);
}
/**
* e.g. PUT /resource-registry/schema/relatedTo
* e.g. PUT /resource-registry/schema/isRelatedTo
*
* BODY: {...}
*
@ -110,12 +122,14 @@ public class SchemaManager {
* @throws SchemaException
*/
@PUT
@Path(SchemaPath.RELATED_TO_PATH_PART)
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@Path(SchemaPath.IS_RELATED_TO_PATH_PART)
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String registerRelatedToSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested RelatedTo registration with schema {} ",jsonSchema);
return schemaManager.registerRelatedToSchema(jsonSchema);
public String registerIsRelatedToSchema(String jsonSchema)
throws SchemaException {
logger.trace("Requested {} registration with schema {} ",
IsRelatedTo.NAME, jsonSchema);
return schemaManager.registerIsRelatedToSchema(jsonSchema);
}
}

View File

@ -4,9 +4,13 @@
package org.gcube.informationsystem.resourceregistry.resources.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
@ -44,6 +48,7 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
* TODO Create an instance for each Registered Type in a management
* SecurityContext so that that management context can be used to see
* Entity and Relations as graph.
*
*/
public class SchemaManagementImpl implements SchemaManagement {
@ -99,8 +104,17 @@ public class SchemaManagementImpl implements SchemaManagement {
}
}
protected static String serializeOClass(OClass oClass)
protected static JSONObject serializeOClassAsJSON(OClass oClass)
throws SchemaException {
String jsonString = serializeOClass(oClass);
try {
return new JSONObject(jsonString);
} catch (JSONException e) {
throw new SchemaException(e);
}
}
protected static String serializeOClass(OClass oClass) {
ODocument oDocument = ((OClassImpl) oClass).toStream();
return oDocument.toJSON();
}
@ -195,8 +209,7 @@ public class SchemaManagementImpl implements SchemaManagement {
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(
orientGraphNoTx,
typeDefinition,
baseType == Embedded.class ? null : baseType
.getSimpleName());
baseType.getSimpleName());
oClass.setSuperClasses(oSuperclasses);
if (Resource.class.isAssignableFrom(baseType)) {
@ -267,6 +280,65 @@ public class SchemaManagementImpl implements SchemaManagement {
}
}
protected String getListOfType(String type, String baseType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
OrientGraphFactory orientGraphFactory = SecurityContextMapper
.getSecurityContextFactory(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
PermissionMode.WRITER);
OrientGraphNoTx orientGraphNoTx = null;
try {
orientGraphNoTx = orientGraphFactory.getNoTx();
JSONArray jsonArray = new JSONArray();
OClass baseOClass = null;
if(baseType.compareTo(Embedded.NAME)!=0){
baseOClass = getTypeSchema(orientGraphNoTx, type, baseType);
if (includeSchema) {
jsonArray.put(serializeOClassAsJSON(baseOClass));
} else {
jsonArray.put(baseOClass.getName());
}
}
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
OSchema oSchema = oMetadata.getSchema();
Collection<OClass> oClasses = oSchema.getClasses();
for (OClass oClass : oClasses) {
if(baseType.compareTo(Embedded.NAME)!=0){
if (oClass.isSubClassOf(baseOClass)) {
if (includeSchema) {
jsonArray.put(serializeOClassAsJSON(oClass));
} else {
jsonArray.put(oClass.getName());
}
}
}else{
if (!oClass.isSubClassOf("V") && !oClass.isSubClassOf("E")) {
if (includeSchema) {
jsonArray.put(serializeOClassAsJSON(oClass));
} else {
jsonArray.put(oClass.getName());
}
}
}
}
return jsonArray.toString();
} catch (SchemaException e) {
throw e;
} catch (Exception e) {
throw new SchemaException(e);
} finally {
if (orientGraphNoTx != null) {
orientGraphNoTx.shutdown();
}
}
}
@Override
public String registerEntitySchema(String jsonSchema)
throws SchemaException {
@ -291,6 +363,12 @@ public class SchemaManagementImpl implements SchemaManagement {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String getEntityTypes(String baseEntityType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(baseEntityType, Entity.NAME, includeSchema);
}
@Override
public String registerFacetSchema(String jsonSchema) throws SchemaException {
return registerTypeSchema(jsonSchema, Facet.class);
@ -314,6 +392,12 @@ public class SchemaManagementImpl implements SchemaManagement {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String getFacetTypes(String baseFacetType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(baseFacetType, Facet.NAME, includeSchema);
}
@Override
public String registerResourceSchema(String jsonSchema)
throws SchemaException {
@ -338,6 +422,12 @@ public class SchemaManagementImpl implements SchemaManagement {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String getResourceTypes(String baseResourceType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(baseResourceType, Resource.NAME, includeSchema);
}
@Override
public String registerEmbeddedTypeSchema(String jsonSchema)
throws SchemaException {
@ -362,6 +452,12 @@ public class SchemaManagementImpl implements SchemaManagement {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String getEmbeddedTypes(String embeddedType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(embeddedType, Embedded.NAME, includeSchema);
}
@Override
public String registerRelationSchema(String jsonSchema)
throws SchemaException {
@ -387,51 +483,70 @@ public class SchemaManagementImpl implements SchemaManagement {
}
@Override
public String registerConsistOfSchema(String jsonSchema)
public String getRelationTypes(String baseRelationType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(baseRelationType, Relation.NAME, includeSchema);
}
@Override
public String registerConsistsOfSchema(String jsonSchema)
throws SchemaException {
return registerTypeSchema(jsonSchema, ConsistsOf.class);
}
@Override
public String getConsistOfSchema(String consistOfType)
public String getConsistsOfSchema(String consistsOfType)
throws SchemaNotFoundException {
return getTypeSchemaAsString(consistOfType, ConsistsOf.NAME);
return getTypeSchemaAsString(consistsOfType, ConsistsOf.NAME);
}
@Override
public String updateConsistOfSchema(String consistOfType, String jsonSchema)
public String updateConsistsOfSchema(String consistsOfType, String jsonSchema)
throws SchemaNotFoundException, SchemaException {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String deleteConsistOfSchema(String consistOfType)
public String deleteConsistsOfSchema(String consistsOfType)
throws SchemaNotFoundException {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String registerRelatedToSchema(String jsonSchema)
public String getConsistsOfTypes(String consistsOfType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(consistsOfType, ConsistsOf.NAME, includeSchema);
}
@Override
public String registerIsRelatedToSchema(String jsonSchema)
throws SchemaException {
return registerTypeSchema(jsonSchema, IsRelatedTo.class);
}
@Override
public String getRelatedToSchema(String relatedToType)
public String getIsRelatedToSchema(String isRelatedToType)
throws SchemaNotFoundException {
return getTypeSchemaAsString(relatedToType, IsRelatedTo.NAME);
return getTypeSchemaAsString(isRelatedToType, IsRelatedTo.NAME);
}
@Override
public String updateRelatedToSchema(String relatedToType, String jsonSchema)
throws SchemaNotFoundException, SchemaException {
public String updateIsRelatedToSchema(String isRelatedToType,
String jsonSchema) throws SchemaNotFoundException, SchemaException {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String deleteRelatedToSchema(String relatedToType)
public String deleteIsRelatedToSchema(String isRelatedToType)
throws SchemaException {
throw new UnsupportedOperationException("Not Yet implemented");
}
@Override
public String getIsRelatedToTypes(String isRelatedToType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
return getListOfType(isRelatedToType, IsRelatedTo.NAME, includeSchema);
}
}

View File

@ -162,21 +162,21 @@ public class EntityRegistrationFactory implements Factory<SchemaManagement>{
}
@Override
public String registerConsistOfSchema(String jsonSchema)
public String registerConsistsOfSchema(String jsonSchema)
throws SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getConsistOfSchema(String consistOfType)
public String getConsistsOfSchema(String consistsOfType)
throws SchemaNotFoundException {
// TODO Auto-generated method stub
return null;
}
@Override
public String updateConsistOfSchema(String consistOfType,
public String updateConsistsOfSchema(String consistsOfType,
String jsonSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
@ -184,28 +184,28 @@ public class EntityRegistrationFactory implements Factory<SchemaManagement>{
}
@Override
public String deleteConsistOfSchema(String consistOfType)
public String deleteConsistsOfSchema(String consistsOfType)
throws SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String registerRelatedToSchema(String jsonSchema)
public String registerIsRelatedToSchema(String jsonSchema)
throws SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getRelatedToSchema(String relatedToType)
public String getIsRelatedToSchema(String isRelatedToType)
throws SchemaNotFoundException {
// TODO Auto-generated method stub
return null;
}
@Override
public String updateRelatedToSchema(String relatedToType,
public String updateIsRelatedToSchema(String isRelatedToType,
String jsonSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
@ -213,13 +213,66 @@ public class EntityRegistrationFactory implements Factory<SchemaManagement>{
}
@Override
public String deleteRelatedToSchema(String relatedToType)
public String deleteIsRelatedToSchema(String isRelatedToType)
throws SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getEntityTypes(String entityType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getFacetTypes(String facetType, boolean includeSchema)
throws SchemaNotFoundException, SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getResourceTypes(String resourceType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getEmbeddedTypes(String embeddedType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getRelationTypes(String relationType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getConsistsOfTypes(String consistsOfType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getIsRelatedToTypes(String isRelatedToType,
boolean includeSchema) throws SchemaNotFoundException,
SchemaException {
// TODO Auto-generated method stub
return null;
}
};
}

View File

@ -4,11 +4,18 @@
package org.gcube.informationsystem.resourceregistry.resources.impl;
import org.gcube.informationsystem.model.embedded.AccessPolicy;
import org.gcube.informationsystem.model.embedded.Embedded;
import org.gcube.informationsystem.model.embedded.Header;
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.facet.ContactFacet;
import org.gcube.informationsystem.model.entity.resource.Actor;
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.isrelatedto.Hosts;
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
import org.gcube.informationsystem.types.TypeBinder;
import org.junit.Test;
import org.slf4j.Logger;
@ -80,4 +87,34 @@ public class SchemaManagementImplTest {
logger.trace(json);
//new SchemaManagementImpl().registerFacetSchema(json);
}
@Test
public void getList() throws Exception{
SchemaManagement schemaManagement = new SchemaManagementImpl();
String list = schemaManagement.getEmbeddedTypes(Embedded.NAME, false);
logger.debug("{} list : {}", Embedded.NAME, list);
list = schemaManagement.getEntityTypes(Entity.NAME, false);
logger.debug("{} list : {}", Entity.NAME, list);
list = schemaManagement.getResourceTypes(Resource.NAME, false);
logger.debug("{} list : {}", Resource.NAME, list);
list = schemaManagement.getFacetTypes(Facet.NAME, false);
logger.debug("{} list : {}", Facet.NAME, list);
list = schemaManagement.getRelationTypes(Relation.NAME, false);
logger.debug("{} list : {}", Relation.NAME, list);
list = schemaManagement.getConsistsOfTypes(ConsistsOf.NAME, false);
logger.debug("{} list : {}", ConsistsOf.NAME, list);
list = schemaManagement.getIsRelatedToTypes(IsRelatedTo.NAME, false);
logger.debug("{} list : {}", IsRelatedTo.NAME, list);
}
}