TSK-1357: fixed sql statements in MonitorMapper when using TimeStampReport with classsification filter

This commit is contained in:
Mustapha Zorgati 2020-08-07 12:48:55 +02:00
parent f64bb3d2da
commit 8cb056f078
8 changed files with 98 additions and 15 deletions

View File

@ -197,13 +197,13 @@ public interface MonitorMapper {
+ "AND DOMAIN IN (<foreach collection='domains' item='domain' separator=','>#{domain}</foreach>) "
+ "</if>"
+ "<if test='classificationIds != null'>"
+ "AND CLASSIFICATION_ID IN (<foreach collection='classificationIds' item='classificationId' separator=','>#{classificationId}</foreach>) "
+ "AND T.CLASSIFICATION_ID IN (<foreach collection='classificationIds' item='classificationId' separator=','>#{classificationId}</foreach>) "
+ "</if>"
+ "<if test='excludedClassificationIds != null'>"
+ "AND 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 test='customAttributeFilter != null'>"
+ "AND (<foreach collection='customAttributeFilter.keys' item='key' separator=' AND '>(${key} = '${customAttributeFilter.get(key)}')</foreach>) "
+ "AND (<foreach collection='customAttributeFilter.keys' item='key' separator=' AND '>(T.${key} = '${customAttributeFilter.get(key)}')</foreach>) "
+ "</if>"
+ "AND T.${timestamp} IS NOT NULL "
+ "</where>"
@ -265,7 +265,7 @@ public interface MonitorMapper {
@Result(column = "AGE_IN_DAYS", property = "ageInDays"),
@Result(column = "NUMBER_OF_TASKS", property = "numberOfTasks")
})
List<MonitorQueryItem> getTaskCountOfCustomFieldValues(
List<MonitorQueryItem> getTaskCountOfTaskCustomFieldValues(
@Param("customField") TaskCustomField taskCustomField,
@Param("workbasketIds") List<String> workbasketIds,
@Param("states") List<TaskState> states,
@ -417,22 +417,22 @@ public interface MonitorMapper {
+ "FROM TASK AS T INNER JOIN WORKBASKET AS W ON T.WORKBASKET_KEY=W.KEY "
+ "<where>"
+ "<if test=\"status.name() == 'COMPLETED'\">"
+ "T.COMPLETED IS NOT NULL"
+ "T.COMPLETED IS NOT NULL "
+ "</if>"
+ "<if test='classificationCategories != null'>"
+ "AND CLASSIFICATION_CATEGORY IN (<foreach collection='classificationCategories' item='category' separator=','>#{category}</foreach>) "
+ "AND T.CLASSIFICATION_CATEGORY IN (<foreach collection='classificationCategories' item='category' separator=','>#{category}</foreach>) "
+ "</if>"
+ "<if test='classificationIds != null'>"
+ "AND CLASSIFICATION_ID IN (<foreach collection='classificationIds' item='classificationId' separator=','>#{classificationId}</foreach>) "
+ "AND T.CLASSIFICATION_ID IN (<foreach collection='classificationIds' item='classificationId' separator=','>#{classificationId}</foreach>) "
+ "</if>"
+ "<if test='excludedClassificationIds != null'>"
+ "AND 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 test='domains != null'>"
+ "AND DOMAIN IN (<foreach collection='domains' item='domain' separator=','>#{domain}</foreach>) "
+ "</if>"
+ "<if test='customAttributeFilter != null'>"
+ "AND (<foreach collection='customAttributeFilter.keys' item='key' separator=' AND '>(${key} = '${customAttributeFilter.get(key)}')</foreach>) "
+ "AND (<foreach collection='customAttributeFilter.keys' item='key' separator=' AND '>(T.${key} = '${customAttributeFilter.get(key)}')</foreach>) "
+ "</if>"
+ "</where>"
+ ") AS A "

View File

@ -50,7 +50,7 @@ public class TaskCustomFieldValueReportBuilderImpl
this.taskanaEngine.openConnection();
TaskCustomFieldValueReport report = new TaskCustomFieldValueReport(this.columnHeaders);
List<MonitorQueryItem> monitorQueryItems =
this.monitorMapper.getTaskCountOfCustomFieldValues(
this.monitorMapper.getTaskCountOfTaskCustomFieldValues(
this.taskCustomField,
this.workbasketIds,
this.states,

View File

@ -54,6 +54,24 @@ class ProvideClassificationCategoryReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("MANUAL").getDisplayName()).isEqualTo("MANUAL");
}
@WithAccessId(user = "monitor")
@Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()
throws Exception {
List<TimeIntervalColumnHeader> columnHeaders = getListOfColumnHeaders();
ClassificationCategoryReport report =
MONITOR_SERVICE
.createClassificationCategoryReportBuilder()
.withColumnHeaders(columnHeaders)
.classificationIdIn(
Collections.singletonList("CLI:000000000000000000000000000000000001"))
.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isOne();
assertThat(report.getRow("EXTERN").getCells()).isEqualTo(new int[] {7, 2, 0, 0, 1, 0, 0, 0, 0});
}
@WithAccessId(user = "monitor")
@Test
void testGetTotalNumbersOfTasksOfCategoryReport() throws Exception {

View File

@ -54,6 +54,24 @@ class ProvideClassificationReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("L50000").getDisplayName()).isEqualTo("Dynamik-Ablehnung");
}
@WithAccessId(user = "monitor")
@Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()
throws Exception {
List<TimeIntervalColumnHeader> columnHeaders = getListOfColumnsHeaders();
ClassificationReport report =
MONITOR_SERVICE
.createClassificationReportBuilder()
.withColumnHeaders(columnHeaders)
.classificationIdIn(
Collections.singletonList("CLI:000000000000000000000000000000000001"))
.buildReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isOne();
assertThat(report.getRow("L10000").getCells()).isEqualTo(new int[] {7, 2, 0, 0, 1, 0, 0, 0, 0});
}
@WithAccessId(user = "monitor")
@Test
void testGetTotalNumbersOfTasksOfClassificationReport() throws Exception {

View File

@ -46,6 +46,29 @@ class ProvideDetailedClassificationReportAccTest extends AbstractReportAccTest {
assertThatThrownBy(call).isInstanceOf(NotAuthorizedException.class);
}
@WithAccessId(user = "monitor")
@Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()
throws Exception {
List<TimeIntervalColumnHeader> columnHeaders = getListOfColumnHeaders();
DetailedClassificationReport report =
MONITOR_SERVICE
.createClassificationReportBuilder()
.withColumnHeaders(columnHeaders)
.classificationIdIn(
Collections.singletonList("CLI:000000000000000000000000000000000001"))
.buildDetailedReport();
assertThat(report).isNotNull();
assertThat(report.rowSize()).isOne();
DetailedClassificationRow row = report.getRow("L10000");
assertThat(row.getCells()).isEqualTo(new int[] {7, 2, 0, 0, 1, 0, 0, 0, 0});
assertThat(row.getFoldableRow("L11000").getCells())
.isEqualTo(new int[] {2, 0, 0, 0, 1, 0, 0, 0, 0});
assertThat(row.getFoldableRow("N/A").getCells())
.isEqualTo(new int[] {5, 2, 0, 0, 0, 0, 0, 0, 0});
}
@WithAccessId(user = "monitor")
@Test
void should_augmentDisplayNames_When_ReportIsBuild() throws Exception {

View File

@ -35,6 +35,30 @@ class ProvideTimestampReportAccTest extends AbstractReportAccTest {
assertThat(report.getRow("COMPLETED").getDisplayName()).isEqualTo("COMPLETED");
}
@WithAccessId(user = "monitor")
@Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()
throws Exception {
List<TimeIntervalColumnHeader> headers =
IntStream.rangeClosed(-14, 0)
.mapToObj(TimeIntervalColumnHeader.Date::new)
.collect(Collectors.toList());
TimestampReport report =
MONITOR_SERVICE
.createTimestampReportBuilder()
.withColumnHeaders(headers)
.classificationIdIn(
Collections.singletonList("CLI:000000000000000000000000000000000001"))
.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, 10});
assertThat(report.getRow("COMPLETED").getCells())
.isEqualTo(new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1});
}
/**
* This test covers every insert operation of the TimestampReport. We have two definitions for org
* level 1: 'org1' and 'N/A'. All other org levels only contain 'N/A'. Thus this test only tests

View File

@ -69,7 +69,7 @@ class ProvideWorkbasketReportAccTest extends AbstractReportAccTest {
@WithAccessId(user = "monitor")
@Test
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsAplied()
void should_FilterTasksAccordingToClassificationId_When_ClassificationIdFilterIsApplied()
throws Exception {
List<TimeIntervalColumnHeader> columnHeaders = getListOfColumnHeaders();
WorkbasketReport report =

View File

@ -66,7 +66,7 @@ class TaskCustomFieldValueReportBuilderImplTest {
monitorQueryItem.setKey("Geschaeftsstelle A");
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
when(monitorMapperMock.getTaskCountOfCustomFieldValues(
when(monitorMapperMock.getTaskCountOfTaskCustomFieldValues(
TaskCustomField.CUSTOM_1,
workbasketIds,
states,
@ -94,7 +94,7 @@ class TaskCustomFieldValueReportBuilderImplTest {
verify(taskanaEngineMock).getWorkingDaysToDaysConverter();
verify(internalTaskanaEngineMock, times(2)).getEngine();
verify(monitorMapperMock)
.getTaskCountOfCustomFieldValues(
.getTaskCountOfTaskCustomFieldValues(
any(), any(), any(), any(), any(), any(), any(), any(), any());
verify(internalTaskanaEngineMock).returnConnection();
verifyNoMoreInteractions(
@ -128,7 +128,7 @@ class TaskCustomFieldValueReportBuilderImplTest {
monitorQueryItem.setAgeInDays(0);
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
when(monitorMapperMock.getTaskCountOfCustomFieldValues(
when(monitorMapperMock.getTaskCountOfTaskCustomFieldValues(
TaskCustomField.CUSTOM_1,
workbasketIds,
states,
@ -157,7 +157,7 @@ class TaskCustomFieldValueReportBuilderImplTest {
verify(taskanaEngineMock).getWorkingDaysToDaysConverter();
verify(internalTaskanaEngineMock, times(2)).getEngine();
verify(monitorMapperMock)
.getTaskCountOfCustomFieldValues(
.getTaskCountOfTaskCustomFieldValues(
any(), any(), any(), any(), any(), any(), any(), any(), any());
verify(internalTaskanaEngineMock).returnConnection();
verifyNoMoreInteractions(