TSK-1375: fixed SQL Error during display name augmentation in the reports

This commit is contained in:
Mustapha Zorgati 2020-09-15 12:21:49 +02:00
parent fa19359795
commit a2d79c8a7b
9 changed files with 149 additions and 5 deletions

View File

@ -459,7 +459,7 @@ public interface MonitorMapper {
+ "AND T.CLASSIFICATION_ID NOT IN (<foreach collection='excludedClassificationIds' item='excludedClassificationId' separator=','>#{excludedClassificationId}</foreach>) " + "AND T.CLASSIFICATION_ID NOT IN (<foreach collection='excludedClassificationIds' item='excludedClassificationId' separator=','>#{excludedClassificationId}</foreach>) "
+ "</if>" + "</if>"
+ "<if test='domains != null'>" + "<if test='domains != null'>"
+ "AND DOMAIN IN (<foreach collection='domains' item='domain' separator=','>#{domain}</foreach>) " + "AND T.DOMAIN IN (<foreach collection='domains' item='domain' separator=','>#{domain}</foreach>) "
+ "</if>" + "</if>"
+ "<if test='customAttributeFilter != null'>" + "<if test='customAttributeFilter != null'>"
+ "AND (<foreach collection='customAttributeFilter.keys' item='key' separator=' AND '>(T.${key} = '${customAttributeFilter.get(key)}')</foreach>) " + "AND (<foreach collection='customAttributeFilter.keys' item='key' separator=' AND '>(T.${key} = '${customAttributeFilter.get(key)}')</foreach>) "

View File

@ -70,7 +70,10 @@ public class ClassificationReportBuilderImpl
Map<String, String> displayMap = Map<String, String> displayMap =
classificationService classificationService
.createClassificationQuery() .createClassificationQuery()
.keyIn(report.getRows().keySet().toArray(new String[0])) .keyIn(
report.getRows().isEmpty()
? null
: report.getRows().keySet().toArray(new String[0]))
.domainIn(domains != null ? domains.toArray(new String[0]) : null) .domainIn(domains != null ? domains.toArray(new String[0]) : null)
.list() .list()
.stream() .stream()
@ -119,12 +122,12 @@ public class ClassificationReportBuilderImpl
.map(report::getRow) .map(report::getRow)
.flatMap(row -> row.getFoldableRows().values().stream()) .flatMap(row -> row.getFoldableRows().values().stream())
.map(Row::getKey); .map(Row::getKey);
String[] keys =
Stream.concat(attachmentKeys, report.getRows().keySet().stream()).toArray(String[]::new);
Map<String, String> displayMap = Map<String, String> displayMap =
classificationService classificationService
.createClassificationQuery() .createClassificationQuery()
.keyIn( .keyIn(keys.length == 0 ? null : keys)
Stream.concat(attachmentKeys, report.getRows().keySet().stream())
.toArray(String[]::new))
.domainIn(domains != null ? domains.toArray(new String[0]) : null) .domainIn(domains != null ? domains.toArray(new String[0]) : null)
.list() .list()
.stream() .stream()

View File

@ -25,6 +25,7 @@ import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.monitor.api.MonitorService; import pro.taskana.monitor.api.MonitorService;
import pro.taskana.monitor.api.TaskTimestamp; import pro.taskana.monitor.api.TaskTimestamp;
import pro.taskana.monitor.api.reports.ClassificationCategoryReport; import pro.taskana.monitor.api.reports.ClassificationCategoryReport;
import pro.taskana.monitor.api.reports.ClassificationCategoryReport.Builder;
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader; import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
import pro.taskana.task.api.TaskCustomField; import pro.taskana.task.api.TaskCustomField;
import pro.taskana.task.api.TaskState; import pro.taskana.task.api.TaskState;
@ -54,6 +55,22 @@ class ProvideClassificationCategoryReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("MANUAL").getDisplayName()).isEqualTo("MANUAL"); assertThat(report.getRow("MANUAL").getDisplayName()).isEqualTo("MANUAL");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_ReportContainsNoRows() {
Builder builder =
MONITOR_SERVICE
.createClassificationCategoryReportBuilder()
.classificationIdIn(Collections.singletonList("DOES NOT EXIST"));
ThrowingCallable test =
() -> {
ClassificationCategoryReport report = builder.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied() void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()

View File

@ -25,6 +25,7 @@ import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.monitor.api.MonitorService; import pro.taskana.monitor.api.MonitorService;
import pro.taskana.monitor.api.TaskTimestamp; import pro.taskana.monitor.api.TaskTimestamp;
import pro.taskana.monitor.api.reports.ClassificationReport; import pro.taskana.monitor.api.reports.ClassificationReport;
import pro.taskana.monitor.api.reports.ClassificationReport.Builder;
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader; import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
import pro.taskana.task.api.TaskCustomField; import pro.taskana.task.api.TaskCustomField;
import pro.taskana.task.api.TaskState; import pro.taskana.task.api.TaskState;
@ -54,6 +55,22 @@ class ProvideClassificationReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("L50000").getDisplayName()).isEqualTo("Dynamik-Ablehnung"); assertThat(report.getRow("L50000").getDisplayName()).isEqualTo("Dynamik-Ablehnung");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_ReportContainsNoRows() {
Builder builder =
MONITOR_SERVICE
.createClassificationReportBuilder()
.classificationIdIn(Collections.singletonList("DOES NOT EXIST"));
ThrowingCallable test =
() -> {
ClassificationReport report = builder.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied() void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()

View File

@ -24,6 +24,7 @@ import pro.taskana.common.internal.security.JaasExtension;
import pro.taskana.common.internal.security.WithAccessId; import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.monitor.api.MonitorService; import pro.taskana.monitor.api.MonitorService;
import pro.taskana.monitor.api.TaskTimestamp; import pro.taskana.monitor.api.TaskTimestamp;
import pro.taskana.monitor.api.reports.ClassificationReport.Builder;
import pro.taskana.monitor.api.reports.ClassificationReport.DetailedClassificationReport; import pro.taskana.monitor.api.reports.ClassificationReport.DetailedClassificationReport;
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader; import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
import pro.taskana.monitor.api.reports.item.DetailedMonitorQueryItem; import pro.taskana.monitor.api.reports.item.DetailedMonitorQueryItem;
@ -107,6 +108,22 @@ class ProvideDetailedClassificationReportAccTest extends AbstractReportAccTest {
assertThat(row.getFoldableRow("N/A").getDisplayName()).isEqualTo("N/A"); assertThat(row.getFoldableRow("N/A").getDisplayName()).isEqualTo("N/A");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_DetailedReportContainsNoRows() {
Builder builder =
MONITOR_SERVICE
.createClassificationReportBuilder()
.classificationIdIn(Collections.singletonList("DOES NOT EXIST"));
ThrowingCallable test =
() -> {
DetailedClassificationReport report = builder.buildDetailedReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void testGetTotalNumbersOfTasksOfDetailedClassificationReport() throws Exception { void testGetTotalNumbersOfTasksOfDetailedClassificationReport() throws Exception {

View File

@ -25,6 +25,7 @@ import pro.taskana.common.internal.security.WithAccessId;
import pro.taskana.monitor.api.MonitorService; import pro.taskana.monitor.api.MonitorService;
import pro.taskana.monitor.api.TaskTimestamp; import pro.taskana.monitor.api.TaskTimestamp;
import pro.taskana.monitor.api.reports.TaskCustomFieldValueReport; import pro.taskana.monitor.api.reports.TaskCustomFieldValueReport;
import pro.taskana.monitor.api.reports.TaskCustomFieldValueReport.Builder;
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader; import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
import pro.taskana.task.api.TaskCustomField; import pro.taskana.task.api.TaskCustomField;
import pro.taskana.task.api.TaskState; import pro.taskana.task.api.TaskState;
@ -63,6 +64,22 @@ class ProvideTaskCustomFieldValueReportAccTest extends AbstractReportAccTest {
.isEqualTo("Geschaeftsstelle C"); .isEqualTo("Geschaeftsstelle C");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_ReportContainsNoRows() {
Builder builder =
MONITOR_SERVICE
.createTaskCustomFieldValueReportBuilder(TaskCustomField.CUSTOM_1)
.classificationIdIn(Collections.singletonList("DOES NOT EXIST"));
ThrowingCallable test =
() -> {
TaskCustomFieldValueReport report = builder.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void testGetTotalNumbersOfTasksOfCustomFieldValueReportForCustom1() throws Exception { void testGetTotalNumbersOfTasksOfCustomFieldValueReportForCustom1() throws Exception {

View File

@ -7,6 +7,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.TestTemplate;
@ -68,6 +69,22 @@ class ProvideTaskStatusReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("USER-1-3").getDisplayName()).isEqualTo("PPK User 1 KSC 3"); assertThat(report.getRow("USER-1-3").getDisplayName()).isEqualTo("PPK User 1 KSC 3");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_ReportContainsNoRows() {
TaskStatusReport.Builder builder =
MONITOR_SERVICE
.createTaskStatusReportBuilder()
.domainIn(Collections.singletonList("DOES NOT EXIST"));
ThrowingCallable test =
() -> {
TaskStatusReport report = builder.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void testCompleteTaskStatusReport() throws Exception { void testCompleteTaskStatusReport() throws Exception {

View File

@ -1,6 +1,7 @@
package acceptance.report; package acceptance.report;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -8,6 +9,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -35,6 +37,44 @@ class ProvideTimestampReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("COMPLETED").getDisplayName()).isEqualTo("COMPLETED"); assertThat(report.getRow("COMPLETED").getDisplayName()).isEqualTo("COMPLETED");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_ReportContainsNoRows() {
TimestampReport.Builder builder =
MONITOR_SERVICE
.createTimestampReportBuilder()
.domainIn(Collections.singletonList("DOES_NOT_EXIST"));
ThrowingCallable test =
() -> {
TimestampReport report = builder.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor")
@Test
void should_FilterTasksAccordingToDomain_When_DomainFilterIsApplied() throws Exception {
List<TimeIntervalColumnHeader> headers =
IntStream.rangeClosed(-14, 0)
.mapToObj(TimeIntervalColumnHeader.Date::new)
.collect(Collectors.toList());
TimestampReport report =
MONITOR_SERVICE
.createTimestampReportBuilder()
.withColumnHeaders(headers)
.domainIn(Collections.singletonList("DOMAIN_A"))
.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isEqualTo(2);
assertThat(report.getRow("CREATED").getCells())
.isEqualTo(new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26});
assertThat(report.getRow("COMPLETED").getCells())
.isEqualTo(new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0});
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied() void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()

View File

@ -52,6 +52,22 @@ class ProvideWorkbasketReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("USER-1-3").getDisplayName()).isEqualTo("PPK User 1 KSC 3"); assertThat(report.getRow("USER-1-3").getDisplayName()).isEqualTo("PPK User 1 KSC 3");
} }
@WithAccessId(user = "monitor")
@Test
void should_NotThrowSqlExceptionDuringAugmentation_When_ReportContainsNoRows() {
WorkbasketReport.Builder builder =
MONITOR_SERVICE
.createWorkbasketReportBuilder()
.domainIn(Collections.singletonList("DOES_NOT_EXIST"));
ThrowingCallable test =
() -> {
WorkbasketReport report = builder.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isZero();
};
assertThatCode(test).doesNotThrowAnyException();
}
@WithAccessId(user = "monitor") @WithAccessId(user = "monitor")
@Test @Test
void testGetTotalNumbersOfTasksOfWorkbasketReportBasedOnDueDate() throws Exception { void testGetTotalNumbersOfTasksOfWorkbasketReportBasedOnDueDate() throws Exception {