Skip to content
Permalink
Browse files
Bug fix in fetching COLLECTION_GROUP in resource queries
  • Loading branch information
isururanawaka committed Sep 13, 2021
1 parent caf980a commit 37e1b4fd6aac5fc0e04773f9e0922e6ade1eb4c4
Showing 5 changed files with 53 additions and 49 deletions.
@@ -529,14 +529,13 @@ public void searchResource(ResourceSearchRequest
responseObserver.onCompleted();
return;
} else {
String query = "";
Map<String, Object> userProps = new HashMap<>();
userProps.put("username", callUser.getUsername());
userProps.put("tenantId", callUser.getTenantId());
if ((value.equals("FILE") || value.equals("COLLECTION"))) {
for (String storageId : storageList) {

for (String storageId : storageList) {
Map<String, Object> userProps = new HashMap<>();
userProps.put("username", callUser.getUsername());
userProps.put("tenantId", callUser.getTenantId());

String query = "";
if ((value.equals("FILE") || value.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)<-[relRM:SHARED_WITH]-(m)<-[:CHILD_OF*]-(rm:" + value + ")-[:CHILD_OF*]->(s:Storage{entityId:'" + storageId + "'})" +
@@ -563,51 +562,56 @@ public void searchResource(ResourceSearchRequest
keyList.add("r2:relR2");
keyList.add("r3:relR3");
}
logger.debug("Search query {}", query);

List<Record> records = this.neo4JConnector.searchNodes(userProps, query);

} else {
List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
allowedResourceList.addAll(genericResourceList);
}
} else {
query = " MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId" +
" OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u) " +
" OPTIONAL MATCH (u)<-[relRM:SHARED_WITH]-(m)<-[:CHILD_OF*]-(rm:" + value + ")" +
" , (r:" + value + ")-[relR:SHARED_WITH]->(u)" +
" OPTIONAL MATCH (g)<-[relRMG:SHARED_WITH]-(mg)<-[:CHILD_OF*]-(rmg:" + value + ")" +
" , (rg:" + value + ")-[relRG:SHARED_WITH]->(g)" +
" return distinct rm,relRM, r,relR, rmg,relRMG, rg, relRG ";
keyList = new ArrayList();
keyList.add("rm:relRM");
keyList.add("r:relR");
keyList.add("rmg:relRMG");
keyList.add("rg:relRG");
if (depth == 1) {
query = " MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId" +
" OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u) " +
" OPTIONAL MATCH (u)<-[relRM:SHARED_WITH]-(m)<-[:CHILD_OF*]-(rm:" + value + ")" +
" , (r:" + value + ")-[relR:SHARED_WITH]->(u)" +
" OPTIONAL MATCH (g)<-[relRMG:SHARED_WITH]-(mg)<-[:CHILD_OF*]-(rmg:" + value + ")" +
" , (rg:" + value + ")-[relRG:SHARED_WITH]->(g)" +
" return distinct rm,relRM, r,relR, rmg,relRMG, rg, relRG ";
" OPTIONAL MATCH (r:" + value + ")-[relR:SHARED_WITH]->(u)" +
" OPTIONAL MATCH (rg:" + value + ")-[relRG:SHARED_WITH]->(g)" +
" return distinct r,relR, rg, relRG ";
keyList = new ArrayList();
keyList.add("rm:relRM");
keyList.add("r:relR");
keyList.add("rmg:relRMG");
keyList.add("rg:relRG");
if (depth == 1) {
query = " MATCH (u:User) where u.username = $username AND u.tenantId = $tenantId" +
" OPTIONAL MATCH (g:Group)<-[:MEMBER_OF]-(u) " +
" OPTIONAL MATCH (r:" + value + ")-[relR:SHARED_WITH]->(u)" +
" OPTIONAL MATCH (rg:" + value + ")-[relRG:SHARED_WITH]->(g)" +
" return distinct r,relR, rg, relRG ";
keyList = new ArrayList();
keyList.add("r:relR");
keyList.add("rg:relRG");
}
}

logger.debug("Search query {}", query);

List<Record> records = this.neo4JConnector.searchNodes(userProps, query);

List<GenericResource> genericResourceList = GenericResourceDeserializer.deserializeList(records, keyList);
allowedResourceList.addAll(genericResourceList);
}
ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
builder.addAllResources(allowedResourceList);
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}


} catch (Exception e) {
}
ResourceSearchResponse.Builder builder = ResourceSearchResponse.newBuilder();
builder.addAllResources(allowedResourceList);
responseObserver.onNext(builder.build());
responseObserver.onCompleted();

} catch (
Exception e) {
logger.error("Errored while searching generic resources; Message: {}", e.getMessage(), e);
responseObserver.onError(Status.INTERNAL.withDescription("Errored while searching generic resources "
+ e.getMessage()).asRuntimeException());
}

}


