JpaDistributionSet#metadata made Map (#2411)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-05-21 13:45:18 +03:00
committed by GitHub
parent ceba4f5cfb
commit 452d8618d7
26 changed files with 382 additions and 1216 deletions

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.validation.constraints.NotEmpty;
@@ -30,7 +31,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -124,29 +124,38 @@ public interface DistributionSetManagement extends RepositoryManagement<Distribu
List<DistributionSet> unassignTag(@NotEmpty Collection<Long> ids, long tagId);
/**
* Creates a list of distribution set meta-data entries.
* Creates a map of distribution set meta-data entries.
*
* @param id if the {@link DistributionSet} the metadata has to be created for
* @param metadata the meta-data entries to create or update
* @return the updated or created distribution set meta-data entries
* @throws EntityNotFoundException if given set does not exist
* @throws EntityAlreadyExistsException in case one of the meta-data entry already exists for the specific key
* @throws AssignmentQuotaExceededException if the maximum number of {@link MetaData} entries is exceeded for the addressed
* {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<DistributionSetMetadata> putMetaData(long id, @NotEmpty Collection<MetaData> metadata);
void createMetadata(long id, @NotEmpty Map<String, String> metadata);
/**
* Updates a distribution set meta-data value if corresponding entry exists.
* Finds all meta-data by the given distribution set id.
*
* @param id the distribution set id to retrieve the meta-data from
* @return a paged result of all meta-data entries for a given distribution set id
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Map<String, String> getMetadata(long id);
/**
* Updates a distribution set meta-data values by adding them.
*
* @param id {@link DistributionSet} of the meta-data entry to be updated
* @param metadata meta-data entry to be updated
* @return the updated meta-data entry
* @param key meta data-entry key to be updated
* @param value meta data-entry to be new value
* @throws EntityNotFoundException in case the meta-data entry does not exist and cannot be updated
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSetMetadata updateMetaData(long id, @NotNull MetaData metadata);
void updateMetadata(long id, @NotNull String key, @NotNull String value);
/**
* Deletes a distribution set meta-data entry.
@@ -156,7 +165,7 @@ public interface DistributionSetManagement extends RepositoryManagement<Distribu
* @throws EntityNotFoundException if given set does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteMetaData(long id, @NotEmpty String key);
void deleteMetadata(long id, @NotEmpty String key);
/**
* Locks a distribution set. From then on its functional properties could not be changed, and it could be assigned to targets
@@ -221,33 +230,6 @@ public interface DistributionSetManagement extends RepositoryManagement<Distribu
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSet> findByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version);
/**
* Finds all meta-data by the given distribution set id.
*
* @param id the distribution set id to retrieve the meta-data from
* @param pageable the page request to page the result
* @return a paged result of all meta-data entries for a given distribution
* set id
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetMetadata> findMetaDataByDistributionSetId(long id, @NotNull Pageable pageable);
/**
* Finds all meta-data by the given distribution set id.
*
* @param id the distribution set id to retrieve the meta-data from
* @param rsqlParam rsql query string
* @param pageable the page request to page the result
* @return a paged result of all meta-data entries for a given distribution set id
* @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the given
* {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException if the RSQL syntax is wrong
* @throws EntityNotFoundException of distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetMetadata> findMetaDataByDistributionSetIdAndRsql(long id, @NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Finds all {@link DistributionSet}s based on completeness.
*
@@ -295,25 +277,6 @@ public interface DistributionSetManagement extends RepositoryManagement<Distribu
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSet> findByRsqlAndTag(@NotNull String rsqlParam, long tagId, @NotNull Pageable pageable);
/**
* Finds a single distribution set meta-data by its id.
*
* @param id of the {@link DistributionSet}
* @param key of the meta-data element
* @return the found DistributionSetMetadata
* @throws EntityNotFoundException is set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSetMetadata> findMetaDataByDistributionSetId(long id, @NotEmpty String key);/**
* Counts all meta-data by the given distribution set id.
*
* @param id the distribution set id to retrieve the meta-data count from
* @return count of ds metadata
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countMetaDataByDistributionSetId(long id);
/**
* Counts all {@link DistributionSet}s based on completeness.
*

View File

@@ -9,9 +9,6 @@
*/
package org.eclipse.hawkbit.repository;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
import org.eclipse.hawkbit.repository.builder.DistributionSetBuilder;
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder;
@@ -43,17 +40,6 @@ public interface EntityFactory {
*/
DistributionSetBuilder distributionSet();
/**
* Generates an {@link MetaData} element for distribution set without
* persisting it.
*
* @param key {@link MetaData#getKey()}
* @param value {@link MetaData#getValue()}
* @return {@link MetaData} object
*/
MetaData generateDsMetadata(@Size(min = 1, max = MetaData.KEY_MAX_SIZE) @NotNull String key,
@Size(max = MetaData.VALUE_MAX_SIZE) String value);
/**
* @return {@link SoftwareModuleMetadataBuilder} object
*/

View File

@@ -23,6 +23,16 @@ import java.util.Set;
*/
public interface DistributionSet extends NamedVersionedEntity {
/**
* Maximum length of metadata key.
*/
int METADATA_KEY_SIZE = 128;
/**
* Maximum length of metadata value.
*/
int METADATA_VALUE_SIZE = 4000;
/**
* @return type of the {@link DistributionSet}.
*/

View File

@@ -1,26 +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.model;
/**
* {@link MetaData} of a {@link DistributionSet}.
*/
public interface DistributionSetMetadata extends MetaData {
/**
* @return {@link DistributionSet} of this {@link MetaData} entry.
*/
DistributionSet getDistributionSet();
@Override
default Long getEntityId() {
return getDistributionSet().getId();
}
}