TargetType management over common RepositoryManagement (#2581)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-08-01 19:24:49 +03:00
committed by GitHub
parent c79e35b9de
commit a689733d4c
40 changed files with 435 additions and 762 deletions

View File

@@ -92,10 +92,12 @@ public interface DistributionSetTypeManagement<T extends DistributionSetType>
@ToString(callSuper = true)
final class Create extends UpdateCreate {
@ValidString
@Size(min = 1, max = Type.KEY_MAX_SIZE)
@NotNull
private String key;
@ValidString
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
@NotNull
private String name;

View File

@@ -14,7 +14,6 @@ import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
import org.eclipse.hawkbit.repository.builder.TargetFilterQueryBuilder;
import org.eclipse.hawkbit.repository.builder.TargetTypeBuilder;
import org.eclipse.hawkbit.repository.model.BaseEntity;
/**
@@ -42,11 +41,6 @@ public interface EntityFactory {
*/
TargetBuilder target();
/**
* @return {@link TargetTypeBuilder} object
*/
TargetTypeBuilder targetType();
/**
* @return {@link TargetFilterQueryBuilder} object
*/

View File

@@ -52,10 +52,12 @@ public interface SoftwareModuleTypeManagement<T extends SoftwareModuleType>
@ToString(callSuper = true)
final class Create extends UpdateCreate {
@ValidString
@Size(min = 1, max = Type.KEY_MAX_SIZE)
@NotNull
private String key;
@ValidString
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
@NotNull
private String name;

View File

@@ -43,13 +43,13 @@ public interface TargetTagManagement<T extends TargetTag>
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
final class Create extends DistributionSetTagManagement.UpdateCreate {}
final class Create extends UpdateCreate {}
@SuperBuilder
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
final class Update extends DistributionSetTagManagement.UpdateCreate implements Identifiable<Long> {
final class Update extends UpdateCreate implements Identifiable<Long> {
@NotNull
private Long id;

View File

@@ -12,26 +12,29 @@ package org.eclipse.hawkbit.repository;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.BRACKET_CLOSE;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.BRACKET_OPEN;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_AND;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_CREATE_TARGET_TYPE;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_DELETE_TARGET_TYPE;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_PREFIX;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_READ_TARGET_TYPE;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_SUFFIX;
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET_TYPE;
import java.util.Collection;
import java.util.List;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.builder.TargetTypeCreate;
import org.eclipse.hawkbit.repository.builder.TargetTypeUpdate;
import org.eclipse.hawkbit.repository.exception.TargetTypeKeyOrNameRequiredException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.springframework.data.domain.Page;
import org.eclipse.hawkbit.repository.model.Type;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -39,7 +42,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
/**
* Management service for {@link TargetType}s.
*/
public interface TargetTypeManagement {
public interface TargetTypeManagement<T extends TargetType>
extends RepositoryManagement<T, TargetTypeManagement.Create, TargetTypeManagement.Update> {
String HAS_AUTH_READ_DISTRIBUTION_SET_AND_UPDATE_TARGET_TYPE = BRACKET_OPEN +
HAS_AUTH_PREFIX + SpPermission.READ_DISTRIBUTION_SET + HAS_AUTH_SUFFIX +
@@ -47,6 +51,11 @@ public interface TargetTypeManagement {
HAS_AUTH_PREFIX + SpPermission.UPDATE_TARGET_TYPE + HAS_AUTH_SUFFIX +
BRACKET_CLOSE;
@Override
default String permissionGroup() {
return "TARGET_TYPE";
}
/**
* @param key as {@link TargetType#getKey()}
* @return {@link TargetType}
@@ -61,12 +70,6 @@ public interface TargetTypeManagement {
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
Optional<TargetType> getByName(@NotEmpty String name);
/**
* @return total count
*/
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
long count();
/**
* @param name as {@link TargetType#getName()}
* @return total count by name
@@ -74,41 +77,6 @@ public interface TargetTypeManagement {
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
long countByName(String name);
/**
* @param create TargetTypeCreate
* @return targetType
*/
@PreAuthorize(HAS_AUTH_CREATE_TARGET_TYPE)
TargetType create(@NotNull @Valid TargetTypeCreate create);
/**
* @param creates List of TargetTypeCreate
* @return List of targetType
*/
@PreAuthorize(HAS_AUTH_CREATE_TARGET_TYPE)
List<TargetType> create(@NotEmpty @Valid Collection<TargetTypeCreate> creates);
/**
* @param id targetTypeId
*/
@PreAuthorize(HAS_AUTH_DELETE_TARGET_TYPE)
void delete(@NotNull Long id);
/**
* @param pageable Page
* @return TargetType page
*/
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
Slice<TargetType> findAll(@NotNull Pageable pageable);
/**
* @param rsql query param
* @param pageable Page
* @return Target type
*/
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
Page<TargetType> findByRsql(@NotEmpty String rsql, @NotNull Pageable pageable);
/**
* Retrieves {@link TargetType}s by filtering on the given parameters.
*
@@ -119,27 +87,6 @@ public interface TargetTypeManagement {
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
Slice<TargetType> findByName(String name, @NotNull Pageable pageable);
/**
* @param id Target type ID
* @return Target Type
*/
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
Optional<TargetType> get(long id);
/**
* @param ids List of Target type ID
* @return Target type list
*/
@PreAuthorize(HAS_AUTH_READ_TARGET_TYPE)
List<TargetType> get(@NotEmpty Collection<Long> ids);
/**
* @param update TargetTypeUpdate
* @return Target Type
*/
@PreAuthorize(HAS_AUTH_UPDATE_TARGET_TYPE)
TargetType update(@NotNull @Valid TargetTypeUpdate update);
/**
* @param id Target type ID
* @param distributionSetTypeIds Distribution set ID
@@ -155,4 +102,60 @@ public interface TargetTypeManagement {
*/
@PreAuthorize(HAS_AUTH_READ_DISTRIBUTION_SET_AND_UPDATE_TARGET_TYPE)
TargetType unassignDistributionSetType(long id, long distributionSetTypeIds);
@SuperBuilder
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
final class Create extends UpdateCreate {
@ValidString
@Size(min = 1, max = Type.KEY_MAX_SIZE)
@NotNull
private String key;
@ValidString
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
@NotNull
private String name;
private Set<DistributionSetType> distributionSetTypes;
private Create(final CreateBuilder<?, ?> builder) {
super(builder);
if (builder.key == null && builder.name == null) {
throw new TargetTypeKeyOrNameRequiredException("Key or name of the target type shall be specified!");
}
key = builder.key == null ? builder.name : builder.key;
name = builder.name == null ? builder.key : builder.name;
this.distributionSetTypes = builder.distributionSetTypes == null ? Collections.emptySet() : builder.distributionSetTypes;
}
}
@SuperBuilder
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
final class Update extends UpdateCreate implements Identifiable<Long> {
@NotNull
private Long id;
@ValidString
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
private String name;
}
@SuperBuilder
@Getter
class UpdateCreate {
@ValidString
@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE)
private String description;
@ValidString
@Size(max = Type.COLOUR_MAX_SIZE)
private String colour;
}
}

View File

@@ -1,29 +0,0 @@
/**
* Copyright (c) 2021 Bosch.IO 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.builder;
import org.eclipse.hawkbit.repository.model.TargetType;
/**
* Builder for {@link TargetType}.
*/
public interface TargetTypeBuilder {
/**
* @param id of the updatable entity
* @return builder instance
*/
TargetTypeUpdate update(long id);
/**
* @return builder instance
*/
TargetTypeCreate create();
}

View File

@@ -1,83 +0,0 @@
/**
* Copyright (c) 2021 Bosch.IO 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.builder;
import java.util.Collection;
import java.util.Collections;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.Type;
/**
* Builder to create a new {@link TargetType} entry. Defines all fields
* that can be set at creation time. Other fields are set by the repository
* automatically, e.g. {@link BaseEntity#getCreatedAt()}.
*/
public interface TargetTypeCreate {
/**
* @param name for {@link TargetType#getName()}
* @return updated builder instance
*/
TargetTypeCreate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotEmpty String name);
/**
* @param description for {@link TargetType#getDescription()}
* @return updated builder instance
*/
TargetTypeCreate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
/**
* @param key for {@link TargetType#getName()}
* @return updated builder instance
*/
TargetTypeCreate key(@Size(min = 1, max = Type.KEY_MAX_SIZE) @NotEmpty String key);
/**
* @param colour for {@link TargetType#getColour()}
* @return updated builder instance
*/
TargetTypeCreate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
/**
* @param compatible for {@link TargetType#getCompatibleDistributionSetTypes()}
* @return updated builder instance
*/
TargetTypeCreate compatible(@NotEmpty Collection<Long> compatible);
/**
* @param compatible for {@link TargetType#getCompatibleDistributionSetTypes()}
* @return updated builder instance
*/
default TargetTypeCreate compatible(@NotNull final Long compatible) {
return compatible(Collections.singletonList(compatible));
}
/**
* @param compatible for {@link TargetType#getCompatibleDistributionSetTypes()}
* @return updated builder instance
*/
default TargetTypeCreate compatible(@NotNull final DistributionSetType compatible) {
return compatible(compatible.getId());
}
/**
* @return peek on current state of {@link TargetType} in the
* builder
*/
TargetType build();
}

View File

@@ -1,41 +0,0 @@
/**
* Copyright (c) 2021 Bosch.IO 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.builder;
import jakarta.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.Type;
/**
* Builder to update an existing {@link TargetType} entry. Defines all
* fields that can be updated.
*/
public interface TargetTypeUpdate {
/**
* @param description for {@link TargetType#getDescription()}
* @return updated builder instance
*/
TargetTypeUpdate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
/**
* @param colour for {@link TargetType#getColour()}
* @return updated builder instance
*/
TargetTypeUpdate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
/**
* @param name Name
* @return updated builder instance
*/
TargetTypeUpdate name(@Size(max = NamedEntity.NAME_MAX_SIZE) String name);
}

View File

@@ -28,20 +28,11 @@ public interface TargetType extends Type {
}
/**
* Gets compatible distribution set types
*
* @return immutable set of optional {@link DistributionSetType}s
*/
Set<DistributionSetType> getCompatibleDistributionSetTypes();
/**
* Checks if the given {@link DistributionSetType} is in
* {@link #getCompatibleDistributionSetTypes()}.
*
* @param distributionSetTypeId search by {@link DistributionSetType#getId()}
* @return <code>true</code> if found
*/
default boolean containsCompatibleDistributionSetType(final Long distributionSetTypeId) {
return getCompatibleDistributionSetTypes().stream().anyMatch(element -> element.getId().equals(distributionSetTypeId));
}
Set<DistributionSetType> getDistributionSetTypes();
/**
* Unassigns a {@link DistributionSetType} from {@link TargetType}
@@ -49,5 +40,5 @@ public interface TargetType extends Type {
* @param dsTypeId that will be removed from {@link TargetType}
* @return the resulting target type
*/
TargetType removeDistributionSetType(final Long dsTypeId);
void removeDistributionSetType(final Long dsTypeId);
}