@@ -67,7 +67,7 @@ private void configureEventListener(String configPath) {
custosEventListener.consume(new ConsumerCallback() {
@Override
public void process(Message notificationEvent) throws Exception {
LOGGER.debug("Message Id" + notificationEvent.getMessageId());
LOGGER.info("Process from kafka message Id" + notificationEvent.getMessageId());
EventDemux.delegateEvents(notificationEvent);
}
});
@@ -24,13 +24,13 @@ public class CustosDataFetchingJob implements Job {
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
LOGGER.debug("Executing CustosDataFetchingJob ....... ");
JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
String path = jobDataMap.getString("configurationPath");
Configuration configuration = loadConfiguration(path);
UserAndGroupHandler userAndGroupHandler = new UserAndGroupHandler();
userAndGroupHandler.mergeUserAndGroups(configuration);
SharingHandler sharingHandler = new SharingHandler();
sharingHandler.mergeSharings(configuration);
// JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
// String path = jobDataMap.getString("configurationPath");
// Configuration configuration = loadConfiguration(path);
// UserAndGroupHandler userAndGroupHandler = new UserAndGroupHandler();
// userAndGroupHandler.mergeUserAndGroups(configuration);
// SharingHandler sharingHandler = new SharingHandler();
// sharingHandler.mergeSharings(configuration);
} catch (Exception ex) {
String msg = "Error occurred while executing job" + ex.getMessage();
LOGGER.error(msg, ex);
@@ -51,7 +51,7 @@ public void consume(ConsumerCallback callback) {
try {
callback.process(record.value());
} catch (Exception exception) {
exception.printStackTrace();
LOGGER.info("Exception occurred in kafka listener ",exception.getMessage());
} finally {
consumer.commitSync(Collections.singletonMap(partition, new OffsetAndMetadata(record.offset() + 1)));
}
@@ -1,17 +1,17 @@
pollingInterval: 60
dataResourceManagementService:
dbURI: "bolt://192.168.0.14:7687"
dbURI: "bolt://149.165.156.173:7687"
dbUser: "neo4j"
dbPassword: "123456"
dbPassword: "blastcovid19"
custos:
host: "custos.scigap.org"
port: 31499
custosId: "custos-whedmgamitu357p4wuke-10002708"
custosSec: "mrMdl86Ia1H94cikW7CvHoh7L0ASNXQVt2aRzSIj"
custosId: "custos-ii8g0cfwsz6ruwezykn9-10002640"
custosSec: "OxXECszt9dL4lHJQyL444UOU0lKN317D51ez067R"
custosBrokerURL: "149.165.156.200:9092"
consumerGroup: "custosEventsGroup"
maxPollRecordsConfig: 10
topics:
- "10002708-754b89b5-3a57-496c-aa34-8e2b4916fbc"
- "10002640-561b67b4-fa7d-4368-8643-dcd9d0159c1d"
tenantsToBeSynced:
- "custos-whedmgamitu357p4wuke-10002708"
- "custos-ii8g0cfwsz6ruwezykn9-10002640"

0 comments on commit 37e1b4f

Please sign in to comment.