Skip to content

Commit

Permalink
Small serach fields refactoring (add lombok & style) (#1823)
Browse files Browse the repository at this point in the history
Signed-off-by: Marinov Avgustin <[email protected]>
  • Loading branch information
avgustinmm committed Aug 23, 2024
1 parent ac34b95 commit 55cc600
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,57 @@
*/
package org.eclipse.hawkbit.repository;

import java.util.Arrays;
import lombok.Getter;

import java.util.Collections;
import java.util.List;

/**
* Sort and search fields for actions.
*/
@Getter
public enum ActionFields implements FieldNameProvider, FieldValueConverter<ActionFields> {

/**
* The status field.
*/
ID("id"),
STATUS("active"),

/**
* The detailed action status
*/
DETAILSTATUS("status"),

/**
* The last action status code
*/
LASTSTATUSCODE("lastActionStatusCode"),

/**
* The id field.
*/
ID("id"),

/**
* The weight field.
*/
WEIGHT("weight"),

/**
* The target field
*/
TARGET("target", TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(),
TARGET("target",
TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(),
TargetFields.UPDATESTATUS.getFieldName(), TargetFields.IPADDRESS.getFieldName()),

/**
* The distribution set field
*/
DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(),
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()),


/**
* The weight field.
*/
EXTERNALREF("externalRef");

private static final String ACTIVE = "pending";
private static final String INACTIVE = "finished";

private final String fieldName;
private final List<String> subEntityAttributes;

private List<String> subEntityAttributes;

private ActionFields(final String fieldName) {
ActionFields(final String fieldName) {
this.fieldName = fieldName;
this.subEntityAttributes = Collections.emptyList();
}

private ActionFields(final String fieldName, final String... subEntityAttributes) {
ActionFields(final String fieldName, final String... subEntityAttributes) {
this.fieldName = fieldName;
this.subEntityAttributes = Arrays.asList(subEntityAttributes);
}

@Override
public List<String> getSubEntityAttributes() {
return subEntityAttributes;
}

@Override
public String getFieldName() {
return fieldName;
this.subEntityAttributes = List.of(subEntityAttributes);
}

@Override
public Object convertValue(final ActionFields e, final String value) {
if (STATUS == e) {
return convertStatusValue(value);
}
return value;
return STATUS == e ? convertStatusValue(value) : value;
}

@Override
public String[] possibleValues(final ActionFields e) {
if (STATUS == e) {
return new String[] { ACTIVE, INACTIVE };
}
return new String[0];
return STATUS == e ? new String[] { ACTIVE, INACTIVE } : new String[0];
}

private static Object convertStatusValue(final String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,20 @@
*/
package org.eclipse.hawkbit.repository;

import lombok.Getter;

/**
* Sort fields for {@link ActionStatusRest}.
*
*
*
*
* Sort and search fields for action status.
*/
@Getter
public enum ActionStatusFields implements FieldNameProvider {

/**
* The id field.
*/
ID("id"),

/**
* The reportedAt field.
*/
REPORTEDAT("createdAt");

private final String fieldName;

private ActionStatusFields(final String fieldName) {
ActionStatusFields(final String fieldName) {
this.fieldName = fieldName;
}

@Override
public String getFieldName() {
return fieldName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
*/
package org.eclipse.hawkbit.repository;

import lombok.Getter;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
Expand All @@ -19,104 +20,47 @@
/**
* Describing the fields of the DistributionSet model which can be used in the
* REST API e.g. for sorting etc.
*
*
*
*
*/
@Getter
public enum DistributionSetFields implements FieldNameProvider {
/**
* The name field.
*/

ID("id"),
TYPE("type.key"),
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The createdAt field.
*/
CREATEDAT("createdAt"),
/**
* The lastModifiedAt field.
*/
LASTMODIFIEDAT("lastModifiedAt"),
/**
* The version field.
*/
VERSION("version"),
/**
* The complete field.
*/
COMPLETE("complete"),
/**
* The id field.
*/
ID("id"),
/**
* The module field.
*/
MODULE("modules", SoftwareModuleFields.ID.getFieldName(), SoftwareModuleFields.NAME.getFieldName()),
/**
* The tags field.
*/
TAG("tags.name"),
/**
* The sw type key field.
*/
TYPE("type.key"),
/**
* The metadata.
*/
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
/**
* The valid field.
*/
VALID("valid");

private final String fieldName;
private boolean mapField;
private Entry<String, String> subEntityMapTuple;

private final Entry<String, String> subEntityMapTuple;
private final List<String> subEntityAttributes;

private DistributionSetFields(final String fieldName) {
this(fieldName, false, null, Collections.emptyList());
DistributionSetFields(final String fieldName) {
this(fieldName, null, Collections.emptyList());
}

private DistributionSetFields(final String fieldName, final String... subEntityAttributes) {
this(fieldName, false, null, Arrays.asList(subEntityAttributes));
DistributionSetFields(final String fieldName, final String... subEntityAttributes) {
this(fieldName, null, List.of(subEntityAttributes));
}

private DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) {
this(fieldName, true, subEntityMapTuple, Collections.emptyList());
DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) {
this(fieldName, subEntityMapTuple, Collections.emptyList());
}

private DistributionSetFields(final String fieldName, final boolean mapField,
final Entry<String, String> subEntityMapTuple, List<String> subEntityAttributes) {
DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple, List<String> subEntityAttributes) {
this.fieldName = fieldName;
this.mapField = mapField;
this.subEntityMapTuple = subEntityMapTuple;
this.subEntityAttributes = subEntityAttributes;
}

@Override
public List<String> getSubEntityAttributes() {
return Collections.unmodifiableList(subEntityAttributes);
}

@Override
public Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.ofNullable(subEntityMapTuple);
}

@Override
public boolean isMap() {
return mapField;
}

@Override
public String getFieldName() {
return fieldName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,25 @@
*/
package org.eclipse.hawkbit.repository;

import lombok.Getter;

/**
* Sort fields for DistributionSetMetadata.
*
*
*
*
*/
@Getter
public enum DistributionSetMetadataFields implements FieldNameProvider {

/**
* The value field.
*/
VALUE("value"),
/**
* The key field.
*/
KEY("key");
KEY("key"),
VALUE("value");

private final String fieldName;

private DistributionSetMetadataFields(final String fieldName) {
DistributionSetMetadataFields(final String fieldName) {
this.fieldName = fieldName;
}

@Override
public String getFieldName() {
return fieldName;
}

@Override
public String identifierFieldName() {
return KEY.getFieldName();
}
}
}
Loading

0 comments on commit 55cc600

Please sign in to comment.