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:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
50
docs-core/src/main/java/com/sismics/util/JsonUtil.java
Normal file
50
docs-core/src/main/java/com/sismics/util/JsonUtil.java
Normal 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("_");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user