in data-resource-management-service/drms-graph-impl/drms-api/src/main/java/org/apache/airavata/drms/api/handlers/ResourceServiceHandler.java [893:943]
public void addResourceMetadata(AddResourceMetadataRequest request, StreamObserver<Empty> responseObserver) {
try {
AuthenticatedUser callUser = request.getAuthToken().getAuthenticatedUser();
String parentResourceId = request.getResourceId();
String type = request.getType();
Struct struct = request.getMetadata();
String message = JsonFormat.printer().print(struct);
JSONObject json = new JSONObject(message);
Map<String, Object> map = json.toMap();
mergeProperties(parentResourceId, type, callUser.getTenantId(), parentResourceId, map);
Map<String, Object> parameters = new HashMap<>();
Map<String, Object> properties = new HashMap<>();
// parameters.put("props", properties);
parameters.put("parentResourceId", parentResourceId);
parameters.put("resourceId", UUID.randomUUID().toString());
parameters.put("tenantId", callUser.getTenantId());
if (type == null || type.isEmpty()) {
type = "";
} else {
type = ":" + type;
}
Optional<List<String>> jsonList = readMetadata(parentResourceId, type, callUser.getTenantId());
if (jsonList.isPresent() && !jsonList.get().isEmpty()) {
String oldJSON = jsonList.get().get(0);
message = mergeJSON(oldJSON, message);
}
parameters.put("metadata", message);
String query = " MATCH (r" + type + ") where r.entityId= $parentResourceId AND r.tenantId= $tenantId with r" +
" MERGE (r)-[:HAS_FULL_METADATA]->(cr:FULL_METADATA_NODE{tenantId: $tenantId}) ON CREATE SET cr.metadata= $metadata " +
" ON MATCH SET cr.metadata = $metadata";
this.neo4JConnector.runTransactionalQuery(parameters, query);
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
} catch (Exception ex) {
String msg = " Error occurred while adding resource metadata " + ex.getMessage();
// Issue https://github.com/neo4j/neo4j-java-driver/issues/773
logger.error("Error occurred while adding resource metadata: Messages {}", ex.getMessage());
responseObserver.onError(Status.INTERNAL.withDescription(msg).asRuntimeException());
}
}