From fa503eb8286d6fcd83c6fb29914424c8015ab525 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 18 Jul 2022 14:19:05 +0200 Subject: [PATCH] Fixing raw query --- .../dbinitialization/DatabaseEnvironment.java | 5 ++++- .../resourceregistry/queries/QueryImpl.java | 12 +++++++++--- .../resourceregistry/rest/Access.java | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java index 9f15cf0..149a0ba 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java @@ -170,7 +170,7 @@ public class DatabaseEnvironment { DEFAULT_PASSWORDS.put(PermissionMode.WRITER, DEFAULT_CREATED_WRITER_USER_PASSWORD); DEFAULT_PASSWORDS.put(PermissionMode.READER, DEFAULT_CREATED_READER_USER_PASSWORD); - } catch(Exception e) { + } catch(Throwable e) { logger.error("Unable to load properties from {}", PROPERTY_FILENAME); throw new RuntimeException("Unable to load properties", e); } @@ -288,6 +288,8 @@ public class DatabaseEnvironment { oDatabaseDocument.set(ATTRIBUTES.DATETIMEFORMAT, Element.DATETIME_PATTERN); } + @Deprecated + // This code must be removed for OrientDB versions higher than 3.2.X protected static void setRecordLevelSecurity(OMetadata oMetadata) { logger.trace( "Setting Record-level Security (see https://orientdb.org/docs/3.2.x/security/Database-Security.html#record-level-security-deprecated-in-v-31)"); @@ -383,6 +385,7 @@ public class DatabaseEnvironment { logger.trace("Updated password for user {}", permissionMode.toString()); }catch (Exception e) { logger.trace("Unable to update password for user {}. {}", permissionMode.toString(), e.getMessage()); + throw new RuntimeException(e); } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java index a1d588c..bcb12df 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java @@ -68,13 +68,19 @@ public class QueryImpl implements Query { while(resultSet.hasNext()) { OResult oResult = resultSet.next(); - OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement()); try { JsonNode jsonNode = null; if(raw) { - jsonNode = Utility.toJsonNode(element, false); + if(oResult.isElement()) { + OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement()); + jsonNode = Utility.toJsonNode(element, false); + }else { + ObjectMapper mapper = new ObjectMapper(); + jsonNode = mapper.readTree(oResult.toJSON()); + } } else { + OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement()); ElementManagement erManagement = ElementManagementUtility.getERManagement(securityContext, oDatabaseDocument, element); jsonNode = erManagement.serializeAsJsonNode(); @@ -83,7 +89,7 @@ public class QueryImpl implements Query { } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", - element.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); + oResult.toJSON(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java index 79bf40a..460f896 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java @@ -233,6 +233,7 @@ public class Access extends BaseRest { * * https://orientdb.com/docs/last/Fetching-Strategies.html * + * @param raw request a raw response (not a Element based response) * @return The JSON representation of the result * @throws InvalidQueryException if the query is invalid or not idempotent */ @@ -244,7 +245,7 @@ public class Access extends BaseRest { @QueryParam(AccessPath.FETCH_PLAN_PARAM) @DefaultValue(AccessPath.DEFAULT_FETCH_PLAN_PARAM) String fetchPlan, @QueryParam(AccessPath.RAW_PARAM) @DefaultValue(AccessPath.DEFAULT_RAW_PARAM) Boolean raw) throws InvalidQueryException { - logger.info("Requested query (fetch plan {}, limit : {}, Raw : raw):\n{}", fetchPlan, limit, query, raw); + logger.info("Requested query (fetch plan {}, limit {}, Raw {}):\n{}", fetchPlan, limit, raw, query); CalledMethodProvider.instance.set("graphQuery"); checkHierarchicalMode();