Add new endpoint for single action (#1316)

* Add new endpoint for single action
* Adding the new endpoint to the documentation
+ reverse the representation mode to FULL

Signed-off-by: Stanislav Trailov <stanislav.trailov@bosch.io>
This commit is contained in:
Stanislav Trailov
2023-02-06 14:13:58 +02:00
committed by GitHub
parent a64c2bc28e
commit 64bc0417b1
5 changed files with 137 additions and 12 deletions

View File

@@ -14,6 +14,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,16 +56,29 @@ public class MgmtActionResource implements MgmtActionRestApi {
totalActionCount = this.deploymentManagement.countActionsAll();
}
final MgmtRepresentationMode repMode = MgmtRepresentationMode.fromValue(representationModeParam)
.orElseGet(() -> {
// no need for a 400, just apply a safe fallback
LOG.warn("Received an invalid representation mode: {}", representationModeParam);
return MgmtRepresentationMode.COMPACT;
});
final MgmtRepresentationMode repMode = getRepresentationModeFromString(representationModeParam);
return ResponseEntity
.ok(new PagedList<>(MgmtActionMapper.toResponse(actions.getContent(), repMode), totalActionCount));
}
@Override
public ResponseEntity<MgmtAction> getAction(final Long actionId) {
final Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
return ResponseEntity.ok(MgmtActionMapper.toResponse(action, MgmtRepresentationMode.FULL));
}
private MgmtRepresentationMode getRepresentationModeFromString(final String representationModeParam) {
return MgmtRepresentationMode.fromValue(representationModeParam)
.orElseGet(() -> {
// no need for a 400, just apply a safe fallback
LOG.warn("Received an invalid representation mode: {}", representationModeParam);
return MgmtRepresentationMode.COMPACT;
});
}
}