TSK-342: replaced sql timestamp with Instant.toString().

This commit is contained in:
Holger Hagen 2018-02-23 11:22:21 +01:00
parent 0c96464e17
commit 25107f5760
5 changed files with 14 additions and 67 deletions

View File

@ -1,7 +1,5 @@
package pro.taskana.rest.resource;
import java.sql.Timestamp;
import org.springframework.hateoas.ResourceSupport;
public class ClassificationResource extends ResourceSupport {
@ -13,7 +11,7 @@ public class ClassificationResource extends ResourceSupport {
public String type;
public String domain;
public boolean isValidInDomain;
public Timestamp created;
public String created; // ISO-8601
public String name;
public String description;
public int priority;
@ -33,7 +31,7 @@ public class ClassificationResource extends ResourceSupport {
public ClassificationResource(String classificationId, String key, String parentId, String category, String type,
String domain,
boolean isValidInDomain, Timestamp created, String name, String description,
boolean isValidInDomain, String 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) {

View File

@ -1,7 +1,5 @@
package pro.taskana.rest.resource;
import java.sql.Timestamp;
import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport;
@ -24,8 +22,8 @@ public class WorkbasketResource extends ResourceSupport {
@NotNull
public WorkbasketType type;
public Timestamp created;
public Timestamp modified;
public String created; // ISO-8601
public String modified; // ISO-8601
public String description;
public String owner;
public String custom1;
@ -41,8 +39,8 @@ public class WorkbasketResource extends ResourceSupport {
}
public WorkbasketResource(String workbasketId, String key, String name, String domain, WorkbasketType type,
Timestamp created,
Timestamp modified, String description, String owner, String custom1, String custom2, String custom3,
String created,
String 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

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

View File

@ -2,8 +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 java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,8 +20,8 @@ public class WorkbasketMapper {
public WorkbasketResource toResource(Workbasket wb) {
WorkbasketResource resource = new WorkbasketResource(wb.getId(), wb.getKey(), wb.getName(), wb.getDomain(),
wb.getType(), convertToTimestampFromInstant(wb.getCreated()),
convertToTimestampFromInstant(wb.getModified()), wb.getDescription(), wb.getOwner(), wb.getCustom1(),
wb.getType(), wb.getCreated().toString(), wb.getModified().toString(), wb.getDescription(), wb.getOwner(),
wb.getCustom1(),
wb.getCustom2(), wb.getCustom3(),
wb.getCustom4(),
wb.getOrgLevel1(), wb.getOrgLevel2(), wb.getOrgLevel3(), wb.getOrgLevel4());
@ -36,8 +36,8 @@ public class WorkbasketMapper {
wbModel.setId(wbResource.workbasketId);
wbModel.setName(wbResource.name);
wbModel.setType(wbResource.type);
wbModel.setCreated(convertToInstantFromTimestamp(wbResource.created));
wbModel.setModified(convertToInstantFromTimestamp(wbResource.modified));
wbModel.setCreated(Instant.parse(wbResource.created));
wbModel.setModified(Instant.parse(wbResource.modified));
wbModel.setDescription(wbResource.description);
wbModel.setOwner(wbResource.owner);
wbModel.setCustom1(wbResource.custom1);

View File

@ -1,48 +0,0 @@
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;
}
}