Remove FieldValueConverter (#2699)

* (because) used only for ActionFields.STATUS
* could be part of new Node mapping mechanism
* simplify
* Deprecate ActionFields.STATUS, add / replace it with ActionFields.ACTIVE. In future STATUS will become the real action status (and DETAILSTATUS will be removed)
* Deprecate MgmtAction.getStatus add / replace it with MgmtAction.isActive. In future status will become the real action status (and detailStatus will be removed)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-09-26 16:57:10 +03:00
committed by GitHub
parent 1abfa0a2f4
commit a6867219b1
11 changed files with 88 additions and 141 deletions

View File

@@ -17,10 +17,12 @@ import lombok.Getter;
* Sort and search fields for actions.
*/
@Getter
public enum ActionFields implements QueryField, FieldValueConverter<ActionFields> {
public enum ActionFields implements QueryField {
ID("id"),
STATUS("active"), // true if status is "pending", false if "finished"
@Deprecated(since = "0.10.0", forRemoval = true) // use ACTIVE
STATUS("active"), // true if status is "pending", false if "finished", after removal, will deprecate DETAILSTATUS too and replace with STATUS
ACTIVE("active"), // true if st
DETAILSTATUS("status"), // real status
LASTSTATUSCODE("lastActionStatusCode"),
CREATEDAT("createdAt"),
@@ -39,9 +41,6 @@ public enum ActionFields implements QueryField, FieldValueConverter<ActionFields
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getJpaEntityFieldName(), RolloutGroupFields.NAME.getJpaEntityFieldName()),
EXTERNALREF("externalRef");
private static final String ACTIVE = "pending";
private static final String INACTIVE = "finished";
private final String jpaEntityFieldName;
private final List<String> subEntityAttributes;
@@ -50,19 +49,15 @@ public enum ActionFields implements QueryField, FieldValueConverter<ActionFields
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public Object convertValue(final ActionFields enumValue, final String value) {
return STATUS == enumValue ? convertStatusValue(value) : value;
}
private static Object convertStatusValue(final String value) {
@Deprecated(since = "0.10.0", forRemoval = true) // remove together with STATUS (with active meaning)
public static Object convertStatusValue(final String value) {
final String trimmedValue = value.trim();
if (trimmedValue.equalsIgnoreCase(ACTIVE)) {
if (trimmedValue.equalsIgnoreCase("pending")) {
return true;
} else if (trimmedValue.equalsIgnoreCase(INACTIVE)) {
} else if (trimmedValue.equalsIgnoreCase("finished")) {
return false;
} else {
throw new IllegalArgumentException("field 'status' must be one of the following values {" + ACTIVE + ", " + INACTIVE + "}");
throw new IllegalArgumentException("field 'status' must be one of the following values {pending, finished}");
}
}
}

View File

@@ -1,32 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository;
/**
* A value convert which converts given string based values into an object which
* can be used for building generic queries. Mapping external API values e.g.
* REST API to inside representation on database. E.g. mapping 'pending' or
* 'finished' values in rest queries to Action#isActive boolean value.
*
* @param <T> the enum parameter
*/
public interface FieldValueConverter<T extends Enum<T>> {
/**
* Converts the given {@code value} into the representation to build a generic query.
*
* @param enumValue the enum value to build the value for
* @param value the value in string representation
* @return the converted object if conversion is applicable, or if the given enum value does not need to be converted the
* unmodified {@code value} is returned.
* @throws IllegalArgumentException if the value is not supported
*/
Object convertValue(final T enumValue, final String value);
}