Implement target tag management using common RepositoryManagement (and abstract JPA impl) (#2580)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -12,16 +12,13 @@ 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.TagBuilder;
|
||||
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;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
|
||||
/**
|
||||
* central {@link BaseEntity} generation service. Objects are created but not
|
||||
* persisted.
|
||||
* Central {@link BaseEntity} generation service. Objects are created but not persisted.
|
||||
*/
|
||||
public interface EntityFactory {
|
||||
|
||||
@@ -30,11 +27,6 @@ public interface EntityFactory {
|
||||
*/
|
||||
ActionStatusBuilder actionStatus();
|
||||
|
||||
/**
|
||||
* @return {@link TagBuilder} object
|
||||
*/
|
||||
TagBuilder<Tag> tag();
|
||||
|
||||
/**
|
||||
* @return {@link RolloutGroupBuilder} object
|
||||
*/
|
||||
|
||||
@@ -83,7 +83,7 @@ public interface RepositoryManagement<T extends BaseEntity, C, U extends Identif
|
||||
* @return all {@link BaseEntity}s in the repository.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||
Slice<T> findAll(@NotNull Pageable pageable);
|
||||
Page<T> findAll(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link BaseEntity}s with a given specification.
|
||||
|
||||
@@ -9,129 +9,67 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
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.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TagUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
* Management service for {@link TargetTag}s.
|
||||
*/
|
||||
public interface TargetTagManagement {
|
||||
public interface TargetTagManagement<T extends TargetTag>
|
||||
extends RepositoryManagement<T, TargetTagManagement.Create, TargetTagManagement.Update> {
|
||||
|
||||
/**
|
||||
* Count {@link TargetTag}s.
|
||||
*
|
||||
* @return size of {@link TargetTag}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
long count();
|
||||
@Override
|
||||
default String permissionGroup() {
|
||||
return "TARGET";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link TargetTag}.
|
||||
*
|
||||
* @param create to be created
|
||||
* @return the new created {@link TargetTag}
|
||||
* @throws EntityAlreadyExistsException if given object already exists
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TagCreate} for field constraints.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
|
||||
TargetTag create(@NotNull @Valid TagCreate<Tag> create);
|
||||
|
||||
/**
|
||||
* Created multiple {@link TargetTag}s.
|
||||
*
|
||||
* @param creates to be created
|
||||
* @return the new created {@link TargetTag}s
|
||||
* @throws EntityAlreadyExistsException if given object has already an ID.
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TagCreate} for field constraints.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
|
||||
List<TargetTag> create(@NotNull @Valid Collection<TagCreate<Tag>> creates);
|
||||
|
||||
/**
|
||||
* Deletes {@link TargetTag} with given name.
|
||||
*
|
||||
* @param targetTagName tag name of the {@link TargetTag} to be deleted
|
||||
* @throws EntityNotFoundException if tag with given name does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
|
||||
void delete(@NotEmpty String targetTagName);
|
||||
|
||||
/**
|
||||
* returns all {@link TargetTag}s.
|
||||
*
|
||||
* @param pageable page parameter
|
||||
* @return all {@link TargetTag}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetTag> findAll(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all target tags based on the given specification.
|
||||
*
|
||||
* @param rsql rsql query string
|
||||
* @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(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetTag> findByRsql(@NotNull String rsql, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Find {@link TargetTag} based on given Name.
|
||||
*
|
||||
* @param name to look for.
|
||||
* @return {@link TargetTag}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||
Optional<TargetTag> getByName(@NotEmpty String name);
|
||||
|
||||
/**
|
||||
* Finds {@link TargetTag} by given id.
|
||||
*
|
||||
* @param id to search for
|
||||
* @return the found {@link TargetTag}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Optional<TargetTag> get(long id);
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
final class Create extends DistributionSetTagManagement.UpdateCreate {}
|
||||
|
||||
/**
|
||||
* Finds {@link TargetTag} by given ids.
|
||||
*
|
||||
* @param ids the ids to for
|
||||
* @return the found {@link TargetTag}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
List<TargetTag> get(@NotEmpty Collection<Long> ids);
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
final class Update extends DistributionSetTagManagement.UpdateCreate implements Identifiable<Long> {
|
||||
|
||||
/**
|
||||
* Updates the {@link TargetTag}.
|
||||
*
|
||||
* @param update the {@link TargetTag} with updated values
|
||||
* @return the updated {@link TargetTag}
|
||||
* @throws EntityNotFoundException in case the {@link TargetTag} does not exist and cannot be updated
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TagUpdate} for field constraints.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||
TargetTag update(@NotNull @Valid TagUpdate update);
|
||||
@NotNull
|
||||
private Long id;
|
||||
}
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
class UpdateCreate {
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
|
||||
@NotNull(groups = DistributionSetTagManagement.Create.class)
|
||||
private String name;
|
||||
|
||||
@ValidString
|
||||
@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE)
|
||||
private String description;
|
||||
|
||||
@ValidString
|
||||
@Size(max = Tag.COLOUR_MAX_SIZE)
|
||||
private String colour;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +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 org.eclipse.hawkbit.repository.model.Tag;
|
||||
|
||||
/**
|
||||
* Builder for {@link Tag}.
|
||||
*/
|
||||
public interface TagBuilder<T extends Tag> {
|
||||
|
||||
/**
|
||||
* @param id of the updatable entity
|
||||
* @return builder instance
|
||||
*/
|
||||
TagUpdate update(long id);
|
||||
|
||||
/**
|
||||
* @return builder instance
|
||||
*/
|
||||
TagCreate<T> create();
|
||||
}
|
||||
@@ -1,48 +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.Tag;
|
||||
|
||||
/**
|
||||
* Builder to create a new {@link Tag} 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 TagCreate<T extends Tag> {
|
||||
|
||||
/**
|
||||
* @param name for {@link Tag#getName()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TagCreate<T> name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param description for {@link Tag#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TagCreate<T> description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param colour for {@link Tag#getColour()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TagCreate<T> colour(@Size(max = Tag.COLOUR_MAX_SIZE) String colour);
|
||||
|
||||
/**
|
||||
* @return peek on current state of {@link Tag} in the builder
|
||||
*/
|
||||
T build();
|
||||
}
|
||||
@@ -1,41 +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.Tag;
|
||||
|
||||
/**
|
||||
* Builder to update an existing {@link Tag} entry. Defines all fields that can
|
||||
* be updated.
|
||||
*/
|
||||
public interface TagUpdate {
|
||||
|
||||
/**
|
||||
* @param name for {@link Tag#getName()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TagUpdate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param description for {@link Tag#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TagUpdate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param colour for {@link Tag#getColour()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TagUpdate colour(@Size(max = Tag.COLOUR_MAX_SIZE) String colour);
|
||||
}
|
||||
Reference in New Issue
Block a user