diff --git a/lib/taskana-core/src/main/java/pro/taskana/CategoryReportBuilder.java b/lib/taskana-core/src/main/java/pro/taskana/CategoryReportBuilder.java new file mode 100644 index 000000000..a4f81cc59 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/CategoryReportBuilder.java @@ -0,0 +1,143 @@ +package pro.taskana; + +import java.util.List; +import java.util.Map; + +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.SelectedItem; +import pro.taskana.impl.report.impl.CategoryReport; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; + +/** + * The CategoryReportBuilder is used to build a {@link CategoryReport}, list the taskIds of a CategoryReport and list + * the values of an entered custom field. A CategoryReport contains the total numbers of tasks of the respective + * category as well as the total number of all tasks. The tasks of the report can be filtered by workbaskets, states, + * categories, domains, classifications and values of a custom field. Classifications can also be excluded from the + * report. If the {@link TimeIntervalColumnHeader}s are set, the report contains also the number of tasks of the + * respective cluster. The age of the tasks can be counted in days or in working days. Tasks with Timestamp DUE = null + * are not considered. + */ +public interface CategoryReportBuilder { + + /** + * Adds a list {@link TimeIntervalColumnHeader}s to the builder to subdivide the report into clusters. + * + * @param columnHeaders + * the column headers the report should consist of. + * @return the CategoryReportBuilder + */ + CategoryReportBuilder withColumnHeaders(List columnHeaders); + + /** + * If this filter is used, the days of the report are counted in working days. + * + * @return the CategoryReportBuilder + */ + CategoryReportBuilder inWorkingDays(); + + /** + * Adds a list of workbasketIds to the builder. The created report contains only tasks with a workbasketId in this + * list. + * + * @param workbasketIds + * a list of workbasketIds + * @return the CategoryReportBuilder + */ + CategoryReportBuilder workbasketIdIn(List workbasketIds); + + /** + * Adds a list of states to the builder. The created report contains only tasks with a state in this list. + * + * @param states + * a list of states + * @return the CategoryReportBuilder + */ + CategoryReportBuilder stateIn(List states); + + /** + * Adds a list of categories to the builder. The created report contains only tasks with a category in this list. + * + * @param categories + * a list of categories + * @return the CategoryReportBuilder + */ + CategoryReportBuilder categoryIn(List categories); + + /** + * Adds a list of classificationIds to the builder. The created report contains only tasks with a classificationId + * in this list. + * + * @param classificationIds + * a list of classificationIds + * @return the CategoryReportBuilder + */ + CategoryReportBuilder classificationIdIn(List classificationIds); + + /** + * Adds a list of excludedClassificationIds to the builder. The created report contains only tasks with a + * classificationId NOT in this list. + * + * @param excludedClassificationIds + * a list of excludedClassificationIds + * @return the CategoryReportBuilder + */ + CategoryReportBuilder excludedClassificationIdIn(List excludedClassificationIds); + + /** + * Adds a list of domains to the builder. The created report contains only tasks with a domain in this list. + * + * @param domains + * a list of domains + * @return the CategoryReportBuilder + */ + CategoryReportBuilder domainIn(List domains); + + /** + * Adds a map of custom attributes and custom attribute values to the builder. The created report contains only + * tasks with a custom attribute value in this list. + * + * @param customAttributeFilter + * a map of custom attributes and custom attribute value + * @return the CategoryReportBuilder + */ + CategoryReportBuilder customAttributeFilterIn(Map customAttributeFilter); + + /** + * Returns a {@link CategoryReport} containing all tasks after applying the filters. If the column headers are set + * the report is subdivided into clusters. + * + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the CategoryReport + */ + CategoryReport buildReport() throws InvalidArgumentException, NotAuthorizedException; + + /** + * Returns a list of all taskIds of the report that are in the list of selected items. + * + * @param selectedItems + * a list of selectedItems + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all taskIds + */ + List listTaskIdsForSelectedItems(List selectedItems) + throws NotAuthorizedException, InvalidArgumentException; + + /** + * Returns a list of all values of an entered custom field that are in the report. + * + * @param customField + * the customField whose values should appear in the list + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all custom attribute values + */ + List listCustomAttributeValuesForCustomAttributeName(CustomField customField) + throws NotAuthorizedException; +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/ClassificationReportBuilder.java b/lib/taskana-core/src/main/java/pro/taskana/ClassificationReportBuilder.java new file mode 100644 index 000000000..7cef00ccb --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/ClassificationReportBuilder.java @@ -0,0 +1,161 @@ +package pro.taskana; + +import java.util.List; +import java.util.Map; + +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.SelectedItem; +import pro.taskana.impl.report.impl.ClassificationReport; +import pro.taskana.impl.report.impl.DetailedClassificationReport; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; + +/** + * The ClassificationReportBuilder is used to build a {@link ClassificationReport} or a + * {@link DetailedClassificationReport}. Furthermore the taskIds and values of an entered custom field of these reports + * can be listed. A ClassificationReport contains the total numbers of tasks of the respective classification as well as + * the total number of all tasks. A ReportLine of a DetailedClassificationReport contains an additional list of + * ReportLines for the classifications of the attachments of the tasks. The tasks of the report can be filtered by + * workbaskets, states, categories, domains, classifications and values of a custom field. Classifications can also be + * excluded from the report. If the {@link TimeIntervalColumnHeader}s are set, the report contains also the number of + * tasks of the respective cluster. The age of the tasks can be counted in days or in working days. Tasks with Timestamp + * DUE = null are not considered. + */ +public interface ClassificationReportBuilder { + + /** + * Adds a list {@link TimeIntervalColumnHeader}s to the builder to subdivide the report into clusters. + * + * @param columnHeaders + * the column headers the report should consist of. + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder withColumnHeaders(List columnHeaders); + + /** + * If this filter is used, the days of the report are counted in working days. + * + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder inWorkingDays(); + + /** + * Adds a list of workbasket ids to the builder. The created report contains only tasks with a workbasket id in this + * list. + * + * @param workbasketIds + * a list of workbasket ids + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder workbasketIdIn(List workbasketIds); + + /** + * Adds a list of states to the builder. The created report contains only tasks with a state in this list. + * + * @param states + * a list of states + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder stateIn(List states); + + /** + * Adds a list of categories to the builder. The created report contains only tasks with a category in this list. + * + * @param categories + * a list of categories + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder categoryIn(List categories); + + /** + * Adds a list of classificationIds to the builder. The created report contains only tasks with a classificationId + * in this list. + * + * @param classificationIds + * a list of classificationIds + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder classificationIdIn(List classificationIds); + + /** + * Adds a list of excludedClassificationIds to the builder. The created report contains only tasks with a + * classificationId NOT in this list. + * + * @param excludedClassificationIds + * a list of excludedClassificationIds + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder excludedClassificationIdIn(List excludedClassificationIds); + + /** + * Adds a list of domains to the builder. The created report contains only tasks with a domain in this list. + * + * @param domains + * a list of domains + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder domainIn(List domains); + + /** + * Adds a map of custom attributes and custom attribute values to the builder. The created report contains only + * tasks with a custom attribute value in this list. + * + * @param customAttributeFilter + * a map of custom attributes and custom attribute value + * @return the ClassificationReportBuilder + */ + ClassificationReportBuilder customAttributeFilterIn(Map customAttributeFilter); + + /** + * Returns a {@link ClassificationReport} containing all tasks after applying the filters. If the column headers are + * set the report is subdivided into clusters. + * + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the ClassificationReport + */ + ClassificationReport buildReport() throws InvalidArgumentException, NotAuthorizedException; + + /** + * Returns a {@link DetailedClassificationReport} containing all tasks after applying the filters. If the column + * headers are set the report is subdivided into clusters. Its + * {@link pro.taskana.impl.report.impl.DetailedReportRow}s contain an additional list of + * {@link pro.taskana.impl.report.ReportRow}s for the classifications of the attachments of the tasks. + * + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the DetailedClassificationReport + */ + DetailedClassificationReport buildDetailedReport() throws InvalidArgumentException, NotAuthorizedException; + + /** + * Returns a list of all taskIds of the report that are in the list of selected items. + * + * @param selectedItems + * a list of selectedItems + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all taskIds + */ + List listTaskIdsForSelectedItems(List selectedItems) + throws NotAuthorizedException, InvalidArgumentException; + + /** + * Returns a list of all values of an entered custom field that are in the report. + * + * @param customField + * the customField whose values should appear in the list + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all custom attribute values + */ + List listCustomAttributeValuesForCustomAttributeName(CustomField customField) + throws NotAuthorizedException; + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/CustomFieldValueReportBuilder.java b/lib/taskana-core/src/main/java/pro/taskana/CustomFieldValueReportBuilder.java new file mode 100644 index 000000000..72fd18a03 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/CustomFieldValueReportBuilder.java @@ -0,0 +1,149 @@ +package pro.taskana; + +import java.util.List; +import java.util.Map; + +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.SelectedItem; +import pro.taskana.impl.report.impl.CustomFieldValueReport; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; + +/** + * The CustomFieldValueReportBuilder is used to build a {@link CustomFieldValueReport} and list the values of a entered + * custom field. A CustomFieldValueReport contains the total numbers of tasks of the respective custom field as well as + * the total number of all tasks. The tasks of the report can be filtered by workbaskets, states, categories, domains, + * classifications and values of a custom field. Classifications can also be excluded from the report. If the + * {@link TimeIntervalColumnHeader}s are set, the report contains also the number of tasks of the respective cluster. + * The age of the tasks can be counted in days or in working days. Tasks with Timestamp DUE = null are not considered. + */ +public interface CustomFieldValueReportBuilder { + + /** + * Adds a list {@link TimeIntervalColumnHeader}s to the builder to subdivide the report into clusters. + * + * @param columnHeaders + * the column headers the report should consist of. + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder withColumnHeaders(List columnHeaders); + + /** + * If this filter is used, the days of the report are counted in working days. + * + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder inWorkingDays(); + + /** + * Adds a list of workbasket ids to the builder. The created report contains only tasks with a workbasket id in this + * list. + * + * @param workbasketIds + * a list of workbasket ids + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder workbasketIdIn(List workbasketIds); + + /** + * Adds a list of states to the builder. The created report contains only tasks with a state in this list. + * + * @param states + * a list of states + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder stateIn(List states); + + /** + * Adds a list of categories to the builder. The created report contains only tasks with a category in this list. + * + * @param categories + * a list of categories + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder categoryIn(List categories); + + /** + * Adds a list of classificationIds to the builder. The created report contains only tasks with a classificationId + * in this list. + * + * @param classificationIds + * a list of classificationIds + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder classificationIdIn(List classificationIds); + + /** + * Adds a list of excludedClassificationIds to the builder. The created report contains only tasks with a + * classificationId NOT in this list. + * + * @param excludedClassificationIds + * a list of excludedClassificationIds + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder excludedClassificationIdIn(List excludedClassificationIds); + + /** + * Adds a list of domains to the builder. The created report contains only tasks with a domain in this list. + * + * @param domains + * a list of domains + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder domainIn(List domains); + + /** + * Adds a map of custom attributes and custom attribute values to the builder. The created report contains only + * tasks with a custom attribute value in this list. + * + * @param customAttributeFilter + * a map of custom attributes and custom attribute value + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReportBuilder customAttributeFilterIn(Map customAttributeFilter); + + /** + * Returns a {@link CustomFieldValueReportBuilder} containing all tasks after applying the filters. If the column + * headers are set the report is subdivided into clusters. + * + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the CustomFieldValueReportBuilder + */ + CustomFieldValueReport buildReport() throws InvalidArgumentException, NotAuthorizedException; + + /** + * Returns a list of all taskIds of the report that are in the list of selected items. + * + * @param selectedItems + * a list of selectedItems + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all taskIds + */ + List listTaskIdsForSelectedItems(List selectedItems) + throws NotAuthorizedException, InvalidArgumentException; + + /** + * Returns a list of all values of an entered custom field that are in the report. + * + * @param customField + * the customField whose values should appear in the list + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all custom attribute values + */ + List listCustomAttributeValuesForCustomAttributeName(CustomField customField) + throws NotAuthorizedException; + + /** + * Gets the customField property of the CustomFieldValueReportBuilder. + * + * @return the customField property + */ + CustomField getCustomField(); +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskMonitorService.java b/lib/taskana-core/src/main/java/pro/taskana/TaskMonitorService.java index 9d037b131..10a2748a9 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/TaskMonitorService.java +++ b/lib/taskana-core/src/main/java/pro/taskana/TaskMonitorService.java @@ -1,741 +1,53 @@ package pro.taskana; -import java.util.List; -import java.util.Map; - -import pro.taskana.exceptions.InvalidArgumentException; -import pro.taskana.exceptions.NotAuthorizedException; -import pro.taskana.impl.SelectedItem; -import pro.taskana.impl.report.impl.CategoryReport; -import pro.taskana.impl.report.impl.ClassificationReport; -import pro.taskana.impl.report.impl.CombinedClassificationFilter; -import pro.taskana.impl.report.impl.CustomFieldValueReport; -import pro.taskana.impl.report.impl.DetailedClassificationReport; -import pro.taskana.impl.report.impl.TaskStatusReport; -import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; -import pro.taskana.impl.report.impl.WorkbasketLevelReport; +import pro.taskana.impl.CustomFieldValueReportBuilderImpl; +import pro.taskana.impl.TaskStatusReportBuilderImpl; +import pro.taskana.impl.WorkbasketReportBuilderImpl; /** * The Task Monitor Service manages operations on tasks regarding the monitoring. */ public interface TaskMonitorService { - String DIMENSION_CLASSIFICATION_CATEGORY = "CLASSIFICATION_CATEGORY"; - String DIMENSION_CLASSIFICATION_KEY = "CLASSIFICATION_KEY"; - String DIMENSION_WORKBASKET_KEY = "WORKBASKET_KEY"; + /** + * Provides a {@link WorkbasketReportBuilderImpl} for creating a WorkbasketReport, list the task ids of this report + * and list the values of an entered custom attribute. + * + * @return a {@link WorkbasketReportBuilderImpl} + */ + WorkbasketReportBuilderImpl createWorkbasketReportBuilder(); /** - * Returns a {@link WorkbasketLevelReport} grouped by workbaskets. The report contains the total numbers of tasks of - * the respective workbasket as well as the total number of all tasks. If no filter is required, the respective - * parameter should be null. The tasks of the report are filtered by workbaskets, states, categories, domains and - * values of a custom field. Tasks with Timestamp DUE = null are not considered. + * Provides a {@link CategoryReportBuilder} for creating a CategoryReport, list the task ids of this report and list + * the values of an entered custom attribute. + * + * @return a {@link CategoryReportBuilder} + */ + CategoryReportBuilder createCategoryReportBuilder(); + + /** + * Provides a {@link ClassificationReportBuilder} for creating a ClassificationReport or a + * DetailedClassificationReport, list the task ids of these reports and list the values of an entered custom + * attribute. + * + * @return a {@link ClassificationReportBuilder} + */ + ClassificationReportBuilder createClassificationReportBuilder(); + + /** + * Provides a {@link CustomFieldValueReportBuilderImpl} for creating a CustomFieldValueReport and list the values of + * an entered custom attribute. * - * @param workbasketIds - * a list of workbasket ids to filter by workbaskets. To omit this filter, use null for this parameter - * @param states - * a list of states to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param combinedClassificationFilter - * a list of pairs of a classificationId for a task and a classificationId for the corresponding - * attachment that is used to filter by the classification of the attachment. To filter by the - * classification of the task, the classificationId of the attachment should be null. To omit this - * filter, use null for this parameter - * @return the report - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR + * the customField whose values should appear in the report + * @return a {@link CustomFieldValueReportBuilderImpl} */ - WorkbasketLevelReport getWorkbasketLevelReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List combinedClassificationFilter) - throws InvalidArgumentException, NotAuthorizedException; + CustomFieldValueReportBuilderImpl createCustomFieldValueReportBuilder(CustomField customField); /** - * Returns a {@link WorkbasketLevelReport} grouped by workbaskets. For each workbasket the report contains the total - * number of tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. By default the age of the tasks is counted in working days. Furthermore the - * Report contains a sum line that contains the total numbers of the different clusters and the total number of all - * tasks in this report. The tasks of the report are filtered by workbaskets, states, categories, domains and values - * of a custom field. If no filter is required, the respective parameter should be null. Tasks with Timestamp DUE = - * null are not considered. + * Provides a {@link TaskStatusReportBuilderImpl} for creating a TaskStatusReport. * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param combinedClassificationFilter - * a list of pairs of a classificationId for a task and a classificationId for the corresponding - * attachment that is used to filter by the classification of the attachment. To filter by the - * classification of the task, the classificationId of the attachment should be null. To omit this - * filter, use null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @return the report - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR + * @return a {@link TaskStatusReportBuilderImpl} */ - WorkbasketLevelReport getWorkbasketLevelReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List combinedClassificationFilter, List columnHeaders) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link WorkbasketLevelReport} for specific classifications grouped by workbaskets. For each workbasket - * the report contains the total number of tasks and the number of tasks of the respective cluster that are - * specified by the {@link TimeIntervalColumnHeader}s. It can be specified whether the age of the tasks is counted - * in days or in working days. Furthermore the report contains a sum line that contains the total numbers of the - * different clusters and the total number of all tasks. The tasks of the report are filtered by workbaskets, - * states, categories, domains and values of a custom field. If no filter is required, the respective parameter - * should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param combinedClassificationFilter - * a list of pairs of a classificationId for a task and a classificationId for the corresponding - * attachment that is used to filter by the classification of the attachment. To filter by the - * classification of the task, the classificationId of the attachment should be null. To omit this - * filter, use null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @param inWorkingDays - * a boolean parameter that specifies whether the age of the tasks should be counted in days or in - * working days - * @return the report - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - WorkbasketLevelReport getWorkbasketLevelReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List combinedClassificationFilter, List columnHeaders, - boolean inWorkingDays) throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link CategoryReport} grouped by categories. The report contains the total numbers of tasks of the - * respective category as well as the total number of all tasks. The tasks of the report are filtered by - * workbaskets, states, categories, domains and values of a custom field and values of a custom field. If no filter - * is required, the respective parameter should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids to filter by workbaskets. To omit this filter, use null for this parameter - * @param states - * a list of states to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @return the report - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - CategoryReport getCategoryReport(List workbasketIds, List states, List categories, - List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link CategoryReport} grouped by categories. For each category the report contains the total number of - * tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. By default the age of the tasks is counted in working days. Furthermore the - * Report contains a sum line that contains the total numbers of the different clusters and the total number of all - * tasks in this report. The tasks of the report are filtered by workbaskets, states, categories, domains and values - * of a custom field. If no filter is required, the respective parameter should be null. Tasks with Timestamp DUE = - * null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @return the report - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - CategoryReport getCategoryReport(List workbasketIds, List states, List categories, - List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link CategoryReport} grouped by categories. For each category the report contains the total number of - * tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. It can be specified whether the age of the tasks is counted in days or in - * working days. Furthermore the report contains a sum line that contains the total numbers of the different - * clusters and the total number of all tasks. The tasks of the report are filtered by workbaskets, states, - * categories, domains and values of a custom field. If no filter is required, the respective parameter should be - * null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @param inWorkingDays - * a boolean parameter that specifies whether the age of the tasks should be counted in days or in - * working days - * @return the report - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - CategoryReport getCategoryReport(List workbasketIds, List states, List categories, - List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link ClassificationReport} grouped by classifications. The report contains the total numbers of tasks - * of the respective classification as well as the total number of all tasks. The tasks of the report are filtered - * by workbaskets, states, categories, domains and values of a custom field. If no filter is required, the - * respective parameter should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids to filter by workbaskets. To omit this filter, use null for this parameter - * @param states - * a list of states to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @return the ClassificationReport - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - ClassificationReport getClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link ClassificationReport} grouped by classifications. For each classification the report contains - * the total number of tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. By default the age of the tasks is counted in working days. Furthermore the - * Report contains a sum line that contains the total numbers of the different clusters and the total number of all - * tasks in this report. The tasks of the report are filtered by workbaskets, states, categories, domains and values - * of a custom field. If no filter is required, the respective parameter should be null. Tasks with Timestamp DUE = - * null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @return the ClassificationReport - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - ClassificationReport getClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link ClassificationReport} grouped by classification. For each classification the report contains the - * total number of tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. It can be specified whether the age of the tasks is counted in days or in - * working days. Furthermore the report contains a sum line that contains the total numbers of the different - * clusters and the total number of all tasks. The tasks of the report are filtered by workbaskets, states, - * categories, domains and values of a custom field. If no filter is required, the respective parameter should be - * null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @param inWorkingDays - * a boolean parameter that specifies whether the age of the tasks should be counted in days or in - * working days - * @return the ClassificationReport - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - ClassificationReport getClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link DetailedClassificationReport}. The report contains the total numbers of tasks of the respective - * classification as well as the total number of all tasks. Each ReportLine contains an additional list of - * ReportLines for the classifications of the attachments of the tasks. The tasks of the report are filtered by - * workbaskets, states, categories, domains and values of a custom field. If no filter is required, the respective - * parameter should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids to filter by workbaskets. To omit this filter, use null for this parameter - * @param states - * a list of states to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @return the DetailedClassificationReport - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - DetailedClassificationReport getDetailedClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link DetailedClassificationReport}. For each classification the report contains the total number of - * tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. By default the age of the tasks is counted in working days. Each ReportLine - * contains an additional list of ReportLines for the classifications of the attachments of the tasks. Furthermore - * the Report contains a sum line that contains the total numbers of the different clusters and the total number of - * all tasks in this report. The tasks of the report are filtered by workbaskets, states, categories, domains and - * values of a custom field. If no filter is required, the respective parameter should be null. Tasks with Timestamp - * DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @return the DetailedClassificationReport - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - DetailedClassificationReport getDetailedClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link DetailedClassificationReport}. For each classification the report contains the total number of - * tasks and the number of tasks of the respective cluster that are specified by the - * {@link TimeIntervalColumnHeader}s. It can be specified whether the age of the tasks is counted in days or in - * working days. Each ReportLine contains an additional list of ReportLines for the classifications of the - * attachments of the tasks. Furthermore the report contains a sum line that contains the total numbers of the - * different clusters and the total number of all tasks. The tasks of the report are filtered by workbaskets, - * states, categories, domains and values of a custom field. If no filter is required, the respective parameter - * should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @param inWorkingDays - * a boolean parameter that specifies whether the age of the tasks should be counted in days or in - * working days - * @return the DetailedClassificationReport - * @throws InvalidArgumentException - * thrown if DaysToWorkingDaysConverter is initialized with null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - DetailedClassificationReport getDetailedClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link CustomFieldValueReport} grouped by the value of a certain {@link CustomField}. The report - * contains the total numbers of tasks of the respective custom field as well as the total number of all tasks. The - * tasks of the report are filtered by workbaskets, states, categories, domains and values of a custom field. If no - * filter is required, the respective parameter should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids to filter by workbaskets. To omit this filter, use null for this parameter - * @param states - * a list of states to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @return the report - * @throws InvalidArgumentException - * thrown if customField is null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - CustomFieldValueReport getCustomFieldValueReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link CustomFieldValueReport} grouped by the value of a certain {@link CustomField}. For each value of - * the custom field the report contains the total number of tasks and the number of tasks of the respective cluster - * that are specified by the {@link TimeIntervalColumnHeader}s. By default the age of the tasks is counted in - * working days. Furthermore the Report contains a sum line that contains the total numbers of the different - * clusters and the total number of all tasks in this report. The tasks of the report are filtered by workbaskets, - * states, categories, domains and values of a custom field. If no filter is required, the respective parameter - * should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @return the report - * @throws InvalidArgumentException - * thrown if customField is null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - CustomFieldValueReport getCustomFieldValueReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a {@link CustomFieldValueReport} grouped by the value of a certain {@link CustomField}. For each value of - * the custom field the report contains the total number of tasks and the number of tasks of the respective cluster - * that are specified by the {@link TimeIntervalColumnHeader}s. It can be specified whether the age of the tasks is - * counted in days or in working days. Furthermore the report contains a sum line that contains the total numbers of - * the different clusters and the total number of all tasks. The tasks of the report are filtered by workbaskets, - * states, categories, domains and values of a custom field. If no filter is required, the respective parameter - * should be null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @param inWorkingDays - * a boolean parameter that specifies whether the age of the tasks should be counted in days or in - * working days - * @return the report - * @throws InvalidArgumentException - * thrown if customField is null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - CustomFieldValueReport getCustomFieldValueReport(List workbasketIds, List states, - List categories, - List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a list of all task ids in the selected items of a {@link pro.taskana.impl.report.Report}. By default the - * age of the tasks is counted in working days. The tasks of the report are filtered by workbaskets, states, - * categories, domains and values of a custom field. If no filter is required, the respective parameter should be - * null. Tasks with Timestamp DUE = null are not considered. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param customField - * a custom field to filter by the values of the custom field. To omit this filter, use null for this - * parameter - * @param customFieldValues - * a list of custom field values to filter by the values of the custom field. To omit this filter, use - * null for this parameter - * @param columnHeaders - * a list of columnHeaders that specify the subdivision into different cluster of due dates. Days in past - * are represented as negative values and days in the future are represented as positive values. To avoid - * tasks are counted multiple times or not be listed in the report, these columnHeaders should not - * overlap and should not have gaps. If the ReportLineDefinition should represent a single day, - * lowerLimit and upperLimit have to be equal. The outer cluster of a report should have open ends. These - * open ends are represented with Integer.MIN_VALUE and Integer.MAX_VALUE. - * @param inWorkingDays - * a boolean parameter that specifies whether the age of the tasks should be counted in days or in - * working days - * @param selectedItems - * a list of {@link SelectedItem}s that are selected from the report whose task ids should be determined. - * @param dimension - * defines the meaning of the key in the {@link SelectedItem}s. - * @return the list of task ids - * @throws InvalidArgumentException - * thrown if columnHeaders is null or if selectedItems is empty or null - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - List getTaskIdsForSelectedItems(List workbasketIds, List states, List categories, - List domains, List classificationKeys, - List excludedClassificationKeys, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays, List selectedItems, - String dimension) - throws InvalidArgumentException, NotAuthorizedException; - - /** - * Returns a list of distinct custom attribute values for the selection from the entire task pool. - * - * @param workbasketIds - * a list of workbasket ids objects to filter by workbaskets. To omit this filter, use null for this - * parameter - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param categories - * a list of categories to filter by categories. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @param classificationIds - * a List of all classification ids to include in the selection. - * @param excludedClassificationIds - * a List of all classification ids to exclude from the selection. - * @param customAttributeFilter - * a Map containing a key value pair for the custom attributes to be applied as a filter criteria - * @param customAttributeName - * the name of the custom attribute to determine the existing values from. - * @return the list of existing values for the custom attribute with name customAttributeName in the filtered task - * pool. - * @throws InvalidArgumentException - * thrown if the customAttributeName is invalid/empty. - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR - */ - List getCustomAttributeValuesForReport(List workbasketIds, List states, - List categories, List domains, List classificationIds, - List excludedClassificationIds, Map customAttributeFilter, - String customAttributeName) throws InvalidArgumentException, NotAuthorizedException; - - /** - * Overloaded method for {@link #getTaskStatusReport(List, List)}. This method omits all filters. - * - * @return the {@link TaskStatusReport} - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR or ADMIN - */ - TaskStatusReport getTaskStatusReport() throws NotAuthorizedException; - - /** - * Overloaded method for {@link #getTaskStatusReport(List, List)}. This method applies a domain filter and omits the - * state filter. - * - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @return the {@link TaskStatusReport} - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR or ADMIN - */ - TaskStatusReport getTaskStatusReport(List domains) throws NotAuthorizedException; - - /** - * Returns a {@link TaskStatusReport}. For each domain the report contains the total number of tasks, clustered in - * their task status. Furthermore the report contains a sum line that contains the total numbers of the different - * clusters and the total number of all tasks. - * - * @param states - * a list of states objects to filter by states. To omit this filter, use null for this parameter - * @param domains - * a list of domains to filter by domains. To omit this filter, use null for this parameter - * @return the {@link TaskStatusReport} - * @throws NotAuthorizedException - * if the current user is not member of role MONITOR or ADMIN - */ - TaskStatusReport getTaskStatusReport(List domains, List states) throws NotAuthorizedException; - + TaskStatusReportBuilderImpl createTaskStatusReportBuilder(); } diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskStatusReportBuilder.java b/lib/taskana-core/src/main/java/pro/taskana/TaskStatusReportBuilder.java new file mode 100644 index 000000000..dfc9445c5 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/TaskStatusReportBuilder.java @@ -0,0 +1,41 @@ +package pro.taskana; + +import java.util.List; + +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.TaskStatusReport; + +/** + * The TaskStatusReportBuilder is used to build a {@link TaskStatusReport}. A TaskStatusReport contains the total number + * of tasks, clustered in their task status. Furthermore the report contains a sum line that contains the total numbers + * of the different clusters and the total number of all tasks. + */ +public interface TaskStatusReportBuilder { + + /** + * Adds a list of states to the builder. The created report contains only tasks with a state in this list. + * + * @param states + * a list of states + * @return the TaskStatusReportBuilder + */ + TaskStatusReportBuilder stateIn(List states); + + /** + * Adds a list of domains to the builder. The created report contains only tasks with a domain in this list. + * + * @param domains + * a list of domains + * @return the TaskStatusReportBuilder + */ + TaskStatusReportBuilder domainIn(List domains); + + /** + * Returns a {@link TaskStatusReport} containing all tasks after applying the filters. + * + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the TaskStatusReport + */ + TaskStatusReport buildReport() throws NotAuthorizedException; +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/WorkbasketReportBuilder.java b/lib/taskana-core/src/main/java/pro/taskana/WorkbasketReportBuilder.java new file mode 100644 index 000000000..c021a4d86 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/WorkbasketReportBuilder.java @@ -0,0 +1,157 @@ +package pro.taskana; + +import java.util.List; +import java.util.Map; + +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.SelectedItem; +import pro.taskana.impl.WorkbasketReportBuilderImpl; +import pro.taskana.impl.report.impl.CombinedClassificationFilter; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.impl.report.impl.WorkbasketReport; + +/** + * The WorkbasketReportBuilder is used to build a {@link WorkbasketReport}, list the taskIds of a WorkbasketReport and + * list the values of a entered custom field. A WorkbasketReport contains the total numbers of tasks of the respective + * workbasket as well as the total number of all tasks. The tasks of the report can be filtered by workbaskets, states, + * categories, domains, classifications and values of a custom field. Classifications can also be excluded from the + * report. It is also possible to filter by the classifications of the attachments by using the + * {@link CombinedClassificationFilter}. If the {@link TimeIntervalColumnHeader}s are set, the report contains also the + * number of tasks of the respective cluster. The age of the tasks can be counted in days or in working days. Tasks with + * Timestamp DUE = null are not considered. + */ +public interface WorkbasketReportBuilder { + + /** + * Adds a list {@link TimeIntervalColumnHeader}s to the builder to subdivide the report into clusters. + * + * @param columnHeaders + * the column headers the report should consist of. + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder withColumnHeaders(List columnHeaders); + + /** + * If this filter is used, the days of the report are counted in working days. + * + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder inWorkingDays(); + + /** + * Adds a list of workbasket ids to the builder. The created report contains only tasks with a workbasket id in this + * list. + * + * @param workbasketIds + * a list of workbasket ids + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder workbasketIdIn(List workbasketIds); + + /** + * Adds a list of states to the builder. The created report contains only tasks with a state in this list. + * + * @param states + * a list of states + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder stateIn(List states); + + /** + * Adds a list of categories to the builder. The created report contains only tasks with a category in this list. + * + * @param categories + * a list of categories + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder categoryIn(List categories); + + /** + * Adds a list of classificationIds to the builder. The created report contains only tasks with a classificationId + * in this list. + * + * @param classificationIds + * a list of classificationIds + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder classificationIdIn(List classificationIds); + + /** + * Adds a list of excludedClassificationIds to the builder. The created report contains only tasks with a + * classificationId NOT in this list. + * + * @param excludedClassificationIds + * a list of excludedClassificationIds + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder excludedClassificationIdIn(List excludedClassificationIds); + + /** + * Adds a list of domains to the builder. The created report contains only tasks with a domain in this list. + * + * @param domains + * a list of domains + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder domainIn(List domains); + + /** + * Adds a map of custom attributes and custom attribute values to the builder. The created report contains only + * tasks with a custom attribute value in this list. + * + * @param customAttributeFilter + * a map of custom attributes and custom attribute value + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilder customAttributeFilterIn(Map customAttributeFilter); + + /** + * Adds a list of {@link CombinedClassificationFilter} to the builder. The created report contains only tasks with a + * pair of a classificationId for a task and a classificationId for the corresponding attachment in this list. + * + * @param combinedClassificationFilter + * a list of combinedClassificationFilter + * @return the WorkbasketReportBuilder + */ + WorkbasketReportBuilderImpl combinedClassificationFilterIn( + List combinedClassificationFilter); + + /** + * Returns a {@link WorkbasketReport} containing all tasks after applying the filters. If the column headers are set + * the report is subdivided into clusters. + * + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the WorkbasketReport + */ + WorkbasketReport buildReport() throws InvalidArgumentException, NotAuthorizedException; + + /** + * Returns a list of all taskIds of the report that are in the list of selected items. + * + * @param selectedItems + * a list of selectedItems + * @throws InvalidArgumentException + * if the column headers are not initialized + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all taskIds + */ + List listTaskIdsForSelectedItems(List selectedItems) + throws NotAuthorizedException, InvalidArgumentException; + + /** + * Returns a list of all values of an entered custom field that are in the report. + * + * @param customField + * the customField whose values should appear in the list + * @throws NotAuthorizedException + * if the user has no rights to access the monitor + * @return the list of all custom attribute values + */ + List listCustomAttributeValuesForCustomAttributeName(CustomField customField) + throws NotAuthorizedException; +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/CategoryReportBuilderImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/CategoryReportBuilderImpl.java new file mode 100644 index 000000000..789b73757 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/CategoryReportBuilderImpl.java @@ -0,0 +1,107 @@ +package pro.taskana.impl; + +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import pro.taskana.CategoryReportBuilder; +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaRole; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.CategoryReport; +import pro.taskana.impl.report.impl.DaysToWorkingDaysPreProcessor; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * The implementation of CategoryReportBuilder. + */ +public class CategoryReportBuilderImpl extends ReportBuilder implements CategoryReportBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(CategoryReportBuilder.class); + + public CategoryReportBuilderImpl(TaskanaEngine taskanaEngine, TaskMonitorMapper taskMonitorMapper) { + super(taskanaEngine, taskMonitorMapper); + } + + @Override + public CategoryReportBuilder withColumnHeaders(List columnHeaders) { + this.columnHeaders = columnHeaders; + return this; + } + + @Override + public CategoryReportBuilder inWorkingDays() { + this.inWorkingDays = true; + return this; + } + + @Override + public CategoryReportBuilder workbasketIdIn(List workbasketIds) { + this.workbasketIds = workbasketIds; + return this; + } + + @Override + public CategoryReportBuilder stateIn(List states) { + this.states = states; + return this; + } + + @Override + public CategoryReportBuilder categoryIn(List categories) { + this.categories = categories; + return this; + } + + @Override + public CategoryReportBuilder classificationIdIn(List classificationIds) { + this.classificationIds = classificationIds; + return this; + } + + @Override + public CategoryReportBuilder excludedClassificationIdIn(List excludedClassificationIds) { + this.excludedClassificationIds = excludedClassificationIds; + return this; + } + + @Override + public CategoryReportBuilder domainIn(List domains) { + this.domains = domains; + return this; + } + + @Override + public CategoryReportBuilder customAttributeFilterIn(Map customAttributeFilter) { + this.customAttributeFilter = customAttributeFilter; + return this; + } + + @Override + public CategoryReport buildReport() throws InvalidArgumentException, NotAuthorizedException { + LOGGER.debug("entry to buildReport(), this = {}", this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + CategoryReport report = new CategoryReport(this.columnHeaders); + List monitorQueryItems = this.taskMonitorMapper.getTaskCountOfCategories( + this.workbasketIds, + this.states, this.categories, this.domains, this.classificationIds, this.excludedClassificationIds, + this.customAttributeFilter); + report.addItems(monitorQueryItems, + new DaysToWorkingDaysPreProcessor<>(this.columnHeaders, this.inWorkingDays)); + return report; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from buildReport()."); + } + } + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationReportBuilderImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationReportBuilderImpl.java new file mode 100644 index 000000000..2664b8cc0 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/ClassificationReportBuilderImpl.java @@ -0,0 +1,129 @@ +package pro.taskana.impl; + +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import pro.taskana.ClassificationReportBuilder; +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaRole; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.ClassificationReport; +import pro.taskana.impl.report.impl.DaysToWorkingDaysPreProcessor; +import pro.taskana.impl.report.impl.DetailedClassificationReport; +import pro.taskana.impl.report.impl.DetailedMonitorQueryItem; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * The implementation of ClassificationReportBuilder. + */ +public class ClassificationReportBuilderImpl extends ReportBuilder implements ClassificationReportBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationReportBuilder.class); + + public ClassificationReportBuilderImpl(TaskanaEngine taskanaEngine, TaskMonitorMapper taskMonitorMapper) { + super(taskanaEngine, taskMonitorMapper); + } + + @Override + public ClassificationReportBuilder withColumnHeaders(List columnHeaders) { + this.columnHeaders = columnHeaders; + return this; + } + + @Override + public ClassificationReportBuilder inWorkingDays() { + this.inWorkingDays = true; + return this; + } + + @Override + public ClassificationReportBuilder workbasketIdIn(List workbasketIds) { + this.workbasketIds = workbasketIds; + return this; + } + + @Override + public ClassificationReportBuilder stateIn(List states) { + this.states = states; + return this; + } + + @Override + public ClassificationReportBuilder categoryIn(List categories) { + this.categories = categories; + return this; + } + + @Override + public ClassificationReportBuilder domainIn(List domains) { + this.domains = domains; + return this; + } + + @Override + public ClassificationReportBuilder customAttributeFilterIn(Map customAttributeFilter) { + this.customAttributeFilter = customAttributeFilter; + return this; + } + + @Override + public ClassificationReportBuilder classificationIdIn(List classificationIds) { + this.classificationIds = classificationIds; + return this; + } + + @Override + public ClassificationReportBuilder excludedClassificationIdIn(List excludedClassificationIds) { + this.excludedClassificationIds = excludedClassificationIds; + return this; + } + + @Override + public ClassificationReport buildReport() throws InvalidArgumentException, NotAuthorizedException { + LOGGER.debug("entry to buildReport(), this = {}", this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + ClassificationReport report = new ClassificationReport(this.columnHeaders); + List monitorQueryItems = this.taskMonitorMapper.getTaskCountOfClassifications( + this.workbasketIds, this.states, this.categories, this.domains, this.classificationIds, + this.excludedClassificationIds, this.customAttributeFilter); + report.addItems(monitorQueryItems, + new DaysToWorkingDaysPreProcessor<>(this.columnHeaders, this.inWorkingDays)); + return report; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from buildReport()."); + } + } + + @Override + public DetailedClassificationReport buildDetailedReport() throws InvalidArgumentException, NotAuthorizedException { + LOGGER.debug("entry to buildDetailedReport(), this = {}", this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + DetailedClassificationReport report = new DetailedClassificationReport(this.columnHeaders); + List detailedMonitorQueryItems = this.taskMonitorMapper + .getTaskCountOfDetailedClassifications(this.workbasketIds, this.states, this.categories, this.domains, + this.classificationIds, this.excludedClassificationIds, this.customAttributeFilter); + + report.addItems(detailedMonitorQueryItems, + new DaysToWorkingDaysPreProcessor<>(this.columnHeaders, this.inWorkingDays)); + + return report; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from buildDetailedReport()."); + } + } + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/CustomFieldValueReportBuilderImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/CustomFieldValueReportBuilderImpl.java new file mode 100644 index 000000000..52df85673 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/CustomFieldValueReportBuilderImpl.java @@ -0,0 +1,119 @@ +package pro.taskana.impl; + +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import pro.taskana.CustomField; +import pro.taskana.CustomFieldValueReportBuilder; +import pro.taskana.TaskState; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaRole; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.CustomFieldValueReport; +import pro.taskana.impl.report.impl.DaysToWorkingDaysPreProcessor; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * The implementation of CustomFieldValueReportBuilder. + */ +public class CustomFieldValueReportBuilderImpl extends ReportBuilder implements CustomFieldValueReportBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(CustomFieldValueReportBuilderImpl.class); + + public CustomField customField; + + public CustomFieldValueReportBuilderImpl(TaskanaEngine taskanaEngine, TaskMonitorMapper taskMonitorMapper, + CustomField customField) { + super(taskanaEngine, taskMonitorMapper); + this.customField = customField; + } + + @Override + public CustomFieldValueReportBuilderImpl withColumnHeaders(List columnHeaders) { + this.columnHeaders = columnHeaders; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl inWorkingDays() { + this.inWorkingDays = true; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl workbasketIdIn(List workbasketIds) { + this.workbasketIds = workbasketIds; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl stateIn(List states) { + this.states = states; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl categoryIn(List categories) { + this.categories = categories; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl domainIn(List domains) { + this.domains = domains; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl classificationIdIn(List classificationIds) { + this.classificationIds = classificationIds; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl excludedClassificationIdIn(List excludedClassificationIds) { + this.excludedClassificationIds = excludedClassificationIds; + return this; + } + + @Override + public CustomFieldValueReportBuilderImpl customAttributeFilterIn(Map customAttributeFilter) { + this.customAttributeFilter = customAttributeFilter; + return this; + } + + @Override + public CustomFieldValueReport buildReport() + throws InvalidArgumentException, NotAuthorizedException { + LOGGER.debug("entry to buildReport(customField = {}), this = {}", this.customField, this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + CustomFieldValueReport report = new CustomFieldValueReport(this.columnHeaders); + List monitorQueryItems = this.taskMonitorMapper.getTaskCountOfCustomFieldValues( + this.customField, this.workbasketIds, this.states, this.categories, this.domains, + this.classificationIds, + this.excludedClassificationIds, + this.customAttributeFilter); + + report.addItems(monitorQueryItems, + new DaysToWorkingDaysPreProcessor<>(this.columnHeaders, this.inWorkingDays)); + return report; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from buildReport()."); + } + } + + @Override + public CustomField getCustomField() { + return customField; + } + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/ReportBuilder.java b/lib/taskana-core/src/main/java/pro/taskana/impl/ReportBuilder.java new file mode 100644 index 000000000..db7c34135 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/ReportBuilder.java @@ -0,0 +1,181 @@ +package pro.taskana.impl; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import pro.taskana.CategoryReportBuilder; +import pro.taskana.ClassificationReportBuilder; +import pro.taskana.CustomField; +import pro.taskana.CustomFieldValueReportBuilder; +import pro.taskana.TaskState; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaRole; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.exceptions.SystemException; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.impl.util.LoggerUtils; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * The super class of the different report builders. + */ +public abstract class ReportBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(ReportBuilder.class); + + private static final String DIMENSION_CLASSIFICATION_CATEGORY = "CLASSIFICATION_CATEGORY"; + private static final String DIMENSION_CLASSIFICATION_KEY = "CLASSIFICATION_KEY"; + private static final String DIMENSION_WORKBASKET_KEY = "WORKBASKET_KEY"; + + protected TaskanaEngineImpl taskanaEngine; + protected TaskMonitorMapper taskMonitorMapper; + protected List columnHeaders; + protected boolean inWorkingDays; + protected List workbasketIds; + protected List states; + protected List categories; + protected List domains; + protected List classificationIds; + protected List excludedClassificationIds; + protected Map customAttributeFilter; + + public ReportBuilder(TaskanaEngine taskanaEngine, TaskMonitorMapper taskMonitorMapper) { + this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine; + this.taskMonitorMapper = taskMonitorMapper; + this.columnHeaders = Collections.emptyList(); + configureDaysToWorkingDaysConverter(); + } + + public List getColumnHeaders() { + return this.columnHeaders; + } + + public boolean isInWorkingDays() { + return this.inWorkingDays; + } + + public List getWorkbasketIdIn() { + return this.workbasketIds; + } + + public List getStateIn() { + return this.states; + } + + public List getCategoryIn() { + return this.categories; + } + + public List getDomainIn() { + return this.domains; + } + + public List getClassificationIdsIn() { + return this.classificationIds; + } + + public List getExcludedClassificationIdsIn() { + return this.excludedClassificationIds; + } + + public Map getCustomAttributeFilter() { + return this.customAttributeFilter; + } + + public List listTaskIdsForSelectedItems(List selectedItems) + throws NotAuthorizedException, InvalidArgumentException { + LOGGER.debug("entry to listTaskIdsForSelectedItems(selectedItems = {}), this = {}", + LoggerUtils.listToString(selectedItems), this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + if (this.columnHeaders == null) { + throw new InvalidArgumentException("ColumnHeader must not be null."); + } + if (selectedItems == null || selectedItems.size() == 0) { + throw new InvalidArgumentException("SelectedItems must not be null or empty."); + } + boolean joinWithAttachments = subKeyIsSet(selectedItems); + if (!(this instanceof ClassificationReportBuilder) && joinWithAttachments) { + throw new InvalidArgumentException("SubKeys are supported for ClassificationReport only."); + } + String dimension = determineDimension(); + if (this.inWorkingDays) { + selectedItems = convertWorkingDaysToDays(selectedItems, this.columnHeaders); + } + List taskIds = this.taskMonitorMapper.getTaskIdsForSelectedItems(this.workbasketIds, + this.states, this.categories, this.domains, this.classificationIds, this.excludedClassificationIds, + this.customAttributeFilter, dimension, selectedItems, joinWithAttachments); + return taskIds; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from listTaskIdsForSelectedItems()."); + } + } + + private String determineDimension() { + String dimension = null; + if (this instanceof CategoryReportBuilder) { + dimension = DIMENSION_CLASSIFICATION_CATEGORY; + } else if (this instanceof WorkbasketReportBuilderImpl) { + dimension = DIMENSION_WORKBASKET_KEY; + } else if (this instanceof ClassificationReportBuilder) { + dimension = DIMENSION_CLASSIFICATION_KEY; + } else if (this instanceof CustomFieldValueReportBuilder) { + dimension = ((CustomFieldValueReportBuilder) this).getCustomField().toString(); + } else { + throw new SystemException("Internal error. listTaskIdsForSelectedItems() does not support " + this); + } + return dimension; + } + + public List listCustomAttributeValuesForCustomAttributeName(CustomField customField) + throws NotAuthorizedException { + LOGGER.debug("entry to listCustomAttributeValuesForCustomAttributeName(customField = {}), this = {}", + customField, this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + List customAttributeValues = taskMonitorMapper.getCustomAttributeValuesForReport(this.workbasketIds, + this.states, this.categories, this.domains, this.classificationIds, this.excludedClassificationIds, + this.customAttributeFilter, customField); + return customAttributeValues; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from listCustomAttributeValuesForCustomAttributeName()."); + } + } + + private void configureDaysToWorkingDaysConverter() { + DaysToWorkingDaysConverter.setCustomHolidays(this.taskanaEngine.getConfiguration().getCustomHolidays()); + DaysToWorkingDaysConverter.setGermanPublicHolidaysEnabled( + this.taskanaEngine.getConfiguration().isGermanPublicHolidaysEnabled()); + } + + private List convertWorkingDaysToDays(List selectedItems, + List columnHeaders) throws InvalidArgumentException { + DaysToWorkingDaysConverter instance = DaysToWorkingDaysConverter.initialize(columnHeaders); + for (SelectedItem selectedItem : selectedItems) { + selectedItem + .setLowerAgeLimit(Collections.min(instance.convertWorkingDaysToDays(selectedItem.getLowerAgeLimit()))); + selectedItem + .setUpperAgeLimit(Collections.max(instance.convertWorkingDaysToDays(selectedItem.getUpperAgeLimit()))); + } + return selectedItems; + } + + protected boolean subKeyIsSet(List selectedItems) { + for (SelectedItem selectedItem : selectedItems) { + if (selectedItem.getSubKey() != null && !selectedItem.getSubKey().isEmpty()) { + return true; + } + } + return false; + } + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskMonitorServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskMonitorServiceImpl.java index cf4f0e776..7a1a767e5 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskMonitorServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskMonitorServiceImpl.java @@ -1,32 +1,13 @@ package pro.taskana.impl; -import java.util.Collections; -import java.util.List; -import java.util.Map; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import pro.taskana.CategoryReportBuilder; +import pro.taskana.ClassificationReportBuilder; import pro.taskana.CustomField; import pro.taskana.TaskMonitorService; -import pro.taskana.TaskState; import pro.taskana.TaskanaEngine; -import pro.taskana.TaskanaRole; -import pro.taskana.exceptions.InvalidArgumentException; -import pro.taskana.exceptions.NotAuthorizedException; -import pro.taskana.impl.report.impl.CategoryReport; -import pro.taskana.impl.report.impl.ClassificationReport; -import pro.taskana.impl.report.impl.CombinedClassificationFilter; -import pro.taskana.impl.report.impl.CustomFieldValueReport; -import pro.taskana.impl.report.impl.DaysToWorkingDaysPreProcessor; -import pro.taskana.impl.report.impl.DetailedClassificationReport; -import pro.taskana.impl.report.impl.DetailedMonitorQueryItem; -import pro.taskana.impl.report.impl.MonitorQueryItem; -import pro.taskana.impl.report.impl.TaskQueryItem; -import pro.taskana.impl.report.impl.TaskStatusReport; -import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; -import pro.taskana.impl.report.impl.WorkbasketLevelReport; -import pro.taskana.impl.util.LoggerUtils; import pro.taskana.mappings.TaskMonitorMapper; /** @@ -45,400 +26,28 @@ public class TaskMonitorServiceImpl implements TaskMonitorService { } @Override - public WorkbasketLevelReport getWorkbasketLevelReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List combinedClassificationFilter) - throws InvalidArgumentException, NotAuthorizedException { - return getWorkbasketLevelReport(workbasketIds, states, categories, domains, customField, customFieldValues, - combinedClassificationFilter, Collections.emptyList(), false); + public WorkbasketReportBuilderImpl createWorkbasketReportBuilder() { + return new WorkbasketReportBuilderImpl(taskanaEngineImpl, taskMonitorMapper); } @Override - public WorkbasketLevelReport getWorkbasketLevelReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List combinedClassificationFilter, List columnHeaders) - throws InvalidArgumentException, NotAuthorizedException { - return getWorkbasketLevelReport(workbasketIds, states, categories, domains, customField, customFieldValues, - combinedClassificationFilter, columnHeaders, true); + public CategoryReportBuilder createCategoryReportBuilder() { + return new CategoryReportBuilderImpl(taskanaEngineImpl, taskMonitorMapper); } @Override - public WorkbasketLevelReport getWorkbasketLevelReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List combinedClassificationFilter, List columnHeaders, - boolean inWorkingDays) throws InvalidArgumentException, NotAuthorizedException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getWorkbasketLevelReport(workbasketIds = {}, states = {}, categories = {}, " - + "domains = {}, customField = {}, customFieldValues = {}, combinedClassificationFilter = {}, " - + "columnHeaders = {}, inWorkingDays = {})", LoggerUtils.listToString(workbasketIds), - LoggerUtils.listToString(states), LoggerUtils.listToString(categories), - LoggerUtils.listToString(domains), customField, LoggerUtils.listToString(customFieldValues), - LoggerUtils.listToString(combinedClassificationFilter), LoggerUtils.listToString(columnHeaders), - inWorkingDays); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - - configureDaysToWorkingDaysConverter(); - - WorkbasketLevelReport report = new WorkbasketLevelReport(columnHeaders); - List monitorQueryItems = taskMonitorMapper.getTaskCountOfWorkbaskets( - workbasketIds, states, categories, domains, customField, customFieldValues, - combinedClassificationFilter); - - report.addItems(monitorQueryItems, new DaysToWorkingDaysPreProcessor<>(columnHeaders, inWorkingDays)); - - return report; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getWorkbasketLevelReport()."); - } + public ClassificationReportBuilder createClassificationReportBuilder() { + return new ClassificationReportBuilderImpl(taskanaEngineImpl, taskMonitorMapper); } @Override - public CategoryReport getCategoryReport(List workbasketIds, List states, List categories, - List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException { - return getCategoryReport(workbasketIds, states, categories, domains, customField, customFieldValues, - Collections.emptyList(), - false); + public CustomFieldValueReportBuilderImpl createCustomFieldValueReportBuilder(CustomField customField) { + return new CustomFieldValueReportBuilderImpl(taskanaEngineImpl, taskMonitorMapper, customField); } @Override - public CategoryReport getCategoryReport(List workbasketIds, List states, List categories, - List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException { - return getCategoryReport(workbasketIds, states, categories, domains, customField, customFieldValues, - columnHeaders, true); - } - - @Override - public CategoryReport getCategoryReport(List workbasketIds, List states, List categories, - List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getCategoryReport(workbasketIds = {}, states = {}, categories = {}, " - + "domains = {}, customField = {}, customFieldValues = {}, reportLineItemDefinitions = {}, " - + "inWorkingDays = {})", LoggerUtils.listToString(workbasketIds), LoggerUtils.listToString(states), - LoggerUtils.listToString(categories), LoggerUtils.listToString(domains), customField, - LoggerUtils.listToString(customFieldValues), LoggerUtils.listToString(columnHeaders), - inWorkingDays); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - - configureDaysToWorkingDaysConverter(); - - CategoryReport report = new CategoryReport(columnHeaders); - List monitorQueryItems = taskMonitorMapper.getTaskCountOfCategories( - workbasketIds, states, categories, domains, customField, customFieldValues); - - report.addItems(monitorQueryItems, new DaysToWorkingDaysPreProcessor<>(columnHeaders, inWorkingDays)); - - return report; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getCategoryReport()."); - } - } - - @Override - public ClassificationReport getClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException { - return getClassificationReport(workbasketIds, states, categories, domains, customField, customFieldValues, - Collections.emptyList(), false); - } - - @Override - public ClassificationReport getClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException { - return getClassificationReport(workbasketIds, states, categories, domains, customField, customFieldValues, - columnHeaders, true); - } - - @Override - public ClassificationReport getClassificationReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getClassificationReport(workbasketIds = {}, states = {}, categories = {}, " - + "domains = {}, customField = {}, customFieldValues = {}, columnHeaders = {}, " - + "inWorkingDays = {})", LoggerUtils.listToString(workbasketIds), LoggerUtils.listToString(states), - LoggerUtils.listToString(categories), LoggerUtils.listToString(domains), customField, - LoggerUtils.listToString(customFieldValues), LoggerUtils.listToString(columnHeaders), - inWorkingDays); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - - configureDaysToWorkingDaysConverter(); - - ClassificationReport report = new ClassificationReport(columnHeaders); - List monitorQueryItems = taskMonitorMapper.getTaskCountOfClassifications( - workbasketIds, states, categories, domains, customField, customFieldValues); - - report.addItems(monitorQueryItems, new DaysToWorkingDaysPreProcessor<>(columnHeaders, inWorkingDays)); - - return report; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getClassificationReport()."); - } - } - - @Override - public DetailedClassificationReport getDetailedClassificationReport(List workbasketIds, - List states, List categories, List domains, CustomField customField, - List customFieldValues) throws InvalidArgumentException, NotAuthorizedException { - return getDetailedClassificationReport(workbasketIds, states, categories, domains, customField, - customFieldValues, Collections.emptyList(), false); - } - - @Override - public DetailedClassificationReport getDetailedClassificationReport(List workbasketIds, - List states, List categories, List domains, CustomField customField, - List customFieldValues, List columnHeaders) - throws InvalidArgumentException, NotAuthorizedException { - return getDetailedClassificationReport(workbasketIds, states, categories, domains, customField, - customFieldValues, columnHeaders, true); - } - - @Override - public DetailedClassificationReport getDetailedClassificationReport(List workbasketIds, - List states, List categories, List domains, CustomField customField, - List customFieldValues, List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException { - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getDetailedClassificationReport(workbasketIds = {}, states = {}, " - + "categories = {}, domains = {}, customField = {}, customFieldValues = {}, " - + "columnHeaders = {}, inWorkingDays = {})", LoggerUtils.listToString(workbasketIds), - LoggerUtils.listToString(states), LoggerUtils.listToString(categories), - LoggerUtils.listToString(domains), customField, LoggerUtils.listToString(customFieldValues), - LoggerUtils.listToString(columnHeaders), inWorkingDays); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - - configureDaysToWorkingDaysConverter(); - - DetailedClassificationReport report = new DetailedClassificationReport(columnHeaders); - List detailedMonitorQueryItems = taskMonitorMapper - .getTaskCountOfDetailedClassifications(workbasketIds, states, categories, domains, customField, - customFieldValues); - - report.addItems(detailedMonitorQueryItems, - new DaysToWorkingDaysPreProcessor<>(columnHeaders, inWorkingDays)); - - return report; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getDetailedClassificationReport()."); - } - } - - @Override - public CustomFieldValueReport getCustomFieldValueReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues) - throws InvalidArgumentException, NotAuthorizedException { - return getCustomFieldValueReport(workbasketIds, states, categories, domains, customField, customFieldValues, - Collections.emptyList(), false); - } - - @Override - public CustomFieldValueReport getCustomFieldValueReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders) throws InvalidArgumentException, NotAuthorizedException { - return getCustomFieldValueReport(workbasketIds, states, categories, domains, customField, customFieldValues, - columnHeaders, true); - } - - @Override - public CustomFieldValueReport getCustomFieldValueReport(List workbasketIds, List states, - List categories, List domains, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays) - throws InvalidArgumentException, NotAuthorizedException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getCustomFieldValueReport(workbasketIds = {}, states = {}, categories = {}, " - + "domains = {}, customField = {}, customFieldValues = {}, columnHeaders = {}, " - + "inWorkingDays = {})", LoggerUtils.listToString(workbasketIds), LoggerUtils.listToString(states), - LoggerUtils.listToString(categories), LoggerUtils.listToString(domains), customField, - LoggerUtils.listToString(customFieldValues), LoggerUtils.listToString(columnHeaders), - inWorkingDays); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - - if (customField == null) { - throw new InvalidArgumentException("CustomField can´t be used as NULL-Parameter"); - } - - configureDaysToWorkingDaysConverter(); - - CustomFieldValueReport report = new CustomFieldValueReport(columnHeaders); - List monitorQueryItems = taskMonitorMapper.getTaskCountOfCustomFieldValues( - workbasketIds, states, categories, domains, customField, customFieldValues); - - report.addItems(monitorQueryItems, new DaysToWorkingDaysPreProcessor<>(columnHeaders, inWorkingDays)); - - return report; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getCustomFieldValueReport()."); - } - } - - @Override - public List getCustomAttributeValuesForReport(List workbasketIds, List states, - List categories, List domains, List classificationIds, - List excludedClassificationIds, Map customAttributeFilter, - String customAttributeName) throws InvalidArgumentException, NotAuthorizedException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getCustomAttributeValuesForReport(workbasketIds = {}, states = {}, " - + "categories = {}, domains = {}, classificationIds = {}, excludedClassificationIds = {}, customAttributeName = {})", - LoggerUtils.listToString(workbasketIds), LoggerUtils.listToString(states), - LoggerUtils.listToString(categories), LoggerUtils.listToString(domains), - LoggerUtils.listToString(classificationIds), LoggerUtils.listToString(excludedClassificationIds), - customAttributeName); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - - if (customAttributeName == null || customAttributeName.isEmpty()) { - throw new InvalidArgumentException("customAttributeName must not be null."); - } - - List customAttributeValues = taskMonitorMapper.getCustomAttributeValuesForReport(workbasketIds, - states, - categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, - "CUSTOM_" + customAttributeName); - - return customAttributeValues; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getCustomAttributeValuesForReport()."); - } - } - - @Override - public List getTaskIdsForSelectedItems(List workbasketIds, List states, - List categories, List domains, List classificationIds, - List excludedClassificationIds, CustomField customField, List customFieldValues, - List columnHeaders, boolean inWorkingDays, - List selectedItems, String dimension) throws InvalidArgumentException, NotAuthorizedException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("entry to getTaskIdsForSelectedItems(workbasketIds = {}, states = {}, " - + "categories = {}, domains = {}, customField = {}, customFieldValues = {}, " - + "columnHeaders = {}, inWorkingDays = {}, selectedItems = {}, dimension = {})", - LoggerUtils.listToString(workbasketIds), LoggerUtils.listToString(states), - LoggerUtils.listToString(categories), LoggerUtils.listToString(domains), - LoggerUtils.listToString(classificationIds), LoggerUtils.listToString(excludedClassificationIds), - customField, - LoggerUtils.listToString(customFieldValues), LoggerUtils.listToString(columnHeaders), - inWorkingDays, LoggerUtils.listToString(selectedItems), dimension); - } - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR); - try { - taskanaEngineImpl.openConnection(); - if (columnHeaders == null) { - throw new InvalidArgumentException("ColumnHeader must not be null."); - } - if (selectedItems == null || selectedItems.size() == 0) { - throw new InvalidArgumentException( - "SelectedItems must not be null or empty."); - } - boolean joinWithAttachments = subKeyIsSet(selectedItems); - if (joinWithAttachments && !TaskMonitorService.DIMENSION_CLASSIFICATION_KEY.equals(dimension)) { - throw new InvalidArgumentException("SubKeys are supported for dimension CLASSIFICATION_KEY only."); - } - - configureDaysToWorkingDaysConverter(); - - if (inWorkingDays) { - selectedItems = convertWorkingDaysToDays(selectedItems, columnHeaders); - } - - List taskIds = taskMonitorMapper.getTaskIdsForSelectedItems(workbasketIds, states, - categories, domains, classificationIds, excludedClassificationIds, customField, customFieldValues, - dimension, selectedItems, joinWithAttachments); - - return taskIds; - - } finally { - taskanaEngineImpl.returnConnection(); - LOGGER.debug("exit from getTaskIdsForSelectedItems()."); - } - } - - @Override - public TaskStatusReport getTaskStatusReport() throws NotAuthorizedException { - return getTaskStatusReport(null, null); - } - - @Override - public TaskStatusReport getTaskStatusReport(List domains) throws NotAuthorizedException { - return getTaskStatusReport(domains, null); - } - - @Override - public TaskStatusReport getTaskStatusReport(List domains, List states) - throws NotAuthorizedException { - taskanaEngineImpl.checkRoleMembership(TaskanaRole.MONITOR, TaskanaRole.ADMIN); - try { - taskanaEngineImpl.openConnection(); - - List tasks = taskMonitorMapper.getTasksCountByState(domains, states); - TaskStatusReport report = new TaskStatusReport(states); - report.addItems(tasks); - return report; - - } finally { - taskanaEngineImpl.returnConnection(); - } - } - - private List convertWorkingDaysToDays(List selectedItems, - List columnHeaders) throws InvalidArgumentException { - - DaysToWorkingDaysConverter instance = DaysToWorkingDaysConverter.initialize(columnHeaders); - for (SelectedItem selectedItem : selectedItems) { - selectedItem - .setLowerAgeLimit(Collections.min(instance.convertWorkingDaysToDays(selectedItem.getLowerAgeLimit()))); - selectedItem - .setUpperAgeLimit(Collections.max(instance.convertWorkingDaysToDays(selectedItem.getUpperAgeLimit()))); - } - return selectedItems; - } - - private void configureDaysToWorkingDaysConverter() { - DaysToWorkingDaysConverter.setCustomHolidays(taskanaEngineImpl.getConfiguration().getCustomHolidays()); - DaysToWorkingDaysConverter.setGermanPublicHolidaysEnabled( - this.taskanaEngineImpl.getConfiguration().isGermanPublicHolidaysEnabled()); - } - - private boolean subKeyIsSet(List selectedItems) { - for (SelectedItem selectedItem : selectedItems) { - if (selectedItem.getSubKey() != null && !selectedItem.getSubKey().isEmpty()) { - return true; - } - } - return false; + public TaskStatusReportBuilderImpl createTaskStatusReportBuilder() { + return new TaskStatusReportBuilderImpl(taskanaEngineImpl, taskMonitorMapper); } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskStatusReportBuilderImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskStatusReportBuilderImpl.java new file mode 100644 index 000000000..d7a6c4c02 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskStatusReportBuilderImpl.java @@ -0,0 +1,61 @@ +package pro.taskana.impl; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import pro.taskana.TaskState; +import pro.taskana.TaskStatusReportBuilder; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaRole; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.TaskQueryItem; +import pro.taskana.impl.report.impl.TaskStatusReport; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * The implementation of TaskStatusReportBuilder. + */ +public class TaskStatusReportBuilderImpl implements TaskStatusReportBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(TaskStatusReportBuilderImpl.class); + private TaskanaEngineImpl taskanaEngine; + private TaskMonitorMapper taskMonitorMapper; + private List domains; + private List states; + + public TaskStatusReportBuilderImpl(TaskanaEngine taskanaEngine, TaskMonitorMapper taskMonitorMapper) { + this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine; + this.taskMonitorMapper = taskMonitorMapper; + } + + @Override + public TaskStatusReportBuilderImpl stateIn(List states) { + this.states = states; + return this; + } + + @Override + public TaskStatusReportBuilderImpl domainIn(List domains) { + this.domains = domains; + return this; + } + + @Override + public TaskStatusReport buildReport() throws NotAuthorizedException { + LOGGER.debug("entry to buildReport(), this = {}", this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR, TaskanaRole.ADMIN); + try { + this.taskanaEngine.openConnection(); + List tasks = this.taskMonitorMapper.getTasksCountByState(this.domains, this.states); + TaskStatusReport report = new TaskStatusReport(this.states); + report.addItems(tasks); + return report; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from buildReport()."); + } + } + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketReportBuilderImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketReportBuilderImpl.java new file mode 100644 index 000000000..b5b31c9b7 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketReportBuilderImpl.java @@ -0,0 +1,119 @@ +package pro.taskana.impl; + +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaRole; +import pro.taskana.WorkbasketReportBuilder; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.CombinedClassificationFilter; +import pro.taskana.impl.report.impl.DaysToWorkingDaysPreProcessor; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.impl.report.impl.WorkbasketReport; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * The implementation of WorkbasketReportBuilder. + */ +public class WorkbasketReportBuilderImpl extends ReportBuilder implements WorkbasketReportBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketReportBuilderImpl.class); + private List combinedClassificationFilter; + + public WorkbasketReportBuilderImpl(TaskanaEngine taskanaEngine, TaskMonitorMapper taskMonitorMapper) { + super(taskanaEngine, taskMonitorMapper); + } + + @Override + public WorkbasketReportBuilderImpl withColumnHeaders(List columnHeaders) { + this.columnHeaders = columnHeaders; + return this; + } + + @Override + public WorkbasketReportBuilderImpl inWorkingDays() { + this.inWorkingDays = true; + return this; + } + + @Override + public WorkbasketReportBuilderImpl workbasketIdIn(List workbasketIds) { + this.workbasketIds = workbasketIds; + return this; + } + + @Override + public WorkbasketReportBuilderImpl stateIn(List states) { + this.states = states; + return this; + } + + @Override + public WorkbasketReportBuilderImpl categoryIn(List categories) { + this.categories = categories; + return this; + } + + @Override + public WorkbasketReportBuilderImpl domainIn(List domains) { + this.domains = domains; + return this; + } + + @Override + public WorkbasketReportBuilderImpl classificationIdIn(List classificationIds) { + this.classificationIds = classificationIds; + return this; + } + + @Override + public WorkbasketReportBuilderImpl excludedClassificationIdIn(List excludedClassificationIds) { + this.excludedClassificationIds = excludedClassificationIds; + return this; + } + + @Override + public WorkbasketReportBuilderImpl customAttributeFilterIn(Map customAttributeFilter) { + this.customAttributeFilter = customAttributeFilter; + return this; + } + + @Override + public WorkbasketReportBuilderImpl combinedClassificationFilterIn( + List combinedClassificationFilter) { + this.combinedClassificationFilter = combinedClassificationFilter; + return this; + } + + public List getCombinedClassificationFilterIn() { + return this.combinedClassificationFilter; + } + + @Override + public WorkbasketReport buildReport() throws InvalidArgumentException, NotAuthorizedException { + LOGGER.debug("entry to buildReport(), this = {}", this); + this.taskanaEngine.checkRoleMembership(TaskanaRole.MONITOR); + try { + this.taskanaEngine.openConnection(); + WorkbasketReport report = new WorkbasketReport(this.columnHeaders); + List monitorQueryItems = this.taskMonitorMapper.getTaskCountOfWorkbaskets( + this.workbasketIds, this.states, this.categories, this.domains, this.classificationIds, + this.excludedClassificationIds, this.customAttributeFilter, this.combinedClassificationFilter); + report.addItems(monitorQueryItems, + new DaysToWorkingDaysPreProcessor<>(this.columnHeaders, this.inWorkingDays)); + return report; + } finally { + this.taskanaEngine.returnConnection(); + LOGGER.debug("exit from buildReport()."); + } + } + +} diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/CombinedClassificationFilter.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/CombinedClassificationFilter.java index a406e5b9e..4852560d1 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/CombinedClassificationFilter.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/CombinedClassificationFilter.java @@ -2,8 +2,8 @@ package pro.taskana.impl.report.impl; /** * The CombinedClassificationFilter is a pair of a classificationId for a task and a classificationId for the - * corresponding attachment that is used to filter the {@link WorkbasketLevelReport} by the classification of the - * attachment. To filter by the classification of the task, the classificationId of the attachment should be null. + * corresponding attachment that is used to filter the {@link WorkbasketReport} by the classification of the attachment. + * To filter by the classification of the task, the classificationId of the attachment should be null. */ public class CombinedClassificationFilter { diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/WorkbasketLevelReport.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/WorkbasketReport.java similarity index 50% rename from lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/WorkbasketLevelReport.java rename to lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/WorkbasketReport.java index 512855d82..458c901cb 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/WorkbasketLevelReport.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/impl/WorkbasketReport.java @@ -7,9 +7,9 @@ import pro.taskana.impl.report.Report; /** * TODO. */ -public class WorkbasketLevelReport extends Report { +public class WorkbasketReport extends Report { - public WorkbasketLevelReport(List timeIntervalColumnHeaders) { + public WorkbasketReport(List timeIntervalColumnHeaders) { super(timeIntervalColumnHeaders, "WORKBASKET KEYS"); } diff --git a/lib/taskana-core/src/main/java/pro/taskana/mappings/TaskMonitorMapper.java b/lib/taskana-core/src/main/java/pro/taskana/mappings/TaskMonitorMapper.java index 899777e68..6a551c5f3 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/mappings/TaskMonitorMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/mappings/TaskMonitorMapper.java @@ -39,8 +39,14 @@ public interface TaskMonitorMapper { + "" + "AND T.DOMAIN IN (#{domain}) " + "" - + "" - + "AND ${customField} IN (#{customFieldValue}) " + + "" + + "AND CLASSIFICATION_ID IN (#{classificationId}) " + + "" + + "" + + "AND CLASSIFICATION_ID NOT IN (#{excludedClassificationId}) " + + "" + + "" + + "AND ((${key} = '${customAttributeFilter.get(key)}')) " + "" + "" + "AND " @@ -65,8 +71,9 @@ public interface TaskMonitorMapper { @Param("states") List states, @Param("categories") List categories, @Param("domains") List domains, - @Param("customField") CustomField customField, - @Param("customFieldValues") List customFieldValues, + @Param("classificationIds") List classificationIds, + @Param("excludedClassificationIds") List excludedClassificationIds, + @Param("customAttributeFilter") Map customAttributeFilter, @Param("combinedClassificationFilter") List combinedClassificationFilter); @Select("") List getTaskIdsForSelectedItems(@Param("workbasketIds") List workbasketIds, @Param("states") List states, - @Param("categories") List categories, @Param("domains") List domains, + @Param("categories") List categories, + @Param("domains") List domains, @Param("classificationIds") List classificationIds, @Param("excludedClassificationIds") List excludedClassificationIds, - @Param("customField") CustomField customField, @Param("customFieldValues") List customFieldValues, + @Param("customAttributeFilter") Map customAttributeFilter, @Param("groupedBy") String groupedBy, @Param("selectedItems") List selectedItems, @Param("joinWithAttachments") boolean joinWithAttachments); @@ -307,7 +345,7 @@ public interface TaskMonitorMapper { @Param("states") List states); @Select("") @@ -338,7 +376,7 @@ public interface TaskMonitorMapper { @Param("categories") List categories, @Param("domains") List domains, @Param("classificationIds") List classificationIds, @Param("excludedClassificationIds") List excludedClassificationIds, - @Param("customAttributeFilter") Map customAttributeFilter, - @Param("customAttributeName") String customAttributeName); + @Param("customAttributeFilter") Map customAttributeFilter, + @Param("customField") CustomField customField); } diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/GetCustomAttributeValuesForReportAcctest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/GetCustomAttributeValuesForReportAcctest.java index 5ad3992eb..46e123f6f 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/GetCustomAttributeValuesForReportAcctest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/GetCustomAttributeValuesForReportAcctest.java @@ -18,12 +18,12 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import pro.taskana.CustomField; import pro.taskana.TaskMonitorService; import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine.ConnectionManagementMode; import pro.taskana.configuration.TaskanaEngineConfiguration; import pro.taskana.database.TestDataGenerator; -import pro.taskana.exceptions.InvalidArgumentException; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.configuration.DBCleaner; import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest; @@ -59,25 +59,23 @@ public class GetCustomAttributeValuesForReportAcctest { } @Test(expected = NotAuthorizedException.class) - public void testRoleCheck() throws InvalidArgumentException, NotAuthorizedException { + public void testRoleCheck() throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getCustomAttributeValuesForReport( - Collections.singletonList("WBI:000000000000000000000000000000000001"), null, - null, null, null, null, null, - "2"); + taskMonitorService.createWorkbasketReportBuilder() + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_2); + } @WithAccessId( userName = "monitor") @Test - public void testGetCustomAttributeValuesForOneWorkbasket() throws InvalidArgumentException, NotAuthorizedException { + public void testGetCustomAttributeValuesForOneWorkbasket() throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - List values = taskMonitorService.getCustomAttributeValuesForReport( - Collections.singletonList("WBI:000000000000000000000000000000000001"), null, - null, null, null, null, null, - "2"); + List values = taskMonitorService.createWorkbasketReportBuilder() + .workbasketIdIn(Collections.singletonList("WBI:000000000000000000000000000000000001")) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_2); assertNotNull(values); assertEquals(2, values.size()); @@ -88,14 +86,12 @@ public class GetCustomAttributeValuesForReportAcctest { @WithAccessId( userName = "monitor") @Test - public void testGetCustomAttributeValuesForOneDomain() throws InvalidArgumentException, NotAuthorizedException { + public void testGetCustomAttributeValuesForOneDomain() throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - List values = taskMonitorService.getCustomAttributeValuesForReport( - null, null, - null, Collections.singletonList("DOMAIN_A"), null, null, null, - "16"); - + List values = taskMonitorService.createWorkbasketReportBuilder() + .domainIn(Collections.singletonList("DOMAIN_A")) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_16); assertNotNull(values); assertEquals(26, values.size()); } @@ -104,16 +100,16 @@ public class GetCustomAttributeValuesForReportAcctest { userName = "monitor") @Test public void testGetCustomAttributeValuesForCustomAttribute() - throws InvalidArgumentException, NotAuthorizedException { + throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - Map props = new HashMap<>(); - props.put("2", "Vollkasko"); - props.put("1", "Geschaeftsstelle A"); - List values = taskMonitorService.getCustomAttributeValuesForReport( - null, null, - null, null, null, null, props, - "16"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_2, "Vollkasko"); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + + List values = taskMonitorService.createCategoryReportBuilder() + .customAttributeFilterIn(customAttributeFilter) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_16); assertNotNull(values); assertEquals(12, values.size()); @@ -123,17 +119,18 @@ public class GetCustomAttributeValuesForReportAcctest { userName = "monitor") @Test public void testGetCustomAttributeValuesForExcludedClassifications() - throws InvalidArgumentException, NotAuthorizedException { + throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List domains = new ArrayList<>(); domains.add("DOMAIN_A"); domains.add("DOMAIN_B"); domains.add("DOMAIN_C"); - List values = taskMonitorService.getCustomAttributeValuesForReport( - null, null, - null, domains, null, Collections.singletonList("CLI:000000000000000000000000000000000003"), null, - "16"); + + List values = taskMonitorService.createCategoryReportBuilder() + .domainIn(domains) + .excludedClassificationIdIn(Collections.singletonList("CLI:000000000000000000000000000000000003")) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_16); assertNotNull(values); assertEquals(43, values.size()); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCategoryReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCategoryReportAccTest.java index 7abe72336..083fdb4f0 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCategoryReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCategoryReportAccTest.java @@ -8,7 +8,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.sql.DataSource; @@ -68,9 +70,8 @@ public class GetTaskIdsOfCategoryReportAccTest { List columnHeaders = getListOfColumnHeaders(); List selectedItems = new ArrayList<>(); - taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + + taskMonitorService.createCategoryReportBuilder().listTaskIdsForSelectedItems(selectedItems); } @WithAccessId( @@ -101,9 +102,10 @@ public class GetTaskIdsOfCategoryReportAccTest { s3.setUpperAgeLimit(0); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + List ids = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .listTaskIdsForSelectedItems(selectedItems); assertEquals(11, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); @@ -149,9 +151,11 @@ public class GetTaskIdsOfCategoryReportAccTest { s3.setUpperAgeLimit(0); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(workbasketIds, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + List ids = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .workbasketIdIn(workbasketIds) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(4, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); @@ -190,9 +194,11 @@ public class GetTaskIdsOfCategoryReportAccTest { s3.setUpperAgeLimit(0); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, states, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + List ids = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .stateIn(states) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(11, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); @@ -232,9 +238,11 @@ public class GetTaskIdsOfCategoryReportAccTest { s2.setUpperAgeLimit(0); selectedItems.add(s2); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, categories, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + List ids = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .categoryIn(categories) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(3, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); @@ -272,9 +280,11 @@ public class GetTaskIdsOfCategoryReportAccTest { s3.setUpperAgeLimit(0); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, domains, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + List ids = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .domainIn(domains) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(4, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); @@ -290,8 +300,8 @@ public class GetTaskIdsOfCategoryReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); List columnHeaders = getListOfColumnHeaders(); List selectedItems = new ArrayList<>(); @@ -314,10 +324,11 @@ public class GetTaskIdsOfCategoryReportAccTest { s3.setUpperAgeLimit(0); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, null, - customField, - customFieldValues, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + List ids = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .customAttributeFilterIn(customAttributeFilter) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(5, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); @@ -344,9 +355,8 @@ public class GetTaskIdsOfCategoryReportAccTest { s1.setUpperAgeLimit(-2); selectedItems.add(s1); - taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); + taskMonitorService.createCategoryReportBuilder().withColumnHeaders(columnHeaders).listTaskIdsForSelectedItems( + selectedItems); } private List getListOfColumnHeaders() { diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfClassificationReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfClassificationReportAccTest.java index 2af539007..caed430b0 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfClassificationReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfClassificationReportAccTest.java @@ -83,9 +83,7 @@ public class GetTaskIdsOfClassificationReportAccTest { s3.setUpperAgeLimit(-11); selectedItems.add(s3); - taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_KEY); + taskMonitorService.createClassificationReportBuilder().listTaskIdsForSelectedItems(selectedItems); } @WithAccessId( @@ -116,9 +114,10 @@ public class GetTaskIdsOfClassificationReportAccTest { s3.setUpperAgeLimit(-11); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_KEY); + List ids = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .listTaskIdsForSelectedItems(selectedItems); assertEquals(6, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000001")); @@ -160,9 +159,10 @@ public class GetTaskIdsOfClassificationReportAccTest { s3.setUpperAgeLimit(-11); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_KEY); + List ids = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .listTaskIdsForSelectedItems(selectedItems); assertEquals(2, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000001")); @@ -202,9 +202,11 @@ public class GetTaskIdsOfClassificationReportAccTest { domains.add("DOMAIN_B"); domains.add("DOMAIN_C"); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, domains, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_CLASSIFICATION_KEY); + List ids = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .domainIn(domains) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(3, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000001")); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCustomFieldValueReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCustomFieldValueReportAccTest.java new file mode 100644 index 000000000..a2dc7a3e7 --- /dev/null +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfCustomFieldValueReportAccTest.java @@ -0,0 +1,372 @@ +package acceptance.monitoring; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import pro.taskana.CustomField; +import pro.taskana.TaskMonitorService; +import pro.taskana.TaskState; +import pro.taskana.TaskanaEngine; +import pro.taskana.TaskanaEngine.ConnectionManagementMode; +import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.database.TestDataGenerator; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.SelectedItem; +import pro.taskana.impl.TaskanaEngineImpl; +import pro.taskana.impl.configuration.DBCleaner; +import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.security.JAASRunner; +import pro.taskana.security.WithAccessId; + +/** + * Acceptance test for all "get task ids of category report" scenarios. + */ +@RunWith(JAASRunner.class) +public class GetTaskIdsOfCustomFieldValueReportAccTest { + + protected static TaskanaEngineConfiguration taskanaEngineConfiguration; + protected static TaskanaEngine taskanaEngine; + + @BeforeClass + public static void setupTest() throws Exception { + resetDb(); + } + + public static void resetDb() throws SQLException, IOException { + DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource(); + DBCleaner cleaner = new DBCleaner(); + cleaner.clearDb(dataSource, true); + dataSource = TaskanaEngineConfigurationTest.getDataSource(); + taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false); + taskanaEngineConfiguration.setGermanPublicHolidaysEnabled(false); + taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine(); + ((TaskanaEngineImpl) taskanaEngine).setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT); + cleaner.clearDb(dataSource, false); + TestDataGenerator testDataGenerator = new TestDataGenerator(); + testDataGenerator.generateMonitoringTestData(dataSource); + } + + @Test(expected = NotAuthorizedException.class) + public void testRoleCheck() throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .listTaskIdsForSelectedItems(selectedItems); + } + + @WithAccessId( + userName = "monitor") + @Test + public void testGetTaskIdsOfCustomFieldValueReport() throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + SelectedItem s2 = new SelectedItem(); + s2.setKey("Geschaeftsstelle B"); + s2.setLowerAgeLimit(Integer.MIN_VALUE); + s2.setUpperAgeLimit(-11); + selectedItems.add(s2); + + SelectedItem s3 = new SelectedItem(); + s3.setKey("Geschaeftsstelle C"); + s3.setLowerAgeLimit(0); + s3.setUpperAgeLimit(0); + selectedItems.add(s3); + + List ids = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .listTaskIdsForSelectedItems(selectedItems); + + assertEquals(8, ids.size()); + assertTrue(ids.contains("TKI:000000000000000000000000000000000002")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000009")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000024")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000027")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000029")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000033")); + } + + @WithAccessId( + userName = "monitor") + @Test + public void testGetTaskIdsOfCustomFieldValueReportWithWorkbasketFilter() + throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + SelectedItem s2 = new SelectedItem(); + s2.setKey("Geschaeftsstelle B"); + s2.setLowerAgeLimit(Integer.MIN_VALUE); + s2.setUpperAgeLimit(-11); + selectedItems.add(s2); + + SelectedItem s3 = new SelectedItem(); + s3.setKey("Geschaeftsstelle C"); + s3.setLowerAgeLimit(0); + s3.setUpperAgeLimit(0); + selectedItems.add(s3); + + List ids = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .workbasketIdIn(workbasketIds) + .listTaskIdsForSelectedItems(selectedItems); + + assertEquals(3, ids.size()); + assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000009")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); + } + + @WithAccessId( + userName = "monitor") + @Test + public void testGetTaskIdsOfCustomFieldValueReportWithStateFilter() + throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + SelectedItem s2 = new SelectedItem(); + s2.setKey("Geschaeftsstelle B"); + s2.setLowerAgeLimit(Integer.MIN_VALUE); + s2.setUpperAgeLimit(-11); + selectedItems.add(s2); + + SelectedItem s3 = new SelectedItem(); + s3.setKey("Geschaeftsstelle C"); + s3.setLowerAgeLimit(0); + s3.setUpperAgeLimit(0); + selectedItems.add(s3); + + List ids = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .stateIn(Collections.singletonList(TaskState.READY)) + .listTaskIdsForSelectedItems(selectedItems); + + assertEquals(8, ids.size()); + assertTrue(ids.contains("TKI:000000000000000000000000000000000002")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000009")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000024")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000027")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000029")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000033")); + } + + @WithAccessId( + userName = "monitor") + @Test + public void testGetTaskIdsOfCustomFieldValueReportWithCategoryFilter() + throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List categories = Arrays.asList("AUTOMATIC", "MANUAL"); + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + SelectedItem s2 = new SelectedItem(); + s2.setKey("Geschaeftsstelle B"); + s2.setLowerAgeLimit(Integer.MIN_VALUE); + s2.setUpperAgeLimit(-11); + selectedItems.add(s2); + + SelectedItem s3 = new SelectedItem(); + s3.setKey("Geschaeftsstelle C"); + s3.setLowerAgeLimit(0); + s3.setUpperAgeLimit(0); + selectedItems.add(s3); + + List ids = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .categoryIn(categories) + .listTaskIdsForSelectedItems(selectedItems); + + assertEquals(3, ids.size()); + assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000009")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000029")); + } + + @WithAccessId( + userName = "monitor") + @Test + public void testGetTaskIdsOfCustomFieldValueReportWithDomainFilter() + throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + SelectedItem s2 = new SelectedItem(); + s2.setKey("Geschaeftsstelle B"); + s2.setLowerAgeLimit(Integer.MIN_VALUE); + s2.setUpperAgeLimit(-11); + selectedItems.add(s2); + + SelectedItem s3 = new SelectedItem(); + s3.setKey("Geschaeftsstelle C"); + s3.setLowerAgeLimit(0); + s3.setUpperAgeLimit(0); + selectedItems.add(s3); + + List ids = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .domainIn(Collections.singletonList("DOMAIN_A")) + .listTaskIdsForSelectedItems(selectedItems); + + assertEquals(3, ids.size()); + assertTrue(ids.contains("TKI:000000000000000000000000000000000009")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000033")); + } + + @WithAccessId( + userName = "monitor") + @Test + public void testGetTaskIdsOfCustomFieldValueReportWithCustomFieldValueFilter() + throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + SelectedItem s2 = new SelectedItem(); + s2.setKey("Geschaeftsstelle B"); + s2.setLowerAgeLimit(Integer.MIN_VALUE); + s2.setUpperAgeLimit(-11); + selectedItems.add(s2); + + SelectedItem s3 = new SelectedItem(); + s3.setKey("Geschaeftsstelle C"); + s3.setLowerAgeLimit(0); + s3.setUpperAgeLimit(0); + selectedItems.add(s3); + + List ids = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .customAttributeFilterIn(customAttributeFilter) + .listTaskIdsForSelectedItems(selectedItems); + + assertEquals(4, ids.size()); + assertTrue(ids.contains("TKI:000000000000000000000000000000000020")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000024")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000027")); + assertTrue(ids.contains("TKI:000000000000000000000000000000000029")); + } + + @WithAccessId( + userName = "monitor") + @Test(expected = InvalidArgumentException.class) + public void testThrowsExceptionIfSubKeysAreUsed() throws InvalidArgumentException, NotAuthorizedException { + TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); + + List columnHeaders = getListOfColumnHeaders(); + + List selectedItems = new ArrayList<>(); + + SelectedItem s1 = new SelectedItem(); + s1.setKey("Geschaeftsstelle A"); + s1.setSubKey("INVALID"); + s1.setLowerAgeLimit(-5); + s1.setUpperAgeLimit(-2); + selectedItems.add(s1); + + taskMonitorService.createCategoryReportBuilder().withColumnHeaders(columnHeaders).listTaskIdsForSelectedItems( + selectedItems); + } + + private List getListOfColumnHeaders() { + List columnHeaders = new ArrayList<>(); + columnHeaders.add(new TimeIntervalColumnHeader(Integer.MIN_VALUE, -11)); + columnHeaders.add(new TimeIntervalColumnHeader(-10, -6)); + columnHeaders.add(new TimeIntervalColumnHeader(-5, -2)); + columnHeaders.add(new TimeIntervalColumnHeader(-1)); + columnHeaders.add(new TimeIntervalColumnHeader(0)); + columnHeaders.add(new TimeIntervalColumnHeader(1)); + columnHeaders.add(new TimeIntervalColumnHeader(2, 5)); + columnHeaders.add(new TimeIntervalColumnHeader(6, 10)); + columnHeaders.add(new TimeIntervalColumnHeader(11, Integer.MAX_VALUE)); + return columnHeaders; + } + +} diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfWorkbasketReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfWorkbasketReportAccTest.java index 729409bb3..0c624bd17 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfWorkbasketReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/GetTaskIdsOfWorkbasketReportAccTest.java @@ -66,9 +66,7 @@ public class GetTaskIdsOfWorkbasketReportAccTest { List selectedItems = new ArrayList<>(); - taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_WORKBASKET_KEY); + taskMonitorService.createWorkbasketReportBuilder().listTaskIdsForSelectedItems(selectedItems); } @WithAccessId( @@ -99,9 +97,10 @@ public class GetTaskIdsOfWorkbasketReportAccTest { s3.setUpperAgeLimit(Integer.MAX_VALUE); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - null, null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_WORKBASKET_KEY); + List ids = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .listTaskIdsForSelectedItems(selectedItems); assertEquals(7, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000001")); @@ -142,9 +141,11 @@ public class GetTaskIdsOfWorkbasketReportAccTest { s3.setUpperAgeLimit(Integer.MAX_VALUE); selectedItems.add(s3); - List ids = taskMonitorService.getTaskIdsForSelectedItems(null, null, null, null, null, - Collections.singletonList("CLI:000000000000000000000000000000000001"), null, null, - columnHeaders, true, selectedItems, TaskMonitorService.DIMENSION_WORKBASKET_KEY); + List ids = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .excludedClassificationIdIn(Collections.singletonList("CLI:000000000000000000000000000000000001")) + .listTaskIdsForSelectedItems(selectedItems); assertEquals(4, ids.size()); assertTrue(ids.contains("TKI:000000000000000000000000000000000006")); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCategoryReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCategoryReportAccTest.java index 25f276681..4fb93eca2 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCategoryReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCategoryReportAccTest.java @@ -9,7 +9,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.IntStream; import javax.sql.DataSource; @@ -70,7 +72,7 @@ public class ProvideCategoryReportAccTest { public void testRoleCheck() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getCategoryReport(null, null, null, null, null, null); + taskMonitorService.createCategoryReportBuilder().buildReport(); } @WithAccessId( @@ -79,7 +81,7 @@ public class ProvideCategoryReportAccTest { public void testGetTotalNumbersOfTasksOfCategoryReport() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, null, null, null, null); + CategoryReport report = taskMonitorService.createCategoryReportBuilder().buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -106,8 +108,10 @@ public class ProvideCategoryReportAccTest { List columnHeaders = getListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, null, null, null, null, - columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -136,8 +140,10 @@ public class ProvideCategoryReportAccTest { List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, null, null, null, null, - columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -164,8 +170,9 @@ public class ProvideCategoryReportAccTest { List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, null, null, null, null, - columnHeaders, false); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -194,8 +201,11 @@ public class ProvideCategoryReportAccTest { List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(workbasketIds, null, null, null, null, null, - columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .workbasketIdIn(workbasketIds) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -223,8 +233,11 @@ public class ProvideCategoryReportAccTest { List states = Collections.singletonList(TaskState.READY); List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, states, null, null, null, null, - columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .stateIn(states) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -253,8 +266,11 @@ public class ProvideCategoryReportAccTest { List categories = Arrays.asList("AUTOMATIC", "MANUAL"); List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, categories, null, null, null, - columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .categoryIn(categories) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -280,8 +296,11 @@ public class ProvideCategoryReportAccTest { List domains = Collections.singletonList("DOMAIN_A"); List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, null, domains, null, null, - columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .domainIn(domains) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -307,12 +326,15 @@ public class ProvideCategoryReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); List columnHeaders = getShortListOfColumnHeaders(); - CategoryReport report = taskMonitorService.getCategoryReport(null, null, null, null, customField, - customFieldValues, columnHeaders); + CategoryReport report = taskMonitorService.createCategoryReportBuilder() + .withColumnHeaders(columnHeaders) + .customAttributeFilterIn(customAttributeFilter) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideClassificationReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideClassificationReportAccTest.java index 44c569736..8d33c1553 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideClassificationReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideClassificationReportAccTest.java @@ -9,7 +9,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.IntStream; import javax.sql.DataSource; @@ -71,7 +73,7 @@ public class ProvideClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getClassificationReport(null, null, null, null, null, null); + taskMonitorService.createClassificationReportBuilder().buildReport(); } @WithAccessId( @@ -81,7 +83,7 @@ public class ProvideClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, null, null, null, null); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder().buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -110,13 +112,15 @@ public class ProvideClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - List reportLineItemDefinitions = getListOfColumnsHeaders(); + List columnHeaders = getListOfColumnsHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, null, null, null, null, - reportLineItemDefinitions); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(reportToString(report, reportLineItemDefinitions)); + LOGGER.debug(reportToString(report, columnHeaders)); } int sumLineCount = IntStream.of(report.getSumRow().getCells()).sum(); @@ -151,8 +155,10 @@ public class ProvideClassificationReportAccTest { List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, null, null, null, null, - columnHeaders); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -184,13 +190,14 @@ public class ProvideClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - List reportLineItemDefinitions = getShortListOfColumnHeaders(); + List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, null, null, null, null, - reportLineItemDefinitions, false); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .buildReport(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(reportToString(report, reportLineItemDefinitions)); + LOGGER.debug(reportToString(report, columnHeaders)); } assertNotNull(report); @@ -222,9 +229,11 @@ public class ProvideClassificationReportAccTest { List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(workbasketIds, null, null, null, null, - null, - columnHeaders); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .workbasketIdIn(workbasketIds) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -259,8 +268,11 @@ public class ProvideClassificationReportAccTest { List states = Collections.singletonList(TaskState.READY); List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, states, null, null, null, null, - columnHeaders); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .stateIn(states) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -295,8 +307,11 @@ public class ProvideClassificationReportAccTest { List categories = Arrays.asList("AUTOMATIC", "MANUAL"); List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, categories, null, null, - null, columnHeaders); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .categoryIn(categories) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -323,8 +338,11 @@ public class ProvideClassificationReportAccTest { List domains = Collections.singletonList("DOMAIN_A"); List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, null, domains, null, null, - columnHeaders); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .domainIn(domains) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -356,12 +374,15 @@ public class ProvideClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); List columnHeaders = getShortListOfColumnHeaders(); - ClassificationReport report = taskMonitorService.getClassificationReport(null, null, null, null, customField, - customFieldValues, columnHeaders); + ClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .customAttributeFilterIn(customAttributeFilter) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCustomFieldValueReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCustomFieldValueReportAccTest.java index 03118fd37..8f18873c2 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCustomFieldValueReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideCustomFieldValueReportAccTest.java @@ -9,7 +9,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.sql.DataSource; @@ -69,10 +71,7 @@ public class ProvideCustomFieldValueReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - - taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, null); + taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1).buildReport(); } @WithAccessId( @@ -82,10 +81,8 @@ public class ProvideCustomFieldValueReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, null); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -111,10 +108,8 @@ public class ProvideCustomFieldValueReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_2; - - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, null); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_2) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -142,9 +137,10 @@ public class ProvideCustomFieldValueReportAccTest { CustomField customField = CustomField.CUSTOM_1; List columnHeaders = getListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, null, - columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(customField) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -168,12 +164,12 @@ public class ProvideCustomFieldValueReportAccTest { public void testEachItemOfCustomFieldValueReport() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, null, - columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -199,12 +195,11 @@ public class ProvideCustomFieldValueReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, null, - columnHeaders, false); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -231,12 +226,13 @@ public class ProvideCustomFieldValueReportAccTest { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - CustomField customField = CustomField.CUSTOM_1; List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(workbasketIds, null, null, null, - customField, null, - columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .workbasketIdIn(workbasketIds) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -263,12 +259,13 @@ public class ProvideCustomFieldValueReportAccTest { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List states = Collections.singletonList(TaskState.READY); - CustomField customField = CustomField.CUSTOM_1; List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, states, null, null, - customField, null, - columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .stateIn(states) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -295,13 +292,13 @@ public class ProvideCustomFieldValueReportAccTest { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List categories = Arrays.asList("AUTOMATIC", "MANUAL"); - CustomField customField = CustomField.CUSTOM_1; - List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, categories, null, - customField, null, - columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .categoryIn(categories) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -328,12 +325,13 @@ public class ProvideCustomFieldValueReportAccTest { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, domains, - customField, null, - columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .domainIn(domains) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -359,13 +357,15 @@ public class ProvideCustomFieldValueReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); List columnHeaders = getShortListOfColumnHeaders(); - CustomFieldValueReport report = taskMonitorService.getCustomFieldValueReport(null, null, null, null, - customField, - customFieldValues, columnHeaders); + CustomFieldValueReport report = taskMonitorService.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideDetailedClassificationReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideDetailedClassificationReportAccTest.java index 4d7f5dc64..b77c553b9 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideDetailedClassificationReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideDetailedClassificationReportAccTest.java @@ -9,7 +9,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.sql.DataSource; @@ -73,8 +75,7 @@ public class ProvideDetailedClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getDetailedClassificationReport(null, null, null, null, - null, null); + taskMonitorService.createClassificationReportBuilder().buildDetailedReport(); } @WithAccessId( @@ -84,8 +85,8 @@ public class ProvideDetailedClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, null, null, - null, null); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -140,8 +141,10 @@ public class ProvideDetailedClassificationReportAccTest { List columnHeaders = getListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, null, null, - null, null, columnHeaders); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -167,13 +170,15 @@ public class ProvideDetailedClassificationReportAccTest { public void testEachItemOfDetailedClassificationReport() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - List reportLineItemDefinitions = getShortListOfColumnHeaders(); + List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, null, null, - null, null, reportLineItemDefinitions); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(reportToString(report, reportLineItemDefinitions)); + LOGGER.debug(reportToString(report, columnHeaders)); } assertNotNull(report); @@ -230,13 +235,16 @@ public class ProvideDetailedClassificationReportAccTest { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List reportLineItemDefinitions = getShortListOfColumnHeaders(); + List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(workbasketIds, null, - null, null, null, null, reportLineItemDefinitions); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(reportToString(report, reportLineItemDefinitions)); + LOGGER.debug(reportToString(report, columnHeaders)); } assertNotNull(report); @@ -292,8 +300,11 @@ public class ProvideDetailedClassificationReportAccTest { List states = Collections.singletonList(TaskState.READY); List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, states, null, - null, null, null, columnHeaders); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .stateIn(states) + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -351,8 +362,9 @@ public class ProvideDetailedClassificationReportAccTest { List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, null, null, - null, null, columnHeaders, false); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -414,8 +426,11 @@ public class ProvideDetailedClassificationReportAccTest { List categories = Arrays.asList("AUTOMATIC", "MANUAL"); List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, categories, - null, null, null, columnHeaders); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .categoryIn(categories) + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -454,8 +469,11 @@ public class ProvideDetailedClassificationReportAccTest { List domains = Collections.singletonList("DOMAIN_A"); List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, null, - domains, null, null, columnHeaders); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .domainIn(domains) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -511,12 +529,15 @@ public class ProvideDetailedClassificationReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); List columnHeaders = getShortListOfColumnHeaders(); - DetailedClassificationReport report = taskMonitorService.getDetailedClassificationReport(null, null, - null, null, customField, customFieldValues, columnHeaders); + DetailedClassificationReport report = taskMonitorService.createClassificationReportBuilder() + .customAttributeFilterIn(customAttributeFilter) + .inWorkingDays() + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideTaskStatusReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideTaskStatusReportAccTest.java index 9fd1beea7..d63fdf1a9 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideTaskStatusReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideTaskStatusReportAccTest.java @@ -39,7 +39,7 @@ import pro.taskana.security.WithAccessId; @RunWith(JAASRunner.class) public class ProvideTaskStatusReportAccTest { - private static final Logger LOGGER = LoggerFactory.getLogger(ProvideWorkbasketLevelReportAccTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProvideWorkbasketReportAccTest.class); protected static TaskanaEngineConfiguration taskanaEngineConfiguration; protected static TaskanaEngine taskanaEngine; @@ -65,7 +65,7 @@ public class ProvideTaskStatusReportAccTest { @Test(expected = NotAuthorizedException.class) public void testRoleCheck() throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getTaskStatusReport(); + taskMonitorService.createTaskStatusReportBuilder().buildReport(); } @WithAccessId( @@ -75,7 +75,7 @@ public class ProvideTaskStatusReportAccTest { // given TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); // when - TaskStatusReport report = taskMonitorService.getTaskStatusReport(); + TaskStatusReport report = taskMonitorService.createTaskStatusReportBuilder().buildReport(); // then if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -105,7 +105,7 @@ public class ProvideTaskStatusReportAccTest { @Test public void testCompleteTaskStatusReportAsAdmin() throws NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getTaskStatusReport(); + taskMonitorService.createTaskStatusReportBuilder().buildReport(); } @WithAccessId( @@ -115,7 +115,10 @@ public class ProvideTaskStatusReportAccTest { // given TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); // when - TaskStatusReport report = taskMonitorService.getTaskStatusReport(asList("DOMAIN_C", "DOMAIN_A")); + TaskStatusReport report = taskMonitorService + .createTaskStatusReportBuilder() + .domainIn(asList("DOMAIN_C", "DOMAIN_A")) + .buildReport(); // then if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -143,8 +146,10 @@ public class ProvideTaskStatusReportAccTest { // given TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); // when - TaskStatusReport report = taskMonitorService.getTaskStatusReport(null, - Collections.singletonList(TaskState.READY)); + TaskStatusReport report = taskMonitorService + .createTaskStatusReportBuilder() + .stateIn(Collections.singletonList(TaskState.READY)) + .buildReport(); // then if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); diff --git a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideWorkbasketLevelReportAccTest.java b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideWorkbasketReportAccTest.java similarity index 83% rename from lib/taskana-core/src/test/java/acceptance/monitoring/ProvideWorkbasketLevelReportAccTest.java rename to lib/taskana-core/src/test/java/acceptance/monitoring/ProvideWorkbasketReportAccTest.java index 67e47148c..9b952e1ce 100644 --- a/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideWorkbasketLevelReportAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/monitoring/ProvideWorkbasketReportAccTest.java @@ -9,7 +9,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.IntStream; import javax.sql.DataSource; @@ -33,7 +35,7 @@ import pro.taskana.impl.configuration.DBCleaner; import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest; import pro.taskana.impl.report.impl.CombinedClassificationFilter; import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; -import pro.taskana.impl.report.impl.WorkbasketLevelReport; +import pro.taskana.impl.report.impl.WorkbasketReport; import pro.taskana.security.JAASRunner; import pro.taskana.security.WithAccessId; @@ -41,9 +43,9 @@ import pro.taskana.security.WithAccessId; * Acceptance test for all "workbasket level report" scenarios. */ @RunWith(JAASRunner.class) -public class ProvideWorkbasketLevelReportAccTest { +public class ProvideWorkbasketReportAccTest { - private static final Logger LOGGER = LoggerFactory.getLogger(ProvideWorkbasketLevelReportAccTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProvideWorkbasketReportAccTest.class); protected static TaskanaEngineConfiguration taskanaEngineConfiguration; protected static TaskanaEngine taskanaEngine; @@ -71,19 +73,17 @@ public class ProvideWorkbasketLevelReportAccTest { throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - taskMonitorService.getWorkbasketLevelReport(null, null, null, null, null, null, - null); + taskMonitorService.createWorkbasketReportBuilder().buildReport(); } @WithAccessId( userName = "monitor") @Test - public void testGetTotalNumbersOfTasksOfWorkbasketLevelReport() + public void testGetTotalNumbersOfTasksOfWorkbasketReport() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, null, null, null, - null); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder().buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report)); @@ -102,14 +102,16 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testGetWorkbasketLevelReportWithReportLineItemDefinitions() + public void testGetWorkbasketReportWithReportLineItemDefinitions() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List columnHeaders = getListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, null, null, null, - null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -134,13 +136,15 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReport() throws InvalidArgumentException, NotAuthorizedException { + public void testEachItemOfWorkbasketReport() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, null, null, null, - null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -162,14 +166,15 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportNotInWorkingDays() + public void testEachItemOfWorkbasketReportNotInWorkingDays() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, null, null, null, - null, columnHeaders, false); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -191,15 +196,18 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportWithWorkbasketFilter() + public void testEachItemOfWorkbasketReportWithWorkbasketFilter() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(workbasketIds, null, null, null, - null, null, null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .workbasketIdIn(workbasketIds) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -216,15 +224,18 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportWithStateFilter() + public void testEachItemOfWorkbasketReportWithStateFilter() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List states = Collections.singletonList(TaskState.READY); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, states, null, null, null, null, - null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .stateIn(states) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -246,15 +257,18 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportWithCategoryFilter() + public void testEachItemOfWorkbasketReportWithCategoryFilter() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List categories = Arrays.asList("AUTOMATIC", "MANUAL"); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, categories, null, null, - null, null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .categoryIn(categories) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -277,15 +291,18 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportWithDomainFilter() + public void testEachItemOfWorkbasketReportWithDomainFilter() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); List domains = Collections.singletonList("DOMAIN_A"); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, domains, null, - null, null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .domainIn(domains) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -307,16 +324,19 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportWithCustomFieldValueFilter() + public void testEachItemOfWorkbasketReportWithCustomFieldValueFilter() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); List columnHeaders = getShortListOfColumnHeaders(); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, null, - customField, customFieldValues, null, columnHeaders); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .customAttributeFilterIn(customAttributeFilter) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -338,7 +358,7 @@ public class ProvideWorkbasketLevelReportAccTest { @WithAccessId( userName = "monitor") @Test - public void testEachItemOfWorkbasketLevelReportForSelectedClassifications() + public void testEachItemOfWorkbasketReportForSelectedClassifications() throws InvalidArgumentException, NotAuthorizedException { TaskMonitorService taskMonitorService = taskanaEngine.getTaskMonitorService(); @@ -356,8 +376,11 @@ public class ProvideWorkbasketLevelReportAccTest { combinedClassificationFilter .add(new CombinedClassificationFilter("CLI:000000000000000000000000000000000005")); - WorkbasketLevelReport report = taskMonitorService.getWorkbasketLevelReport(null, null, null, null, null, - null, combinedClassificationFilter, columnHeaders, true); + WorkbasketReport report = taskMonitorService.createWorkbasketReportBuilder() + .withColumnHeaders(columnHeaders) + .combinedClassificationFilterIn(combinedClassificationFilter) + .inWorkingDays() + .buildReport(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(reportToString(report, columnHeaders)); @@ -400,11 +423,11 @@ public class ProvideWorkbasketLevelReportAccTest { return columnHeaders; } - private String reportToString(WorkbasketLevelReport report) { + private String reportToString(WorkbasketReport report) { return reportToString(report, null); } - private String reportToString(WorkbasketLevelReport report, + private String reportToString(WorkbasketReport report, List reportLineItemDefinitions) { String formatColumWidth = "| %-7s "; String formatFirstColumn = "| %-36s %-4s "; @@ -418,7 +441,7 @@ public class ProvideWorkbasketLevelReportAccTest { builder.append("-"); } builder.append("\n"); - builder.append(String.format(formatFirstColumnFirstLine, "Workbasket levels", "Total")); + builder.append(String.format(formatFirstColumnFirstLine, "Workbaskets", "Total")); if (reportLineItemDefinitions != null) { for (TimeIntervalColumnHeader def : reportLineItemDefinitions) { if (def.getLowerAgeLimit() == Integer.MIN_VALUE) { diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/CategoryReportBuilderImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/CategoryReportBuilderImplTest.java new file mode 100644 index 000000000..92ccc9ceb --- /dev/null +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/CategoryReportBuilderImplTest.java @@ -0,0 +1,260 @@ +package pro.taskana.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.powermock.api.mockito.PowerMockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.CategoryReport; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * Unit Test for CategoryBuilderImpl. + */ +@RunWith(MockitoJUnitRunner.class) +public class CategoryReportBuilderImplTest { + + @InjectMocks + private TaskMonitorServiceImpl cut; + + @Mock + private TaskanaEngineImpl taskanaEngineImplMock; + + @Mock + private TaskanaEngineConfiguration taskanaEngineConfiguration; + + @Mock + private TaskMonitorMapper taskMonitorMapperMock; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + Mockito.doNothing().when(taskanaEngineImplMock).openConnection(); + Mockito.doNothing().when(taskanaEngineImplMock).returnConnection(); + doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration(); + doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled(); + doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays(); + } + + @Test + public void testGetTotalNumbersOfCatgoryReport() throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("EXTERN"); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfCategories(workbasketIds, states, categories, + domains, classificationIds, excludedClassificationIds, customAttributeFilter); + + CategoryReport actualResult = cut.createCategoryReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfCategories(any(), any(), any(), any(), any(), any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(actualResult.getRow("EXTERN").getTotalValue(), 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetCategoryReportWithReportLineItemDefinitions() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("EXTERN"); + monitorQueryItem.setAgeInDays(0); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfCategories(workbasketIds, states, categories, + domains, classificationIds, excludedClassificationIds, customAttributeFilter); + + CategoryReport actualResult = cut.createCategoryReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfCategories(any(), any(), any(), any(), any(), any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(actualResult.getRow("EXTERN").getTotalValue(), 1); + assertEquals(actualResult.getRow("EXTERN").getCells()[0], 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testListTaskIdsOfCategoryReportForSelectedItems() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("TKI:000000000000000000000000000000000001"); + when(taskMonitorMapperMock.getTaskIdsForSelectedItems(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + "CLASSIFICATION_CATEGORY", selectedItems, false)).thenReturn(expectedResult); + + List actualResult = cut.createCategoryReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listTaskIdsForSelectedItems(selectedItems); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getTaskIdsForSelectedItems(any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false)); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } + + @Test + public void testListCustomAttributeValuesForCustomAttributeName() + throws NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("Geschaeftsstelle A"); + when(taskMonitorMapperMock.getCustomAttributeValuesForReport(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + CustomField.CUSTOM_1)).thenReturn(expectedResult); + + List actualResult = cut.createCategoryReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_1); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getCustomAttributeValuesForReport(any(), any(), any(), any(), any(), any(), any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } +} diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationReportBuilderImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationReportBuilderImplTest.java new file mode 100644 index 000000000..fda1786c0 --- /dev/null +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/ClassificationReportBuilderImplTest.java @@ -0,0 +1,371 @@ +package pro.taskana.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.powermock.api.mockito.PowerMockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.ClassificationReport; +import pro.taskana.impl.report.impl.DetailedClassificationReport; +import pro.taskana.impl.report.impl.DetailedMonitorQueryItem; +import pro.taskana.impl.report.impl.DetailedReportRow; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * Unit Test for ClassificationReportBuilderImpl. + */ +@RunWith(MockitoJUnitRunner.class) +public class ClassificationReportBuilderImplTest { + + @InjectMocks + private TaskMonitorServiceImpl cut; + + @Mock + private TaskanaEngineImpl taskanaEngineImplMock; + + @Mock + private TaskanaEngineConfiguration taskanaEngineConfiguration; + + @Mock + private TaskMonitorMapper taskMonitorMapperMock; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + Mockito.doNothing().when(taskanaEngineImplMock).openConnection(); + Mockito.doNothing().when(taskanaEngineImplMock).returnConnection(); + doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration(); + doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled(); + doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays(); + } + + @Test + public void testGetTotalNumbersOfClassificationReport() throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfClassifications(workbasketIds, states, + categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter); + + ClassificationReport actualResult = cut.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfClassifications(any(), any(), any(), any(), any(), any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals( + actualResult.getRow("CLI:000000000000000000000000000000000001").getTotalValue(), 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetClassificationReportWithReportLineItemDefinitions() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); + monitorQueryItem.setAgeInDays(0); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfClassifications(workbasketIds, states, + categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter); + + ClassificationReport actualResult = cut.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfClassifications(any(), any(), any(), any(), any(), any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals( + actualResult.getRow("CLI:000000000000000000000000000000000001").getTotalValue(), 1); + assertEquals(actualResult.getRow("CLI:000000000000000000000000000000000001").getCells()[0], 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetTotalNumbersOfDetailedClassificationReport() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + + List expectedResult = new ArrayList<>(); + DetailedMonitorQueryItem detailedMonitorQueryItem = new DetailedMonitorQueryItem(); + detailedMonitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); + detailedMonitorQueryItem.setAttachmentKey("CLI:000000000000000000000000000000000006"); + detailedMonitorQueryItem.setNumberOfTasks(1); + expectedResult.add(detailedMonitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfDetailedClassifications(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter); + + DetailedClassificationReport actualResult = cut.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .buildDetailedReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfDetailedClassifications(any(), any(), any(), any(), any(), + any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + DetailedReportRow line = actualResult.getRow("CLI:000000000000000000000000000000000001"); + assertNotNull(actualResult); + assertEquals(line.getTotalValue(), 1); + assertEquals(line.getDetailRows().get("CLI:000000000000000000000000000000000006").getTotalValue(), 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetDetailedClassificationReportWithReportLineItemDefinitions() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + List expectedResult = new ArrayList<>(); + DetailedMonitorQueryItem detailedMonitorQueryItem = new DetailedMonitorQueryItem(); + detailedMonitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); + detailedMonitorQueryItem.setAttachmentKey("CLI:000000000000000000000000000000000006"); + detailedMonitorQueryItem.setAgeInDays(0); + detailedMonitorQueryItem.setNumberOfTasks(1); + expectedResult.add(detailedMonitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfDetailedClassifications(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter); + + DetailedClassificationReport actualResult = cut.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .buildDetailedReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfDetailedClassifications(any(), any(), any(), any(), any(), + any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + DetailedReportRow line = actualResult.getRow("CLI:000000000000000000000000000000000001"); + assertNotNull(actualResult); + assertEquals(line.getTotalValue(), 1); + assertEquals(line.getDetailRows().get("CLI:000000000000000000000000000000000006").getTotalValue(), 1); + assertEquals(line.getCells()[0], 1); + assertEquals(line.getDetailRows().get("CLI:000000000000000000000000000000000006").getCells()[0], 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + assertEquals(actualResult.getSumRow().getCells()[0], 1); + } + + @Test + public void testGetTaskIdsForSelectedItems() throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("TKI:000000000000000000000000000000000001"); + when(taskMonitorMapperMock.getTaskIdsForSelectedItems(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + "CLASSIFICATION_KEY", selectedItems, false)).thenReturn(expectedResult); + + List actualResult = cut.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listTaskIdsForSelectedItems(selectedItems); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getTaskIdsForSelectedItems(any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false)); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } + + @Test + public void testListCustomAttributeValuesForCustomAttributeName() + throws NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("Geschaeftsstelle A"); + when(taskMonitorMapperMock.getCustomAttributeValuesForReport(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + CustomField.CUSTOM_1)).thenReturn(expectedResult); + + List actualResult = cut.createClassificationReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_1); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getCustomAttributeValuesForReport(any(), any(), any(), any(), any(), any(), any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } + +} diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/CustomFieldValueReportBuilderImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/CustomFieldValueReportBuilderImplTest.java new file mode 100644 index 000000000..8b4457821 --- /dev/null +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/CustomFieldValueReportBuilderImplTest.java @@ -0,0 +1,212 @@ +package pro.taskana.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.powermock.api.mockito.PowerMockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.CustomFieldValueReport; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * Unit Test for CustomFieldValueReportBuilderImpl. + */ +@RunWith(MockitoJUnitRunner.class) +public class CustomFieldValueReportBuilderImplTest { + + @InjectMocks + private TaskMonitorServiceImpl cut; + + @Mock + private TaskanaEngineImpl taskanaEngineImplMock; + + @Mock + private TaskanaEngineConfiguration taskanaEngineConfiguration; + + @Mock + private TaskMonitorMapper taskMonitorMapperMock; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + Mockito.doNothing().when(taskanaEngineImplMock).openConnection(); + Mockito.doNothing().when(taskanaEngineImplMock).returnConnection(); + doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration(); + doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled(); + doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays(); + } + + @Test + public void testGetTotalNumbersOfCustomFieldValueReport() throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("Geschaeftsstelle A"); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock) + .getTaskCountOfCustomFieldValues(CustomField.CUSTOM_1, workbasketIds, states, categories, domains, + classificationIds, excludedClassificationIds, customAttributeFilter); + + CustomFieldValueReport actualResult = cut.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfCustomFieldValues(any(), any(), any(), any(), any(), + any(), any(), + any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(actualResult.getRow("Geschaeftsstelle A").getTotalValue(), 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetCustomFieldValueReportWithReportLineItemDefinitions() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("Geschaeftsstelle A"); + monitorQueryItem.setAgeInDays(0); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock) + .getTaskCountOfCustomFieldValues(CustomField.CUSTOM_1, workbasketIds, states, categories, domains, + classificationIds, excludedClassificationIds, customAttributeFilter); + + CustomFieldValueReport actualResult = cut.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getTaskCountOfCustomFieldValues(any(), any(), any(), any(), any(), any(), any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(actualResult.getRow("Geschaeftsstelle A").getTotalValue(), 1); + assertEquals(actualResult.getRow("Geschaeftsstelle A").getCells()[0], 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testListCustomAttributeValuesForCustomAttributeName() + throws NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("Geschaeftsstelle A"); + when(taskMonitorMapperMock.getCustomAttributeValuesForReport(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + CustomField.CUSTOM_1)).thenReturn(expectedResult); + + List actualResult = cut.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1) + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_1); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getCustomAttributeValuesForReport(any(), any(), any(), any(), any(), any(), any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } +} diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskMonitorServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskMonitorServiceImplTest.java deleted file mode 100644 index e819c83a5..000000000 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskMonitorServiceImplTest.java +++ /dev/null @@ -1,576 +0,0 @@ -package pro.taskana.impl; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InOrder; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; - -import pro.taskana.CustomField; -import pro.taskana.TaskMonitorService; -import pro.taskana.TaskState; -import pro.taskana.configuration.TaskanaEngineConfiguration; -import pro.taskana.exceptions.InvalidArgumentException; -import pro.taskana.exceptions.NotAuthorizedException; -import pro.taskana.impl.report.impl.CategoryReport; -import pro.taskana.impl.report.impl.ClassificationReport; -import pro.taskana.impl.report.impl.CombinedClassificationFilter; -import pro.taskana.impl.report.impl.CustomFieldValueReport; -import pro.taskana.impl.report.impl.DetailedClassificationReport; -import pro.taskana.impl.report.impl.DetailedMonitorQueryItem; -import pro.taskana.impl.report.impl.DetailedReportRow; -import pro.taskana.impl.report.impl.MonitorQueryItem; -import pro.taskana.impl.report.impl.TaskQueryItem; -import pro.taskana.impl.report.impl.TaskStatusReport; -import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; -import pro.taskana.impl.report.impl.WorkbasketLevelReport; -import pro.taskana.mappings.TaskMonitorMapper; - -/** - * Unit Test for TaskMonitorServiceImpl. - */ -@RunWith(MockitoJUnitRunner.class) -public class TaskMonitorServiceImplTest { - - @InjectMocks - private TaskMonitorServiceImpl cut; - - @Mock - private TaskanaEngineImpl taskanaEngineImplMock; - - @Mock - private TaskanaEngineConfiguration taskanaEngineConfiguration; - - @Mock - private TaskMonitorMapper taskMonitorMapperMock; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - Mockito.doNothing().when(taskanaEngineImplMock).openConnection(); - Mockito.doNothing().when(taskanaEngineImplMock).returnConnection(); - doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration(); - doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled(); - doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays(); - } - - @Test - public void testGetTotalNumbersOfWorkbasketLevelReport() throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - List combinedClassificationFilter = Arrays - .asList(new CombinedClassificationFilter("CLI:000000000000000000000000000000000003", - "CLI:000000000000000000000000000000000008")); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("WBI:000000000000000000000000000000000001"); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfWorkbaskets(workbasketIds, states, - categories, domains, customField, customFieldValues, combinedClassificationFilter); - - WorkbasketLevelReport actualResult = cut.getWorkbasketLevelReport(workbasketIds, states, categories, domains, - customField, customFieldValues, combinedClassificationFilter); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfWorkbaskets(any(), any(), any(), any(), - any(), any(), any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals( - actualResult.getRow("WBI:000000000000000000000000000000000001").getTotalValue(), 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetWorkbasketLevelReportWithReportLineItemDefinitions() - throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - List combinedClassificationFilter = Arrays - .asList(new CombinedClassificationFilter("CLI:000000000000000000000000000000000003", - "CLI:000000000000000000000000000000000008")); - List reportLineItemDefinitions = Collections.singletonList( - new TimeIntervalColumnHeader(0, 0)); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("WBI:000000000000000000000000000000000001"); - monitorQueryItem.setAgeInDays(0); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfWorkbaskets(workbasketIds, states, - categories, domains, customField, customFieldValues, combinedClassificationFilter); - - WorkbasketLevelReport actualResult = cut.getWorkbasketLevelReport(workbasketIds, states, categories, domains, - customField, customFieldValues, combinedClassificationFilter, reportLineItemDefinitions); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfWorkbaskets(any(), any(), any(), any(), any(), any(), - any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals( - actualResult.getRow("WBI:000000000000000000000000000000000001").getTotalValue(), 1); - assertEquals(actualResult.getRow("WBI:000000000000000000000000000000000001").getCells()[0], 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetTotalNumbersOfCatgoryReport() throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("EXTERN"); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfCategories(workbasketIds, states, categories, - domains, customField, customFieldValues); - - CategoryReport actualResult = cut.getCategoryReport(workbasketIds, states, categories, domains, - customField, customFieldValues); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfCategories(any(), any(), any(), any(), any(), any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals(actualResult.getRow("EXTERN").getTotalValue(), 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetCategoryReportWithReportLineItemDefinitions() - throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - List reportLineItemDefinitions = Collections.singletonList( - new TimeIntervalColumnHeader(0, 0)); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("EXTERN"); - monitorQueryItem.setAgeInDays(0); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfCategories(workbasketIds, states, categories, - domains, customField, customFieldValues); - - CategoryReport actualResult = cut.getCategoryReport(workbasketIds, states, categories, domains, - customField, customFieldValues, reportLineItemDefinitions); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfCategories(any(), any(), any(), any(), any(), any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals(actualResult.getRow("EXTERN").getTotalValue(), 1); - assertEquals(actualResult.getRow("EXTERN").getCells()[0], 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetTotalNumbersOfClassificationReport() throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfClassifications(workbasketIds, states, - categories, domains, customField, customFieldValues); - - ClassificationReport actualResult = cut.getClassificationReport(workbasketIds, states, categories, domains, - customField, customFieldValues); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfClassifications(any(), any(), any(), any(), any(), any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals( - actualResult.getRow("CLI:000000000000000000000000000000000001").getTotalValue(), 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetClassificationReportWithReportLineItemDefinitions() - throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - - List reportLineItemDefinitions = Collections.singletonList( - new TimeIntervalColumnHeader(0, 0)); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); - monitorQueryItem.setAgeInDays(0); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfClassifications(workbasketIds, states, - categories, domains, customField, customFieldValues); - - ClassificationReport actualResult = cut.getClassificationReport(workbasketIds, states, categories, domains, - customField, customFieldValues, reportLineItemDefinitions); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfClassifications(any(), any(), any(), any(), any(), any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals( - actualResult.getRow("CLI:000000000000000000000000000000000001").getTotalValue(), 1); - assertEquals(actualResult.getRow("CLI:000000000000000000000000000000000001").getCells()[0], 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetTotalNumbersOfDetailedClassificationReport() - throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - - List expectedResult = new ArrayList<>(); - DetailedMonitorQueryItem detailedMonitorQueryItem = new DetailedMonitorQueryItem(); - detailedMonitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); - detailedMonitorQueryItem.setAttachmentKey("CLI:000000000000000000000000000000000006"); - detailedMonitorQueryItem.setNumberOfTasks(1); - expectedResult.add(detailedMonitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfDetailedClassifications(workbasketIds, - states, categories, domains, customField, customFieldValues); - - DetailedClassificationReport actualResult = cut.getDetailedClassificationReport(workbasketIds, states, - categories, domains, customField, customFieldValues); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfDetailedClassifications(any(), any(), any(), any(), any(), - any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - DetailedReportRow line = actualResult.getRow("CLI:000000000000000000000000000000000001"); - assertNotNull(actualResult); - assertEquals(line.getTotalValue(), 1); - assertEquals(line.getDetailRows().get("CLI:000000000000000000000000000000000006").getTotalValue(), 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetDetailedClassificationReportWithReportLineItemDefinitions() - throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - List reportLineItemDefinitions = Collections.singletonList( - new TimeIntervalColumnHeader(0, 0)); - - List expectedResult = new ArrayList<>(); - DetailedMonitorQueryItem detailedMonitorQueryItem = new DetailedMonitorQueryItem(); - detailedMonitorQueryItem.setKey("CLI:000000000000000000000000000000000001"); - detailedMonitorQueryItem.setAttachmentKey("CLI:000000000000000000000000000000000006"); - detailedMonitorQueryItem.setAgeInDays(0); - detailedMonitorQueryItem.setNumberOfTasks(1); - expectedResult.add(detailedMonitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfDetailedClassifications(workbasketIds, - states, categories, domains, customField, customFieldValues); - - DetailedClassificationReport actualResult = cut.getDetailedClassificationReport(workbasketIds, states, - categories, domains, customField, customFieldValues, reportLineItemDefinitions); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfDetailedClassifications(any(), any(), any(), any(), any(), - any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - DetailedReportRow line = actualResult.getRow("CLI:000000000000000000000000000000000001"); - assertNotNull(actualResult); - assertEquals(line.getTotalValue(), 1); - assertEquals(line.getDetailRows().get("CLI:000000000000000000000000000000000006").getTotalValue(), 1); - assertEquals(line.getCells()[0], 1); - assertEquals(line.getDetailRows().get("CLI:000000000000000000000000000000000006").getCells()[0], 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - assertEquals(actualResult.getSumRow().getCells()[0], 1); - } - - @Test - public void testGetTotalNumbersOfCustomFieldValueReport() throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("Geschaeftsstelle A"); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock) - .getTaskCountOfCustomFieldValues(workbasketIds, states, categories, domains, customField, - customFieldValues); - - CustomFieldValueReport actualResult = cut.getCustomFieldValueReport(workbasketIds, states, categories, domains, - customField, customFieldValues); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)).getTaskCountOfCustomFieldValues(any(), any(), any(), any(), any(), - any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals(actualResult.getRow("Geschaeftsstelle A").getTotalValue(), 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetCustomFieldValueReportWithReportLineItemDefinitions() - throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - List reportLineItemDefinitions = Collections.singletonList( - new TimeIntervalColumnHeader(0, 0)); - - List expectedResult = new ArrayList<>(); - MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); - monitorQueryItem.setKey("Geschaeftsstelle A"); - monitorQueryItem.setAgeInDays(0); - monitorQueryItem.setNumberOfTasks(1); - expectedResult.add(monitorQueryItem); - doReturn(expectedResult).when(taskMonitorMapperMock) - .getTaskCountOfCustomFieldValues(workbasketIds, states, categories, domains, customField, - customFieldValues); - - CustomFieldValueReport actualResult = cut.getCustomFieldValueReport(workbasketIds, states, categories, domains, - customField, customFieldValues, reportLineItemDefinitions); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)) - .getTaskCountOfCustomFieldValues(any(), any(), any(), any(), any(), any()); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals(actualResult.getRow("Geschaeftsstelle A").getTotalValue(), 1); - assertEquals(actualResult.getRow("Geschaeftsstelle A").getCells()[0], 1); - assertEquals(actualResult.getSumRow().getTotalValue(), 1); - } - - @Test - public void testGetTaskIdsForSelectedItems() throws InvalidArgumentException, NotAuthorizedException { - List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); - List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); - List categories = Collections.singletonList("EXTERN"); - List domains = Collections.singletonList("DOMAIN_A"); - List classificationIds = Collections.singletonList("L10000"); - List excludedClassificationIds = Collections.singletonList("L20000"); - CustomField customField = CustomField.CUSTOM_1; - List customFieldValues = Collections.singletonList("Geschaeftsstelle A"); - List reportLineItemDefinitions = Collections.singletonList( - new TimeIntervalColumnHeader(0, 0)); - - SelectedItem selectedItem = new SelectedItem(); - selectedItem.setKey("EXTERN"); - selectedItem.setLowerAgeLimit(1); - selectedItem.setUpperAgeLimit(5); - List selectedItems = Collections.singletonList(selectedItem); - - List expectedResult = Collections.singletonList("TKI:000000000000000000000000000000000001"); - when(taskMonitorMapperMock.getTaskIdsForSelectedItems(workbasketIds, - states, categories, domains, classificationIds, excludedClassificationIds, customField, customFieldValues, - "CLASSIFICATION_CATEGORY", selectedItems, false)).thenReturn(expectedResult); - - List actualResult = cut.getTaskIdsForSelectedItems(workbasketIds, states, categories, domains, - classificationIds, excludedClassificationIds, - customField, customFieldValues, reportLineItemDefinitions, true, selectedItems, - TaskMonitorService.DIMENSION_CLASSIFICATION_CATEGORY); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(2)).getConfiguration(); - verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); - verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); - verify(taskMonitorMapperMock, times(1)) - .getTaskIdsForSelectedItems(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), - eq(false)); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); - - assertNotNull(actualResult); - assertEquals(expectedResult, actualResult); - } - - @Test - public void testGetTaskStateReportWithoutFilters() throws NotAuthorizedException { - // given - TaskQueryItem queryItem1 = new TaskQueryItem(); - queryItem1.setCount(50); - queryItem1.setState(TaskState.READY); - queryItem1.setDomain("DOMAIN_X"); - TaskQueryItem queryItem2 = new TaskQueryItem(); - queryItem2.setCount(30); - queryItem2.setState(TaskState.COMPLETED); - queryItem2.setDomain("DOMAIN_X"); - List queryItems = Arrays.asList(queryItem1, queryItem2); - when(taskMonitorMapperMock.getTasksCountByState(null, null)).thenReturn(queryItems); - - // when - TaskStatusReport report = cut.getTaskStatusReport(); - - // then - InOrder inOrder = inOrder(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineImplMock); - inOrder.verify(taskanaEngineImplMock).openConnection(); - inOrder.verify(taskMonitorMapperMock).getTasksCountByState(eq(null), eq(null)); - inOrder.verify(taskanaEngineImplMock).returnConnection(); - - assertNotNull(report); - assertEquals(1, report.rowSize()); - assertArrayEquals(new int[] {50, 0, 30}, report.getRow("DOMAIN_X").getCells()); - assertArrayEquals(new int[] {50, 0, 30}, report.getSumRow().getCells()); - assertEquals(80, report.getRow("DOMAIN_X").getTotalValue()); - assertEquals(80, report.getSumRow().getTotalValue()); - } - - @Test - public void testGetTotalNumberOfTaskStateReport() throws NotAuthorizedException { - // given - TaskQueryItem queryItem1 = new TaskQueryItem(); - queryItem1.setCount(50); - queryItem1.setState(TaskState.READY); - queryItem1.setDomain("DOMAIN_X"); - TaskQueryItem queryItem2 = new TaskQueryItem(); - queryItem2.setCount(30); - queryItem2.setState(TaskState.COMPLETED); - queryItem2.setDomain("DOMAIN_X"); - List queryItems = Arrays.asList(queryItem1, queryItem2); - when(taskMonitorMapperMock.getTasksCountByState(eq(null), eq(Collections.emptyList()))).thenReturn(queryItems); - - // when - TaskStatusReport report = cut.getTaskStatusReport(null, Collections.emptyList()); - - // then - InOrder inOrder = inOrder(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineImplMock); - inOrder.verify(taskanaEngineImplMock).openConnection(); - inOrder.verify(taskMonitorMapperMock).getTasksCountByState(eq(null), eq(Collections.emptyList())); - inOrder.verify(taskanaEngineImplMock).returnConnection(); - - assertNotNull(report); - assertEquals(1, report.rowSize()); - assertArrayEquals(new int[0], report.getRow("DOMAIN_X").getCells()); - assertArrayEquals(new int[0], report.getSumRow().getCells()); - assertEquals(80, report.getRow("DOMAIN_X").getTotalValue()); - assertEquals(80, report.getSumRow().getTotalValue()); - } -} diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskStatusReportBuilderImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskStatusReportBuilderImplTest.java new file mode 100644 index 000000000..a2fa36d92 --- /dev/null +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskStatusReportBuilderImplTest.java @@ -0,0 +1,117 @@ +package pro.taskana.impl; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.inOrder; +import static org.powermock.api.mockito.PowerMockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InOrder; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import pro.taskana.TaskState; +import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.TaskQueryItem; +import pro.taskana.impl.report.impl.TaskStatusReport; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * Unit Test for TaskStatusReportBuilderImpl. + */ +@RunWith(MockitoJUnitRunner.class) +public class TaskStatusReportBuilderImplTest { + + @InjectMocks + private TaskMonitorServiceImpl cut; + + @Mock + private TaskanaEngineImpl taskanaEngineImplMock; + + @Mock + private TaskanaEngineConfiguration taskanaEngineConfiguration; + + @Mock + private TaskMonitorMapper taskMonitorMapperMock; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + Mockito.doNothing().when(taskanaEngineImplMock).openConnection(); + Mockito.doNothing().when(taskanaEngineImplMock).returnConnection(); + } + + @Test + public void testGetTaskStateReportWithoutFilters() throws NotAuthorizedException { + // given + TaskQueryItem queryItem1 = new TaskQueryItem(); + queryItem1.setCount(50); + queryItem1.setState(TaskState.READY); + queryItem1.setDomain("DOMAIN_X"); + TaskQueryItem queryItem2 = new TaskQueryItem(); + queryItem2.setCount(30); + queryItem2.setState(TaskState.COMPLETED); + queryItem2.setDomain("DOMAIN_X"); + List queryItems = Arrays.asList(queryItem1, queryItem2); + when(taskMonitorMapperMock.getTasksCountByState(null, null)).thenReturn(queryItems); + + // when + TaskStatusReport report = cut.createTaskStatusReportBuilder().buildReport(); + + // then + InOrder inOrder = inOrder(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineImplMock); + inOrder.verify(taskanaEngineImplMock).openConnection(); + inOrder.verify(taskMonitorMapperMock).getTasksCountByState(eq(null), eq(null)); + inOrder.verify(taskanaEngineImplMock).returnConnection(); + + assertNotNull(report); + assertEquals(1, report.rowSize()); + assertArrayEquals(new int[] {50, 0, 30}, report.getRow("DOMAIN_X").getCells()); + assertArrayEquals(new int[] {50, 0, 30}, report.getSumRow().getCells()); + assertEquals(80, report.getRow("DOMAIN_X").getTotalValue()); + assertEquals(80, report.getSumRow().getTotalValue()); + } + + @Test + public void testGetTotalNumberOfTaskStateReport() throws NotAuthorizedException { + // given + TaskQueryItem queryItem1 = new TaskQueryItem(); + queryItem1.setCount(50); + queryItem1.setState(TaskState.READY); + queryItem1.setDomain("DOMAIN_X"); + TaskQueryItem queryItem2 = new TaskQueryItem(); + queryItem2.setCount(30); + queryItem2.setState(TaskState.COMPLETED); + queryItem2.setDomain("DOMAIN_X"); + List queryItems = Arrays.asList(queryItem1, queryItem2); + when(taskMonitorMapperMock.getTasksCountByState(eq(null), eq(Collections.emptyList()))).thenReturn(queryItems); + + // when + TaskStatusReport report = cut.createTaskStatusReportBuilder().stateIn(Collections.emptyList()).buildReport(); + + // then + InOrder inOrder = inOrder(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineImplMock); + inOrder.verify(taskanaEngineImplMock).openConnection(); + inOrder.verify(taskMonitorMapperMock).getTasksCountByState(eq(null), eq(Collections.emptyList())); + inOrder.verify(taskanaEngineImplMock).returnConnection(); + + assertNotNull(report); + assertEquals(1, report.rowSize()); + assertArrayEquals(new int[0], report.getRow("DOMAIN_X").getCells()); + assertArrayEquals(new int[0], report.getSumRow().getCells()); + assertEquals(80, report.getRow("DOMAIN_X").getTotalValue()); + assertEquals(80, report.getSumRow().getTotalValue()); + } +} diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketReportBuilderImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketReportBuilderImplTest.java new file mode 100644 index 000000000..f9ff2c007 --- /dev/null +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketReportBuilderImplTest.java @@ -0,0 +1,274 @@ +package pro.taskana.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.powermock.api.mockito.PowerMockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import pro.taskana.CustomField; +import pro.taskana.TaskState; +import pro.taskana.configuration.TaskanaEngineConfiguration; +import pro.taskana.exceptions.InvalidArgumentException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.report.impl.CombinedClassificationFilter; +import pro.taskana.impl.report.impl.MonitorQueryItem; +import pro.taskana.impl.report.impl.TimeIntervalColumnHeader; +import pro.taskana.impl.report.impl.WorkbasketReport; +import pro.taskana.mappings.TaskMonitorMapper; + +/** + * Unit Test for WorkbasketReportBuilderImpl. + */ +@RunWith(MockitoJUnitRunner.class) +public class WorkbasketReportBuilderImplTest { + + @InjectMocks + private TaskMonitorServiceImpl cut; + + @Mock + private TaskanaEngineImpl taskanaEngineImplMock; + + @Mock + private TaskanaEngineConfiguration taskanaEngineConfiguration; + + @Mock + private TaskMonitorMapper taskMonitorMapperMock; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + Mockito.doNothing().when(taskanaEngineImplMock).openConnection(); + Mockito.doNothing().when(taskanaEngineImplMock).returnConnection(); + doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration(); + doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled(); + doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays(); + } + + @Test + public void testGetTotalNumbersOfWorkbasketReport() throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List combinedClassificationFilter = Arrays + .asList(new CombinedClassificationFilter("CLI:000000000000000000000000000000000003", + "CLI:000000000000000000000000000000000008")); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("WBI:000000000000000000000000000000000001"); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfWorkbaskets(workbasketIds, states, + categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + combinedClassificationFilter); + + WorkbasketReport actualResult = cut.createWorkbasketReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .combinedClassificationFilterIn(combinedClassificationFilter) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)) + .openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfWorkbaskets(any(), any(), any(), any(), + any(), any(), any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals( + actualResult.getRow("WBI:000000000000000000000000000000000001").getTotalValue(), 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetWorkbasketReportWithReportLineItemDefinitions() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List combinedClassificationFilter = Arrays + .asList(new CombinedClassificationFilter("CLI:000000000000000000000000000000000003", + "CLI:000000000000000000000000000000000008")); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + List expectedResult = new ArrayList<>(); + MonitorQueryItem monitorQueryItem = new MonitorQueryItem(); + monitorQueryItem.setKey("WBI:000000000000000000000000000000000001"); + monitorQueryItem.setAgeInDays(0); + monitorQueryItem.setNumberOfTasks(1); + expectedResult.add(monitorQueryItem); + doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfWorkbaskets(workbasketIds, states, + categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + combinedClassificationFilter); + + WorkbasketReport actualResult = cut.createWorkbasketReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .combinedClassificationFilterIn(combinedClassificationFilter) + .withColumnHeaders(columnHeaders) + .buildReport(); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)).getTaskCountOfWorkbaskets(any(), any(), any(), any(), any(), any(), + any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals( + actualResult.getRow("WBI:000000000000000000000000000000000001").getTotalValue(), 1); + assertEquals(actualResult.getRow("WBI:000000000000000000000000000000000001").getCells()[0], 1); + assertEquals(actualResult.getSumRow().getTotalValue(), 1); + } + + @Test + public void testGetTaskIdsOfCategoryReportForSelectedItems() + throws InvalidArgumentException, NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("TKI:000000000000000000000000000000000001"); + when(taskMonitorMapperMock.getTaskIdsForSelectedItems(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + "WORKBASKET_KEY", selectedItems, false)).thenReturn(expectedResult); + + List actualResult = cut.createWorkbasketReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listTaskIdsForSelectedItems(selectedItems); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getTaskIdsForSelectedItems(any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false)); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } + + @Test + public void testListCustomAttributeValuesForCustomAttributeName() + throws NotAuthorizedException { + List workbasketIds = Collections.singletonList("WBI:000000000000000000000000000000000001"); + List states = Arrays.asList(TaskState.CLAIMED, TaskState.READY); + List categories = Collections.singletonList("EXTERN"); + List domains = Collections.singletonList("DOMAIN_A"); + List classificationIds = Collections.singletonList("L10000"); + List excludedClassificationIds = Collections.singletonList("L20000"); + Map customAttributeFilter = new HashMap<>(); + customAttributeFilter.put(CustomField.CUSTOM_1, "Geschaeftsstelle A"); + List columnHeaders = Collections.singletonList( + new TimeIntervalColumnHeader(0, 0)); + + SelectedItem selectedItem = new SelectedItem(); + selectedItem.setKey("EXTERN"); + selectedItem.setLowerAgeLimit(1); + selectedItem.setUpperAgeLimit(5); + List selectedItems = Collections.singletonList(selectedItem); + + List expectedResult = Collections.singletonList("Geschaeftsstelle A"); + when(taskMonitorMapperMock.getCustomAttributeValuesForReport(workbasketIds, + states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter, + CustomField.CUSTOM_1)).thenReturn(expectedResult); + + List actualResult = cut.createWorkbasketReportBuilder() + .workbasketIdIn(workbasketIds) + .stateIn(states) + .categoryIn(categories) + .domainIn(domains) + .classificationIdIn(classificationIds) + .excludedClassificationIdIn(excludedClassificationIds) + .customAttributeFilterIn(customAttributeFilter) + .withColumnHeaders(columnHeaders) + .listCustomAttributeValuesForCustomAttributeName(CustomField.CUSTOM_1); + + verify(taskanaEngineImplMock, times(1)).openConnection(); + verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); + verify(taskanaEngineImplMock, times(2)).getConfiguration(); + verify(taskanaEngineConfiguration, times(1)).isGermanPublicHolidaysEnabled(); + verify(taskanaEngineConfiguration, times(1)).getCustomHolidays(); + verify(taskMonitorMapperMock, times(1)) + .getCustomAttributeValuesForReport(any(), any(), any(), any(), any(), any(), any(), any()); + verify(taskanaEngineImplMock, times(1)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineImplMock, taskMonitorMapperMock, taskanaEngineConfiguration); + + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); + } +} diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java index a33f60268..9ac757a6e 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/MonitorController.java @@ -72,7 +72,11 @@ public class MonitorController { @Transactional(readOnly = true, rollbackFor = Exception.class) public ResponseEntity getTaskStatusReport(@RequestParam(required = false) List domains, @RequestParam(required = false) List states) throws NotAuthorizedException { + // return ResponseEntity.status(HttpStatus.OK) + // .body(reportAssembler.toResource(taskMonitorService.getTaskStatusReport(domains, states), domains, states)); return ResponseEntity.status(HttpStatus.OK) - .body(reportAssembler.toResource(taskMonitorService.getTaskStatusReport(domains, states), domains, states)); + .body(reportAssembler.toResource( + taskMonitorService.createTaskStatusReportBuilder().stateIn(states).domainIn(domains).buildReport(), + domains, states)); } }