Skip to content
This repository has been archived by the owner on Nov 17, 2017. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
keiono committed Jun 26, 2015
2 parents 731b75c + 40bab51 commit bbf18ef
Show file tree
Hide file tree
Showing 17 changed files with 1,019 additions and 130 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ branches:
only:
- develop
- master

after_success:
- mvn clean cobertura:cobertura coveralls:cobertura
- mvn clean cobertura:cobertura coveralls:report
19 changes: 13 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<properties>
<bundle.symbolicName>org.cytoscape.rest.cy-rest</bundle.symbolicName>
<bundle.namespace>org.cytoscape.rest</bundle.namespace>
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<osgi.api.version>4.2.0</osgi.api.version>
<junit.version>4.12</junit.version>
<jersey.version>2.18</jersey.version>
Expand All @@ -17,7 +17,7 @@

<groupId>org.cytoscape</groupId>
<artifactId>cy-rest</artifactId>
<version>0.9.17</version>
<version>1.1.0</version>
<packaging>bundle</packaging>
<name>cyREST</name>

Expand Down Expand Up @@ -79,7 +79,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.3</version>
<version>2.5.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand Down Expand Up @@ -150,12 +150,19 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>2.2.0</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
Expand All @@ -177,7 +184,7 @@
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Cytoscape 3 Dependencies -->
<dependency>
Expand Down Expand Up @@ -259,7 +266,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
<version>2.5.4</version>
</dependency>

