Skip to content

Commit

Permalink
Merge pull request #18 from hms-dbmi/QA
Browse files Browse the repository at this point in the history
1.2 Release
  • Loading branch information
JREastonMarks authored Aug 31, 2016
2 parents 229e014 + ebccdb4 commit a25c826
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 37 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>edu.harvard.hms.dbmi.bd2k.irct</groupId>
<artifactId>IRCT-CL</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>war</packaging>
<name>INTER-RESOURCE COMMUNICATION TOOL : Communication Layer</name>
<description></description>
Expand Down Expand Up @@ -49,19 +49,19 @@
<dependency>
<groupId>edu.harvard.hms.dbmi.bd2k.irct</groupId>
<artifactId>IRCT-RI</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>

<dependency>
<groupId>edu.harvard.hms.dbmi.bd2k.irct</groupId>
<artifactId>IRCT-API</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>

<dependency>
<groupId>edu.harvard.hms.dbmi.bd2k.irct</groupId>
<artifactId>IRCT-EXT</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>

<!-- JWT OAuth -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import edu.harvard.hms.dbmi.bd2k.irct.controller.PathController;
import edu.harvard.hms.dbmi.bd2k.irct.controller.ResourceController;
import edu.harvard.hms.dbmi.bd2k.irct.exception.ResourceInterfaceException;
import edu.harvard.hms.dbmi.bd2k.irct.model.find.FindByOntology;
import edu.harvard.hms.dbmi.bd2k.irct.model.find.FindByPath;
import edu.harvard.hms.dbmi.bd2k.irct.model.find.FindInformationInterface;
import edu.harvard.hms.dbmi.bd2k.irct.model.ontology.Entity;
import edu.harvard.hms.dbmi.bd2k.irct.model.resource.Resource;
import edu.harvard.hms.dbmi.bd2k.irct.model.security.SecureSession;
Expand Down Expand Up @@ -161,6 +164,77 @@ public Response search(@Context UriInfo info) {
return Response.ok(response.build(), MediaType.APPLICATION_JSON)
.build();
}

@GET
@Path("/find{path : .*}")
@Produces(MediaType.APPLICATION_JSON)
public Response find(@PathParam("path") String path, @Context UriInfo info) {
JsonArrayBuilder response = Json.createArrayBuilder();
List<Entity> entities = null;
FindInformationInterface findInformation;

if(info.getQueryParameters().containsKey("term")) {
findInformation = new FindByPath();
} else if(info.getQueryParameters().containsKey("ontologyTerm") && info.getQueryParameters().containsKey("ontologyType")) {
findInformation = new FindByOntology();
} else {
return invalidRequest("Find is missing parameters");
}

// Set up path information
Resource resource = null;
Entity resourcePath = null;

if (path != null && !path.isEmpty()) {
path = "/" + path;
path = path.substring(1);
resource = rc.getResource(path.split("/")[1]);

resourcePath = new Entity(path);
}

// Load all values into find information object
for(String key : info.getQueryParameters().keySet()) {
findInformation.setValue(key, info.getQueryParameters().getFirst(key));
}

if(findInformation instanceof FindByPath) {
String searchTerm = info.getQueryParameters().getFirst("term");
String strategy = "exact";
if (searchTerm.charAt(0) == '%') {
if (searchTerm.charAt(searchTerm.length() - 1) == '%') {
searchTerm = searchTerm.substring(1, searchTerm.length() - 1);
strategy = "contains";
} else {
searchTerm = searchTerm.substring(1);
strategy = "right";
}
} else if (searchTerm.charAt(searchTerm.length() - 1) == '%') {
searchTerm = searchTerm.substring(0, searchTerm.length() - 1);
strategy = "left";
}
findInformation.setValue("term", searchTerm);
findInformation.setValue("strategy", strategy);
}

// Run find
try {
entities = pc.searchForTerm(resource, resourcePath, findInformation, (SecureSession) session.getAttribute("secureSession"));
} catch (ResourceInterfaceException e) {
log.log(Level.INFO,
"Error in /resourceService/find"
+ e.getMessage());
return invalidRequest(null);
}

if (entities != null) {
for (Entity entity : entities) {
response.add(entity.toJson());
}
}

return Response.ok(response.build(), MediaType.APPLICATION_JSON).build();
}

/**
* Returns a list of entities. This could be from traversing the paths, or
Expand All @@ -181,15 +255,10 @@ public Response search(@Context UriInfo info) {
@GET
@Path("/path{path : .*}")
@Produces(MediaType.APPLICATION_JSON)
public Response path(@PathParam("path") String path,
@QueryParam("relationship") String relationshipString,
@QueryParam("searchTerm") String searchTerm,
@QueryParam("searchOntologyType") String ontologyType,
@QueryParam("searchOntologyTerm") String ontologyTerm) {

public Response path(@PathParam("path") String path, @QueryParam("relationship") String relationshipString) {
JsonArrayBuilder response = Json.createArrayBuilder();
List<Entity> entities = null;

Resource resource = null;
Entity resourcePath = null;

Expand All @@ -201,8 +270,7 @@ public Response path(@PathParam("path") String path,
resourcePath = new Entity(path);
}

if (resource != null && searchTerm == null && ontologyType == null
&& ontologyTerm == null) {
if (resource != null) {
if (relationshipString == null) {
relationshipString = "child";
}
Expand All @@ -217,28 +285,6 @@ public Response path(@PathParam("path") String path,
+ e.getMessage());
return invalidRequest(e.getMessage());
}
} else if (searchTerm != null) {
try {
entities = pc.searchForTerm(resource, resourcePath, searchTerm,
(SecureSession) session.getAttribute("secureSession"));
} catch (ResourceInterfaceException e) {
log.log(Level.INFO, "Error in /resourceService/path/" + path
+ "?searchTerm=" + searchTerm + " : " + e.getMessage());
return invalidRequest(null);
}
} else if (ontologyType != null && ontologyTerm != null) {
try {
entities = pc.searchForOntology(resource, resourcePath,
ontologyType, ontologyTerm,
(SecureSession) session.getAttribute("secureSession"));
} catch (ResourceInterfaceException e) {
log.log(Level.INFO,
"Error in /resourceService/path/" + path
+ "?searchOntologyType=" + ontologyType
+ "&searchOntologyTerm" + ontologyTerm + " : "
+ e.getMessage());
return invalidRequest(null);
}
} else if (path == null || path.isEmpty()) {
entities = pc.getAllResourcePaths();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.logging.Logger;

import javax.annotation.Resource;
import javax.enterprise.concurrent.ManagedExecutorService;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
Expand Down

0 comments on commit a25c826

Please sign in to comment.