public void fetchChildResources()

in data-resource-management-service/drms-graph-impl/drms-api/src/main/java/org/apache/airavata/drms/api/handlers/ResourceServiceHandler.java [235:296]


    public void fetchChildResources(ChildResourceFetchRequest request,
                                    StreamObserver<ChildResourceFetchResponse> responseObserver) {
        try {
            AuthenticatedUser callUser = request.getAuthToken().getAuthenticatedUser();

            String resourceId = request.getResourceId();
            String type = request.getType();
            int depth = request.getDepth();
            if (type == null || type.isEmpty()) {
                type = "";
            } else {
                type = ":" + type;
            }

            Map<String, Object> userProps = new HashMap<>();
            userProps.put("username", callUser.getUsername());
            userProps.put("tenantId", callUser.getTenantId());
            userProps.put("entityId", resourceId);

//            String query = " MATCH (u:User),  (r" + type + ") where u.username = $username AND u.tenantId = $tenantId AND " +
//                    " r.entityId = $entityId AND r.tenantId = $tenantId" +
//                    " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)" +
//                    " OPTIONAL MATCH (u)<-[crRel:SHARED_WITH]-(r)<-[:CHILD_OF*]-(cr)" +
//                    " OPTIONAL MATCH (g)<-[chgrRel:SHARED_WITH]-(r)<-[:CHILD_OF*]-(chgr)" +
//                    " OPTIONAL MATCH (u)<-[prRelU:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*]-(r)<-[:CHILD_OF]-(x)" +
//                    " OPTIONAL MATCH (g)<-[prRelG:SHARED_WITH]-(prg:COLLECTION)<-[:CHILD_OF*]-(r)<-[:CHILD_OF]-(y)" +
//                    " return distinct  cr,crRel, chgr,chgrRel, x, prRelU,y,prRelG";
//
//            if (depth == 1) {
            String query = " MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId with u  " +
                    " Match (r" + type + ") where r.entityId = $entityId AND r.tenantId = $tenantId with u, r" +
                    " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)" +
                    " OPTIONAL MATCH (u)<-[crRel:SHARED_WITH]-(r)<-[:CHILD_OF]-(cr)" +
                    " OPTIONAL MATCH (g)<-[chgrRel:SHARED_WITH]-(r)<-[:CHILD_OF]-(chgr)" +
                    " OPTIONAL MATCH (u)<-[prRelU:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*]-(r)<-[:CHILD_OF]-(x)" +
                    " OPTIONAL MATCH (g)<-[prRelG:SHARED_WITH]-(prg:COLLECTION)<-[:CHILD_OF*]-(r)<-[:CHILD_OF]-(y)" +
                    " return distinct  cr,crRel, chgr,chgrRel, x, prRelU,y,prRelG";
//            }

            logger.debug("Fetch child query {}", query);


            List<Record> records = this.neo4JConnector.searchNodes(userProps, query);
            List keyList = new ArrayList();
            keyList.add("cr:crRel");
            keyList.add("chgr:chgrRel");
            keyList.add("chcgr:chcgrRel");
            keyList.add("x:prRelU");
            keyList.add("y:prRelG");
            List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
            ChildResourceFetchResponse.Builder builder = ChildResourceFetchResponse.newBuilder();
            builder.addAllResources(genericResourceList);
            responseObserver.onNext(builder.build());
            responseObserver.onCompleted();


        } catch (Exception ex) {
            logger.error("Error occurred while fetching child resource {}", request.getResourceId(), ex);
            responseObserver.onError(Status.INTERNAL.withDescription("Error occurred while fetching child resource"
                    + ex.getMessage()).asRuntimeException());
        }
    }