Skip to content
Permalink
Browse files
Merge pull request #77 from isururanawaka/sharing_service_impl
metadata search improvement
  • Loading branch information
isururanawaka committed Sep 15, 2021
2 parents e5199ea + cd34a78 commit db6cd1ad6928a90cf6d2a4c79be1fb3e24dd68d1
Showing 2 changed files with 39 additions and 34 deletions.
@@ -486,31 +486,33 @@ public void searchResource(ResourceSearchRequest
}

//TODO: replace with proper neo4j query
for (String strId : storageList) {


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 {
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);
for (String strId : storageList) {
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;
}
} 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);
.getPropertySearchQueryForSharedByMe(value, key, val, username, callUser.getTenantId(), neo4JConnector);
genericResources.forEach(res -> {
try {
if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
@@ -524,6 +526,7 @@ public void searchResource(ResourceSearchRequest
return;
}
});

} catch (Exception exception) {
logger.error("Errored while searching generic resources");
responseObserver
@@ -537,24 +540,26 @@ public void searchResource(ResourceSearchRequest
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);
for (String strId : storageList) {
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;
}
} 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);
.getPropertySearchQueryForSharedWithMe(value, key, val, username, callUser.getTenantId(), neo4JConnector);
genericResources.forEach(res -> {
try {
if (hasAccessForResource(callUser.getUsername(), callUser.getTenantId(), res.getResourceId(), "COLLECTION")) {
@@ -578,7 +583,7 @@ public void searchResource(ResourceSearchRequest
});

} else {

for (String strId : storageList) {
Optional<String> metadataSearchQueryOP = Utils.getMetadataSearchQuery(resourceSearchQueries, value, strId);
Optional<String> ownPropertySearchQuery = Utils.getPropertySearchQuery(resourceSearchQueries, value, strId);
if (metadataSearchQueryOP.isPresent()) {
@@ -111,7 +111,7 @@ public static List<GenericResource> getMetadataSearchQueryForSharedByMe(String t
}


public static List<GenericResource> getPropertySearchQueryForSharedByMe(String type, String key, String value, String storageId,
public static List<GenericResource> getPropertySearchQueryForSharedByMe(String type, String key, String value,
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 " +
@@ -182,7 +182,7 @@ public static List<GenericResource> getMetadataSearchQueryForSharedWithMe(String
}


public static List<GenericResource> getPropertySearchQueryForSharedWithMe(String type, String key, String value, String storageId,
public static List<GenericResource> getPropertySearchQueryForSharedWithMe(String type, String key, String value,
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) " +

0 comments on commit db6cd1a

Please sign in to comment.