Add support for target tag retrieval via REST (#1782)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -851,6 +852,16 @@ public interface TargetManagement {
|
||||
boolean isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(@NotNull String controllerId,
|
||||
long distributionSetId, @NotNull String targetFilterQuery);
|
||||
|
||||
/**
|
||||
* Finds a single target tags its id.
|
||||
*
|
||||
* @param controllerId of the {@link Target}
|
||||
* @return the found Tag set
|
||||
* @throws EntityNotFoundException if target with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Set<TargetTag> getTagsByControllerId(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Creates a list of target meta data entries.
|
||||
*
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
@@ -178,6 +179,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return targetRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TargetTag> getTagsByControllerId(@NotEmpty String controllerId) {
|
||||
// the method has PreAuthorized by itself
|
||||
return getByControllerID(controllerId).map(JpaTarget.class::cast).map(JpaTarget::getTags)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(include = {
|
||||
|
||||
@@ -207,11 +207,7 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
}
|
||||
|
||||
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));
|
||||
return targetManagement.getTagsByControllerId(controllerId);
|
||||
}
|
||||
|
||||
private JpaRollout refresh(final Rollout rollout) {
|
||||
|
||||
@@ -201,7 +201,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private final <T> Collection<T> concat(final Collection<T>... targets) {
|
||||
private <T> Collection<T> concat(final Collection<T>... targets) {
|
||||
final List<T> result = new ArrayList<>();
|
||||
Arrays.asList(targets).forEach(result::addAll);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user