TSK-342: REST Instant to Timestamp with Converter.

This commit is contained in:
Marcel Lengl 2018-02-22 15:50:31 +01:00 committed by Holger Hagen
parent b5d5125632
commit 0c96464e17
8 changed files with 86 additions and 20 deletions

View File

@ -3,7 +3,7 @@ INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('2', '2', 'Max', true, true,
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('3', '3', 'Simone', true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('4', '4', 'user_1_1', true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
-- KSC authorizations ( ID, WB_KEY, ACCESS_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE, C1, .., C12)
-- KSC authorizations ( ID, WB_ID, ACCESS_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE, C1, .., C12)
-- PPKs
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('WAI:100000000000000000000000000000000001', 'WBI:100000000000000000000000000000000004', 'teamlead_1', true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('WAI:100000000000000000000000000000000002', 'WBI:100000000000000000000000000000000005', 'teamlead_2', true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);

View File

@ -1,10 +1,11 @@
package pro.taskana.rest.resource;
import java.time.Instant;
import java.sql.Timestamp;
import org.springframework.hateoas.ResourceSupport;
public class ClassificationResource extends ResourceSupport {
public String classificationId;
public String key;
public String parentId;
@ -12,7 +13,7 @@ public class ClassificationResource extends ResourceSupport {
public String type;
public String domain;
public boolean isValidInDomain;
public Instant created;
public Timestamp created;
public String name;
public String description;
public int priority;
@ -27,11 +28,15 @@ public class ClassificationResource extends ResourceSupport {
public String custom7;
public String custom8;
public ClassificationResource(String classificationId, String key, String parentId, String category, String type, String domain,
boolean isValidInDomain, Instant created, String name, String description,
int priority, String serviceLevel, String applicationEntryPoint, String custom1,
String custom2, String custom3, String custom4, String custom5, String custom6,
String custom7, String custom8) {
public ClassificationResource() {
}
public ClassificationResource(String classificationId, String key, String parentId, String category, String type,
String domain,
boolean isValidInDomain, Timestamp created, String name, String description,
int priority, String serviceLevel, String applicationEntryPoint, String custom1,
String custom2, String custom3, String custom4, String custom5, String custom6,
String custom7, String custom8) {
super();
this.classificationId = classificationId;
this.key = key;

View File

@ -32,6 +32,9 @@ public class WorkbasketAccessItemResource extends ResourceSupport {
public boolean permCustom11;
public boolean permCustom12;
public WorkbasketAccessItemResource() {
}
public WorkbasketAccessItemResource(String accessItemId, String workbasketId, String accessId, boolean permRead,
boolean permOpen, boolean permAppend, boolean permTransfer, boolean permDistribute, boolean permCustom1,
boolean permCustom2, boolean permCustom3, boolean permCustom4, boolean permCustom5, boolean permCustom6,

View File

@ -1,6 +1,6 @@
package pro.taskana.rest.resource;
import java.time.Instant;
import java.sql.Timestamp;
import javax.validation.constraints.NotNull;
@ -24,8 +24,8 @@ public class WorkbasketResource extends ResourceSupport {
@NotNull
public WorkbasketType type;
public Instant created;
public Instant modified;
public Timestamp created;
public Timestamp modified;
public String description;
public String owner;
public String custom1;
@ -37,9 +37,12 @@ public class WorkbasketResource extends ResourceSupport {
public String orgLevel3;
public String orgLevel4;
public WorkbasketResource() {
}
public WorkbasketResource(String workbasketId, String key, String name, String domain, WorkbasketType type,
Instant created,
Instant modified, String description, String owner, String custom1, String custom2, String custom3,
Timestamp created,
Timestamp modified, String description, String owner, String custom1, String custom2, String custom3,
String custom4, String orgLevel1, String orgLevel2, String orgLevel3, String orgLevel4) {
super();
this.workbasketId = workbasketId;

View File

@ -29,6 +29,9 @@ public class WorkbasketSummaryResource extends ResourceSupport {
public String orgLevel3;
public String orgLevel4;
public WorkbasketSummaryResource() {
}
public WorkbasketSummaryResource(String workbasketId, String key, String name, String description, String owner,
String domain, WorkbasketType type, String orgLevel1, String orgLevel2, String orgLevel3, String orgLevel4) {
super();

View File

@ -1,5 +1,7 @@
package pro.taskana.rest.resource.mapper;
import static pro.taskana.rest.util.TimeConverter.convertToTimestampFromInstant;
import pro.taskana.Classification;
import pro.taskana.rest.resource.ClassificationResource;
@ -14,7 +16,7 @@ public class ClassificationMapper {
classification.getType(),
classification.getDomain(),
classification.getIsValidInDomain(),
classification.getCreated(),
convertToTimestampFromInstant(classification.getCreated()),
classification.getName(),
classification.getDescription(),
classification.getPriority(),
@ -27,7 +29,6 @@ public class ClassificationMapper {
classification.getCustom5(),
classification.getCustom6(),
classification.getCustom7(),
classification.getCustom8()
);
classification.getCustom8());
}
}

View File

@ -2,6 +2,8 @@ package pro.taskana.rest.resource.mapper;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static pro.taskana.rest.util.TimeConverter.convertToInstantFromTimestamp;
import static pro.taskana.rest.util.TimeConverter.convertToTimestampFromInstant;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,8 +20,9 @@ public class WorkbasketMapper {
public WorkbasketResource toResource(Workbasket wb) {
WorkbasketResource resource = new WorkbasketResource(wb.getId(), wb.getKey(), wb.getName(), wb.getDomain(),
wb.getType(), wb.getCreated(),
wb.getModified(), wb.getDescription(), wb.getOwner(), wb.getCustom1(), wb.getCustom2(), wb.getCustom3(),
wb.getType(), convertToTimestampFromInstant(wb.getCreated()),
convertToTimestampFromInstant(wb.getModified()), wb.getDescription(), wb.getOwner(), wb.getCustom1(),
wb.getCustom2(), wb.getCustom3(),
wb.getCustom4(),
wb.getOrgLevel1(), wb.getOrgLevel2(), wb.getOrgLevel3(), wb.getOrgLevel4());
@ -33,8 +36,8 @@ public class WorkbasketMapper {
wbModel.setId(wbResource.workbasketId);
wbModel.setName(wbResource.name);
wbModel.setType(wbResource.type);
wbModel.setCreated(wbResource.created);
wbModel.setModified(wbResource.modified);
wbModel.setCreated(convertToInstantFromTimestamp(wbResource.created));
wbModel.setModified(convertToInstantFromTimestamp(wbResource.modified));
wbModel.setDescription(wbResource.description);
wbModel.setOwner(wbResource.owner);
wbModel.setCustom1(wbResource.custom1);

View File

@ -0,0 +1,48 @@
package pro.taskana.rest.util;
import java.sql.Timestamp;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
/**
* This class is used to convert {@link Instant} to {@link Timestamp} and {@link Timestamp} to {@link Instant} for
* incompatible REST-Models.
*/
public class TimeConverter {
/**
* Converting a {@link Timestamp} to {@link Instant} using UTC as ZoneOffset.
*
* @param timestamp
* which should be converted to Instant.
* @return {@link Instant} representing the timestamp with UTC ZoneOffset or NULL if parameter is NULL, too.
*/
public static Instant convertToInstantFromTimestamp(Timestamp timestamp) {
Instant instant = null;
if (timestamp != null) {
instant = timestamp.toLocalDateTime().atOffset(ZoneOffset.UTC).toInstant();
}
return instant;
}
/**
* Converting an {@link Instant}-Time into a UTC-{@link Timestamp} using UTC-ZoneOffset.
*
* @param instantTime
* which should be converted to {@link Timestamp}.
* @return timestamp using UTC or NULL if the parameter was NULL, too.
* @throws DateTimeException
* when the value does exceeds the supported range.
*/
public static Timestamp convertToTimestampFromInstant(Instant instantTime)
throws DateTimeException {
Timestamp timestamp = null;
if (instantTime != null) {
LocalDateTime ldt = LocalDateTime.ofInstant(instantTime, ZoneOffset.UTC);
timestamp = Timestamp.valueOf(ldt);
}
return timestamp;
}
}