Remove target tag to target reference (#1772)
* Remove target tag to target reference it is not used and could lead to extensive memory usage if JPA provider load targets while loading tags Also, remove search field controller id as not meaningful Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com> * Fix review findings --------- Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -29,9 +29,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
@@ -146,14 +143,4 @@ public class JpaTargetTagManagement implements TargetTagManagement {
|
||||
public Page<TargetTag> findAll(final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, pageable, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetTag> findByTarget(final Pageable pageable, final String controllerId) {
|
||||
if (!targetRepository.exists(TargetSpecifications.hasControllerId(controllerId))) {
|
||||
throw new EntityNotFoundException(Target.class, controllerId);
|
||||
}
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, pageable,
|
||||
Collections.singletonList(TagSpecification.ofTarget(controllerId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,13 +96,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
@Pattern(regexp = "[\\S]*", message = "has whitespaces which are not allowed")
|
||||
private String controllerId;
|
||||
|
||||
@CascadeOnDelete
|
||||
@ManyToMany(targetEntity = JpaTargetTag.class)
|
||||
@JoinTable(name = "sp_target_target_tag", joinColumns = {
|
||||
@JoinColumn(name = "target", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target")) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "tag", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag")) })
|
||||
private Set<TargetTag> tags;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, targetEntity = JpaAction.class)
|
||||
private List<JpaAction> actions;
|
||||
@@ -111,7 +104,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
* the security token of the target which allows if enabled to authenticate
|
||||
* with this security token.
|
||||
*/
|
||||
@Column(name = "sec_token", updatable = true, nullable = false, length = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@Column(name = "sec_token", nullable = false, length = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@NotNull
|
||||
private String securityToken;
|
||||
@@ -149,40 +142,50 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
@JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds"))
|
||||
private JpaDistributionSet assignedDistributionSet;
|
||||
|
||||
/**
|
||||
* Read only on management API. Are committed by controller.
|
||||
*/
|
||||
@CascadeOnDelete
|
||||
@ElementCollection
|
||||
@Column(name = "attribute_value", length = Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE)
|
||||
@MapKeyColumn(name = "attribute_key", nullable = false, length = Target.CONTROLLER_ATTRIBUTE_KEY_SIZE)
|
||||
@CollectionTable(name = "sp_target_attributes", joinColumns = {
|
||||
@JoinColumn(name = "target_id", nullable = false, updatable = false) }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target"))
|
||||
private Map<String, String> controllerAttributes;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = true, targetEntity = JpaTargetType.class)
|
||||
@JoinColumn(name = "target_type", nullable = true, updatable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_relation_target_type"))
|
||||
private TargetType targetType;
|
||||
|
||||
// set default request controller attributes to true, because we want to
|
||||
// request them the first
|
||||
// time
|
||||
// set default request controller attributes to true, because we want to request them the first time
|
||||
@Column(name = "request_controller_attributes", nullable = false)
|
||||
private boolean requestControllerAttributes = true;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, targetEntity = JpaTargetMetadata.class)
|
||||
private List<TargetMetadata> metadata;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "target", orphanRemoval = true)
|
||||
@PrimaryKeyJoinColumn
|
||||
private JpaAutoConfirmationStatus autoConfirmationStatus;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = JpaTargetType.class)
|
||||
@JoinColumn(name = "target_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_relation_target_type"))
|
||||
private TargetType targetType;
|
||||
|
||||
@CascadeOnDelete
|
||||
@ManyToMany(targetEntity = JpaTargetTag.class)
|
||||
@JoinTable(
|
||||
name = "sp_target_target_tag",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "target", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target")) },
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "tag", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag"))
|
||||
})
|
||||
private Set<TargetTag> tags;
|
||||
|
||||
/**
|
||||
* Supplied / committed by the controller. Read-only via management API.
|
||||
*/
|
||||
@CascadeOnDelete
|
||||
@ElementCollection
|
||||
@Column(name = "attribute_value", length = Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE)
|
||||
@MapKeyColumn(name = "attribute_key", nullable = false, length = Target.CONTROLLER_ATTRIBUTE_KEY_SIZE)
|
||||
@CollectionTable(
|
||||
name = "sp_target_attributes",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "target_id", nullable = false, updatable = false) }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target"))
|
||||
private Map<String, String> controllerAttributes;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, targetEntity = JpaTargetMetadata.class)
|
||||
private List<TargetMetadata> metadata;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param controllerId
|
||||
* controller ID of the {@link Target}
|
||||
* @param controllerId controller ID of the {@link Target}
|
||||
*/
|
||||
public JpaTarget(final String controllerId) {
|
||||
this(controllerId, SecurityTokenGeneratorHolder.getInstance().generateToken());
|
||||
@@ -191,22 +194,16 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param controllerId
|
||||
* controller ID of the {@link Target}
|
||||
* @param securityToken
|
||||
* for target authentication if enabled
|
||||
* @param controllerId controller ID of the {@link Target}
|
||||
* @param securityToken for target authentication if enabled
|
||||
*/
|
||||
public JpaTarget(final String controllerId, final String securityToken) {
|
||||
this.controllerId = controllerId;
|
||||
setName(truncateControllerIdToMaxNameLength(controllerId));
|
||||
// truncate controller ID to max name length (if needed)
|
||||
setName(controllerId != null && controllerId.length() > NAME_MAX_SIZE ? controllerId.substring(0, NAME_MAX_SIZE) : controllerId);
|
||||
this.securityToken = securityToken;
|
||||
}
|
||||
|
||||
private static String truncateControllerIdToMaxNameLength(final String controllerId) {
|
||||
return controllerId != null && controllerId.length() > NAME_MAX_SIZE ? controllerId.substring(0, NAME_MAX_SIZE)
|
||||
: controllerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
@@ -9,72 +9,44 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.io.Serial;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||
import org.eclipse.persistence.annotations.CascadeOnDelete;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
|
||||
/**
|
||||
* A {@link TargetTag} is used to describe Target attributes and use them also
|
||||
* for filtering the target list.
|
||||
*
|
||||
* A {@link TargetTag} is used to describe Target attributes and use them also for filtering the target list.
|
||||
*/
|
||||
@NoArgsConstructor // Default constructor for JPA.
|
||||
@ToString(callSuper = true)
|
||||
@Entity
|
||||
@Table(name = "sp_target_tag", indexes = { @Index(name = "sp_idx_target_tag_prim", columnList = "tenant,id"),
|
||||
@Index(name = "sp_idx_target_tag_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
|
||||
"name", "tenant" }, name = "uk_targ_tag"))
|
||||
public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@CascadeOnDelete
|
||||
@ManyToMany(mappedBy = "tags", targetEntity = JpaTarget.class, fetch = FetchType.LAZY)
|
||||
private List<Target> assignedToTargets;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name
|
||||
* of {@link TargetTag}
|
||||
* @param description
|
||||
* of {@link TargetTag}
|
||||
* @param colour
|
||||
* of {@link TargetTag}
|
||||
*/
|
||||
public JpaTargetTag(final String name, final String description, final String colour) {
|
||||
super(name, description, colour);
|
||||
}
|
||||
|
||||
public JpaTargetTag() {
|
||||
// Default constructor for JPA.
|
||||
}
|
||||
|
||||
public List<Target> getAssignedToTargets() {
|
||||
if (assignedToTargets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(assignedToTargets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireCreateEvent(final DescriptorEvent descriptorEvent) {
|
||||
EventPublisherHolder.getInstance().getEventPublisher()
|
||||
.publishEvent(new TargetTagCreatedEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +59,5 @@ public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity
|
||||
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
|
||||
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new TargetTagDeletedEvent(getTenant(),
|
||||
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,57 +11,28 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
|
||||
import jakarta.persistence.criteria.Join;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
/**
|
||||
* Specifications class for {@link Tag}s. The class provides Spring Data JPQL
|
||||
* Specifications.
|
||||
*
|
||||
* Specifications class for {@link org.eclipse.hawkbit.repository.model.Tag}s.
|
||||
* The class provides Spring Data JPQL Specifications.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class TagSpecification {
|
||||
private TagSpecification() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link TargetTag}s by assigned
|
||||
* {@link Target}.
|
||||
*
|
||||
* @param controllerId
|
||||
* of the target
|
||||
*
|
||||
* @return the {@link JpaTargetTag} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTargetTag> ofTarget(final String controllerId) {
|
||||
return (targetRoot, query, criteriaBuilder) -> {
|
||||
final Join<JpaTargetTag, JpaTarget> tagJoin = targetRoot.join(JpaTargetTag_.assignedToTargets);
|
||||
|
||||
query.distinct(true);
|
||||
|
||||
return criteriaBuilder.equal(tagJoin.get(JpaTarget_.controllerId), controllerId);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSetTag}s by
|
||||
* assigned {@link DistributionSet}.
|
||||
*
|
||||
* @param dsId
|
||||
* of the distribution set
|
||||
*
|
||||
* @param dsId of the distribution set
|
||||
* @return the {@link JpaDistributionSetTag} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSetTag> ofDistributionSet(final Long dsId) {
|
||||
@@ -75,5 +46,4 @@ public final class TagSpecification {
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.JoinType;
|
||||
import jakarta.persistence.criteria.ListJoin;
|
||||
import jakarta.persistence.criteria.MapJoin;
|
||||
import jakarta.persistence.criteria.Order;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
@@ -27,13 +26,14 @@ import jakarta.persistence.criteria.SetJoin;
|
||||
import jakarta.persistence.criteria.Subquery;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
@@ -57,22 +57,15 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.query.QueryUtils;
|
||||
|
||||
/**
|
||||
* Specifications class for {@link Target}s. The class provides Spring Data JPQL
|
||||
* Specifications.
|
||||
*
|
||||
* Specifications class for {@link Target}s. The class provides Spring Data JPQL Specifications.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class TargetSpecifications {
|
||||
private TargetSpecifications() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s including
|
||||
* {@link TargetTag}s.
|
||||
*
|
||||
* @param controllerIDs
|
||||
* to search for
|
||||
* {@link Specification} for retrieving {@link Target}s including {@link TargetTag}s.
|
||||
*
|
||||
* @param controllerIDs to search for
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> byControllerIdWithTagsInJoin(final Collection<String> controllerIDs) {
|
||||
@@ -87,9 +80,7 @@ public final class TargetSpecifications {
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s by controllerId
|
||||
*
|
||||
* @param controllerID
|
||||
* to search for
|
||||
*
|
||||
* @param controllerID to search for
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> hasControllerId(final String controllerID) {
|
||||
@@ -99,9 +90,7 @@ public final class TargetSpecifications {
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link Target}s by controllerId
|
||||
*
|
||||
* @param controllerIDs
|
||||
* to search for
|
||||
*
|
||||
* @param controllerIDs to search for
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> hasControllerIdIn(final Collection<String> controllerIDs) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@@ -28,6 +29,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionStatusRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
|
||||
@@ -44,6 +46,7 @@ import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetTypeRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TenantMetaDataRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -203,6 +206,14 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Action.Status.FINISHED));
|
||||
}
|
||||
|
||||
protected Set<TargetTag> getTargetTags(final String controllerId) {
|
||||
return targetRepository
|
||||
.findOne(TargetSpecifications.hasControllerId(controllerId))
|
||||
.map(JpaTarget.class::cast)
|
||||
.map(JpaTarget::getTags)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
}
|
||||
|
||||
private JpaRollout refresh(final Rollout rollout) {
|
||||
return rolloutRepository.findById(rollout.getId()).get();
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
|
||||
assignedTargets.forEach(target -> assertThat(
|
||||
targetTagManagement.findByTarget(PAGE, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
|
||||
getTargetTags(target.getControllerId()).size()).isEqualTo(1));
|
||||
|
||||
final TargetTag findTargetTag = targetTagManagement.getByName("Tag1").orElseThrow(IllegalStateException::new);
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
|
||||
@@ -410,7 +410,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target unAssignTarget = targetManagement.unassignTag("targetId123", findTargetTag.getId());
|
||||
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, unAssignTarget.getControllerId())).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(unAssignTarget.getControllerId())).as("Tag size is wrong")
|
||||
.isEmpty();
|
||||
targetTagManagement.getByName("Tag1").orElseThrow(NoSuchElementException::new);
|
||||
assertThat(targetManagement.findByTag(PAGE, targetTag.getId())).as("Assigned targets are wrong").hasSize(3);
|
||||
@@ -569,7 +569,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
private void checkTargetHasTags(final boolean strict, final Iterable<Target> targets, final TargetTag... tags) {
|
||||
_target: for (final Target tl : targets) {
|
||||
for (final Tag tt : targetTagManagement.findByTarget(PAGE, tl.getControllerId())) {
|
||||
for (final Tag tt : getTargetTags(tl.getControllerId())) {
|
||||
for (final Tag tag : tags) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
continue _target;
|
||||
@@ -588,7 +588,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.getByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : targetTagManagement.findByTarget(PAGE, tl.getControllerId())) {
|
||||
for (final Tag tt : getTargetTags(tl.getControllerId())) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
fail("Target should have no tags");
|
||||
}
|
||||
@@ -719,16 +719,16 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target t11 = targetManagement.getByControllerID(t1.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).doesNotContain(toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.getByControllerID(t2.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t21.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).containsAll(t2Tags);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
assertThat(getTargetTags(t21.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).doesNotContain(toArray(t1Tags, TargetTag.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
verifyThrownExceptionBy(() -> targetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
||||
"TargetTag");
|
||||
|
||||
verifyThrownExceptionBy(() -> targetTagManagement.findByTarget(PAGE, NOT_EXIST_ID), "Target");
|
||||
verifyThrownExceptionBy(() -> getTargetTags(NOT_EXIST_ID), "Target");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,7 +237,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetTag toDelete = tags.iterator().next();
|
||||
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent())
|
||||
assertThat(getTargetTags(target.getControllerId()))
|
||||
.contains(toDelete);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// check
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent())
|
||||
assertThat(getTargetTags(target.getControllerId()))
|
||||
.doesNotContain(toDelete);
|
||||
}
|
||||
assertThat(targetTagRepository.findById(toDelete.getId())).as("No tag should be found").isNotPresent();
|
||||
|
||||
Reference in New Issue
Block a user