<!-- Jersey -->
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/cytoscape/rest/internal/CyActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.cytoscape.io.read.InputStreamTaskFactory;
import org.cytoscape.io.util.StreamUtil;
import org.cytoscape.io.write.CyNetworkViewWriterFactory;
import org.cytoscape.io.write.PresentationWriterFactory;
import org.cytoscape.io.write.VizmapWriterFactory;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
Expand Down Expand Up @@ -83,6 +84,10 @@ public void start(BundleContext bc) {
final MappingFactoryManager mappingFactoryManager = new MappingFactoryManager();
registerServiceListener(bc, mappingFactoryManager, "addFactory", "removeFactory",
VisualMappingFunctionFactory.class);

final GraphicsWriterManager graphicsWriterManager = new GraphicsWriterManager();
registerServiceListener(bc, graphicsWriterManager, "addFactory", "removeFactory",
PresentationWriterFactory.class);

@SuppressWarnings("unchecked")
final CyProperty<Properties> cyPropertyServiceRef = getService(bc, CyProperty.class,
Expand Down Expand Up @@ -156,7 +161,7 @@ public void start(BundleContext bc) {
networkSelectedNodesAndEdgesTaskFactory, edgeListReaderFactory, netViewFact, tableFactory, fitContent,
new EdgeBundlerImpl(edgeBundler), renderingEngineManager, sessionManager,
saveSessionAsTaskFactory, openSessionTaskFactory, newSessionTaskFactory, desktop,
new LevelOfDetails(showDetailsTaskFactory), selectFirstNeighborsTaskFactory);
new LevelOfDetails(showDetailsTaskFactory), selectFirstNeighborsTaskFactory, graphicsWriterManager);
this.grizzlyServerManager = new GrizzlyServerManager(binder, cyPropertyServiceRef);
try {
this.grizzlyServerManager.startServer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cytoscape.rest.internal;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.cytoscape.io.CyFileFilter;
import org.cytoscape.io.write.PresentationWriterFactory;

public class GraphicsWriterManager {

private final Map<String, PresentationWriterFactory> factories;

public GraphicsWriterManager() {
factories = new HashMap<>();
}

public PresentationWriterFactory getFactory(final String fileType) {
return factories.get(fileType);
}

@SuppressWarnings("rawtypes")
public void addFactory(PresentationWriterFactory factory, Map properties) {
final CyFileFilter ff = factory.getFileFilter();
final Set<String> ext = ff.getExtensions();

final String firstExt = ext.iterator().next();
System.out.println("Got writer: " + firstExt);

factories.put(firstExt, factory);
}

@SuppressWarnings("rawtypes")
public void removeFactory(PresentationWriterFactory factory, Map properties) {
final CyFileFilter ff = factory.getFileFilter();
final Set<String> ext = ff.getExtensions();
factories.remove(ext.iterator().next());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class NetworkResource extends AbstractResource {
protected SelectFirstNeighborsTaskFactory selectFirstNeighborsTaskFactory;

// Preset types
private static final String DEF_COLLECTION_PREFIX = "Posted: ";
private static final String DEF_COLLECTION_PREFIX = "Created by cyREST: ";

public NetworkResource() {
super();
Expand All @@ -82,8 +82,9 @@ public NetworkResource() {
@GET
@Path("/count")
@Produces(MediaType.APPLICATION_JSON)
public String getNetworkCount() {
return getNumberObjectString(JsonTags.COUNT, networkManager.getNetworkSet().size());
public Response getNetworkCount() {
final String result = getNumberObjectString(JsonTags.COUNT, networkManager.getNetworkSet().size());
return Response.ok(result).build();
}

/**
Expand All @@ -97,8 +98,9 @@ public String getNetworkCount() {
@GET
@Path("/{networkId}/nodes/count")
@Produces(MediaType.APPLICATION_JSON)
public String getNodeCount(@PathParam("networkId") Long networkId) {
return getNumberObjectString(JsonTags.COUNT, getCyNetwork(networkId).getNodeCount());
public Response getNodeCount(@PathParam("networkId") Long networkId) {
final String result = getNumberObjectString(JsonTags.COUNT, getCyNetwork(networkId).getNodeCount());
return Response.ok(result).build();
}

/**
Expand All @@ -113,8 +115,9 @@ public String getNodeCount(@PathParam("networkId") Long networkId) {
@GET
@Path("/{networkId}/edges/count")
@Produces(MediaType.APPLICATION_JSON)
public String getEdgeCount(@PathParam("networkId") Long networkId) {
return getNumberObjectString(JsonTags.COUNT, getCyNetwork(networkId).getEdgeCount());
public Response getEdgeCount(@PathParam("networkId") Long networkId) {
final String result = getNumberObjectString(JsonTags.COUNT, getCyNetwork(networkId).getEdgeCount());
return Response.ok(result).build();
}


Expand Down Expand Up @@ -265,7 +268,7 @@ public Response getSelectedNodes(@PathParam("networkId") Long networkId) {
@GET
@Path("/{networkId}/nodes/selected/neighbors")
@Produces(MediaType.APPLICATION_JSON)
public Response getNeighbors(@PathParam("networkId") Long networkId) {
public Response getNeighborsSelected(@PathParam("networkId") Long networkId) {
final CyNetwork network = getCyNetwork(networkId);
final List<CyNode> selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);

Expand Down Expand Up @@ -461,14 +464,15 @@ public Collection<Long> getAdjEdges(@PathParam("networkId") Long networkId, @Pat
@GET
@Path("/{networkId}/nodes/{nodeId}/pointer")
@Produces(MediaType.APPLICATION_JSON)
public String getNetworkPointer(@PathParam("networkId") Long networkId, @PathParam("nodeId") Long nodeId) {
public Response getNetworkPointer(@PathParam("networkId") Long networkId, @PathParam("nodeId") Long nodeId) {
final CyNetwork network = getCyNetwork(networkId);
final CyNode node = getNode(network, nodeId);
final CyNetwork pointer = node.getNetworkPointer();
if (pointer == null) {
throw getError("Could not find network pointer.", new RuntimeException(), Response.Status.NOT_FOUND);
}
return getNumberObjectString(JsonTags.NETWORK_SUID, pointer.getSUID());

return Response.ok(getNumberObjectString(JsonTags.NETWORK_SUID, pointer.getSUID())).build();
}

/**
Expand All @@ -486,11 +490,12 @@ public String getNetworkPointer(@PathParam("networkId") Long networkId, @PathPar
@GET
@Path("/{networkId}/nodes/{nodeId}/neighbors")
@Produces(MediaType.APPLICATION_JSON)
public Collection<Long> getNeighbours(@PathParam("networkId") Long networkId, @PathParam("nodeId") Long nodeId) {
public Response getNeighbours(@PathParam("networkId") Long networkId, @PathParam("nodeId") Long nodeId) {
final CyNetwork network = getCyNetwork(networkId);
final CyNode node = getNode(network, nodeId);
final List<CyNode> nodes = network.getNeighborList(node, Type.ANY);
return getGraphObjectArray(nodes);

return Response.status(Response.Status.OK).entity(getGraphObjectArray(nodes)).build();
}

/**
Expand All @@ -501,11 +506,9 @@ public Collection<Long> getNeighbours(@PathParam("networkId") Long networkId, @P
* @return
*/
private final Collection<Long> getGraphObjectArray(final Collection<? extends CyIdentifiable> objects) {
final Collection<Long> suids = new ArrayList<Long>();
for (final CyIdentifiable obj : objects) {
suids.add(obj.getSUID());
}
return suids;
return objects.stream()
.map(CyIdentifiable::getSUID)
.collect(Collectors.toList());
}

/**
Expand All @@ -529,7 +532,7 @@ private final Collection<Long> getGraphObjectArray(final Collection<? extends Cy
@Path("/{networkId}/nodes")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String createNode(@PathParam("networkId") Long networkId, final InputStream is) {
public Response createNode(@PathParam("networkId") Long networkId, final InputStream is) {
final CyNetwork network = getCyNetwork(networkId);
final ObjectMapper objMapper = new ObjectMapper();
JsonNode rootNode = null;
Expand Down Expand Up @@ -566,7 +569,8 @@ public String createNode(@PathParam("networkId") Long networkId, final InputStre
} catch (Exception e) {
throw getError("Could not create node list.", e, Response.Status.INTERNAL_SERVER_ERROR);
}
return result;

return Response.status(Response.Status.CREATED).entity(result).build();
} else {
throw getError("Need to post as array.", new IllegalArgumentException(),
Response.Status.PRECONDITION_FAILED);
Expand Down Expand Up @@ -598,7 +602,7 @@ public String createNode(@PathParam("networkId") Long networkId, final InputStre
@Path("/{networkId}/edges")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String createEdge(@PathParam("networkId") Long networkId, final InputStream is) {
public Response createEdge(@PathParam("networkId") Long networkId, final InputStream is) {
final CyNetwork network = getCyNetwork(networkId);
final ObjectMapper objMapper = new ObjectMapper();

Expand Down Expand Up @@ -665,9 +669,10 @@ public String createEdge(@PathParam("networkId") Long networkId, final InputStre
stream.close();
updateViews(network);
} catch (Exception e) {
e.printStackTrace();
throw getError("Could not create edge.", e, Response.Status.INTERNAL_SERVER_ERROR);
}
return result;
return Response.status(Response.Status.CREATED).entity(result).build();
} else {
throw getError("Need to POST as array.", new IllegalArgumentException(),
Response.Status.INTERNAL_SERVER_ERROR);
Expand All @@ -683,11 +688,11 @@ public String createEdge(@PathParam("networkId") Long networkId, final InputStre
*/
@DELETE
@Path("/")
public void deleteAllNetworks() {
final Set<CyNetwork> allNetworks = this.networkManager.getNetworkSet();
for (final CyNetwork network : allNetworks) {
this.networkManager.destroyNetwork(network);
}
public Response deleteAllNetworks() {
this.networkManager.getNetworkSet().stream()
.forEach(network->this.networkManager.destroyNetwork(network));

return Response.ok().build();
}

/**
Expand Down Expand Up @@ -715,6 +720,7 @@ public Response deleteAllNodes(@PathParam("networkId") Long networkId) {
final CyNetwork network = getCyNetwork(networkId);
network.removeNodes(network.getNodeList());
updateViews(network);

return Response.ok().build();
}

Expand All @@ -726,10 +732,12 @@ public Response deleteAllNodes(@PathParam("networkId") Long networkId) {
*/
@DELETE
@Path("/{networkId}/edges")
public void deleteAllEdges(@PathParam("networkId") Long networkId) {
public Response deleteAllEdges(@PathParam("networkId") Long networkId) {
final CyNetwork network = getCyNetwork(networkId);
network.removeEdges(network.getEdgeList());
updateViews(network);

return Response.ok().build();
}


Expand All @@ -743,7 +751,7 @@ public void deleteAllEdges(@PathParam("networkId") Long networkId) {
*/
@DELETE
@Path("/{networkId}/nodes/{nodeId}")
public void deleteNode(@PathParam("networkId") Long networkId, @PathParam("nodeId") Long nodeId) {
public Response deleteNode(@PathParam("networkId") Long networkId, @PathParam("nodeId") Long nodeId) {
final CyNetwork network = getCyNetwork(networkId);
final CyNode node = network.getNode(nodeId);
if (node == null) {
Expand All @@ -753,6 +761,8 @@ public void deleteNode(@PathParam("networkId") Long networkId, @PathParam("nodeI
nodes.add(node);
network.removeNodes(nodes);
updateViews(network);

return Response.ok().build();
}


Expand All @@ -767,7 +777,7 @@ public void deleteNode(@PathParam("networkId") Long networkId, @PathParam("nodeI
*/
@DELETE
@Path("/{networkId}/edges/{edgeId}")
public void deleteEdge(@PathParam("networkId") Long networkId, @PathParam("edgeId") Long edgeId) {
public Response deleteEdge(@PathParam("networkId") Long networkId, @PathParam("edgeId") Long edgeId) {
final CyNetwork network = getCyNetwork(networkId);
final CyEdge edge = network.getEdge(edgeId);
if (edge == null) {
Expand All @@ -777,6 +787,8 @@ public void deleteEdge(@PathParam("networkId") Long networkId, @PathParam("edgeI
edges.add(edge);
network.removeEdges(edges);
updateViews(network);

return Response.ok().build();
}

/**
Expand Down Expand Up @@ -849,6 +861,7 @@ public String createNetwork(@DefaultValue(DEF_COLLECTION_PREFIX) @QueryParam("co
try {
reader.run(new HeadlessTaskMonitor());
} catch (Exception e) {
e.printStackTrace();
throw getError("Could not parse the given network JSON.", e, Response.Status.PRECONDITION_FAILED);
}

Expand Down
Loading

0 comments on commit bbf18ef

Please sign in to comment.