[#1509] Sync Target type with SW and DS types / getByKey (Mgmt Layer) (#1516)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2023-12-13 16:42:10 +02:00
committed by GitHub
parent 4ac42c80d7
commit d951cee6b2
5 changed files with 84 additions and 27 deletions

View File

@@ -89,6 +89,11 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
this.quotaManagement = quotaManagement;
}
@Override
public Optional<TargetType> getByKey(final String key) {
return targetTypeRepository.findOne(TargetTypeSpecification.hasKey(key)).map(TargetType.class::cast);
}
@Override
public Optional<TargetType> getByName(final String name) {
return targetTypeRepository.findOne(TargetTypeSpecification.hasName(name)).map(TargetType.class::cast);

View File

@@ -50,18 +50,7 @@ public interface TargetTypeRepository
* {@link TargetType#getName()}
*/
default List<JpaTargetType> findByDsType(@Param("id") final Long dsTypeId) {
return this.findAll(Specification.where(TargetTypeSpecification.hasDsSetType(dsTypeId)));
}
/**
*
* @param name
* to search for
* @return all {@link TargetType}s in the repository with given
* {@link TargetType#getName()}
*/
default Optional<JpaTargetType> findByName(final String name) {
return this.findOne(Specification.where(TargetTypeSpecification.hasName(name)));
return findAll(Specification.where(TargetTypeSpecification.hasDsSetType(dsTypeId)));
}
/**

View File

@@ -133,6 +133,18 @@ public final class TargetTypeSpecification {
};
}
/**
* {@link Specification} for retrieving {@link TargetType} with
* given {@link TargetType#getKey()} including fetching the
* elements list.
*
* @param key
* to search
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasKey(final String key) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTargetType_.key), key);
}
/**
* {@link Specification} for retrieving {@link TargetType} with