diff --git a/afs-ws/afs-ws-client-utils/src/main/java/com/powsybl/afs/ws/client/utils/ClientUtils.java b/afs-ws/afs-ws-client-utils/src/main/java/com/powsybl/afs/ws/client/utils/ClientUtils.java index 12bc8800..3fc80f66 100644 --- a/afs-ws/afs-ws-client-utils/src/main/java/com/powsybl/afs/ws/client/utils/ClientUtils.java +++ b/afs-ws/afs-ws-client-utils/src/main/java/com/powsybl/afs/ws/client/utils/ClientUtils.java @@ -93,7 +93,6 @@ public static T readEntityIfOk(Response response, Class entityType) { } else { throw createUnexpectedResponseStatus(status); } - } public static T readEntityIfOk(Response response, GenericType entityType) { @@ -114,16 +113,11 @@ public static T readEntityIfOk(Response response, GenericType entityType) public static Optional readOptionalEntityIfOk(Response response, Class entityType) { Response.Status status = Response.Status.fromStatusCode(response.getStatus()); - if (status == Response.Status.OK) { - return Optional.of(readEntityAndLog(response, entityType)); - } else if (status == Response.Status.NO_CONTENT) { + if (status == Response.Status.NO_CONTENT || status == Response.Status.NOT_FOUND) { LOGGER.trace(" --> null"); return Optional.empty(); - } else if (status == Response.Status.INTERNAL_SERVER_ERROR) { - throw createServerErrorException(response); - } else { - throw createUnexpectedResponseStatus(status); } + return Optional.of(readEntityIfOk(response, entityType)); } public static UserSession authenticate(URI baseUri, String login, String password) { diff --git a/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java b/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java index 18df54d6..2d3f2cf1 100644 --- a/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java +++ b/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java @@ -13,8 +13,8 @@ import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.afs.storage.buffer.*; -import com.powsybl.afs.ws.server.utils.JwtTokenNeeded; import com.powsybl.afs.ws.server.utils.AppDataBean; +import com.powsybl.afs.ws.server.utils.JwtTokenNeeded; import com.powsybl.afs.ws.utils.AfsRestApi; import com.powsybl.afs.ws.utils.gzip.Compress; import com.powsybl.timeseries.DoubleDataChunk; @@ -109,7 +109,7 @@ public Response createNode(@ApiParam(value = "File system name") @PathParam("fil @ApiParam(value = "Version") @QueryParam("version") int version, @ApiParam(value = "Node Meta Data") NodeGenericMetadata nodeMetadata) { AppStorage storage = appDataBean.getStorage(fileSystemName); - NodeInfo newNodeInfo = storage.createNode(nodeId, childName, nodePseudoClass, description, version, nodeMetadata); + NodeInfo newNodeInfo = storage.createNode(nodeId, childName, nodePseudoClass, description, version, nodeMetadata); return Response.ok().entity(newNodeInfo).build(); } @@ -138,7 +138,7 @@ public Response getParentNode(@ApiParam(value = "File system name") @PathParam(" if (parentNodeInfo.isPresent()) { return Response.ok().entity(parentNodeInfo.get()).build(); } else { - return Response.noContent().build(); + return Response.status(Status.NOT_FOUND).build(); } } @@ -155,7 +155,7 @@ public Response getChildNode(@ApiParam(value = "File system name") @PathParam("f if (childNodeInfo.isPresent()) { return Response.status(Status.OK).entity(childNodeInfo.get()).build(); } else { - return Response.status(Status.NO_CONTENT).build(); + return Response.status(Status.NOT_FOUND).build(); } }