Changed orientdb deprecated api for query

This commit is contained in:
Luca Frosini 2019-11-06 12:13:19 +01:00
parent f683681a8a
commit e59af36a4f
26 changed files with 133 additions and 124 deletions

View File

@ -153,7 +153,15 @@ public abstract class ERManagement<El extends OElement> {
checkJsonNode(); checkJsonNode();
} }
public static OClass getOClass(OElement oElement) throws SchemaException, ResourceRegistryException { public static <E extends OElement> E getElementFromOptional(Optional<E> optional) throws ResourceRegistryException {
if(optional.isPresent()) {
return optional.get();
}else {
throw new ResourceRegistryException("An element not belonging to any defined type should not exists. Please contact the administrator.");
}
}
public static OClass getOClass(OElement oElement) throws ResourceRegistryException {
Optional<OClass> optional = oElement.getSchemaType(); Optional<OClass> optional = oElement.getSchemaType();
if(optional.isPresent()) { if(optional.isPresent()) {
return optional.get(); return optional.get();

View File

@ -12,9 +12,9 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.EntityManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relation.RelationManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relation.RelationManagement;

View File

@ -11,7 +11,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.Rela
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement; import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.utils.Utility; import org.gcube.informationsystem.resourceregistry.utils.Utility;

View File

@ -1,7 +1,6 @@
package org.gcube.informationsystem.resourceregistry.instances.context; package org.gcube.informationsystem.resourceregistry.instances.context;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.UUID; import java.util.UUID;
@ -17,6 +16,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
@ -28,7 +28,8 @@ import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.record.ODirection; import com.orientechnologies.orient.core.record.ODirection;
import com.orientechnologies.orient.core.record.OVertex; import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -209,30 +210,25 @@ public class ContextUtility {
ScopeBean scopeBean = new ScopeBean(fullName); ScopeBean scopeBean = new ScopeBean(fullName);
String name = scopeBean.name(); String name = scopeBean.name();
// TODO Rewrite the query using Gremlin // TODO Rewrite better query. This query works because all the scope parts has a different name
// Please note that this query works because all the scope parts has a String select = "SELECT FROM " + Context.class.getSimpleName() + " WHERE " + Context.NAME_PROPERTY + " = :name";
// different name Map<String, String> map = new HashMap<>();
String select = "SELECT FROM " + Context.class.getSimpleName() + " WHERE " + Context.NAME_PROPERTY + " = \"" map.put("name", name);
+ name + "\"";
;
OSQLSynchQuery<OVertex> osqlSynchQuery = new OSQLSynchQuery<OVertex>(select);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
Iterable<OVertex> vertexes = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER).command(osqlSynchQuery) OResultSet resultSet = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER).query(select, map);
.execute();
if(vertexes == null || !vertexes.iterator().hasNext()) { if(resultSet == null || !resultSet.hasNext()) {
throw new ContextNotFoundException("Error retrieving context with name " + fullName); throw new ContextNotFoundException("Error retrieving context with name " + fullName);
} }
Iterator<OVertex> iterator = vertexes.iterator(); OResult oResult = resultSet.next();
OVertex context = iterator.next(); OVertex context = ERManagement.getElementFromOptional(oResult.getVertex());
logger.trace("Context Representing Vertex : {}", Utility.toJsonString(context, true)); logger.trace("Context Representing Vertex : {}", Utility.toJsonString(context, true));
if(iterator.hasNext()) { if(resultSet.hasNext()) {
throw new ContextNotFoundException("Found more than one context with name " + name throw new ContextNotFoundException("Found more than one context with name " + name
+ "but required the one with path" + fullName + ". Please Reimplement the query"); + "but required the one with path" + fullName + ". Please Reimplement the query");
} }

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.resourceregistry.instances.context.entities; package org.gcube.informationsystem.resourceregistry.instances.context.entities;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
@ -36,7 +37,7 @@ import com.orientechnologies.orient.core.record.ODirection;
import com.orientechnologies.orient.core.record.OEdge; import com.orientechnologies.orient.core.record.OEdge;
import com.orientechnologies.orient.core.record.OVertex; import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import com.orientechnologies.orient.core.sql.executor.OResultSet;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -107,7 +108,6 @@ public class ContextManagement extends BaseEntityManagement<Context> {
if(parentContext != null) { if(parentContext != null) {
String parentId = parentContext.getElement().getIdentity().toString(); String parentId = parentContext.getElement().getIdentity().toString();
// TODO Rewrite using Gremlin
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parentId String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parentId
+ " MAXDEPTH 1) WHERE " + Context.NAME_PROPERTY + "=\"" + getName() + "\" AND " + " MAXDEPTH 1) WHERE " + Context.NAME_PROPERTY + "=\"" + getName() + "\" AND "
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY + "<>\"" + parentContext.uuid + "\""; + Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY + "<>\"" + parentContext.uuid + "\"";
@ -122,23 +122,20 @@ public class ContextManagement extends BaseEntityManagement<Context> {
logger.trace("Checking if {} -> {}", message, select); logger.trace("Checking if {} -> {}", message, select);
OSQLSynchQuery<OVertex> osqlSynchQuery = new OSQLSynchQuery<OVertex>(select); OResultSet resultSet = oDatabaseDocument.command(select, new HashMap<>());
Iterable<OVertex> vertexes = oDatabaseDocument.command(osqlSynchQuery).execute();
if(vertexes != null && vertexes.iterator().hasNext()) { if(resultSet != null && resultSet.hasNext()) {
throw new ContextAlreadyPresentException(message.toString()); throw new ContextAlreadyPresentException(message.toString());
} }
} else { } else {
// TODO Rewrite using Gremlin
String select = "SELECT FROM " + Context.NAME + " WHERE " String select = "SELECT FROM " + Context.NAME + " WHERE "
+ Context.NAME_PROPERTY + " = \"" + getName() + "\"" + " AND in(\"" + IsParentOf.NAME + Context.NAME_PROPERTY + " = \"" + getName() + "\"" + " AND in(\"" + IsParentOf.NAME
+ "\").size() = 0"; + "\").size() = 0";
OSQLSynchQuery<OVertex> osqlSynchQuery = new OSQLSynchQuery<OVertex>(select); OResultSet resultSet = oDatabaseDocument.command(select, new HashMap<>());
Iterable<OVertex> vertexes = oDatabaseDocument.command(osqlSynchQuery).execute();
if(vertexes != null && vertexes.iterator().hasNext()) { if(resultSet != null && resultSet.hasNext()) {
throw new ContextAlreadyPresentException( throw new ContextAlreadyPresentException(
"A root context with the same name (" + this.getName() + ") already exist"); "A root context with the same name (" + this.getName() + ") already exist");
} }

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.instances.model.entity; package org.gcube.informationsystem.resourceregistry.instances.model.entities;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -40,7 +40,8 @@ import com.orientechnologies.orient.core.record.OEdge;
import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.OVertex; import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -387,10 +388,11 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
String select = selectStringBuilder.toString(); String select = selectStringBuilder.toString();
logger.trace(select); logger.trace(select);
OSQLSynchQuery<OElement> osqlSynchQuery = new OSQLSynchQuery<OElement>(select); OResultSet resultSet = oDatabaseDocument.command(select,new HashMap<>());
Iterable<OElement> elements = oDatabaseDocument.command(osqlSynchQuery).execute();
for(OElement element : elements) { while(resultSet.hasNext()) {
OResult oResult = resultSet.next();
OElement element = ERManagement.getElementFromOptional(oResult.getElement());
if(polymorphic) { if(polymorphic) {
OClass oClass = null; OClass oClass = null;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.instances.model.entity; package org.gcube.informationsystem.resourceregistry.instances.model.entities;
import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.instances.model.entity; package org.gcube.informationsystem.resourceregistry.instances.model.entities;
import java.util.Iterator; import java.util.Iterator;

View File

@ -13,7 +13,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfNotFoundException;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.document.ODatabaseDocument;

View File

@ -12,7 +12,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.document.ODatabaseDocument;

View File

@ -21,9 +21,9 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement; import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.EntityManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient; import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient;

View File

@ -1,5 +1,8 @@
package org.gcube.informationsystem.resourceregistry.query; package org.gcube.informationsystem.resourceregistry.query;
import java.util.HashMap;
import java.util.Map;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
@ -17,8 +20,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.record.OElement; import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import com.orientechnologies.orient.core.sql.executor.OResultSet;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -34,35 +37,46 @@ public class QueryImpl implements Query {
} }
limit = (limit <= 0) ? AccessPath.UNBOUNDED : limit; limit = (limit <= 0) ? AccessPath.UNBOUNDED : limit;
ODatabaseDocument orientGraph = null; ODatabaseDocument oDatabaseDocument = null;
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {
SecurityContext securityContext = ContextUtility.getCurrentSecurityContext(); SecurityContext securityContext = ContextUtility.getCurrentSecurityContext();
orientGraph = securityContext.getDatabaseDocument(PermissionMode.READER); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.READER);
orientGraph.begin(); oDatabaseDocument.begin();
OSQLSynchQuery<ODocument> osqlSynchQuery = new OSQLSynchQuery<>(query, limit); StringBuffer stringBuffer = new StringBuffer();
osqlSynchQuery.setFetchPlan(fetchPlan); stringBuffer.append(query);
osqlSynchQuery.setCacheableResult(true); stringBuffer.append(" limit :limit");
logger.debug("Going to execute query : \"{}\", fetchPlan : \"{}\", limit : {}", osqlSynchQuery.getText(), Map<String, Object> map = new HashMap<>();
osqlSynchQuery.getFetchPlan(), osqlSynchQuery.getLimit()); map.put("limit", limit);
Iterable<OElement> elements = orientGraph.command(osqlSynchQuery).execute(); if(fetchPlan!=null) {
stringBuffer.append(" fetchplan ");
stringBuffer.append(fetchPlan);
logger.debug("Going to execute query '{} limit {} fetchPlan {}'", query, limit, fetchPlan);
}else {
logger.debug("Going to execute query '{} limit {}'", query, limit);
}
OResultSet resultSet = oDatabaseDocument.query(stringBuffer.toString(), map);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = objectMapper.createArrayNode(); ArrayNode arrayNode = objectMapper.createArrayNode();
while(resultSet.hasNext()) {
OResult oResult = resultSet.next();
OElement element = ERManagement.getElementFromOptional(oResult.getElement());
for(OElement element : elements) {
try { try {
JsonNode jsonNode = null; JsonNode jsonNode = null;
if(raw) { if(raw) {
jsonNode = Utility.toJsonNode(element, false); jsonNode = Utility.toJsonNode(element, false);
} else { } else {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ERManagement erManagement = ERManagementUtility.getERManagement(securityContext, orientGraph, ERManagement erManagement = ERManagementUtility.getERManagement(securityContext, oDatabaseDocument,
element); element);
jsonNode = erManagement.serializeAsJson(); jsonNode = erManagement.serializeAsJson();
} }
@ -79,8 +93,11 @@ public class QueryImpl implements Query {
} catch(Exception e) { } catch(Exception e) {
throw new InvalidQueryException(e.getMessage()); throw new InvalidQueryException(e.getMessage());
} finally { } finally {
if(orientGraph != null) { if(oDatabaseDocument != null) {
orientGraph.close(); oDatabaseDocument.close();
}
if(current!=null) {
current.activateOnCurrentThread();
} }
} }

View File

@ -37,7 +37,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement; import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl; import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
import org.gcube.informationsystem.resourceregistry.query.Query; import org.gcube.informationsystem.resourceregistry.query.Query;

View File

@ -1,6 +1,6 @@
package org.gcube.informationsystem.resourceregistry.utils; package org.gcube.informationsystem.resourceregistry.utils;
import java.util.Iterator; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.properties.BaseProperty;
@ -9,6 +9,7 @@ import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
@ -24,7 +25,8 @@ import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.OVertex; import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -97,21 +99,22 @@ public class Utility {
String select = "SELECT FROM " + elementType + " WHERE " + Relation.HEADER_PROPERTY + "." + Header.UUID_PROPERTY String select = "SELECT FROM " + elementType + " WHERE " + Relation.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
+ " = \"" + uuid.toString() + "\""; + " = \"" + uuid.toString() + "\"";
OSQLSynchQuery<El> osqlSynchQuery = new OSQLSynchQuery<>(select); OResultSet resultSet = oDatabaseDocument.query(select, new HashMap<>());
Iterable<El> elements = oDatabaseDocument.command(osqlSynchQuery).execute();
if(elements == null || !elements.iterator().hasNext()) { if(resultSet == null || !resultSet.hasNext()) {
String error = String.format("No %s with UUID %s was found", elementType, uuid.toString()); String error = String.format("No %s with UUID %s was found", elementType, uuid.toString());
logger.info(error); logger.info(error);
throw new NotFoundException(error); throw new NotFoundException(error);
} }
Iterator<El> iterator = elements.iterator(); OResult oResult = resultSet.next();
El element = iterator.next(); @SuppressWarnings("unchecked")
El element = (El) ERManagement.getElementFromOptional(oResult.getElement());
logger.trace("{} with id {} is : {}", elementType, uuid.toString(), Utility.toJsonString(element, true)); logger.trace("{} with id {} is : {}", elementType, uuid.toString(), Utility.toJsonString(element, true));
if(iterator.hasNext()) { if(resultSet.hasNext()) {
throw new ResourceRegistryException("Found more than one " + elementType + " with uuid " + uuid.toString() throw new ResourceRegistryException("Found more than one " + elementType + " with uuid " + uuid.toString()
+ ". This is a fatal error please contact Admnistrator"); + ". This is a fatal error please contact Admnistrator");
} }

View File

@ -1,31 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.access;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class QueryImplTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(QueryImplTest.class);
@Test
public void testQuery() throws InvalidQueryException{
QueryImpl queryImpl = new QueryImpl();
String query = "select * from SoftwareFacet";
String ret = queryImpl.query(query, -7, null, false);
logger.debug(ret);
}
}

View File

@ -13,9 +13,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagementTest;
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement; import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagementTest;
import org.gcube.informationsystem.resourceregistry.security.ContextSecurityContext; import org.gcube.informationsystem.resourceregistry.security.ContextSecurityContext;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.er; package org.gcube.informationsystem.resourceregistry.instances;
import org.gcube.informationsystem.base.reference.ER; import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.er; package org.gcube.informationsystem.resourceregistry.instances;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.gcube.informationsystem.resourceregistry.er; package org.gcube.informationsystem.resourceregistry.instances;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -35,8 +35,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.er; package org.gcube.informationsystem.resourceregistry.instances;
import java.security.Key; import java.security.Key;

View File

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.gcube.informationsystem.resourceregistry.er; package org.gcube.informationsystem.resourceregistry.instances;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -35,7 +35,7 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy; import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
import org.gcube.informationsystem.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.ContainerStateFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.ContainerStateFacetImpl;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.er.entity; package org.gcube.informationsystem.resourceregistry.instances.model.entity;
import java.util.UUID; import java.util.UUID;
@ -9,9 +9,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility; import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.gcube.informationsystem.resourceregistry.er.ERManagementTest; import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility; import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.er.entity; package org.gcube.informationsystem.resourceregistry.instances.model.entity;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -12,7 +12,7 @@ import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;

View File

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.gcube.informationsystem.resourceregistry.er.multicontext; package org.gcube.informationsystem.resourceregistry.instances.multicontext;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -22,10 +22,10 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.er.SmartgearResourcesTest; import org.gcube.informationsystem.resourceregistry.instances.SmartgearResourcesTest;
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.resourceregistry.er.multicontext; package org.gcube.informationsystem.resourceregistry.instances.multicontext;
import java.util.UUID; import java.util.UUID;
@ -8,8 +8,8 @@ import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
import org.gcube.informationsystem.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;

View File

@ -1,19 +1,36 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.query; package org.gcube.informationsystem.resourceregistry.query;
import org.gcube.informationsystem.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class QueryTest extends ContextTest { public class QueryTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(QueryTest.class); private static Logger logger = LoggerFactory.getLogger(QueryTest.class);
//@Test @Test
public void testGremlinQuery() throws InvalidQueryException { public void testQuery() throws InvalidQueryException{
Query query = new QueryImpl(); QueryImpl queryImpl = new QueryImpl();
String ret = query.gremlinQuery("g.V()");
logger.debug("Gremlin Query Result is : {}", ret); String query = "select from SoftwareFacet";
String ret = queryImpl.query(query, -7, AccessPath.DEFAULT_FETCH_PLAN_PARAM, false);
logger.debug(ret);
ret = queryImpl.query(query, -7, null, false);
logger.debug(ret);
} }
} }