DDI API: /controller/v1/{controllerid}/installedBase/{actionId} (#1220)
* installedBase DDI: initial impl + rest docs Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * refactor installedBase implementation Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * ddi installed base tests Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * restructure root controller rest docs Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * fix some java docs and formatting Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * don't add action history message when calling /installedBase Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * fix test after removing action history message Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * fix review comments Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * fix review comments Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io>
This commit is contained in:
@@ -21,11 +21,11 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
@@ -499,4 +499,13 @@ public interface ControllerManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
void deleteExistingTarget(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Finds an {@link Action} based on the target that it's assigned to
|
||||
*
|
||||
* @param controllerId
|
||||
* of the target the action is assigned to
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
Optional<Action> getInstalledActionByTarget(@NotEmpty String controllerId);
|
||||
}
|
||||
|
||||
@@ -189,6 +189,18 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
@Query("Select a from JpaAction a join a.distributionSet ds join ds.modules modul where a.target.controllerId = :target and modul.id = :module order by a.id desc")
|
||||
List<Action> findActionByTargetAndSoftwareModule(@Param("target") String targetId, @Param("module") Long moduleId);
|
||||
|
||||
/**
|
||||
* Retrieves latest {@link Action} for given target and {@link DistributionSet}.
|
||||
*
|
||||
* @param targetId
|
||||
* to search for
|
||||
* @param dsId
|
||||
* to search for
|
||||
* @return action if there is one with assigned target and assigned
|
||||
* {@link DistributionSet}.
|
||||
*/
|
||||
Optional<Action> findFirstByTargetIdAndDistributionSetId(@Param("target") long targetId, @Param("ds") Long dsId);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s which are referring the given
|
||||
* {@link DistributionSet} and {@link Target}.
|
||||
|
||||
@@ -1056,6 +1056,20 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
return actionRepository.findByExternalRef(externalRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Action> getInstalledActionByTarget(final String controllerId) {
|
||||
final JpaTarget jpaTarget = targetRepository.findOne(TargetSpecifications.hasControllerId(controllerId))
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
final JpaDistributionSet installedDistributionSet = jpaTarget.getInstalledDistributionSet();
|
||||
if (null != installedDistributionSet) {
|
||||
return actionRepository.findFirstByTargetIdAndDistributionSetId(jpaTarget.getId(),
|
||||
installedDistributionSet.getId());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
|
||||
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(
|
||||
new CancelTargetAssignmentEvent(target, actionId, eventPublisherHolder.getApplicationId())));
|
||||
|
||||
Reference in New Issue
Block a user