Additional target filtering by target and DS ids
Signed-off-by: Stanislav Trailov <Stanislav.Trailov@bosch.io>
This commit is contained in:
@@ -70,4 +70,7 @@ public interface DistributionSetTagManagement extends RepositoryManagement<Distr
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<DistributionSetTag> findByDistributionSet(@NotNull Pageable pageable, long setId);
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<DistributionSetTag> findByRsqlWithDistributionSetTagSpec(@NotNull Pageable pageable, @NotNull String rsqlParam);
|
||||
|
||||
}
|
||||
|
||||
@@ -135,6 +135,9 @@ public interface TargetTagManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetTag> findByRsql(@NotNull Pageable pageable, @NotNull String rsqlParam);
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetTag> findByRsqlWithTargetTagSpec(@NotNull Pageable pageable, @NotNull String rsqlParam);
|
||||
|
||||
/**
|
||||
* Find {@link TargetTag} based on given Name.
|
||||
*
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagFields;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
@@ -23,8 +26,10 @@ import org.eclipse.hawkbit.repository.builder.TagUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -146,6 +151,15 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
|
||||
Collections.singletonList(TagSpecification.ofDistributionSet(setId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<DistributionSetTag> findByRsqlWithDistributionSetTagSpec(Pageable pageable, String rsqlParam) {
|
||||
final Specification<JpaDistributionSetTag> spec = RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetTagFields.class,
|
||||
virtualPropertyReplacer, database);
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTagRepository, pageable,
|
||||
Collections.singletonList(spec));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(include = {
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTagFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.GenericTagUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||
@@ -108,6 +109,12 @@ public class JpaTargetTagManagement implements TargetTagManagement {
|
||||
RSQLUtility.buildRsqlSpecification(rsqlParam, TagFields.class, virtualPropertyReplacer, database)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetTag> findByRsqlWithTargetTagSpec(Pageable pageable, String rsqlParam) {
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, pageable, Collections.singletonList(
|
||||
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetTagFields.class, virtualPropertyReplacer, database)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return targetTagRepository.count();
|
||||
|
||||
@@ -80,7 +80,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
count = distributionSetTagManagement.count();
|
||||
|
||||
} else {
|
||||
final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsql(pageable, rsqlParam);
|
||||
final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsqlWithDistributionSetTagSpec(pageable, rsqlParam);
|
||||
distributionSetTags = page;
|
||||
count = page.getTotalElements();
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cz.jirutka.rsql.parser.RSQLParser;
|
||||
import cz.jirutka.rsql.parser.ast.RSQLOperators;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtAssignedTargetRequestBody;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
|
||||
@@ -85,7 +87,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
findTargetsAll = this.tagManagement.findAll(pageable);
|
||||
|
||||
} else {
|
||||
findTargetsAll = this.tagManagement.findByRsql(pageable, rsqlParam);
|
||||
findTargetsAll = this.tagManagement.findByRsqlWithTargetTagSpec(pageable, rsqlParam);
|
||||
|
||||
}
|
||||
|
||||
final List<MgmtTag> rest = MgmtTagMapper.toResponse(findTargetsAll.getContent());
|
||||
|
||||
@@ -73,6 +73,68 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id.")
|
||||
public void getDistributionSetTagsByDistributionSetId() throws Exception {
|
||||
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
|
||||
final DistributionSetTag tag1 = tags.get(0);
|
||||
final DistributionSetTag tag2 = tags.get(1);
|
||||
|
||||
final DistributionSet distributionSet1 = testdataFactory.createDistributionSet();
|
||||
final DistributionSet distributionSet2 = testdataFactory.createDistributionSet();
|
||||
distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId(), distributionSet2.getId()), tag1.getName());
|
||||
distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId()), tag2.getName());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
|
||||
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "distributionset.id==" + distributionSet1.getId())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(applyBaseEntityMatcherOnPagedResult(tag1))
|
||||
.andExpect(applyBaseEntityMatcherOnPagedResult(tag2))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, DISTRIBUTIONSETTAGS_ROOT + tag1.getId()))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag2, DISTRIBUTIONSETTAGS_ROOT + tag2.getId()))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
|
||||
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "distributionset.id==" + distributionSet2.getId())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(applyBaseEntityMatcherOnPagedResult(tag1))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, DISTRIBUTIONSETTAGS_ROOT + tag1.getId()))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id field AND tag field.")
|
||||
public void getDistributionSetTagsByDistributionSetIdAndTagDescription() throws Exception {
|
||||
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
|
||||
final DistributionSetTag tag1 = tags.get(0);
|
||||
final DistributionSetTag tag2 = tags.get(1);
|
||||
|
||||
final DistributionSet distributionSet1 = testdataFactory.createDistributionSet();
|
||||
final DistributionSet distributionSet2 = testdataFactory.createDistributionSet();
|
||||
distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId(), distributionSet2.getId()), tag1.getName());
|
||||
distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId()), tag2.getName());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
|
||||
+ "?" + MgmtRestConstants.REQUEST_PARAMETER_SEARCH +
|
||||
"=distributionset.id==" + distributionSet1.getId() + ";description==" + tag1.getDescription())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(applyBaseEntityMatcherOnPagedResult(tag1))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, DISTRIBUTIONSETTAGS_ROOT + tag1.getId()))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that a single result of a DS tag reflects the content on the repository side.")
|
||||
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) })
|
||||
|
||||
@@ -75,6 +75,74 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that a paged result list of target tags reflects on the content of assigned tags for specific controller/target ID")
|
||||
public void getTargetTagsByTargetId() throws Exception {
|
||||
final String controllerId1 = "controllerTestId1";
|
||||
final String controllerId2 = "controllerTestId2";
|
||||
testdataFactory.createTarget(controllerId1);
|
||||
testdataFactory.createTarget(controllerId2);
|
||||
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final TargetTag tag1 = tags.get(0);
|
||||
final TargetTag tag2 = tags.get(1);
|
||||
|
||||
targetManagement.toggleTagAssignment(List.of(controllerId1, controllerId2), tag1.getName());
|
||||
targetManagement.toggleTagAssignment(List.of(controllerId2), tag2.getName());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
|
||||
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "target.controllerId==" + controllerId2)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(applyTagMatcherOnPagedResult(tag1))
|
||||
.andExpect(applyTagMatcherOnPagedResult(tag2))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, TARGETTAGS_ROOT + tag1.getId()))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag2, TARGETTAGS_ROOT + tag2.getId()))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
|
||||
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "target.controllerId==" + controllerId1)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(applyTagMatcherOnPagedResult(tag1))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, TARGETTAGS_ROOT + tag1.getId()))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that a page result when listing tags reflects on the content in the repository when filtered by 2 fields - one tag field and one target field")
|
||||
public void getTargetTagsFilteredByColorAndTargetId() throws Exception {
|
||||
final String controllerId1 = "controllerTestId1";
|
||||
final String controllerId2 = "controllerTestId2";
|
||||
testdataFactory.createTarget(controllerId1);
|
||||
testdataFactory.createTarget(controllerId2);
|
||||
|
||||
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
|
||||
final TargetTag tag1 = tags.get(0);
|
||||
final TargetTag tag2 = tags.get(1);
|
||||
|
||||
targetManagement.toggleTagAssignment(List.of(controllerId1, controllerId2), tag1.getName());
|
||||
targetManagement.toggleTagAssignment(List.of(controllerId2), tag2.getName());
|
||||
|
||||
// pass here q directly as a pure string because .queryParam method delimiters the parameters in q with ,
|
||||
// which is logical OR, we want AND here
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING +
|
||||
"?" + MgmtRestConstants.REQUEST_PARAMETER_SEARCH + "=target.controllerId==" + controllerId2 + ";colour==" + tag1.getColour())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(applyTagMatcherOnPagedResult(tag1))
|
||||
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, TARGETTAGS_ROOT + tag1.getId()))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
|
||||
}
|
||||
@Test
|
||||
@Description("Verfies that a single result of a target tag reflects the content on the repository side.")
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) })
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<scope>test</scope>
|
||||
<!-- <scope>test</scope>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
|
||||
Reference in New Issue
Block a user