Merge feature/soql into feature/soql
This commit is contained in:
msmock 2017-12-03 20:00:00 +01:00
commit ea047e1080
4 changed files with 50 additions and 38 deletions

View File

@ -17,11 +17,15 @@ package li.strolch.service.api;
import java.io.Serializable;
import com.google.gson.JsonObject;
import li.strolch.utils.helper.ExceptionHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ServiceResult implements Serializable {
private static final long serialVersionUID = 1L;
private ServiceResultState state;
private String message;
private Throwable throwable;
@ -30,27 +34,15 @@ public class ServiceResult implements Serializable {
//
}
/**
* @param state
*/
public ServiceResult(ServiceResultState state) {
this.state = state;
}
/**
* @param state
* @param message
*/
public ServiceResult(ServiceResultState state, String message) {
this.state = state;
this.message = message;
}
/**
* @param state
* @param message
* @param throwable
*/
public ServiceResult(ServiceResultState state, String message, Throwable throwable) {
this.state = state;
this.message = message;
@ -71,32 +63,18 @@ public class ServiceResult implements Serializable {
return this.state != ServiceResultState.SUCCESS;
}
/**
* @return the state
*/
public ServiceResultState getState() {
return this.state;
}
/**
* @param state
* the state to set
*/
public void setState(ServiceResultState state) {
this.state = state;
}
/**
* @return the message
*/
public String getMessage() {
return this.message;
}
/**
* @param message
* the message to set
*/
public void setMessage(String message) {
this.message = message;
}
@ -122,17 +100,10 @@ public class ServiceResult implements Serializable {
return t;
}
/**
* @return the throwable
*/
public Throwable getThrowable() {
return this.throwable;
}
/**
* @param throwable
* the throwable to set
*/
public void setThrowable(Throwable throwable) {
this.throwable = throwable;
}
@ -160,4 +131,14 @@ public class ServiceResult implements Serializable {
public static ServiceResult failed(String error, Throwable t) {
return new ServiceResult(ServiceResultState.FAILED, error, t);
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("state", state.name());
json.addProperty("message", message);
json.addProperty("throwable", ExceptionHelper.formatException(throwable));
return json;
}
}

View File

@ -19,6 +19,7 @@ import static li.strolch.utils.helper.StringHelper.NULL;
import java.util.Date;
import com.google.gson.JsonObject;
import li.strolch.utils.helper.StringHelper;
import li.strolch.utils.iso8601.ISO8601FormatFactory;
@ -64,7 +65,8 @@ public class ModelStatistics {
/**
* Adds the statistics of the other statistics to this statistics instance
*
* @param statistics further statistics to add to this {@link ModelStatistics}
* @param statistics
* further statistics to add to this {@link ModelStatistics}
*/
public void add(ModelStatistics statistics) {
this.nrOfOrders += statistics.nrOfOrders;
@ -89,4 +91,17 @@ public class ModelStatistics {
builder.append("]");
return builder.toString();
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("startTime",
this.startTime == null ? NULL : ISO8601FormatFactory.getInstance().formatDate(this.startTime));
json.addProperty("durationNanos", durationNanos);
json.addProperty("nrOfResources", nrOfResources);
json.addProperty("nrOfOrders", nrOfOrders);
json.addProperty("nrOfActivities", nrOfActivities);
return json;
}
}

View File

@ -7,6 +7,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
@ -63,6 +64,10 @@ public class ResponseUtil {
return Response.ok(json, MediaType.APPLICATION_JSON).build();
}
public static <T> Response toResponse(String member, T t, Function<T, JsonObject> toJson) {
return toResponse(member, toJson.apply(t));
}
public static Response toResponse(String member, JsonElement jsonElement) {
JsonObject response = new JsonObject();
response.addProperty(MSG, StringHelper.DASH);
@ -73,6 +78,10 @@ public class ResponseUtil {
return Response.ok(json, MediaType.APPLICATION_JSON).build();
}
public static <T> Response toResponse(String member, List<T> list, Function<T, JsonObject> toJson) {
return toResponse(member, list.stream().map(toJson).collect(Collectors.toList()));
}
public static Response toResponse(String member, List<JsonObject> jsonObjects) {
JsonObject response = new JsonObject();
response.addProperty(MSG, StringHelper.DASH);

View File

@ -15,6 +15,7 @@
*/
package li.strolch.service.executor;
import com.google.gson.JsonObject;
import li.strolch.service.api.ServiceResult;
import li.strolch.utils.helper.StringHelper;
@ -27,10 +28,6 @@ public class ServiceExecutionStatus {
private volatile boolean started;
private volatile ServiceResult result;
public ServiceExecutionStatus() {
// no arg constructor for JAXB
}
public ServiceExecutionStatus(String serviceName) {
this.serviceName = serviceName;
}
@ -72,4 +69,14 @@ public class ServiceExecutionStatus {
public synchronized void started() {
this.started = true;
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("serviceName", serviceName);
json.addProperty("started", started);
json.add("result", result.toJson());
return json;
}
}