Fixing raw query

This commit is contained in:
Luca Frosini 2022-07-18 14:19:05 +02:00
parent 0ffca0008e
commit fa503eb828
3 changed files with 15 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -233,6 +233,7 @@ public class Access extends BaseRest {
* <a href="https://orientdb.com/docs/last/Fetching-Strategies.html" target="_blank">
* https://orientdb.com/docs/last/Fetching-Strategies.html
* </a>
* @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();