diff --git a/ch.eitchnet.utils b/ch.eitchnet.utils index 8e75a7651..6338690ad 160000 --- a/ch.eitchnet.utils +++ b/ch.eitchnet.utils @@ -1 +1 @@ -Subproject commit 8e75a7651ae64b0cd47cfe923244d6828a9f4c93 +Subproject commit 6338690ad2f849bdcb8c4c728b6bf96a87db42d8 diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/Result.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/Result.java index 174ffec70..225756b16 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/model/Result.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/Result.java @@ -15,11 +15,14 @@ */ package li.strolch.rest.model; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; +import li.strolch.service.api.ServiceResult; import ch.eitchnet.utils.helper.StringHelper; /** @@ -44,6 +47,17 @@ public class Result { this.exceptionMsg = StringHelper.formatExceptionMessage(e); } + public Result(ServiceResult svcResult) { + if (svcResult.isOk()) { + this.msg = StringHelper.DASH; + } else { + this.msg = svcResult.getMessage(); + Throwable t = svcResult.getThrowable(); + if (t != null) + this.exceptionMsg = StringHelper.formatExceptionMessage(t); + } + } + public Result() { this.msg = StringHelper.DASH; } @@ -63,4 +77,12 @@ public class Result { public void setExceptionMsg(String exceptionMsg) { this.exceptionMsg = exceptionMsg; } + + public static Response toResponse(ServiceResult svcResult) { + Result result = new Result(svcResult); + if (svcResult.isOk()) + return Response.ok(result, MediaType.APPLICATION_JSON).build(); + else + return Response.serverError().type(MediaType.APPLICATION_JSON).entity(result).build(); + } }