You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by is...@apache.org on 2021/09/14 03:56:12 UTC

[airavata-data-lake] branch master updated: Bug fix in resource search

This is an automated email from the ASF dual-hosted git repository.

isjarana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-data-lake.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ddc6ef  Bug fix in resource search
     new 6deb7db  Merge pull request #74 from isururanawaka/sharing_service_impl
5ddc6ef is described below

commit 5ddc6ef6e1afe75d175d7b1c5ab58b292a196eae
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Mon Sep 13 23:55:19 2021 -0400

    Bug fix in resource search
---
 .../drms/api/handlers/ResourceServiceHandler.java  | 227 +++++++++++++++------
 .../org/apache/airavata/drms/api/utils/Utils.java  | 155 +++++++++++---
 2 files changed, 292 insertions(+), 90 deletions(-)

diff --git a/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/handlers/ResourceServiceHandler.java b/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/handlers/ResourceServiceHandler.java
index 63b70eb..21a0882 100644
--- a/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/handlers/ResourceServiceHandler.java
+++ b/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/handlers/ResourceServiceHandler.java
@@ -428,72 +428,102 @@ public class ResourceServiceHandler extends ResourceServiceGrpc.ResourceServiceI
             List keyList = new ArrayList();
             if (!resourceSearchQueries.isEmpty()) {
 
+                keyList = new ArrayList();
+                Map<String, Map<String, String>> searchParameterMap = new HashMap<>();
+
                 for (ResourceSearchQuery qry : resourceSearchQueries) {
                     if (qry.getField().equals("storageId")) {
                         storageList.clear();
                         storageList.add(qry.getValue());
+                    } else if (qry.getField().equals("sharedBy")) {
+                        searchParameterMap.computeIfAbsent("sharedBy", map -> new HashMap<>()).put("username", qry.getValue());
+                    } else if (qry.getField().equals("sharedWith")) {
+                        searchParameterMap.computeIfAbsent("sharedWith", map -> new HashMap<>()).put("username", qry.getValue());
+                    } else {
+                        searchParameterMap.computeIfAbsent("searchParams", map -> new HashMap<>()).put(qry.getField(), qry.getValue());
                     }
-                    if (qry.getField().equals("sharedBy")) {
-                        String val = qry.getValue();
-                        String query = " Match (m:" + value + ")-[r:SHARED_WITH]->(l) " +
-                                "where r.sharedBy=$sharedBy AND m.tenantId=$tenantId AND  l.tenantId=$tenantId  AND NOT l.username=$sharedBy " +
-                                "return m, r ";
-                        Map<String, Object> objectMap = new HashMap<>();
-                        objectMap.put("sharedBy", val);
-                        objectMap.put("tenantId", callUser.getTenantId());
-                        List<Record> records = this.neo4JConnector.searchNodes(objectMap, query);
-                        keyList = new ArrayList();
-                        keyList.add("m:r");
-                        List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
-                        ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
-                        builder.addAllResources(genericResourceList);
-                        responseObserver.onNext(builder.build());
-                        responseObserver.onCompleted();
-                        return;
-                    }
+                }
 
-                    if (qry.getField().equals("sharedWith")) {
-                        String val = qry.getValue();
-                        String query = "MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId " +
-                                " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)  " +
-                                " OPTIONAL MATCH (u)<-[pRel:SHARED_WITH]-(p:COLLECTION)<-[:CHILD_OF*] -(x:" + value + ")-[relR:SHARED_WITH]->(u)" +
-                                " where NOT  x.owner  = '" + val + "'  " +
-                                " OPTIONAL MATCH (g)<-[pxRel:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*] -(px:" + value + ")-[relR:SHARED_WITH]->(g)" +
-                                " where NOT  px.owner  = '" + val + "'" +
-                                " return distinct  p,pRel, px,pxRel";
-                        Map<String, Object> objectMap = new HashMap<>();
-                        objectMap.put("username", val);
-                        objectMap.put("tenantId", callUser.getTenantId());
-                        List<Record> records = this.neo4JConnector.searchNodes(objectMap, query);
-                        keyList = new ArrayList();
-                        keyList.add("p:pRel");
-                        keyList.add("px:pxRel");
-                        List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
-                        ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
-                        builder.addAllResources(genericResourceList);
-                        responseObserver.onNext(builder.build());
-                        responseObserver.onCompleted();
-                        return;
-                    }
+                if (searchParameterMap.containsKey("sharedBy") &&
+                        (!searchParameterMap.containsKey("searchParams") || searchParameterMap.get("searchParams").isEmpty())) {
+                    String val = searchParameterMap.get("sharedBy").get("username");
+                    String query = " Match (m:" + value + ")-[r:SHARED_WITH]->(l) " +
+                            "where r.sharedBy=$sharedBy AND m.tenantId=$tenantId AND  l.tenantId=$tenantId  AND NOT l.username=$sharedBy " +
+                            "return m, r ";
+                    Map<String, Object> objectMap = new HashMap<>();
+                    objectMap.put("sharedBy", val);
+                    objectMap.put("tenantId", callUser.getTenantId());
+                    List<Record> records = this.neo4JConnector.searchNodes(objectMap, query);
+                    keyList.add("m:r");
+                    List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
+                    ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
+                    builder.addAllResources(genericResourceList);
+                    responseObserver.onNext(builder.build());
+                    responseObserver.onCompleted();
+                    return;
+                } else if (searchParameterMap.containsKey("sharedWith") &&
+                        (!searchParameterMap.containsKey("searchParams") || searchParameterMap.get("searchParams").isEmpty())) {
+                    String val = searchParameterMap.get("sharedWith").get("username");
+                    String query = "MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId " +
+                            " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)  " +
+                            " OPTIONAL MATCH (u)<-[pRel:SHARED_WITH]-(p:COLLECTION)<-[:CHILD_OF*] -(x:" + value + ")-[relR:SHARED_WITH]->(u)" +
+                            " where NOT  x.owner  = '" + val + "'  " +
+                            " OPTIONAL MATCH (g)<-[pxRel:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*] -(px:" + value + ")-[relR:SHARED_WITH]->(g)" +
+                            " where NOT  px.owner  = '" + val + "'" +
+                            " return distinct  p,pRel, px,pxRel";
+                    Map<String, Object> objectMap = new HashMap<>();
+                    objectMap.put("username", val);
+                    objectMap.put("tenantId", callUser.getTenantId());
+                    List<Record> records = this.neo4JConnector.searchNodes(objectMap, query);
+                    keyList.add("p:pRel");
+                    keyList.add("px:pxRel");
+                    List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
+                    ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
+                    builder.addAllResources(genericResourceList);
+                    responseObserver.onNext(builder.build());
+                    responseObserver.onCompleted();
+                    return;
                 }
 
                 //TODO: replace with proper neo4j query
                 for (String strId : storageList) {
 
-                    Optional<String> metadataSearchQueryOP = Utils.getMetadataSearchQuery(resourceSearchQueries, value, strId);
-                    Optional<String> ownPropertySearchQuery = Utils.getPropertySearchQuery(resourceSearchQueries, value, strId);
-                    if (metadataSearchQueryOP.isPresent()) {
-                        String query = metadataSearchQueryOP.get();
-
-                        List<Record> records = this.neo4JConnector.searchNodes(query);
-                        List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records);
-
-
-                        genericResourceList.forEach(res -> {
+                    if (searchParameterMap.containsKey("sharedBy") && (searchParameterMap.containsKey("searchParams")
+                            && !searchParameterMap.get("searchParams").isEmpty())) {
+                        String username = searchParameterMap.get("sharedBy").get("username");
+                        searchParameterMap.get("searchParams").forEach((key, val) -> {
                             try {
-                                if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
-                                    allowedResourceList.add(res);
-                                }
+                                List<GenericResource> genericResourceList = Utils
+                                        .getMetadataSearchQueryForSharedByMe(value, key, val, strId, username, callUser.getTenantId(), neo4JConnector);
+                                genericResourceList.forEach(res -> {
+                                    try {
+                                        if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
+                                            allowedResourceList.add(res);
+                                        }
+                                    } catch (Exception exception) {
+                                        logger.error("Errored while searching generic resources");
+                                        responseObserver
+                                                .onError(Status.INTERNAL.withDescription("Errored while searching generic resources ")
+                                                        .asRuntimeException());
+                                        return;
+                                    }
+                                });
+
+                                List<GenericResource> genericResources = Utils
+                                        .getPropertySearchQueryForSharedByMe(value, key, val, strId, username, callUser.getTenantId(), neo4JConnector);
+                                genericResources.forEach(res -> {
+                                    try {
+                                        if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
+                                            allowedResourceList.add(res);
+                                        }
+                                    } catch (Exception exception) {
+                                        logger.error("Errored while searching generic resources");
+                                        responseObserver
+                                                .onError(Status.INTERNAL.withDescription("Errored while searching generic resources ")
+                                                        .asRuntimeException());
+                                        return;
+                                    }
+                                });
                             } catch (Exception exception) {
                                 logger.error("Errored while searching generic resources");
                                 responseObserver
@@ -502,11 +532,63 @@ public class ResourceServiceHandler extends ResourceServiceGrpc.ResourceServiceI
                                 return;
                             }
                         });
+                    } else if (searchParameterMap.containsKey("sharedWith") && (searchParameterMap.containsKey("searchParams")
+                            && !searchParameterMap.get("searchParams").isEmpty())) {
+                        String username = searchParameterMap.get("sharedWith").get("username");
+                        searchParameterMap.get("searchParams").forEach((key, val) -> {
+                            try {
+                                List<GenericResource> genericResourceList = Utils
+                                        .getMetadataSearchQueryForSharedWithMe(value, key, val, strId, username, callUser.getTenantId(), neo4JConnector);
+                                genericResourceList.forEach(res -> {
+                                    try {
+                                        if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
+                                            allowedResourceList.add(res);
+                                        }
+                                    } catch (Exception exception) {
+                                        logger.error("Errored while searching generic resources");
+                                        responseObserver
+                                                .onError(Status.INTERNAL.withDescription("Errored while searching generic resources ")
+                                                        .asRuntimeException());
+                                        return;
+                                    }
+                                });
+
+                                List<GenericResource> genericResources = Utils
+                                        .getPropertySearchQueryForSharedWithMe(value, key, val, strId, username, callUser.getTenantId(), neo4JConnector);
+                                genericResources.forEach(res -> {
+                                    try {
+                                        if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
+                                            allowedResourceList.add(res);
+                                        }
+                                    } catch (Exception exception) {
+                                        logger.error("Errored while searching generic resources");
+                                        responseObserver
+                                                .onError(Status.INTERNAL.withDescription("Errored while searching generic resources ")
+                                                        .asRuntimeException());
+                                        return;
+                                    }
+                                });
+                            } catch (Exception exception) {
+                                logger.error("Errored while searching generic resources");
+                                responseObserver
+                                        .onError(Status.INTERNAL.withDescription("Errored while searching generic resources ")
+                                                .asRuntimeException());
+                                return;
+                            }
+                        });
+
+                    } else {
+
+                        Optional<String> metadataSearchQueryOP = Utils.getMetadataSearchQuery(resourceSearchQueries, value, strId);
+                        Optional<String> ownPropertySearchQuery = Utils.getPropertySearchQuery(resourceSearchQueries, value, strId);
+                        if (metadataSearchQueryOP.isPresent()) {
+                            String query = metadataSearchQueryOP.get();
 
-                        if (ownPropertySearchQuery.isPresent()) {
-                            List<Record> ownPropertySearchRecords = this.neo4JConnector.searchNodes(ownPropertySearchQuery.get());
-                            List<GenericResource> genericResources = GenericResourceDeserializer.deserializeList(ownPropertySearchRecords);
-                            genericResources.forEach(res -> {
+                            List<Record> records = this.neo4JConnector.searchNodes(query);
+                            List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records);
+
+
+                            genericResourceList.forEach(res -> {
                                 try {
                                     if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
                                         allowedResourceList.add(res);
@@ -520,14 +602,33 @@ public class ResourceServiceHandler extends ResourceServiceGrpc.ResourceServiceI
                                 }
                             });
 
+                            if (ownPropertySearchQuery.isPresent()) {
+                                List<Record> ownPropertySearchRecords = this.neo4JConnector.searchNodes(ownPropertySearchQuery.get());
+                                List<GenericResource> genericResources = GenericResourceDeserializer.deserializeList(ownPropertySearchRecords);
+                                genericResources.forEach(res -> {
+                                    try {
+                                        if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
+                                            allowedResourceList.add(res);
+                                        }
+                                    } catch (Exception exception) {
+                                        logger.error("Errored while searching generic resources");
+                                        responseObserver
+                                                .onError(Status.INTERNAL.withDescription("Errored while searching generic resources ")
+                                                        .asRuntimeException());
+                                        return;
+                                    }
+                                });
+
+                            }
                         }
+
                     }
+                    ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
+                    builder.addAllResources(allowedResourceList);
+                    responseObserver.onNext(builder.build());
+                    responseObserver.onCompleted();
+                    return;
                 }
