Add resource collection /rest/v1/actions to Management REST API (#1299)

* Initial commit

Signed-off-by: Stefan Behl <stefan.behl@bosch.io>

* Added filtering by RSQL

Signed-off-by: Stefan Behl <stefan.behl@bosch.io>

* Support for filtering actions by distribution set, target, rollout

* Added REST docs

* Fixed REST docs

* Introduce a config property which allows to disable the actions endpoint

* Introduce representation mode parameter

* Adapt REST docs

* Incorporate review findings

* Adapt REST docs

* Improve unit tests

* Minor improvements

* Fix REST docs

* Fix REST docs

* Fix PR review findings

Signed-off-by: Stefan Behl <stefan.behl@bosch.io>
This commit is contained in:
Stefan Behl
2023-01-10 17:19:05 +01:00
committed by GitHub
parent 27872282f5
commit d7796121d1
19 changed files with 1046 additions and 37 deletions

View File

@@ -8,9 +8,12 @@
*/
package org.eclipse.hawkbit.repository;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Sort fields for {@link ActionRest}.
*
*/
public enum ActionFields implements FieldNameProvider, FieldValueConverter<ActionFields> {
@@ -18,22 +21,65 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter<Actio
* The status field.
*/
STATUS("active"),
/**
* The detailed action status
*/
DETAILSTATUS("status"),
/**
* The id field.
*/
ID("id"),
/**
* The weight field.
*/
WEIGHT("weight");
WEIGHT("weight"),
/**
* The target field
*/
TARGET("target", TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(),
TargetFields.UPDATESTATUS.getFieldName(), TargetFields.IPADDRESS.getFieldName()),
/**
* The distribution set field
*/
DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(),
DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(),
DistributionSetFields.TYPE.getFieldName()),
/**
* The rollout field
*/
ROLLOUT("rollout", RolloutFields.ID.getFieldName(), RolloutFields.NAME.getFieldName()),
/**
* The rollout field
*/
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getFieldName(), RolloutGroupFields.NAME.getFieldName());
private static final String ACTIVE = "pending";
private static final String INACTIVE = "finished";
private final String fieldName;
private List<String> subEntityAttributes;
private ActionFields(final String fieldName) {
this.fieldName = fieldName;
this.subEntityAttributes = Collections.emptyList();
}
private ActionFields(final String fieldName, final String... subEntityAttributes) {
this.fieldName = fieldName;
this.subEntityAttributes = Arrays.asList(subEntityAttributes);
}
@Override
public List<String> getSubEntityAttributes() {
return subEntityAttributes;
}
@Override
@@ -49,6 +95,14 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter<Actio
return value;
}
@Override
public String[] possibleValues(final ActionFields e) {
if (STATUS == e) {
return new String[] { ACTIVE, INACTIVE };
}
return new String[0];
}
private static Object convertStatusValue(final String value) {
final String trimmedValue = value.trim();
if (trimmedValue.equalsIgnoreCase(ACTIVE)) {
@@ -60,11 +114,4 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter<Actio
}
}
@Override
public String[] possibleValues(final ActionFields e) {
if (STATUS == e) {
return new String[] { ACTIVE, INACTIVE };
}
return new String[0];
}
}