1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-14 02:06:25 +00:00

#159: display and validate route steps

This commit is contained in:
Benjamin Gamard
2018-02-02 12:37:56 +01:00
parent 8a854bb37d
commit 5b8cd18128
20 changed files with 292 additions and 50 deletions

View File

@@ -1,6 +1,10 @@
package com.sismics.docs.core.dao.jpa.dto;
import com.sismics.docs.core.constant.RouteStepType;
import com.sismics.util.JsonUtil;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
/**
* Route step DTO.
@@ -147,4 +151,23 @@ public class RouteStepDto {
this.validatorUserName = validatorUserName;
return this;
}
/**
* Transform in JSON.
*
* @return JSON object builder
*/
public JsonObjectBuilder toJson() {
return Json.createObjectBuilder()
.add("name", getName())
.add("type", getType().name())
.add("comment", JsonUtil.nullable(getComment()))
.add("end_date", JsonUtil.nullable(getEndDateTimestamp()))
.add("validator_username", JsonUtil.nullable(getValidatorUserName()))
.add("target", Json.createObjectBuilder()
.add("id", getTargetId())
.add("name", JsonUtil.nullable(getTargetName()))
.add("type", getTargetType()))
.add("transition", JsonUtil.nullable(getTransition()));
}
}

View File

@@ -0,0 +1,50 @@
package com.sismics.util;
import javax.json.Json;
import javax.json.JsonValue;
/**
* JSON utilities.
*
* @author bgamard
*/
public class JsonUtil {
/**
* Returns a JsonValue from a String.
*
* @param value Value
* @return JsonValue
*/
public static JsonValue nullable(String value) {
if (value == null) {
return JsonValue.NULL;
}
return Json.createObjectBuilder().add("_", value).build().get("_");
}
/**
* Returns a JsonValue from an Integer.
*
* @param value Value
* @return JsonValue
*/
public static JsonValue nullable(Integer value) {
if (value == null) {
return JsonValue.NULL;
}
return Json.createObjectBuilder().add("_", value).build().get("_");
}
/**
* Returns a JsonValue from an Long.
*
* @param value Value
* @return JsonValue
*/
public static JsonValue nullable(Long value) {
if (value == null) {
return JsonValue.NULL;
}
return Json.createObjectBuilder().add("_", value).build().get("_");
}
}