-                ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
-                builder.addAllResources(allowedResourceList);
-                responseObserver.onNext(builder.build());
-                responseObserver.onCompleted();
-                return;
             } else {
                 String query = "";
                 Map<String, Object> userProps = new HashMap<>();
diff --git a/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/utils/Utils.java b/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/utils/Utils.java
index d765ebf..3eeb4c6 100644
--- a/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/utils/Utils.java
+++ b/data-resource-management-service/drms-api/src/main/java/org/apache/airavata/drms/api/utils/Utils.java
@@ -1,16 +1,17 @@
 package org.apache.airavata.drms.api.utils;
 
 import io.grpc.Context;
+import org.apache.airavata.datalake.drms.resource.GenericResource;
 import org.apache.airavata.datalake.drms.storage.ResourceSearchQuery;
+import org.apache.airavata.drms.core.Neo4JConnector;
+import org.apache.airavata.drms.core.deserializer.GenericResourceDeserializer;
+import org.neo4j.driver.Record;
 
 import java.math.BigInteger;
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 public class Utils {
@@ -74,35 +75,135 @@ public class Utils {
         return Optional.empty();
     }
 
-    public static Optional<String> getSharedByQuery(List<ResourceSearchQuery> resourceSearchQueries,
-                                                    String tenantId) {
-        if (!resourceSearchQueries.isEmpty()) {
-            for (ResourceSearchQuery qry : resourceSearchQueries) {
-                if (qry.getField().equals("sharedBy")) {
-                    String value = qry.getValue();
-                    String query = " Match (m)-[r:SHARED_WITH]->(l) where r.sharedBy=$sharedBy AND m.tenantId=$tenantId and l.tenantId=$tenantId " +
-                            "return (m) ";
-                    Map<String, Object> objectMap = new HashMap<>();
-                    objectMap.put("sharedBy", value);
-                    objectMap.put("tenantId", tenantId);
-                    return Optional.ofNullable(query);
-                }
-            }
+    public static List<GenericResource> getMetadataSearchQueryForSharedByMe(String type, String key, String value, String storageId,
+                                                                            String sharedBy, String tenantId, Neo4JConnector neo4JConnector) throws Exception {
+        String preRegex = "'(?i).*";
+        String postRegex = ".*'";
+        String query = "";
+
+        if ((type.equals("FILE") || type.equals("COLLECTION")) && !storageId.isEmpty()) {
+            query = " MATCH (s:Storage{entityId:'" + storageId + "'})<-[:CHILD_OF*]-(r:" + type + ")-[:HAS_METADATA*]->(m)," +
+                    " (r)-[rel:SHARED_WITH]->(l)" +
+                    " WHERE ";
+        } else {
+            query = " MATCH (r:" + type + ")-[:HAS_METADATA*]->(m), (r)-[rel:SHARED_WITH]->(l) " +
+                    " WHERE ";
         }
-        return Optional.empty();
+
+        if (key.contains(" ")) {
+            query = " MATCH (r:" + type + ")-[:HAS_METADATA*]->(m:METADATA_NODE{`" + key + "`: '" + value + "'}), (r)-[rel:SHARED_WITH]->(l) " +
+                    " where r.sharedBy=$sharedBy AND r.tenantId=$tenantId AND  l.tenantId=$tenantId  AND NOT l.username=$sharedBy  " +
+                    " Return r ";
+        } else {
+            String finalSearchStr = preRegex + value + postRegex;
+            query = query + " m." + key + "=~ " + finalSearchStr + " AND  r.sharedBy=$sharedBy AND " +
+                    "r.tenantId=$tenantId AND  l.tenantId=$tenantId  AND NOT l.username=$sharedBy return r,rel";
+        }
+
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("sharedBy", sharedBy);
+        objectMap.put("tenantId", tenantId);
+        List<Record> records = neo4JConnector.searchNodes(objectMap, query);
+        List<String> keyList = new ArrayList<>();
+        keyList.add("r:rel");
+        return GenericResourceDeserializer.deserializeList(records, keyList);
+
     }
 
-    public static Optional<String> getSharedQueryExceptOwner(List<ResourceSearchQuery> resourceSearchQueries, String type) {
-        if (!resourceSearchQueries.isEmpty()) {
-            for (ResourceSearchQuery qry : resourceSearchQueries) {
-                String query = " MATCH (r:" + type +
-                        ") where r." + qry.getField() + " contains  '" + qry.getValue() + "' Return r ";
-                return Optional.ofNullable(query);
-            }
+
+    public static List<GenericResource> getPropertySearchQueryForSharedByMe(String type, String key, String value, String storageId,
+                                                                            String sharedBy, String tenantId, Neo4JConnector neo4JConnector) throws Exception {
+        String query = " match (m)-[r:SHARED_WITH]-(l) where r.sharedBy=$sharedBy AND m.tenantId=$tenantId AND " +
+                " l.tenantId=$tenantId  AND NOT l.username=$sharedBy " +
+                " OPTIONAL MATCH (m)<-[:CHILD_OF*]-(x) where x." + key + " contains  '" + value + "'" +
+                " OPTIONAL MATCH (m2)-[r2:SHARED_WITH]->(l) where  m2.tenantId=$tenantId AND  m2." + key + " contains  '" + value + "'" +
+                " return m2,r2 ,x,r ";
+
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("sharedBy", sharedBy);
+        objectMap.put("tenantId", tenantId);
+        List<Record> records = neo4JConnector.searchNodes(objectMap, query);
+        List<String> keyList = new ArrayList<>();
+        keyList.add("m2:r2");
+        keyList.add("x:r");
+        return GenericResourceDeserializer.deserializeList(records, keyList);
+    }
+
+
+    public static List<GenericResource> getMetadataSearchQueryForSharedWithMe(String type, String key, String value, String storageId,
+                                                                              String sharedWith, String tenantId, Neo4JConnector neo4JConnector) throws Exception {
+        String preRegex = "'(?i).*";
+        String postRegex = ".*'";
+        String finalSearchStr = preRegex + value + postRegex;
+        String query = "";
+
+        if ((type.equals("FILE") || type.equals("COLLECTION")) && !storageId.isEmpty()) {
+            query = " MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId " +
+                    " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)  " +
+                    " OPTIONAL MATCH (u)<-[pRel:SHARED_WITH]-(p:COLLECTION)<-[:CHILD_OF*] -(x:" + type + ")-[relR:SHARED_WITH]->(u)," +
+                    " (s:Storage{entityId:'" + storageId + "'})<-[:CHILD_OF*]-(x)-[:HAS_METADATA*]->(m)" +
+                    " where NOT  x.owner  = $sharedWith AND m." + key + "=~ " + finalSearchStr +
+                    " OPTIONAL MATCH (g)<-[pxRel:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*] -(px:" + type + ")-[relR:SHARED_WITH]->(g)," +
+                    " (s:Storage{entityId:'" + storageId + "'})<-[:CHILD_OF*]-(px)-[:HAS_METADATA*]->(m)" +
+                    " where NOT  px.owner  = $sharedWith AND m." + key + "=~ " + finalSearchStr +
+                    " return distinct  p,pRel, px,pxRel";
+        } else {
+            query = " MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId " +
+                    " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)  " +
+                    " OPTIONAL MATCH (u)<-[pRel:SHARED_WITH]-(p:COLLECTION)<-[:CHILD_OF*] -(x:" + type + ")-[relR:SHARED_WITH]->(u), " +
+                    " (x)-[:HAS_METADATA*]->(m)" +
+                    " where NOT  x.owner  = $sharedWith AND m." + key + "=~ " + finalSearchStr +
+                    " OPTIONAL MATCH (g)<-[pxRel:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*] -(px:" + type + ")-[relR:SHARED_WITH]->(g), " +
+                    " (px)-[:HAS_METADATA*]->(m) " +
+                    " where NOT  px.owner  = $sharedWith AND m." + key + "=~ " + finalSearchStr +
+                    " return distinct  p,pRel, px,pxRel";
         }
-        return Optional.empty();
+
+        if (key.contains(" ")) {
+            query = "MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId " +
+                    " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)  " +
+                    " OPTIONAL MATCH (u)<-[pRel:SHARED_WITH]-(p:COLLECTION)<-[:CHILD_OF*] -(x:" + type + ")-[relR:SHARED_WITH]->(u), " +
+                    " (x)-[:HAS_METADATA*]->(m:METADATA_NODE{`" + key + "`: '" + value + "'})" +
+                    " where NOT  x.owner  = $sharedWith" +
+                    " OPTIONAL MATCH (g)<-[pxRel:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*] -(px:" + value + ")-[relR:SHARED_WITH]->(g)" +
+                    " (px)-[:HAS_METADATA*]->(m:METADATA_NODE{`" + key + "`: '" + value + "'})" +
+                    " where NOT  px.owner  = $sharedWith" +
+                    " return distinct  p,pRel, px,pxRel";
+        }
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("sharedWith", sharedWith);
+        objectMap.put("username", sharedWith);
+        objectMap.put("tenantId", tenantId);
+        List<Record> records = neo4JConnector.searchNodes(objectMap, query);
+        List<String> keyList = new ArrayList<>();
+        keyList.add("p:pRel");
+        keyList.add("px:pxRel");
+        return GenericResourceDeserializer.deserializeList(records, keyList);
+    }
+
+
+    public static List<GenericResource> getPropertySearchQueryForSharedWithMe(String type, String key, String value, String storageId,
+                                                                              String sharedWith, String tenantId, Neo4JConnector neo4JConnector) throws Exception {
+        String query = "MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId " +
+                " OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u)  " +
+                " OPTIONAL MATCH (u)<-[pRel:SHARED_WITH]-(p:COLLECTION)<-[:CHILD_OF*] -(x:" + type + ")" +
+                " where NOT  x.owner  = $sharedWith AND x." + key + " contains  '" + value + "'" +
+                " OPTIONAL MATCH (g)<-[pxRel:SHARED_WITH]-(pr:COLLECTION)<-[:CHILD_OF*] -(px:" + type + ")" +
+                " where NOT  px.owner  = $sharedWith AND px." + key + " contains  '" + value + "'" +
+                " return distinct  x,pRel, px,pxRel";
+
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("sharedWith", sharedWith);
+        objectMap.put("username", sharedWith);
+        objectMap.put("tenantId", tenantId);
+        List<Record> records = neo4JConnector.searchNodes(objectMap, query);
+        List<String> keyList = new ArrayList<>();
+        keyList.add("x:pRel");
+        keyList.add("px:pxRel");
+        return GenericResourceDeserializer.deserializeList(records, keyList);
     }
 
+
     public static String getId(String message) throws NoSuchAlgorithmException {
         MessageDigest md = MessageDigest.getInstance("SHA-256");
         // digest() method called