TSK-447: code cleanup
This commit is contained in:
parent
cf0921ba8d
commit
44dfbb983e
|
|
@ -396,8 +396,15 @@ public class ClassificationServiceImpl implements ClassificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isReferentialIntegrityConstraintViolation(PersistenceException e) {
|
private boolean isReferentialIntegrityConstraintViolation(PersistenceException e) {
|
||||||
return e.getCause() instanceof SQLException && ((SQLException) e.getCause()).getSQLState().equals("23503")
|
return isH2OrPostgresIntegrityConstraintViolation(e) || isDb2IntegrityConstraintViolation(e);
|
||||||
|| e.getCause() instanceof SQLIntegrityConstraintViolationException && e.getMessage().contains("-532");
|
}
|
||||||
|
|
||||||
|
private boolean isDb2IntegrityConstraintViolation(PersistenceException e) {
|
||||||
|
return e.getCause() instanceof SQLIntegrityConstraintViolationException && e.getMessage().contains("-532");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isH2OrPostgresIntegrityConstraintViolation(PersistenceException e) {
|
||||||
|
return e.getCause() instanceof SQLException && ((SQLException) e.getCause()).getSQLState().equals("23503");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -487,10 +487,9 @@ public class TaskServiceImpl implements TaskService {
|
||||||
taskanaEngine.openConnection();
|
taskanaEngine.openConnection();
|
||||||
LOGGER.debug("entry to transferBulk(targetWbId = {}, taskIds = {})", destinationWorkbasketId, taskIds);
|
LOGGER.debug("entry to transferBulk(targetWbId = {}, taskIds = {})", destinationWorkbasketId, taskIds);
|
||||||
// Check pre-conditions with trowing Exceptions
|
// Check pre-conditions with trowing Exceptions
|
||||||
if (destinationWorkbasketId == null || destinationWorkbasketId.isEmpty() || taskIds == null
|
if (destinationWorkbasketId == null || destinationWorkbasketId.isEmpty()) {
|
||||||
|| taskIds.isEmpty()) {
|
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"DestinationWorkbasketId or TaskIds must not be null or empty.");
|
"DestinationWorkbasketId must not be null or empty.");
|
||||||
}
|
}
|
||||||
Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketId);
|
Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketId);
|
||||||
|
|
||||||
|
|
@ -510,9 +509,9 @@ public class TaskServiceImpl implements TaskService {
|
||||||
LOGGER.debug("entry to transferBulk(targetWbKey = {}, domain = {}, taskIds = {})", destinationWorkbasketKey,
|
LOGGER.debug("entry to transferBulk(targetWbKey = {}, domain = {}, taskIds = {})", destinationWorkbasketKey,
|
||||||
destinationWorkbasketDomain, taskIds);
|
destinationWorkbasketDomain, taskIds);
|
||||||
// Check pre-conditions with trowing Exceptions
|
// Check pre-conditions with trowing Exceptions
|
||||||
if (destinationWorkbasketKey == null || destinationWorkbasketDomain == null || taskIds == null) {
|
if (destinationWorkbasketKey == null || destinationWorkbasketDomain == null) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"DestinationWorkbasketKey or domain or TaskIds can´t be used as NULL-Parameter.");
|
"DestinationWorkbasketKey or domain can´t be used as NULL-Parameter.");
|
||||||
}
|
}
|
||||||
Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketKey,
|
Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketKey,
|
||||||
destinationWorkbasketDomain);
|
destinationWorkbasketDomain);
|
||||||
|
|
@ -527,6 +526,12 @@ public class TaskServiceImpl implements TaskService {
|
||||||
|
|
||||||
private BulkOperationResults<String, TaskanaException> transferTasks(List<String> taskIdsToBeTransferred,
|
private BulkOperationResults<String, TaskanaException> transferTasks(List<String> taskIdsToBeTransferred,
|
||||||
Workbasket destinationWorkbasket) throws InvalidArgumentException {
|
Workbasket destinationWorkbasket) throws InvalidArgumentException {
|
||||||
|
// Check pre-conditions with trowing Exceptions
|
||||||
|
if (taskIdsToBeTransferred == null
|
||||||
|
|| taskIdsToBeTransferred.isEmpty() || taskIdsToBeTransferred.contains("")) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
"TaskIds must not be null,empty or an empty string.");
|
||||||
|
}
|
||||||
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
|
|
||||||
// convert to ArrayList<String> if necessary to prevent a UnsupportedOperationException while removing
|
// convert to ArrayList<String> if necessary to prevent a UnsupportedOperationException while removing
|
||||||
|
|
@ -558,7 +563,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
}
|
}
|
||||||
// check source WB (read)+transfer
|
// check source WB (read)+transfer
|
||||||
Set<String> workbasketIds = new HashSet<>();
|
Set<String> workbasketIds = new HashSet<>();
|
||||||
taskSummaries.stream().forEach(t -> workbasketIds.add(t.getWorkbasketId()));
|
taskSummaries.forEach(t -> workbasketIds.add(t.getWorkbasketId()));
|
||||||
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
|
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
|
||||||
query.setUsedToAugmentTasks(true);
|
query.setUsedToAugmentTasks(true);
|
||||||
List<WorkbasketSummary> sourceWorkbaskets;
|
List<WorkbasketSummary> sourceWorkbaskets;
|
||||||
|
|
@ -585,8 +590,8 @@ public class TaskServiceImpl implements TaskService {
|
||||||
bulkLog.addError(currentTaskId,
|
bulkLog.addError(currentTaskId,
|
||||||
new InvalidStateException("Completed task with id " + currentTaskId + " cannot be transferred."));
|
new InvalidStateException("Completed task with id " + currentTaskId + " cannot be transferred."));
|
||||||
taskIdIterator.remove();
|
taskIdIterator.remove();
|
||||||
} else if (!sourceWorkbaskets.stream()
|
} else if (sourceWorkbaskets.stream()
|
||||||
.anyMatch(wb -> taskSummary.getWorkbasketId().equals(wb.getId()))) {
|
.noneMatch(wb -> taskSummary.getWorkbasketId().equals(wb.getId()))) {
|
||||||
bulkLog.addError(currentTaskId,
|
bulkLog.addError(currentTaskId,
|
||||||
new NotAuthorizedException(
|
new NotAuthorizedException(
|
||||||
"The workbasket of this task got not TRANSFER permissions. TaskId=" + currentTaskId));
|
"The workbasket of this task got not TRANSFER permissions. TaskId=" + currentTaskId));
|
||||||
|
|
@ -1397,43 +1402,6 @@ public class TaskServiceImpl implements TaskService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* hold a pair of priority and Duration.
|
|
||||||
*
|
|
||||||
* @author bbr
|
|
||||||
*/
|
|
||||||
static class PrioDurationHolder {
|
|
||||||
|
|
||||||
private Duration duration;
|
|
||||||
|
|
||||||
private int prio;
|
|
||||||
|
|
||||||
PrioDurationHolder(Duration duration, int prio) {
|
|
||||||
super();
|
|
||||||
this.duration = duration;
|
|
||||||
this.prio = prio;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getDuration() {
|
|
||||||
return duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPrio() {
|
|
||||||
return prio;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("PrioDurationHolder [duration=");
|
|
||||||
builder.append(duration);
|
|
||||||
builder.append(", prio=");
|
|
||||||
builder.append(prio);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BulkOperationResults<String, Exception> classificationChanged(String taskId, String classificationId)
|
BulkOperationResults<String, Exception> classificationChanged(String taskId, String classificationId)
|
||||||
throws TaskNotFoundException, ClassificationNotFoundException {
|
throws TaskNotFoundException, ClassificationNotFoundException {
|
||||||
LOGGER.debug("entry to classificationChanged(taskId = {} , classificationId = {} )", taskId, classificationId);
|
LOGGER.debug("entry to classificationChanged(taskId = {} , classificationId = {} )", taskId, classificationId);
|
||||||
|
|
@ -1501,4 +1469,41 @@ public class TaskServiceImpl implements TaskService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hold a pair of priority and Duration.
|
||||||
|
*
|
||||||
|
* @author bbr
|
||||||
|
*/
|
||||||
|
static class PrioDurationHolder {
|
||||||
|
|
||||||
|
private Duration duration;
|
||||||
|
|
||||||
|
private int prio;
|
||||||
|
|
||||||
|
PrioDurationHolder(Duration duration, int prio) {
|
||||||
|
super();
|
||||||
|
this.duration = duration;
|
||||||
|
this.prio = prio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Duration getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPrio() {
|
||||||
|
return prio;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("PrioDurationHolder [duration=");
|
||||||
|
builder.append(duration);
|
||||||
|
builder.append(", prio=");
|
||||||
|
builder.append(prio);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,9 +183,7 @@ public interface TaskMapper {
|
||||||
@Param("referencetask") TaskSummaryImpl referencetask);
|
@Param("referencetask") TaskSummaryImpl referencetask);
|
||||||
|
|
||||||
@Select("<script>SELECT ID, STATE, WORKBASKET_ID FROM TASKANA.TASK "
|
@Select("<script>SELECT ID, STATE, WORKBASKET_ID FROM TASKANA.TASK "
|
||||||
+ "<if test=\" taskIds != null and !taskIds.isEmpty() \">"
|
|
||||||
+ "WHERE ID IN( <foreach item='item' collection='taskIds' separator=',' >#{item}</foreach> ) "
|
+ "WHERE ID IN( <foreach item='item' collection='taskIds' separator=',' >#{item}</foreach> ) "
|
||||||
+ "</if>"
|
|
||||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||||
+ "</script>")
|
+ "</script>")
|
||||||
@Results(value = {
|
@Results(value = {
|
||||||
|
|
|
||||||
|
|
@ -193,9 +193,7 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
@WithAccessId(userName = "teamlead_1", groupNames = {"group_1"})
|
@WithAccessId(userName = "teamlead_1", groupNames = {"group_1"})
|
||||||
@Test
|
@Test
|
||||||
public void testBulkTransferTaskWithExceptions()
|
public void testBulkTransferTaskWithExceptions()
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, TaskNotFoundException {
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
InvalidStateException, InvalidOwnerException {
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket("USER_1_1", "DOMAIN_A");
|
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket("USER_1_1", "DOMAIN_A");
|
||||||
Instant before = Instant.now();
|
Instant before = Instant.now();
|
||||||
|
|
@ -203,7 +201,6 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000006"); // working
|
taskIdList.add("TKI:000000000000000000000000000000000006"); // working
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000041"); // NotAuthorized READ
|
taskIdList.add("TKI:000000000000000000000000000000000041"); // NotAuthorized READ
|
||||||
taskIdList.add("TKI:200000000000000000000000000000000006"); // NotAuthorized TRANSFER
|
taskIdList.add("TKI:200000000000000000000000000000000006"); // NotAuthorized TRANSFER
|
||||||
taskIdList.add(""); // InvalidArgument
|
|
||||||
taskIdList.add(null); // InvalidArgument (added with ""), duplicate
|
taskIdList.add(null); // InvalidArgument (added with ""), duplicate
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000099"); // TaskNotFound
|
taskIdList.add("TKI:000000000000000000000000000000000099"); // TaskNotFound
|
||||||
taskIdList.add("TKI:100000000000000000000000000000000006"); // already completed
|
taskIdList.add("TKI:100000000000000000000000000000000006"); // already completed
|
||||||
|
|
@ -257,14 +254,11 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
userName = "teamlead_1",
|
userName = "teamlead_1",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test
|
@Test
|
||||||
public void testTransferTasksWithListNotSupportingRemove()
|
public void testTransferTasksWithListNotSupportingRemove() throws NotAuthorizedException, InvalidArgumentException,
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
WorkbasketNotFoundException {
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
InvalidStateException, InvalidOwnerException {
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
List<String> taskIds = Collections.singletonList("");
|
List<String> taskIds = Collections.singletonList("TKI:000000000000000000000000000000000006");
|
||||||
taskService.transferTasks("WBI:100000000000000000000000000000000006", taskIds);
|
taskService.transferTasks("WBI:100000000000000000000000000000000006", taskIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue