TSK-2000: add filtering by classification parent key

This commit is contained in:
Elena Mokeeva 2023-02-14 15:02:34 +01:00 committed by Mustapha Zorgati
parent adf8a792d5
commit 3dbf98bf92
No known key found for this signature in database
GPG Key ID: BFF92FDA34CDC6FB
6 changed files with 297 additions and 0 deletions

View File

@ -1158,6 +1158,98 @@ class TaskQueryImplAccTest {
}
}
@Nested
@TestInstance(Lifecycle.PER_CLASS)
class ClassificationParentKey {
WorkbasketSummary wb;
TaskSummary taskSummary1;
TaskSummary taskSummary2;
TaskSummary taskSummary3;
@WithAccessId(user = "user-1-1")
@BeforeAll
void setup() throws Exception {
wb = createWorkbasketWithPermission();
defaultTestClassification()
.key("L21111")
.buildAndStore(classificationService, "businessadmin");
ClassificationSummary class1 =
defaultTestClassification()
.key("L2050")
.parentKey("L21111")
.buildAndStore(classificationService, "businessadmin");
taskSummary1 =
taskInWorkbasket(wb).classificationSummary(class1).buildAndStoreAsSummary(taskService);
ClassificationSummary class2 =
defaultTestClassification()
.key("L20501")
.parentKey("L2050")
.buildAndStore(classificationService, "businessadmin");
taskSummary2 =
taskInWorkbasket(wb).classificationSummary(class2).buildAndStoreAsSummary(taskService);
ClassificationSummary class3 =
defaultTestClassification()
.key("L2111")
.parentKey("L20501")
.buildAndStore(classificationService, "businessadmin");
taskSummary3 =
taskInWorkbasket(wb).classificationSummary(class3).buildAndStoreAsSummary(taskService);
}
@WithAccessId(user = "user-1-1")
@Test
void should_ApplyFilter_When_QueryingForParentKeyIn() {
List<TaskSummary> list =
taskService
.createTaskQuery()
.workbasketIdIn(wb.getId())
.classificationParentKeyIn("L2050")
.list();
assertThat(list).containsExactly(taskSummary2);
}
@WithAccessId(user = "user-1-1")
@Test
void should_ApplyFilter_When_QueryingForKeyParentNotIn() {
List<TaskSummary> list =
taskService
.createTaskQuery()
.workbasketIdIn(wb.getId())
.classificationParentKeyNotIn("L2050")
.list();
assertThat(list).containsExactlyInAnyOrder(taskSummary1, taskSummary3);
}
@WithAccessId(user = "user-1-1")
@Test
void should_ApplyFilter_When_QueryingForParentKeyLike() {
List<TaskSummary> list =
taskService
.createTaskQuery()
.workbasketIdIn(wb.getId())
.classificationParentKeyLike("L2050%")
.list();
assertThat(list).containsExactlyInAnyOrder(taskSummary2, taskSummary3);
}
@WithAccessId(user = "user-1-1")
@Test
void should_ApplyFilter_When_QueryingForKeyParentNotLike() {
List<TaskSummary> list =
taskService
.createTaskQuery()
.workbasketIdIn(wb.getId())
.classificationParentKeyNotLike("L2050%")
.list();
assertThat(list).containsExactlyInAnyOrder(taskSummary1);
}
}
@Nested
@TestInstance(Lifecycle.PER_CLASS)
class ClassificationCategory {

View File

@ -585,6 +585,45 @@ public interface TaskQuery extends BaseQuery<TaskSummary, TaskQueryColumnName> {
*/
TaskQuery orderByClassificationKey(SortDirection sortDirection);
// endregion
// region classificationParentKey
/**
* Add these keys of the parent Classification to your query.
*
* @param classificationParentKeys the classification parent keys
* @return the query
*/
TaskQuery classificationParentKeyIn(String... classificationParentKeys);
/**
* Exclude these keys of the parent Classification from your query.
*
* @param classificationParentKeys the keys of the parent Classifications
* @return the query
*/
TaskQuery classificationParentKeyNotIn(String... classificationParentKeys);
/**
* Add these keys of the parent Classification for pattern matching to your query. It will be
* compared in SQL with the LIKE operator. You may use a wildcard like % to specify the pattern.
* If you specify multiple arguments they are combined with the OR keyword.
*
* @param classificationParentKeys the keys of the parent Classification
* @return the query
*/
TaskQuery classificationParentKeyLike(String... classificationParentKeys);
/**
* Exclude these keys of the parent Classification for pattern matching from your query. It will
* be compared in SQL with the LIKE operator. You may use a wildcard like % to specify the
* pattern. If you specify multiple arguments they are combined with the OR keyword.
*
* @param classificationParentKeys the keys of the parent Classification
* @return the query
*/
TaskQuery classificationParentKeyNotLike(String... classificationParentKeys);
// endregion
// region classificationCategory

View File

@ -110,6 +110,10 @@ public class TaskQueryImpl implements TaskQuery {
private String[] classificationKeyNotIn;
private String[] classificationKeyLike;
private String[] classificationKeyNotLike;
private String[] classificationParentKeyIn;
private String[] classificationParentKeyNotIn;
private String[] classificationParentKeyLike;
private String[] classificationParentKeyNotLike;
private String[] classificationCategoryIn;
private String[] classificationCategoryNotIn;
private String[] classificationCategoryLike;
@ -663,9 +667,39 @@ public class TaskQueryImpl implements TaskQuery {
: addOrderCriteria("t.CLASSIFICATION_KEY", sortDirection);
}
@Override
public TaskQuery classificationParentKeyIn(String... classificationParentKeys) {
this.classificationParentKeyIn = classificationParentKeys;
this.joinWithClassifications = true;
return this;
}
@Override
public TaskQuery classificationParentKeyNotIn(String... classificationParentKeys) {
this.classificationParentKeyNotIn = classificationParentKeys;
this.joinWithClassifications = true;
return this;
}
@Override
public TaskQuery classificationParentKeyLike(String... classificationParentKeys) {
this.classificationParentKeyLike = toLowerCopy(classificationParentKeys);
this.joinWithClassifications = true;
return this;
}
@Override
public TaskQuery classificationParentKeyNotLike(String... classificationParentKeys) {
this.classificationParentKeyNotLike = toLowerCopy(classificationParentKeys);
this.joinWithClassifications = true;
return this;
}
@Override
public TaskQuery classificationCategoryIn(String... classificationCategories) {
this.classificationCategoryIn = classificationCategories;
this.joinWithClassifications = true;
return this;
}
@ -2310,6 +2344,14 @@ public class TaskQueryImpl implements TaskQuery {
+ Arrays.toString(classificationKeyLike)
+ ", classificationKeyNotLike="
+ Arrays.toString(classificationKeyNotLike)
+ ", classificationParentKeyIn="
+ Arrays.toString(classificationParentKeyIn)
+ ", classificationParentKeyNotIn="
+ Arrays.toString(classificationParentKeyNotIn)
+ ", classificationParentKeyLike="
+ Arrays.toString(classificationParentKeyLike)
+ ", classificationParentKeyNotLike="
+ Arrays.toString(classificationParentKeyNotLike)
+ ", classificationCategoryIn="
+ Arrays.toString(classificationCategoryIn)
+ ", classificationCategoryNotIn="

View File

@ -444,6 +444,7 @@ public class TaskQuerySqlProvider {
commonWhereClauses("businessProcessId", "t.BUSINESS_PROCESS_ID", sb);
commonWhereClauses("classificationCategory", "CLASSIFICATION_CATEGORY", sb);
commonWhereClauses("classificationKey", "t.CLASSIFICATION_KEY", sb);
commonWhereClauses("classificationParentKey", "c.PARENT_KEY", sb);
commonWhereClauses("classificationName", "c.NAME", sb);
commonWhereClauses("creator", "t.CREATOR", sb);
commonWhereClauses("name", "t.NAME", sb);

View File

@ -527,6 +527,37 @@ public class TaskQueryFilterParameter implements QueryParameter<TaskQuery, Void>
@JsonProperty("classification-key-not-like")
private final String[] classificationKeyNotLike;
// endregion
// region classificationParentKey
/**
* Filter by the key of the parent Classification of the Classification of the Task. This is an
* exact match.
*/
@JsonProperty("classification-parent-key")
private final String[] classificationParentKeyIn;
/**
* Filter by what the key of the parent Classification of the Classification of the Task shouldn't
* be. This is an exact match.
*/
@JsonProperty("classification-parent-key-not")
private final String[] classificationParentKeyNotIn;
/**
* Filter by the key of the parent Classification of the Classification of the Task. This results
* in a substring search (% is appended to the front and end of the requested value). Further SQL
* "LIKE" wildcard characters will be resolved correctly.
*/
@JsonProperty("classification-parent-key-like")
private final String[] classificationParentKeyLike;
/**
* Filter by what the key of the parent Classification of the Classification of the Task shouldn't
* be. This results in a substring search (% is appended to the front and end of the requested
* value). Further SQL "LIKE" wildcard characters will be resolved correctly.
*/
@JsonProperty("classification-parent-key-not-like")
private final String[] classificationParentKeyNotLike;
// endregion
// region classificationCategory
/** Filter by the classification category of the Task. This is an exact match. */
@JsonProperty("classification-category")
@ -1169,6 +1200,10 @@ public class TaskQueryFilterParameter implements QueryParameter<TaskQuery, Void>
"classification-key-not",
"classification-key-like",
"classification-key-not-like",
"classification-parent-key",
"classification-parent-key-not",
"classification-parent-key-like",
"classification-parent-key-not-like",
"classification-category",
"classification-category-not",
"classification-category-like",
@ -1315,6 +1350,10 @@ public class TaskQueryFilterParameter implements QueryParameter<TaskQuery, Void>
String[] classificationKeyNotIn,
String[] classificationKeyLike,
String[] classificationKeyNotLike,
String[] classificationParentKeyIn,
String[] classificationParentKeyNotIn,
String[] classificationParentKeyLike,
String[] classificationParentKeyNotLike,
String[] classificationCategoryIn,
String[] classificationCategoryNotIn,
String[] classificationCategoryLike,
@ -1460,6 +1499,10 @@ public class TaskQueryFilterParameter implements QueryParameter<TaskQuery, Void>
this.classificationKeyNotIn = classificationKeyNotIn;
this.classificationKeyLike = classificationKeyLike;
this.classificationKeyNotLike = classificationKeyNotLike;
this.classificationParentKeyIn = classificationParentKeyIn;
this.classificationParentKeyNotIn = classificationParentKeyNotIn;
this.classificationParentKeyLike = classificationParentKeyLike;
this.classificationParentKeyNotLike = classificationParentKeyNotLike;
this.classificationCategoryIn = classificationCategoryIn;
this.classificationCategoryNotIn = classificationCategoryNotIn;
this.classificationCategoryLike = classificationCategoryLike;
@ -1681,6 +1724,16 @@ public class TaskQueryFilterParameter implements QueryParameter<TaskQuery, Void>
.map(this::wrapElementsInLikeStatement)
.ifPresent(query::classificationKeyNotLike);
Optional.ofNullable(classificationParentKeyIn).ifPresent(query::classificationParentKeyIn);
Optional.ofNullable(classificationParentKeyNotIn)
.ifPresent(query::classificationParentKeyNotIn);
Optional.ofNullable(classificationParentKeyLike)
.map(this::wrapElementsInLikeStatement)
.ifPresent(query::classificationParentKeyLike);
Optional.ofNullable(classificationParentKeyNotLike)
.map(this::wrapElementsInLikeStatement)
.ifPresent(query::classificationParentKeyNotLike);
Optional.ofNullable(classificationCategoryIn).ifPresent(query::classificationCategoryIn);
Optional.ofNullable(classificationCategoryNotIn).ifPresent(query::classificationCategoryNotIn);
Optional.ofNullable(classificationCategoryLike)

View File

@ -586,6 +586,76 @@ class TaskControllerIntTest {
assertThat(response.getBody().getContent()).hasSize(22);
}
@Test
void should_ReturnAllTasks_For_SpecifiedWorkbasketIdAndClassificationParentKeyIn() {
String parentKey = "L11010";
String url =
restHelper.toUrl(RestEndpoints.URL_TASKS)
+ String.format(
"?workbasket-id=WBI:100000000000000000000000000000000006"
+ "&classification-parent-key=%s",
parentKey);
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("user-1-1"));
ResponseEntity<TaskSummaryPagedRepresentationModel> response =
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThat(response.getBody()).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(response.getBody().getContent()).hasSize(1);
}
@Test
void should_ReturnAllTasks_For_SpecifiedWorkbasketIdAndClassificationParentKeyNotIn() {
String parentKey = "L11010";
String url =
restHelper.toUrl(RestEndpoints.URL_TASKS)
+ String.format(
"?workbasket-id=WBI:100000000000000000000000000000000006"
+ "&classification-parent-key-not=%s",
parentKey);
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("user-1-1"));
ResponseEntity<TaskSummaryPagedRepresentationModel> response =
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThat(response.getBody()).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(response.getBody().getContent()).hasSize(2);
}
@Test
void should_ReturnAllTasks_For_SpecifiedWorkbasketIdAndClassificationParentKeyLike() {
String parentKey = "L%";
String url =
restHelper.toUrl(RestEndpoints.URL_TASKS)
+ String.format(
"?classification-parent-key-like=%s",
parentKey);
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("admin"));
ResponseEntity<TaskSummaryPagedRepresentationModel> response =
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThat(response.getBody()).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(response.getBody().getContent()).hasSize(3);
}
@Test
void should_ReturnAllTasks_For_SpecifiedWorkbasketIdAndClassificationParentKeyNotLike() {
String parentKey = "L%";
String url =
restHelper.toUrl(RestEndpoints.URL_TASKS)
+ String.format(
"?classification-parent-key-not-like=%s",
parentKey);
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("admin"));
ResponseEntity<TaskSummaryPagedRepresentationModel> response =
TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE);
assertThat(response.getBody()).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull();
assertThat(response.getBody().getContent()).hasSize(89);
}
@Test
void should_ReturnAllTasks_For_ProvidedPrimaryObjectReference() {
String url =