TSK-276 Classification.CREATE in the schema should be a Timestamp rather than a Date

This commit is contained in:
BerndBreier 2018-02-15 12:09:00 +01:00 committed by Holger Hagen
parent 6a644b7db2
commit 28e13608b1
10 changed files with 70 additions and 160 deletions

View File

@ -1,7 +1,5 @@
package pro.taskana;
import java.time.Instant;
/**
* ClassificationQuery for generating dynamic sql.
*/
@ -64,11 +62,11 @@ public interface ClassificationQuery extends BaseQuery<ClassificationSummary> {
/**
* Add your created-Dates to your query.
*
* @param created
* date (as instant) of classification creation.
* @param createdIn
* the {@link TimeInterval} within which the searched-for classifications were created.
* @return the query
*/
ClassificationQuery created(Instant... created);
ClassificationQuery createdWithin(TimeInterval... createdIn);
/**
* Add your name to your query.

View File

@ -338,8 +338,7 @@ public interface TaskService {
* @return the result of the operations with Id and Exception for each failed task completion.
* @throws InvalidArgumentException
* If the taskId parameter is NULL.
* @throws NotAuthorizedException
*/
BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds)
throws InvalidArgumentException, NotAuthorizedException;
throws InvalidArgumentException;
}

View File

@ -28,7 +28,11 @@ public class TimeInterval {
}
public boolean isValid() {
return begin != null || end != null;
boolean isValid = begin != null || end != null;
if (begin != null && end != null && begin.isAfter(end)) {
isValid = false;
}
return isValid;
}
public Instant getBegin() {

View File

@ -1,6 +1,5 @@
package pro.taskana.impl;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
@ -12,6 +11,7 @@ import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery;
import pro.taskana.ClassificationSummary;
import pro.taskana.TaskanaEngine;
import pro.taskana.TimeInterval;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
@ -32,10 +32,10 @@ public class ClassificationQueryImpl implements ClassificationQuery {
private String[] type;
private String[] domain;
private Boolean validInDomain;
private Instant[] created;
private TimeInterval[] createdIn;
private String[] nameIn;
private String[] nameLike;
private String description;
private String descriptionLike;
private int[] priority;
private String[] serviceLevelIn;
private String[] serviceLevelLike;
@ -99,8 +99,13 @@ public class ClassificationQueryImpl implements ClassificationQuery {
}
@Override
public ClassificationQuery created(Instant... created) {
this.created = created;
public ClassificationQuery createdWithin(TimeInterval... createdIn) {
this.createdIn = createdIn;
for (TimeInterval ti : createdIn) {
if (!ti.isValid()) {
throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
}
}
return this;
}
@ -118,7 +123,7 @@ public class ClassificationQueryImpl implements ClassificationQuery {
@Override
public ClassificationQuery descriptionLike(String description) {
this.description = description;
this.descriptionLike = description;
return this;
}
@ -313,250 +318,126 @@ public class ClassificationQueryImpl implements ClassificationQuery {
return key;
}
public void setKey(String[] key) {
this.key = key;
}
public String[] getParentClassificationKey() {
return parentClassificationKey;
}
public void setParentClassificationKey(String[] parentClassificationKey) {
this.parentClassificationKey = parentClassificationKey;
}
public String[] getCategory() {
return category;
}
public void setCategory(String[] category) {
this.category = category;
}
public String[] getType() {
return type;
}
public void setType(String[] type) {
this.type = type;
}
public String[] getNameIn() {
return nameIn;
}
public void setNameIn(String[] nameIn) {
this.nameIn = nameIn;
}
public String[] getNameLike() {
return nameLike;
}
public void setNameLike(String[] nameLike) {
this.nameLike = nameLike;
}
public String getDescriptionLike() {
return description;
}
public void setDescriptionLike(String description) {
this.description = description;
return descriptionLike;
}
public int[] getPriority() {
return priority;
}
public void setPriority(int[] priority) {
this.priority = priority;
}
public String[] getServiceLevelIn() {
return serviceLevelIn;
}
public void setServiceLevelIn(String[] serviceLevel) {
this.serviceLevelIn = serviceLevel;
}
public String[] getServiceLevelLike() {
return serviceLevelLike;
}
public void setServiceLevelLike(String[] serviceLevelLike) {
this.serviceLevelLike = serviceLevelLike;
}
public String[] getDomain() {
return domain;
}
public void setDomain(String[] domain) {
this.domain = domain;
}
public Boolean getValidInDomain() {
return validInDomain;
}
public void setValidInDomain(Boolean validInDomain) {
this.validInDomain = validInDomain;
}
public Instant[] getCreated() {
return created;
}
public void setCreated(Instant[] created) {
this.created = created;
public TimeInterval[] getCreatedIn() {
return createdIn;
}
public String[] getApplicationEntryPointIn() {
return applicationEntryPointIn;
}
public void setApplicationEntryPointIn(String[] applicationEntryPoint) {
this.applicationEntryPointIn = applicationEntryPoint;
}
public String[] getApplicationEntryPointLike() {
return applicationEntryPointLike;
}
public void setApplicationEntryPointLike(String[] applicationEntryPoint) {
this.applicationEntryPointLike = applicationEntryPoint;
}
public String[] getCustom1In() {
return custom1In;
}
public void setCustom1In(String[] custom1In) {
this.custom1In = custom1In;
}
public String[] getCustom1Like() {
return custom1Like;
}
public void setCustom1Like(String[] custom1Like) {
this.custom1Like = custom1Like;
}
public String[] getCustom2In() {
return custom2In;
}
public void setCustom2In(String[] custom2In) {
this.custom2In = custom2In;
}
public String[] getCustom2Like() {
return custom2Like;
}
public void setCustom2Like(String[] custom2Like) {
this.custom2Like = custom2Like;
}
public String[] getCustom3In() {
return custom3In;
}
public void setCustom3In(String[] custom3In) {
this.custom3In = custom3In;
}
public String[] getCustom3Like() {
return custom3Like;
}
public void setCustom3Like(String[] custom3Like) {
this.custom3Like = custom3Like;
}
public String[] getCustom4In() {
return custom4In;
}
public void setCustom4In(String[] custom4In) {
this.custom4In = custom4In;
}
public String[] getCustom4Like() {
return custom4Like;
}
public void setCustom4Like(String[] custom4Like) {
this.custom4Like = custom4Like;
}
public String[] getCustom5In() {
return custom5In;
}
public void setCustom5In(String[] custom5In) {
this.custom5In = custom5In;
}
public String[] getCustom5Like() {
return custom5Like;
}
public void setCustom5Like(String[] custom5Like) {
this.custom5Like = custom5Like;
}
public String[] getCustom6In() {
return custom6In;
}
public void setCustom6In(String[] custom6In) {
this.custom6In = custom6In;
}
public String[] getCustom6Like() {
return custom6Like;
}
public void setCustom6Like(String[] custom6Like) {
this.custom6Like = custom6Like;
}
public String[] getCustom7In() {
return custom7In;
}
public void setCustom7In(String[] custom7In) {
this.custom7In = custom7In;
}
public String[] getCustom7Like() {
return custom7Like;
}
public void setCustom7Like(String[] custom7Like) {
this.custom7Like = custom7Like;
}
public String[] getCustom8In() {
return custom8In;
}
public void setCustom8In(String[] custom8In) {
this.custom8In = custom8In;
}
public String[] getCustom8Like() {
return custom8Like;
}
public void setCustom8Like(String[] custom8Like) {
this.custom8Like = custom8Like;
}
@Override
public long count() {
LOGGER.debug("entry to count(), this = {}", this);
@ -574,8 +455,8 @@ public class ClassificationQueryImpl implements ClassificationQuery {
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ClassificationQueryImpl [taskanaEngineImpl=");
builder.append(taskanaEngineImpl);
builder.append("ClassificationQueryImpl [key=");
builder.append(Arrays.toString(key));
builder.append(", parentClassificationKey=");
builder.append(Arrays.toString(parentClassificationKey));
builder.append(", category=");
@ -586,14 +467,14 @@ public class ClassificationQueryImpl implements ClassificationQuery {
builder.append(Arrays.toString(domain));
builder.append(", validInDomain=");
builder.append(validInDomain);
builder.append(", created=");
builder.append(Arrays.toString(created));
builder.append(", createdIn=");
builder.append(Arrays.toString(createdIn));
builder.append(", nameIn=");
builder.append(Arrays.toString(nameIn));
builder.append(", nameLike=");
builder.append(Arrays.toString(nameLike));
builder.append(", descriptionLike=");
builder.append(description);
builder.append(descriptionLike);
builder.append(", priority=");
builder.append(Arrays.toString(priority));
builder.append(", serviceLevelIn=");
@ -639,4 +520,5 @@ public class ClassificationQueryImpl implements ClassificationQuery {
builder.append("]");
return builder.toString();
}
}

View File

@ -209,7 +209,7 @@ public class TaskServiceImpl implements TaskService {
@Override
public BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds)
throws InvalidArgumentException, NotAuthorizedException {
throws InvalidArgumentException {
try {
LOGGER.debug("entry to completeTasks(taskIds = {})", taskIds);
taskanaEngineImpl.openConnection();

View File

@ -136,7 +136,7 @@ public interface QueryMapper {
+ "<if test='type != null'>AND TYPE IN(<foreach item='item' collection='type' separator=',' >#{item}</foreach>)</if> "
+ "<if test='domain != null'>AND DOMAIN IN(<foreach item='item' collection='domain' separator=',' >#{item}</foreach>)</if> "
+ "<if test='validInDomain != null'>AND VALID_IN_DOMAIN = #{validInDomain}</if> "
+ "<if test='created != null'>AND CREATED IN(<foreach item='item' collection='created' separator=',' >SUBSTRING(#{item}, 1, 10)</foreach>)</if> "
+ "<if test='createdIn !=null'> AND ( <foreach item='item' collection='createdIn' separator=' OR ' > ( <if test='item.begin!=null'> CREATED &gt;= #{item.begin} </if> <if test='item.begin!=null and item.end!=null'> AND </if><if test='item.end!=null'> CREATED &lt;=#{item.end} </if>)</foreach>)</if> "
+ "<if test='nameIn != null'>AND NAME IN(<foreach item='item' collection='nameIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='nameLike != null'>AND (<foreach item='item' collection='nameLike' separator=' OR '>NAME LIKE #{item}</foreach>)</if> "
+ "<if test='descriptionLike != null'>AND DESCRIPTION like #{descriptionLike}</if> "
@ -351,7 +351,7 @@ public interface QueryMapper {
+ "<if test='type != null'>AND TYPE IN(<foreach item='item' collection='type' separator=',' >#{item}</foreach>)</if> "
+ "<if test='domain != null'>AND DOMAIN IN(<foreach item='item' collection='domain' separator=',' >#{item}</foreach>)</if> "
+ "<if test='validInDomain != null'>AND VALID_IN_DOMAIN = #{validInDomain}</if> "
+ "<if test='created != null'>AND CREATED IN(<foreach item='item' collection='created' separator=',' >SUBSTRING(#{item}, 1, 10)</foreach>)</if> "
+ "<if test='createdIn !=null'> AND ( <foreach item='item' collection='createdIn' separator=' OR ' > ( <if test='item.begin!=null'> CREATED &gt;= #{item.begin} </if> <if test='item.begin!=null and item.end!=null'> AND </if><if test='item.end!=null'> CREATED &lt;=#{item.end} </if>)</foreach>)</if> "
+ "<if test='nameIn != null'>AND NAME IN(<foreach item='item' collection='nameIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='nameLike != null'>AND (<foreach item='item' collection='nameLike' separator=' OR '>NAME LIKE #{item}</foreach>)</if> "
+ "<if test='descriptionLike != null'>AND DESCRIPTION like #{descriptionLike}</if> "

View File

@ -81,7 +81,7 @@ CREATE TABLE CLASSIFICATION(
TYPE VARCHAR(32),
DOMAIN VARCHAR(255) NOT NULL,
VALID_IN_DOMAIN BOOLEAN NOT NULL,
CREATED DATE NULL,
CREATED TIMESTAMP NULL,
NAME VARCHAR(255) NULL,
DESCRIPTION VARCHAR(255) NULL,
PRIORITY INT NULL,

View File

@ -1,11 +1,11 @@
package pro.taskana.impl;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import pro.taskana.ClassificationQuery;
import pro.taskana.ClassificationSummary;
import pro.taskana.TimeInterval;
/**
* Created by BV on 26.10.2017.
@ -52,7 +52,7 @@ public class TestClassificationQuery implements ClassificationQuery {
}
@Override
public ClassificationQuery created(Instant... created) {
public ClassificationQuery createdWithin(TimeInterval... created) {
return this;
}

View File

@ -9,6 +9,10 @@ import static org.junit.Assert.fail;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;
import javax.security.auth.login.LoginException;
@ -26,6 +30,7 @@ import pro.taskana.ClassificationService;
import pro.taskana.ClassificationSummary;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.TimeInterval;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
@ -183,11 +188,10 @@ public class ClassificationServiceImplIntAutoCommitTest {
InvalidArgumentException {
Classification classification = this.createDummyClassificationWithUniqueKey("", "type1");
classification = classificationService.createClassification(classification);
Instant today = Instant.now();
List<ClassificationSummary> list = classificationService.createClassificationQuery()
.validInDomain(Boolean.TRUE)
.created(today)
.createdWithin(today())
.list();
Assert.assertEquals(1, list.size());
@ -269,7 +273,10 @@ public class ClassificationServiceImplIntAutoCommitTest {
Assert.assertEquals(1, list.size());
list = classificationService.createClassificationQuery().custom1In("custom2").list();
Assert.assertEquals(1, list.size());
list = classificationService.createClassificationQuery().descriptionLike("DESC1").categoryIn("category1").list();
list = classificationService.createClassificationQuery()
.descriptionLike("DESC1")
.categoryIn("category1")
.list();
Assert.assertEquals(2, list.size());
}
@ -375,7 +382,7 @@ public class ClassificationServiceImplIntAutoCommitTest {
list = classificationService.createClassificationQuery().validInDomain(true).list();
Assert.assertEquals(listAll.size(), list.size());
list = classificationService.createClassificationQuery().created(Instant.now()).list();
list = classificationService.createClassificationQuery().createdWithin(today()).list();
Assert.assertEquals(listAll.size(), list.size());
list = classificationService.createClassificationQuery().domainIn("domain1").validInDomain(false).list();
@ -391,6 +398,12 @@ public class ClassificationServiceImplIntAutoCommitTest {
FileUtils.deleteRecursive("~/data", true);
}
private TimeInterval today() {
Instant begin = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant();
Instant end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant();
return new TimeInterval(begin, end);
}
private Classification createDummyClassificationWithUniqueKey(String domain, String type) {
Classification classification = classificationService.newClassification(domain, "TEST" + counter, type);
counter++;

View File

@ -10,6 +10,10 @@ import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;
import javax.security.auth.login.LoginException;
@ -28,6 +32,7 @@ import pro.taskana.ClassificationService;
import pro.taskana.ClassificationSummary;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.TimeInterval;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException;
@ -204,10 +209,9 @@ public class ClassificationServiceImplIntExplicitTest {
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey("", "t1");
classificationService.createClassification(classification);
Instant today = Instant.now();
List<ClassificationSummary> list = classificationService.createClassificationQuery()
.validInDomain(Boolean.TRUE)
.created(today)
.createdWithin(today())
.list();
Assert.assertEquals(1, list.size());
}
@ -301,7 +305,10 @@ public class ClassificationServiceImplIntExplicitTest {
Assert.assertEquals(1, list.size());
list = classificationService.createClassificationQuery().custom1In("custom2").list();
Assert.assertEquals(1, list.size());
list = classificationService.createClassificationQuery().descriptionLike("DESC1").categoryIn("category1").list();
list = classificationService.createClassificationQuery()
.descriptionLike("DESC1")
.categoryIn("category1")
.list();
Assert.assertEquals(2, list.size());
connection.commit();
}
@ -409,7 +416,7 @@ public class ClassificationServiceImplIntExplicitTest {
list = classificationService.createClassificationQuery().validInDomain(true).list();
Assert.assertEquals(2, list.size());
list = classificationService.createClassificationQuery().created(Instant.now()).list();
list = classificationService.createClassificationQuery().createdWithin(today()).list();
Assert.assertEquals(2, list.size());
list = classificationService.createClassificationQuery().domainIn("domain1").validInDomain(false).list();
Assert.assertEquals(0, list.size());
@ -441,4 +448,11 @@ public class ClassificationServiceImplIntExplicitTest {
counter++;
return classification;
}
private TimeInterval today() {
Instant begin = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant();
Instant end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant();
return new TimeInterval(begin, end);
}
}