Used lambdas to reduce boilerplate code.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -43,7 +43,7 @@ import org.eclipse.hawkbit.repository.model.TargetIdName;
|
|||||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetInfo_;
|
import org.eclipse.hawkbit.repository.model.TargetInfo_;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult;
|
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.Target_;
|
import org.eclipse.hawkbit.repository.model.Target_;
|
||||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||||
@@ -534,7 +534,7 @@ public class TargetManagement {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@NotNull
|
@NotNull
|
||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||||
public TargetTagAssigmentResult toggleTagAssignment(@NotEmpty final List<Target> targets,
|
public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final List<Target> targets,
|
||||||
@NotNull final TargetTag tag) {
|
@NotNull final TargetTag tag) {
|
||||||
return toggleTagAssignment(
|
return toggleTagAssignment(
|
||||||
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());
|
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());
|
||||||
@@ -556,7 +556,7 @@ public class TargetManagement {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@NotNull
|
@NotNull
|
||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||||
public TargetTagAssigmentResult toggleTagAssignment(@NotEmpty final Collection<String> targetIds,
|
public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection<String> targetIds,
|
||||||
@NotNull final String tagName) {
|
@NotNull final String tagName) {
|
||||||
final TargetTag tag = targetTagRepository.findByNameEquals(tagName);
|
final TargetTag tag = targetTagRepository.findByNameEquals(tagName);
|
||||||
final List<Target> alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName, targetIds);
|
final List<Target> alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName, targetIds);
|
||||||
@@ -566,7 +566,7 @@ public class TargetManagement {
|
|||||||
// all are already assigned -> unassign
|
// all are already assigned -> unassign
|
||||||
if (alreadyAssignedTargets.size() == allTargets.size()) {
|
if (alreadyAssignedTargets.size() == allTargets.size()) {
|
||||||
alreadyAssignedTargets.forEach(target -> target.getTags().remove(tag));
|
alreadyAssignedTargets.forEach(target -> target.getTags().remove(tag));
|
||||||
final TargetTagAssigmentResult result = new TargetTagAssigmentResult(0, 0, alreadyAssignedTargets.size(),
|
final TargetTagAssignmentResult result = new TargetTagAssignmentResult(0, 0, alreadyAssignedTargets.size(),
|
||||||
Collections.emptyList(), alreadyAssignedTargets, tag);
|
Collections.emptyList(), alreadyAssignedTargets, tag);
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result)));
|
afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result)));
|
||||||
@@ -576,7 +576,7 @@ public class TargetManagement {
|
|||||||
allTargets.removeAll(alreadyAssignedTargets);
|
allTargets.removeAll(alreadyAssignedTargets);
|
||||||
// some or none are assigned -> assign
|
// some or none are assigned -> assign
|
||||||
allTargets.forEach(target -> target.getTags().add(tag));
|
allTargets.forEach(target -> target.getTags().add(tag));
|
||||||
final TargetTagAssigmentResult result = new TargetTagAssigmentResult(alreadyAssignedTargets.size(),
|
final TargetTagAssignmentResult result = new TargetTagAssignmentResult(alreadyAssignedTargets.size(),
|
||||||
allTargets.size(), 0, targetRepository.save(allTargets), Collections.emptyList(), tag);
|
allTargets.size(), 0, targetRepository.save(allTargets), Collections.emptyList(), tag);
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result)));
|
afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result)));
|
||||||
@@ -607,7 +607,7 @@ public class TargetManagement {
|
|||||||
final List<Target> save = targetRepository.save(allTargets);
|
final List<Target> save = targetRepository.save(allTargets);
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> {
|
afterCommit.afterCommit(() -> {
|
||||||
final TargetTagAssigmentResult assigmentResult = new TargetTagAssigmentResult(0, save.size(), 0, save,
|
final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, save.size(), 0, save,
|
||||||
Collections.emptyList(), tag);
|
Collections.emptyList(), tag);
|
||||||
eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult));
|
eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult));
|
||||||
});
|
});
|
||||||
@@ -620,7 +620,7 @@ public class TargetManagement {
|
|||||||
|
|
||||||
final List<Target> save = targetRepository.save(targets);
|
final List<Target> save = targetRepository.save(targets);
|
||||||
afterCommit.afterCommit(() -> {
|
afterCommit.afterCommit(() -> {
|
||||||
final TargetTagAssigmentResult assigmentResult = new TargetTagAssigmentResult(0, 0, save.size(),
|
final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, 0, save.size(),
|
||||||
Collections.emptyList(), save, tag);
|
Collections.emptyList(), save, tag);
|
||||||
eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult));
|
eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,13 +11,11 @@ package org.eclipse.hawkbit.repository.specifications;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Join;
|
import javax.persistence.criteria.Join;
|
||||||
import javax.persistence.criteria.JoinType;
|
import javax.persistence.criteria.JoinType;
|
||||||
import javax.persistence.criteria.ListJoin;
|
import javax.persistence.criteria.ListJoin;
|
||||||
import javax.persistence.criteria.Path;
|
import javax.persistence.criteria.Path;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
import javax.persistence.criteria.SetJoin;
|
import javax.persistence.criteria.SetJoin;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
@@ -33,9 +31,7 @@ import org.springframework.data.jpa.domain.Specification;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifications class for {@link DistributionSet}s. The class provides Spring
|
* Specifications class for {@link DistributionSet}s. The class provides Spring
|
||||||
* Data JPQL Specifications
|
* Data JPQL Specifications.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class DistributionSetSpecification {
|
public final class DistributionSetSpecification {
|
||||||
@@ -53,16 +49,8 @@ public final class DistributionSetSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> isDeleted(final Boolean isDeleted) {
|
public static Specification<DistributionSet> isDeleted(final Boolean isDeleted) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<Boolean> get(DistributionSet_.deleted), isDeleted);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<Boolean> get(DistributionSet_.deleted), isDeleted);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,16 +63,8 @@ public final class DistributionSetSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> isCompleted(final Boolean isCompleted) {
|
public static Specification<DistributionSet> isCompleted(final Boolean isCompleted) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<Boolean> get(DistributionSet_.complete), isCompleted);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<Boolean> get(DistributionSet_.complete), isCompleted);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,21 +76,15 @@ public final class DistributionSetSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> byId(final Long distid) {
|
public static Specification<DistributionSet> byId(final Long distid) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Predicate predicate = cb.equal(targetRoot.<Long> get(DistributionSet_.id), distid);
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT);
|
||||||
final CriteriaBuilder cb) {
|
targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT);
|
||||||
|
targetRoot.fetch(DistributionSet_.type, JoinType.LEFT);
|
||||||
|
query.distinct(true);
|
||||||
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<Long> get(DistributionSet_.id), distid);
|
return predicate;
|
||||||
targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT);
|
|
||||||
targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT);
|
|
||||||
targetRoot.fetch(DistributionSet_.type, JoinType.LEFT);
|
|
||||||
query.distinct(true);
|
|
||||||
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,20 +96,14 @@ public final class DistributionSetSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> byIds(final Collection<Long> distids) {
|
public static Specification<DistributionSet> byIds(final Collection<Long> distids) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Predicate predicate = targetRoot.<Long> get(DistributionSet_.id).in(distids);
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT);
|
||||||
final CriteriaBuilder cb) {
|
targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT);
|
||||||
|
targetRoot.fetch(DistributionSet_.type, JoinType.LEFT);
|
||||||
final Predicate predicate = targetRoot.<Long> get(DistributionSet_.id).in(distids);
|
query.distinct(true);
|
||||||
targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT);
|
return predicate;
|
||||||
targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT);
|
|
||||||
targetRoot.fetch(DistributionSet_.type, JoinType.LEFT);
|
|
||||||
query.distinct(true);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,21 +115,10 @@ public final class DistributionSetSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> likeNameOrDescriptionOrVersion(final String subString) {
|
public static Specification<DistributionSet> likeNameOrDescriptionOrVersion(final String subString) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> cb.or(
|
||||||
@Override
|
cb.like(cb.lower(targetRoot.<String> get(DistributionSet_.name)), subString.toLowerCase()),
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
cb.like(cb.lower(targetRoot.<String> get(DistributionSet_.version)), subString.toLowerCase()),
|
||||||
final CriteriaBuilder cb) {
|
cb.like(cb.lower(targetRoot.<String> get(DistributionSet_.description)), subString.toLowerCase()));
|
||||||
final Predicate predicate = cb
|
|
||||||
.or(cb.like(cb.lower(targetRoot.<String> get(DistributionSet_.name)), subString.toLowerCase()),
|
|
||||||
cb.like(cb.lower(targetRoot.<String> get(DistributionSet_.version)),
|
|
||||||
subString.toLowerCase()),
|
|
||||||
cb.like(cb.lower(targetRoot.<String> get(DistributionSet_.description)),
|
|
||||||
subString.toLowerCase()));
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,19 +133,13 @@ public final class DistributionSetSpecification {
|
|||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> hasTags(final Collection<String> tagNames,
|
public static Specification<DistributionSet> hasTags(final Collection<String> tagNames,
|
||||||
final Boolean selectDSWithNoTag) {
|
final Boolean selectDSWithNoTag) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final SetJoin<DistributionSet, DistributionSetTag> tags = targetRoot.join(DistributionSet_.tags,
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
JoinType.LEFT);
|
||||||
final CriteriaBuilder cb) {
|
final Predicate predicate = getPredicate(tags, tagNames, selectDSWithNoTag, cb);
|
||||||
final SetJoin<DistributionSet, DistributionSetTag> tags = targetRoot.join(DistributionSet_.tags,
|
query.distinct(true);
|
||||||
JoinType.LEFT);
|
return predicate;
|
||||||
final Predicate predicate = getPredicate(tags, tagNames, selectDSWithNoTag, cb);
|
|
||||||
query.distinct(true);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Predicate getPredicate(final SetJoin<DistributionSet, DistributionSetTag> tags,
|
private static Predicate getPredicate(final SetJoin<DistributionSet, DistributionSetTag> tags,
|
||||||
@@ -218,20 +169,10 @@ public final class DistributionSetSpecification {
|
|||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> equalsNameAndVersionIgnoreCase(final String name,
|
public static Specification<DistributionSet> equalsNameAndVersionIgnoreCase(final String name,
|
||||||
final String version) {
|
final String version) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> cb.and(
|
||||||
@Override
|
cb.equal(cb.lower(targetRoot.<String> get(DistributionSet_.name)), name.toLowerCase()),
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
cb.equal(cb.lower(targetRoot.<String> get(DistributionSet_.version)), version.toLowerCase()));
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.and(
|
|
||||||
// formatter:off
|
|
||||||
cb.equal(cb.lower(targetRoot.<String> get(DistributionSet_.name)), name.toLowerCase()),
|
|
||||||
cb.equal(cb.lower(targetRoot.<String> get(DistributionSet_.version)), version.toLowerCase()));
|
|
||||||
// formatter:on
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,16 +184,8 @@ public final class DistributionSetSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> byType(final DistributionSetType type) {
|
public static Specification<DistributionSet> byType(final DistributionSetType type) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<DistributionSetType> get(DistributionSet_.type), type);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSet> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<DistributionSetType> get(DistributionSet_.type), type);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,18 +196,12 @@ public final class DistributionSetSpecification {
|
|||||||
* installed to the given targetId
|
* installed to the given targetId
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> installedTarget(final String installedTargetId) {
|
public static Specification<DistributionSet> installedTarget(final String installedTargetId) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (dsRoot, query, cb) -> {
|
||||||
@Override
|
final ListJoin<DistributionSet, TargetInfo> installedTargetJoin = dsRoot
|
||||||
public Predicate toPredicate(final Root<DistributionSet> dsRoot, final CriteriaQuery<?> query,
|
.join(DistributionSet_.installedAtTargets, JoinType.INNER);
|
||||||
final CriteriaBuilder cb) {
|
final Join<TargetInfo, Target> targetJoin = installedTargetJoin.join(TargetInfo_.target);
|
||||||
final ListJoin<DistributionSet, TargetInfo> installedTargetJoin = dsRoot
|
return cb.equal(targetJoin.get(Target_.controllerId), installedTargetId);
|
||||||
.join(DistributionSet_.installedAtTargets, JoinType.INNER);
|
|
||||||
final Join<TargetInfo, Target> targetJoin = installedTargetJoin.join(TargetInfo_.target);
|
|
||||||
return cb.equal(targetJoin.get(Target_.controllerId), installedTargetId);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,16 +212,11 @@ public final class DistributionSetSpecification {
|
|||||||
* assigned to the given targetId
|
* assigned to the given targetId
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSet> assignedTarget(final String assignedTargetId) {
|
public static Specification<DistributionSet> assignedTarget(final String assignedTargetId) {
|
||||||
final Specification<DistributionSet> spec = new Specification<DistributionSet>() {
|
return (dsRoot, query, cb) -> {
|
||||||
@Override
|
final ListJoin<DistributionSet, Target> assignedTargetJoin = dsRoot.join(DistributionSet_.assignedToTargets,
|
||||||
public Predicate toPredicate(final Root<DistributionSet> dsRoot, final CriteriaQuery<?> query,
|
JoinType.INNER);
|
||||||
final CriteriaBuilder cb) {
|
return cb.equal(assignedTargetJoin.get(Target_.controllerId), assignedTargetId);
|
||||||
final ListJoin<DistributionSet, Target> assignedTargetJoin = dsRoot
|
|
||||||
.join(DistributionSet_.assignedToTargets, JoinType.INNER);
|
|
||||||
return cb.equal(assignedTargetJoin.get(Target_.controllerId), assignedTargetId);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,22 +8,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.specifications;
|
package org.eclipse.hawkbit.repository.specifications;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Predicate;
|
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType_;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType_;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Specifications class for {@link DistributionSetType}s. The class provides
|
||||||
*
|
* Spring Data JPQL Specifications.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class DistributionSetTypeSpecification {
|
public final class DistributionSetTypeSpecification {
|
||||||
private DistributionSetTypeSpecification() {
|
private DistributionSetTypeSpecification() {
|
||||||
@@ -40,16 +32,7 @@ public final class DistributionSetTypeSpecification {
|
|||||||
* @return the {@link DistributionSetType} {@link Specification}
|
* @return the {@link DistributionSetType} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSetType> isDeleted(final Boolean isDeleted) {
|
public static Specification<DistributionSetType> isDeleted(final Boolean isDeleted) {
|
||||||
final Specification<DistributionSetType> spec = new Specification<DistributionSetType>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<Boolean> get(DistributionSetType_.deleted), isDeleted);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSetType> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<Boolean> get(DistributionSetType_.deleted), isDeleted);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,16 +45,7 @@ public final class DistributionSetTypeSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSetType> byId(final Long distid) {
|
public static Specification<DistributionSetType> byId(final Long distid) {
|
||||||
final Specification<DistributionSetType> spec = new Specification<DistributionSetType>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<Long> get(DistributionSetType_.id), distid);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSetType> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<Long> get(DistributionSetType_.id), distid);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,16 +58,7 @@ public final class DistributionSetTypeSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSetType> byName(final String name) {
|
public static Specification<DistributionSetType> byName(final String name) {
|
||||||
final Specification<DistributionSetType> spec = new Specification<DistributionSetType>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<String> get(DistributionSetType_.name), name);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSetType> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<String> get(DistributionSetType_.name), name);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,16 +71,7 @@ public final class DistributionSetTypeSpecification {
|
|||||||
* @return the {@link DistributionSet} {@link Specification}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<DistributionSetType> byKey(final String key) {
|
public static Specification<DistributionSetType> byKey(final String key) {
|
||||||
final Specification<DistributionSetType> spec = new Specification<DistributionSetType>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<String> get(DistributionSetType_.key), key);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<DistributionSetType> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<String> get(DistributionSetType_.key), key);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.specifications;
|
package org.eclipse.hawkbit.repository.specifications;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||||
@@ -22,8 +19,6 @@ import org.springframework.data.jpa.domain.Specification;
|
|||||||
* Specifications class for {@link SoftwareModule}s. The class provides Spring
|
* Specifications class for {@link SoftwareModule}s. The class provides Spring
|
||||||
* Data JPQL Specifications
|
* Data JPQL Specifications
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class SoftwareModuleSpecification {
|
public final class SoftwareModuleSpecification {
|
||||||
private SoftwareModuleSpecification() {
|
private SoftwareModuleSpecification() {
|
||||||
@@ -39,38 +34,21 @@ public final class SoftwareModuleSpecification {
|
|||||||
* @return the {@link SoftwareModule} {@link Specification}
|
* @return the {@link SoftwareModule} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<SoftwareModule> byId(final Long moduleId) {
|
public static Specification<SoftwareModule> byId(final Long moduleId) {
|
||||||
final Specification<SoftwareModule> spec = new Specification<SoftwareModule>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Predicate predicate = cb.equal(targetRoot.<Long> get(SoftwareModule_.id), moduleId);
|
||||||
public Predicate toPredicate(final Root<SoftwareModule> targetRoot, final CriteriaQuery<?> query,
|
targetRoot.fetch(SoftwareModule_.type);
|
||||||
final CriteriaBuilder cb) {
|
return predicate;
|
||||||
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<Long> get(SoftwareModule_.id), moduleId);
|
|
||||||
targetRoot.fetch(SoftwareModule_.type);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Specification} for retrieving {@link SoftwareModule}s by its
|
* {@link Specification} for retrieving {@link SoftwareModule}s where its
|
||||||
* DELETED attribute.
|
* DELETED attribute is false.
|
||||||
*
|
*
|
||||||
* @param isDeleted
|
|
||||||
* TRUE/FALSE are compared to the attribute DELETED. If NULL the
|
|
||||||
* attribute is ignored
|
|
||||||
* @return the {@link SoftwareModule} {@link Specification}
|
* @return the {@link SoftwareModule} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<SoftwareModule> isDeletedFalse() {
|
public static Specification<SoftwareModule> isDeletedFalse() {
|
||||||
final Specification<SoftwareModule> spec = new Specification<SoftwareModule>() {
|
return (swRoot, query, cb) -> cb.equal(swRoot.<Boolean> get(SoftwareModule_.deleted), Boolean.FALSE);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<SoftwareModule> swRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.equal(swRoot.<Boolean> get(SoftwareModule_.deleted), Boolean.FALSE);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,18 +60,9 @@ public final class SoftwareModuleSpecification {
|
|||||||
* @return the {@link SoftwareModule} {@link Specification}
|
* @return the {@link SoftwareModule} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<SoftwareModule> likeNameOrVersion(final String subString) {
|
public static Specification<SoftwareModule> likeNameOrVersion(final String subString) {
|
||||||
final Specification<SoftwareModule> spec = new Specification<SoftwareModule>() {
|
return (targetRoot, query, cb) -> cb.or(
|
||||||
@Override
|
cb.like(cb.lower(targetRoot.<String> get(SoftwareModule_.name)), subString.toLowerCase()),
|
||||||
public Predicate toPredicate(final Root<SoftwareModule> targetRoot, final CriteriaQuery<?> query,
|
cb.like(cb.lower(targetRoot.<String> get(SoftwareModule_.version)), subString.toLowerCase()));
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.or(
|
|
||||||
cb.like(cb.lower(targetRoot.<String> get(SoftwareModule_.name)), subString.toLowerCase()),
|
|
||||||
cb.like(cb.lower(targetRoot.<String> get(SoftwareModule_.version)), subString.toLowerCase()));
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,16 +74,7 @@ public final class SoftwareModuleSpecification {
|
|||||||
* @return the {@link SoftwareModule} {@link Specification}
|
* @return the {@link SoftwareModule} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<SoftwareModule> equalType(final SoftwareModuleType type) {
|
public static Specification<SoftwareModule> equalType(final SoftwareModuleType type) {
|
||||||
final Specification<SoftwareModule> spec = new Specification<SoftwareModule>() {
|
return (targetRoot, query, cb) -> cb.equal(targetRoot.<SoftwareModuleType> get(SoftwareModule_.type), type);
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<SoftwareModule> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.equal(targetRoot.<SoftwareModuleType> get(SoftwareModule_.type), type);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.specifications;
|
package org.eclipse.hawkbit.repository.specifications;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Predicate;
|
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery_;
|
import org.eclipse.hawkbit.repository.model.TargetFilterQuery_;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Specifications class for {@link TargetFilterQuery}s. The class provides
|
||||||
|
* Spring Data JPQL Specifications.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TargetFilterQuerySpecification {
|
public class TargetFilterQuerySpecification {
|
||||||
@@ -27,16 +23,9 @@ public class TargetFilterQuerySpecification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Specification<TargetFilterQuery> likeName(final String searchText) {
|
public static Specification<TargetFilterQuery> likeName(final String searchText) {
|
||||||
final Specification<TargetFilterQuery> spec = new Specification<TargetFilterQuery>() {
|
return (targetFilterQueryRoot, query, cb) -> {
|
||||||
@Override
|
final String searchTextToLower = searchText.toLowerCase();
|
||||||
public Predicate toPredicate(final Root<TargetFilterQuery> targetFilterQueryRoot,
|
return cb.like(cb.lower(targetFilterQueryRoot.get(TargetFilterQuery_.name)), searchTextToLower);
|
||||||
final CriteriaQuery<?> query, final CriteriaBuilder cb) {
|
|
||||||
final String searchTextToLower = searchText.toLowerCase();
|
|
||||||
final Predicate predicate = cb.like(cb.lower(targetFilterQueryRoot.get(TargetFilterQuery_.name)),
|
|
||||||
searchTextToLower);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Join;
|
import javax.persistence.criteria.Join;
|
||||||
import javax.persistence.criteria.JoinType;
|
import javax.persistence.criteria.JoinType;
|
||||||
import javax.persistence.criteria.Path;
|
import javax.persistence.criteria.Path;
|
||||||
@@ -36,8 +35,6 @@ import org.springframework.data.jpa.domain.Specification;
|
|||||||
* Specifications class for {@link Target}s. The class provides Spring Data JPQL
|
* Specifications class for {@link Target}s. The class provides Spring Data JPQL
|
||||||
* Specifications.
|
* Specifications.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class TargetSpecifications {
|
public final class TargetSpecifications {
|
||||||
private TargetSpecifications() {
|
private TargetSpecifications() {
|
||||||
@@ -54,18 +51,12 @@ public final class TargetSpecifications {
|
|||||||
* @return the {@link Target} {@link Specification}
|
* @return the {@link Target} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<Target> byControllerIdWithStatusAndTagsInJoin(final Collection<String> controllerIDs) {
|
public static Specification<Target> byControllerIdWithStatusAndTagsInJoin(final Collection<String> controllerIDs) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs);
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
targetRoot.fetch(Target_.tags, JoinType.LEFT);
|
||||||
final CriteriaBuilder cb) {
|
query.distinct(true);
|
||||||
final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs);
|
return predicate;
|
||||||
targetRoot.fetch(Target_.tags, JoinType.LEFT);
|
|
||||||
query.distinct(true);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,18 +70,12 @@ public final class TargetSpecifications {
|
|||||||
*/
|
*/
|
||||||
public static Specification<Target> byControllerIdWithStatusAndAssignedInJoin(
|
public static Specification<Target> byControllerIdWithStatusAndAssignedInJoin(
|
||||||
final Collection<String> controllerIDs) {
|
final Collection<String> controllerIDs) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
|
|
||||||
final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs);
|
final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs);
|
||||||
targetRoot.fetch(Target_.assignedDistributionSet);
|
targetRoot.fetch(Target_.assignedDistributionSet);
|
||||||
return predicate;
|
return predicate;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,24 +91,18 @@ public final class TargetSpecifications {
|
|||||||
*/
|
*/
|
||||||
public static Specification<Target> hasTargetUpdateStatus(final Collection<TargetUpdateStatus> updateStatus,
|
public static Specification<Target> hasTargetUpdateStatus(final Collection<TargetUpdateStatus> updateStatus,
|
||||||
final boolean fetch) {
|
final boolean fetch) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
if (fetch) {
|
||||||
final CriteriaBuilder cb) {
|
targetRoot.fetch(Target_.targetInfo);
|
||||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
} else {
|
||||||
if (fetch) {
|
targetRoot.join(Target_.targetInfo);
|
||||||
targetRoot.fetch(Target_.targetInfo);
|
|
||||||
} else {
|
|
||||||
targetRoot.join(Target_.targetInfo);
|
|
||||||
}
|
|
||||||
return targetRoot.get(Target_.targetInfo).get(TargetInfo_.updateStatus).in(updateStatus);
|
|
||||||
}
|
}
|
||||||
final Join<Target, TargetInfo> targetInfoJoin = targetRoot.join(Target_.targetInfo);
|
return targetRoot.get(Target_.targetInfo).get(TargetInfo_.updateStatus).in(updateStatus);
|
||||||
return targetInfoJoin.get(TargetInfo_.updateStatus).in(updateStatus);
|
|
||||||
}
|
}
|
||||||
|
final Join<Target, TargetInfo> targetInfoJoin = targetRoot.join(Target_.targetInfo);
|
||||||
|
return targetInfoJoin.get(TargetInfo_.updateStatus).in(updateStatus);
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,18 +114,11 @@ public final class TargetSpecifications {
|
|||||||
* @return the {@link Target} {@link Specification}
|
* @return the {@link Target} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<Target> likeNameOrDescriptionOrIp(final String searchText) {
|
public static Specification<Target> likeNameOrDescriptionOrIp(final String searchText) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final String searchTextToLower = searchText.toLowerCase();
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
return cb.or(cb.like(cb.lower(targetRoot.get(Target_.name)), searchTextToLower),
|
||||||
final CriteriaBuilder cb) {
|
cb.like(cb.lower(targetRoot.get(Target_.description)), searchTextToLower));
|
||||||
final String searchTextToLower = searchText.toLowerCase();
|
|
||||||
final Predicate predicate = cb.or(cb.like(cb.lower(targetRoot.get(Target_.name)), searchTextToLower),
|
|
||||||
cb.like(cb.lower(targetRoot.get(Target_.description)), searchTextToLower));
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,21 +130,14 @@ public final class TargetSpecifications {
|
|||||||
* @return the {@link Target} {@link Specification}
|
* @return the {@link Target} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<Target> hasInstalledOrAssignedDistributionSet(@NotNull final Long distributionId) {
|
public static Specification<Target> hasInstalledOrAssignedDistributionSet(@NotNull final Long distributionId) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Join<Target, TargetInfo> targetInfoJoin = targetRoot.join(Target_.targetInfo);
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
return cb.or(
|
||||||
final CriteriaBuilder cb) {
|
cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id),
|
||||||
final Join<Target, TargetInfo> targetInfoJoin = targetRoot.join(Target_.targetInfo);
|
distributionId),
|
||||||
final Predicate predicate = cb.or(
|
cb.equal(targetRoot.<DistributionSet> get(Target_.assignedDistributionSet).get(DistributionSet_.id),
|
||||||
cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id),
|
distributionId));
|
||||||
distributionId),
|
|
||||||
cb.equal(targetRoot.<DistributionSet> get(Target_.assignedDistributionSet)
|
|
||||||
.get(DistributionSet_.id), distributionId));
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,18 +152,11 @@ public final class TargetSpecifications {
|
|||||||
*/
|
*/
|
||||||
public static Specification<Target> hasControllerIdAndAssignedDistributionSetIdNot(final List<String> tIDs,
|
public static Specification<Target> hasControllerIdAndAssignedDistributionSetIdNot(final List<String> tIDs,
|
||||||
@NotNull final Long distributionId) {
|
@NotNull final Long distributionId) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> cb
|
||||||
@Override
|
.and(targetRoot.get(Target_.controllerId).in(tIDs),
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
final Predicate predicate = cb.and(targetRoot.get(Target_.controllerId).in(tIDs),
|
|
||||||
cb.or(cb.notEqual(targetRoot.<DistributionSet> get(Target_.assignedDistributionSet)
|
cb.or(cb.notEqual(targetRoot.<DistributionSet> get(Target_.assignedDistributionSet)
|
||||||
.get(DistributionSet_.id), distributionId),
|
.get(DistributionSet_.id), distributionId),
|
||||||
cb.isNull(targetRoot.<DistributionSet> get(Target_.assignedDistributionSet))));
|
cb.isNull(targetRoot.<DistributionSet> get(Target_.assignedDistributionSet))));
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,16 +170,11 @@ public final class TargetSpecifications {
|
|||||||
* @return the {@link Target} {@link Specification}
|
* @return the {@link Target} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<Target> hasTags(final String[] tagNames, final Boolean selectTargetWithNoTag) {
|
public static Specification<Target> hasTags(final String[] tagNames, final Boolean selectTargetWithNoTag) {
|
||||||
final Specification<Target> spec = new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Predicate predicate = getPredicate(targetRoot, cb, selectTargetWithNoTag, tagNames);
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
query.distinct(true);
|
||||||
final CriteriaBuilder cb) {
|
return predicate;
|
||||||
final Predicate predicate = getPredicate(targetRoot, cb, selectTargetWithNoTag, tagNames);
|
|
||||||
query.distinct(true);
|
|
||||||
return predicate;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Predicate getPredicate(final Root<Target> targetRoot, final CriteriaBuilder cb,
|
private static Predicate getPredicate(final Root<Target> targetRoot, final CriteriaBuilder cb,
|
||||||
@@ -248,15 +201,9 @@ public final class TargetSpecifications {
|
|||||||
* @return the {@link Target} {@link Specification}
|
* @return the {@link Target} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<Target> hasAssignedDistributionSet(final Long distributionSetId) {
|
public static Specification<Target> hasAssignedDistributionSet(final Long distributionSetId) {
|
||||||
return new Specification<Target>() {
|
return (targetRoot, query, cb) -> cb.equal(
|
||||||
@Override
|
targetRoot.<DistributionSet> get(Target_.assignedDistributionSet).get(DistributionSet_.id),
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
distributionSetId);
|
||||||
final CriteriaBuilder cb) {
|
|
||||||
return cb.equal(
|
|
||||||
targetRoot.<DistributionSet> get(Target_.assignedDistributionSet).get(DistributionSet_.id),
|
|
||||||
distributionSetId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,14 +215,10 @@ public final class TargetSpecifications {
|
|||||||
* @return the {@link Target} {@link Specification}
|
* @return the {@link Target} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<Target> hasInstalledDistributionSet(final Long distributionSetId) {
|
public static Specification<Target> hasInstalledDistributionSet(final Long distributionSetId) {
|
||||||
return new Specification<Target>() {
|
return (targetRoot, query, cb) -> {
|
||||||
@Override
|
final Join<Target, TargetInfo> targetInfoJoin = targetRoot.join(Target_.targetInfo);
|
||||||
public Predicate toPredicate(final Root<Target> targetRoot, final CriteriaQuery<?> query,
|
return cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id),
|
||||||
final CriteriaBuilder cb) {
|
distributionSetId);
|
||||||
final Join<Target, TargetInfo> targetInfoJoin = targetRoot.join(Target_.targetInfo);
|
|
||||||
return cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id),
|
|
||||||
distributionSetId);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user