TargetManagement over RepositoryManagement (#2599)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
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.model.BaseEntity;
|
||||
|
||||
/**
|
||||
@@ -20,11 +19,6 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
*/
|
||||
public interface EntityFactory {
|
||||
|
||||
/**
|
||||
* @return {@link TargetBuilder} object
|
||||
*/
|
||||
TargetBuilder target();
|
||||
|
||||
/**
|
||||
* @return {@link ActionStatusBuilder} object
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* 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;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds the {@link SecurityTokenGenerator} and make it
|
||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class SecurityTokenGeneratorHolder {
|
||||
|
||||
private static final SecurityTokenGeneratorHolder SINGLETON = new SecurityTokenGeneratorHolder();
|
||||
|
||||
private SecurityTokenGenerator securityTokenGenerator;
|
||||
|
||||
/**
|
||||
* @return a singleton instance of the security token generator holder.
|
||||
*/
|
||||
public static SecurityTokenGeneratorHolder getInstance() {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setSecurityTokenGenerator(final SecurityTokenGenerator securityTokenGenerator) {
|
||||
this.securityTokenGenerator = securityTokenGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* delegates to {@link SecurityTokenGenerator#generateToken()}.
|
||||
*
|
||||
* @return the result {@link SecurityTokenGenerator#generateToken()}
|
||||
*/
|
||||
public String generateToken() {
|
||||
return securityTokenGenerator.generateToken();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ 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;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_DELETE_TARGET;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_PREFIX;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET;
|
||||
@@ -28,15 +27,17 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
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.im.authentication.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
@@ -44,6 +45,7 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
@@ -55,16 +57,17 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Management service for {@link Target}s.
|
||||
*/
|
||||
public interface TargetManagement extends PermissionSupport {
|
||||
public interface TargetManagement<T extends Target>
|
||||
extends RepositoryManagement<T, TargetManagement.Create, TargetManagement.Update> {
|
||||
|
||||
String DETAILS_BASE = "base";
|
||||
String DETAILS_AUTO_CONFIRMATION_STATUS = "autoConfirmationStatus";
|
||||
String DETAILS_TAGS = "tags";
|
||||
String DETAILS_ACTIONS = "actions";
|
||||
|
||||
String HAS_AUTH_READ_DISTRIBUTION_SET_AND_READ_TARGET = BRACKET_OPEN +
|
||||
HAS_AUTH_PREFIX + SpPermission.READ_DISTRIBUTION_SET + HAS_AUTH_SUFFIX +
|
||||
@@ -119,15 +122,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_DISTRIBUTION_SET_AND_READ_TARGET)
|
||||
boolean existsByInstalledOrAssignedDistributionSet(long distributionSetId);
|
||||
|
||||
/**
|
||||
* Count {@link TargetFilterQuery}s for given target filter query.
|
||||
*
|
||||
* @param rsql filter definition in RSQL syntax
|
||||
* @return the found number of {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByRsql(@NotEmpty String rsql);
|
||||
|
||||
/**
|
||||
* Count {@link TargetFilterQuery}s for given target filter query with UPDATE permission.
|
||||
*
|
||||
@@ -149,18 +143,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByRsqlAndCompatible(@NotEmpty String rsql, @NotNull Long distributionSetIdTypeId);
|
||||
|
||||
/**
|
||||
* Count all targets for given {@link TargetFilterQuery} and that are compatible
|
||||
* with the passed {@link DistributionSetType} and UPDATE permission.
|
||||
*
|
||||
* @param rsql filter definition in RSQL syntax
|
||||
* @param distributionSetIdTypeId ID of the {@link DistributionSetType} the targets need to be
|
||||
* compatible with
|
||||
* @return the found number of{@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByRsqlAndCompatibleAndUpdatable(@NotEmpty String rsql, @NotNull Long distributionSetIdTypeId);
|
||||
|
||||
/**
|
||||
* Count all targets with failed actions for specific Rollout and that are
|
||||
* compatible with the passed {@link DistributionSetType} and created after
|
||||
@@ -184,48 +166,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByTargetFilterQuery(long targetFilterQueryId);
|
||||
|
||||
/**
|
||||
* Counts all {@link Target}s in the repository.
|
||||
*
|
||||
* @return number of targets
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long count();
|
||||
|
||||
/**
|
||||
* creating a new {@link Target}.
|
||||
*
|
||||
* @param create to be created
|
||||
* @return the created {@link Target}
|
||||
* @throws EntityAlreadyExistsException given target already exists.
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TargetCreate} for field constraints.
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_CREATE_TARGET)
|
||||
Target create(@NotNull @Valid TargetCreate create);
|
||||
|
||||
/**
|
||||
* creates multiple {@link Target}s. If the given {@link Target}s already exists
|
||||
* in the DB an {@link EntityAlreadyExistsException} is thrown. {@link Target}s
|
||||
* contain all objects of the parameter targets, including duplicates.
|
||||
*
|
||||
* @param creates to be created.
|
||||
* @return the created {@link Target}s
|
||||
* @throws EntityAlreadyExistsException of one of the given targets already exist.
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TargetCreate}
|
||||
* for field constraints.
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_CREATE_TARGET)
|
||||
List<Target> create(@NotNull @Valid Collection<TargetCreate> creates);
|
||||
|
||||
/**
|
||||
* Deletes all targets with the given IDs.
|
||||
*
|
||||
* @param ids the IDs of the targets to be deleted
|
||||
* @throws EntityNotFoundException if (at least one) of the given target IDs does not exist
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_DELETE_TARGET)
|
||||
void delete(@NotEmpty Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Deletes target with the given controller ID.
|
||||
*
|
||||
@@ -372,7 +312,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
* @return List of found{@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
List<Target> getByControllerID(@NotEmpty Collection<String> controllerIDs);
|
||||
List<Target> getByControllerId(@NotEmpty Collection<String> controllerIDs);
|
||||
|
||||
/**
|
||||
* Find a {@link Target} based a given ID.
|
||||
@@ -381,7 +321,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Optional<Target> getByControllerID(@NotEmpty String controllerId);
|
||||
Optional<Target> getByControllerId(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Gets a {@link Target} based a given controller id and includes the details specified by the details key.
|
||||
@@ -408,11 +348,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
return getWithDetails(controllerId, DETAILS_TAGS);
|
||||
}
|
||||
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
default Target getWithActions(@NotEmpty String controllerId) {
|
||||
return getWithDetails(controllerId, DETAILS_ACTIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter {@link Target}s for all the given parameters. If all parameters except
|
||||
* pageable are null, all available {@link Target}s are returned.
|
||||
@@ -463,28 +398,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findByUpdateStatus(@NotNull TargetUpdateStatus status, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all targets.
|
||||
*
|
||||
* @param pageable pagination parameter
|
||||
* @return the found {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Slice<Target> findAll(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all targets.
|
||||
*
|
||||
* @param rsql in RSQL notation
|
||||
* @param pageable pagination parameter
|
||||
* @return the found {@link Target}s, never {@code null}
|
||||
* @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
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Slice<Target> findByRsql(@NotNull String rsql, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all target based on {@link TargetFilterQuery}.
|
||||
*
|
||||
@@ -627,6 +540,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
|
||||
/**
|
||||
* Finds targets by group or subgroup.
|
||||
*
|
||||
* @param group - provided group/subgroup to filter for
|
||||
* @param withSubgroups - whether is a subgroup or not e.g. x/y/z
|
||||
* @param pageable - page parameter
|
||||
@@ -634,6 +548,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findTargetsByGroup(@NotEmpty String group, boolean withSubgroups, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Finds all the distinct target groups in the scope of a tenant
|
||||
*
|
||||
@@ -660,36 +575,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_UPDATE_TARGET)
|
||||
void assignTargetsWithGroup(String group, @NotEmpty List<String> controllerIds);
|
||||
|
||||
/**
|
||||
* updates the {@link Target}.
|
||||
*
|
||||
* @param update to be updated
|
||||
* @return the updated {@link Target}
|
||||
* @throws EntityNotFoundException if given target does not exist
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TargetUpdate}
|
||||
* for field constraints.
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_UPDATE_TARGET)
|
||||
Target update(@NotNull @Valid TargetUpdate update);
|
||||
|
||||
/**
|
||||
* Find a {@link Target} based a given ID.
|
||||
*
|
||||
* @param id to look for
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Optional<Target> get(long id);
|
||||
|
||||
/**
|
||||
* Retrieves all targets.
|
||||
*
|
||||
* @param ids the ids to for
|
||||
* @return the found {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
List<Target> get(@NotNull Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Verifies that {@link Target} with given controller ID exists in the repository.
|
||||
*
|
||||
@@ -801,4 +686,85 @@ public interface TargetManagement extends PermissionSupport {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_UPDATE_REPOSITORY)
|
||||
void deleteMetadata(@NotNull String controllerId, @NotEmpty String key);
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
final class Create extends UpdateCreate {
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = Target.CONTROLLER_ID_MAX_SIZE)
|
||||
@NotNull
|
||||
private String controllerId;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
|
||||
@NotNull(groups = Create.class)
|
||||
private String name;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@NotNull
|
||||
@ToString.Exclude
|
||||
private String securityToken;
|
||||
|
||||
// java:S1144 - constructor is actually used by SuperBuilder's build() method
|
||||
// java:S3358 - better readable that way
|
||||
@SuppressWarnings({ "java:S1144", "java:S3358" })
|
||||
private Create(final CreateBuilder<?, ?> builder) {
|
||||
super(builder);
|
||||
controllerId = builder.controllerId;
|
||||
// truncate controller ID to max name length (if too big)
|
||||
name = ObjectUtils.isEmpty(builder.name)
|
||||
? controllerId != null && controllerId.length() > NamedEntity.NAME_MAX_SIZE
|
||||
? controllerId.substring(0, NamedEntity.NAME_MAX_SIZE)
|
||||
: controllerId
|
||||
: builder.name;
|
||||
securityToken = ObjectUtils.isEmpty(builder.securityToken)
|
||||
? SecurityTokenGeneratorHolder.getInstance().generateToken()
|
||||
: builder.securityToken;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@ToString.Exclude
|
||||
private String securityToken;
|
||||
|
||||
private Boolean requestControllerAttributes;
|
||||
}
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
class UpdateCreate {
|
||||
|
||||
@ValidString
|
||||
@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE)
|
||||
private String description;
|
||||
|
||||
private TargetType targetType;
|
||||
|
||||
@Size(max = Target.ADDRESS_MAX_SIZE)
|
||||
private String address;
|
||||
|
||||
private Long lastTargetQuery;
|
||||
private TargetUpdateStatus updateStatus;
|
||||
|
||||
@ValidString
|
||||
private String group;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
@@ -19,11 +16,9 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.eclipse.hawkbit.im.authentication.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
* Management service for {@link TargetTag}s.
|
||||
@@ -58,7 +53,7 @@ public interface TargetTagManagement<T extends TargetTag>
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
|
||||
@NotNull(groups = DistributionSetTagManagement.Create.class)
|
||||
@NotNull(groups = Create.class)
|
||||
private String name;
|
||||
|
||||
@ValidString
|
||||
|
||||
@@ -35,8 +35,6 @@ 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;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
@@ -112,7 +110,7 @@ public interface TargetTypeManagement<T extends TargetType>
|
||||
}
|
||||
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;
|
||||
distributionSetTypes = builder.distributionSetTypes == null ? Collections.emptySet() : builder.distributionSetTypes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +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.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
/**
|
||||
* Builder for {@link Target}.
|
||||
*/
|
||||
public interface TargetBuilder {
|
||||
|
||||
/**
|
||||
* @param controllerId of the updatable entity
|
||||
* @return builder instance
|
||||
*/
|
||||
TargetUpdate update(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* @return builder instance
|
||||
*/
|
||||
TargetCreate create();
|
||||
}
|
||||
@@ -1,86 +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.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
* Builder to create a new {@link Target} 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 TargetCreate {
|
||||
|
||||
/**
|
||||
* @param controllerId for {@link Target#getControllerId()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate controllerId(@Size(min = 1, max = Target.CONTROLLER_ID_MAX_SIZE) @NotNull String controllerId);
|
||||
|
||||
/**
|
||||
* @param name for {@link Target#getName()} filled with {@link #controllerId(String)} as default if not set explicitly
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param description for {@link Target#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param targetTypeId for {@link Target#getTargetType()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate targetType(Long targetTypeId);
|
||||
|
||||
/**
|
||||
* @param securityToken for {@link Target#getSecurityToken()} is generated with a random sequence as default if not set explicitly
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate securityToken(@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE) @NotNull String securityToken);
|
||||
|
||||
/**
|
||||
* @param address for {@link Target#getAddress()}
|
||||
* @return updated builder instance
|
||||
* @throws IllegalArgumentException If the given string violates RFC 2396
|
||||
*/
|
||||
TargetCreate address(@Size(max = Target.ADDRESS_MAX_SIZE) String address);
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery for {@link Target#getLastTargetQuery()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate lastTargetQuery(Long lastTargetQuery);
|
||||
|
||||
/**
|
||||
* @param status for {@link Target#getUpdateStatus()} is {@link TargetUpdateStatus#UNKNOWN} as default if not set explicitly
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate status(@NotNull TargetUpdateStatus status);
|
||||
|
||||
/**
|
||||
* @param group for setting the group of the target
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate group(String group);
|
||||
|
||||
/**
|
||||
* @return peek on current state of {@link Target} in the builder
|
||||
*/
|
||||
Target build();
|
||||
}
|
||||
@@ -1,80 +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.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
* Builder to update an existing {@link Target} entry. Defines all fields that
|
||||
* can be updated.
|
||||
*/
|
||||
public interface TargetUpdate {
|
||||
|
||||
/**
|
||||
* @param name for {@link Target#getName()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param description for {@link Target#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param securityToken for {@link Target#getSecurityToken()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate securityToken(@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE) @NotNull String securityToken);
|
||||
|
||||
/**
|
||||
* @param targetTypeId for {@link Target#getTargetType()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate targetType(@NotNull Long targetTypeId);
|
||||
|
||||
/**
|
||||
* @param address for {@link Target#getAddress()}
|
||||
* @return updated builder instance
|
||||
* @throws IllegalArgumentException If the given string violates RFC 2396
|
||||
*/
|
||||
TargetUpdate address(@Size(max = Target.ADDRESS_MAX_SIZE) String address);
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery for {@link Target#getLastTargetQuery()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate lastTargetQuery(Long lastTargetQuery);
|
||||
|
||||
/**
|
||||
* @param status for {@link Target#getUpdateStatus()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate status(@NotNull TargetUpdateStatus status);
|
||||
|
||||
/**
|
||||
* @param requestAttributes for {@link Target#isRequestControllerAttributes()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate requestAttributes(Boolean requestAttributes);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param group for {@link Target#getGroup()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate group(String group);
|
||||
}
|
||||
@@ -9,18 +9,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The {@link Target} is the target of all provisioning operations. It contains
|
||||
* the currently installed {@link DistributionSet} (i.e. current state). In
|
||||
* addition it holds the target {@link DistributionSet} that has to be
|
||||
* provisioned next (i.e. target state).
|
||||
* </p>
|
||||
* The {@link Target} is the target of all provisioning operations. It contains the currently installed {@link DistributionSet}
|
||||
* (i.e. current state). In addition, it holds the target {@link DistributionSet} that has to be provisioned next (i.e. target state).
|
||||
*/
|
||||
public interface Target extends NamedEntity {
|
||||
public interface Target extends NamedEntity, Identifiable<Long> {
|
||||
|
||||
/**
|
||||
* Maximum length of controllerId.
|
||||
@@ -79,7 +76,7 @@ public interface Target extends NamedEntity {
|
||||
/**
|
||||
* @return the address under which the target can be reached
|
||||
*/
|
||||
URI getAddress();
|
||||
String getAddress();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when the {@link Target} polled the server the last time or <code>null</code> if target
|
||||
@@ -88,8 +85,7 @@ public interface Target extends NamedEntity {
|
||||
Long getLastTargetQuery();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when
|
||||
* {@link #getInstalledDistributionSet()} was applied.
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when {@link #getInstalledDistributionSet()} was applied.
|
||||
*/
|
||||
Long getInstallationDate();
|
||||
|
||||
@@ -104,10 +100,8 @@ public interface Target extends NamedEntity {
|
||||
TargetType getTargetType();
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the
|
||||
* next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled
|
||||
* before this method returns {@code null}
|
||||
* @return the poll time which holds the last poll time of the target, the next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled before this method returns {@code null}
|
||||
*/
|
||||
PollStatus getPollStatus();
|
||||
|
||||
@@ -120,8 +114,7 @@ public interface Target extends NamedEntity {
|
||||
AutoConfirmationStatus getAutoConfirmationStatus();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the {@link Target} has not jet provided
|
||||
* {@link #getControllerAttributes()}.
|
||||
* @return <code>true</code> if the {@link Target} has not yet provided {@link #getControllerAttributes()}.
|
||||
*/
|
||||
boolean isRequestControllerAttributes();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user