Refactoring of RepostioryManagement and extending classes (#2174)

* createMetaData renamed to putMetaData
* getXXX methods returing Optional are renamed to findXXX
* unified method order (code cosmetics)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-08 14:03:04 +02:00
committed by GitHub
parent cad18fe04b
commit 6504bc26d9
55 changed files with 942 additions and 986 deletions

View File

@@ -36,8 +36,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Statistic;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
@@ -46,8 +44,35 @@ import org.springframework.security.access.prepost.PreAuthorize;
/**
* Management service for {@link DistributionSet}s.
*/
public interface DistributionSetManagement
extends RepositoryManagement<DistributionSet, DistributionSetCreate, DistributionSetUpdate> {
public interface DistributionSetManagement extends RepositoryManagement<DistributionSet, DistributionSetCreate, DistributionSetUpdate> {
/**
* Find {@link DistributionSet} based on given ID including (lazy loaded) details, e.g. {@link DistributionSet#getModules()}. <br/>
* For performance reasons it is recommended to use {@link #get(long)} if the details are not required.
*
* @param id to look for.
* @return {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSet> getWithDetails(long id);
/**
* Find distribution set by id and throw an exception if it is (soft) deleted.
*
* @param id id of {@link DistributionSet}
* @return the found valid {@link DistributionSet}
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSet getOrElseThrowException(long id);
/**
* Sets the specified {@link DistributionSet} as invalidated.
*
* @param distributionSet the ID of the {@link DistributionSet} to be set to invalid
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void invalidate(DistributionSet distributionSet);
/**
* Assigns {@link SoftwareModule} to existing {@link DistributionSet}.
@@ -56,25 +81,34 @@ public interface DistributionSetManagement
* @param moduleIds to get assigned
* @return the updated {@link DistributionSet}.
* @throws EntityNotFoundException if (at least one) given module does not exist
* @throws EntityReadOnlyException if use tries to change the {@link DistributionSet} s while
* the DS is already in use.
* @throws EntityReadOnlyException if tries to change the {@link DistributionSet} s while the DS is already in use.
* @throws UnsupportedSoftwareModuleForThisDistributionSetException if {@link SoftwareModule#getType()} is not supported by this
* {@link DistributionSet#getType()}.
* @throws AssignmentQuotaExceededException if the maximum number of {@link SoftwareModule}s is exceeded
* for the addressed {@link DistributionSet}.
* @throws AssignmentQuotaExceededException if the maximum number of {@link SoftwareModule}s is exceeded for the addressed
* {@link DistributionSet}.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSet assignSoftwareModules(long id, @NotEmpty Collection<Long> moduleIds);
/**
* Assign a {@link DistributionSetTag} assignment to given
* {@link DistributionSet}s.
* Unassigns a {@link SoftwareModule} form an existing {@link DistributionSet}.
*
* @param id to get unassigned form
* @param moduleId to be unassigned
* @return the updated {@link DistributionSet}.
* @throws EntityNotFoundException if given module or DS does not exist
* @throws EntityReadOnlyException if use tries to change the {@link DistributionSet} s while the DS is already in use.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSet unassignSoftwareModule(long id, long moduleId);
/**
* Assign a {@link DistributionSetTag} assignment to given {@link DistributionSet}s.
*
* @param ids to assign for
* @param tagId to assign
* @return list of assigned ds
* @throws EntityNotFoundException if tag with given ID does not exist or (at least one) of the
* distribution sets.
* @throws EntityNotFoundException if tag with given ID does not exist or (at least one) of the distribution sets.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<DistributionSet> assignTag(@NotEmpty Collection<Long> ids, long tagId);
@@ -91,34 +125,42 @@ public interface DistributionSetManagement
List<DistributionSet> unassignTag(@NotEmpty Collection<Long> ids, long tagId);
/**
* Creates a list of distribution set meta data entries.
* Creates a list 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
* @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}
* @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> createMetaData(long id, @NotEmpty Collection<MetaData> metadata);
List<DistributionSetMetadata> putMetaData(long id, @NotEmpty Collection<MetaData> metadata);
/**
* Deletes a distribution set meta data entry.
* Updates a distribution set meta-data value if corresponding entry exists.
*
* @param id where meta data has to be deleted
* @param key of the meta data element
* @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
* @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);
/**
* Deletes a distribution set meta-data entry.
*
* @param id where meta-data has to be deleted
* @param key of the meta-data element
* @throws EntityNotFoundException if given set does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
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
* Locks a distribution set. From then on its functional properties could not be changed, and it could be assigned to targets
*
* @param id the distribution set id
* @throws EntityNotFoundException if distribution set with given ID does not exist
@@ -128,8 +170,8 @@ public interface DistributionSetManagement
/**
* Unlocks a distribution set.<br/>
* Use it with extreme care! In general once distribution set is locked
* it shall not be unlocked. Note that it could have been assigned / deployed to targets.
* Use it with extreme care! In general once distribution set is locked it shall not be unlocked. Note that it could have been assigned /
* deployed to targets.
*
* @param id the distribution set id
* @throws EntityNotFoundException if distribution set with given ID does not exist
@@ -138,41 +180,18 @@ public interface DistributionSetManagement
void unlock(final long id);
/**
* Retrieves the distribution set for a given action.
* Find distribution set by id and throw an exception if it is deleted or invalidated.
*
* @param actionId the action associated with the distribution set
* @return the distribution set which is associated with the action
* @throws EntityNotFoundException if action with given ID does not exist
* @param id id of {@link DistributionSet}
* @return the found valid {@link DistributionSet}
* @throws EntityNotFoundException if distribution set with given ID does not exist
* @throws InvalidDistributionSetException if distribution set with given ID is invalidated
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSet> getByAction(long actionId);
DistributionSet getValid(long id);
/**
* Find {@link DistributionSet} based on given ID including (lazy loaded)
* details, e.g. {@link DistributionSet#getModules()}.
*
* Note: for performance reasons it is recommended to use {@link #get(Long)}
* if details are not necessary.
*
* @param id to look for.
* @return {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSet> getWithDetails(long id);
/**
* Find distribution set by name and version.
*
* @param distributionName name of {@link DistributionSet}; case insensitive
* @param version version of {@link DistributionSet}
* @return the page with the found {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSet> getByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version);
/**
* Find distribution set by id and throw an exception if it is deleted,
* incomplete or invalidated.
* Find distribution set by id and throw an exception if it is deleted, incomplete or invalidated.
*
* @param id id of {@link DistributionSet}
* @return the found valid {@link DistributionSet}
@@ -184,73 +203,57 @@ public interface DistributionSetManagement
DistributionSet getValidAndComplete(long id);
/**
* Find distribution set by id and throw an exception if it is deleted or
* invalidated.
* Retrieves the distribution set for a given action.
*
* @param id id of {@link DistributionSet}
* @return the found valid {@link DistributionSet}
* @throws EntityNotFoundException if distribution set with given ID does not exist
* @throws InvalidDistributionSetException if distribution set with given ID is invalidated
* @param actionId the action associated with the distribution set
* @return the distribution set which is associated with the action
* @throws EntityNotFoundException if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSet getValid(long id);
Optional<DistributionSet> findByAction(long actionId);
/**
* Find distribution set by id and throw an exception if it is (soft)
* deleted.
* Find distribution set by name and version.
*
* @param id id of {@link DistributionSet}
* @return the found valid {@link DistributionSet}
* @throws EntityNotFoundException if distribution set with given ID does not exist
* @param distributionName name of {@link DistributionSet}; case insensitive
* @param version version of {@link DistributionSet}
* @return the page with the found {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSet getOrElseThrowException(long id);
Optional<DistributionSet> findByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version);
/**
* Finds all meta data by the given distribution set id.
* 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
* @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
* @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(@NotNull Pageable pageable, long id);
Page<DistributionSetMetadata> findMetaDataByDistributionSetId(long id, @NotNull Pageable pageable);
/**
* Counts all meta data by the given distribution set id.
* Finds 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);
/**
* Finds all meta data by the given distribution set id.
*
* @param pageable the page request to page the result
* @param id the distribution set id to retrieve the meta data from
* @param id the distribution set id to retrieve the meta-data from
* @param rsqlParam rsql query string
* @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}
* @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(@NotNull Pageable pageable,
long id, @NotNull String rsqlParam);
Page<DistributionSetMetadata> findMetaDataByDistributionSetIdAndRsql(long id, @NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Finds all {@link DistributionSet}s based on completeness.
*
* @param pageable the pagination parameter
* @param complete to <code>true</code> for returning only completed distribution
* sets or <code>false</code> for only incomplete ones nor
* @param complete to <code>true</code> for returning only completed distribution sets or <code>false</code> for only incomplete ones nor
* <code>null</code> to return both.
* @return all found {@link DistributionSet}s
*/
@@ -258,26 +261,69 @@ public interface DistributionSetManagement
Slice<DistributionSet> findByCompleted(@NotNull Pageable pageable, Boolean complete);
/**
* Counts all {@link DistributionSet}s based on completeness.
* Retrieves {@link DistributionSet}s by filtering on the given parameters.
*
* @param complete to <code>true</code> for counting only completed distribution
* sets or <code>false</code> for only incomplete ones nor
* <code>null</code> to count both.
* @return count of all found {@link DistributionSet}s
* @param distributionSetFilter has details of filters to be applied.
* @param pageable page parameter
* @return the page of found {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countByCompleted(Boolean complete);
Slice<DistributionSet> findByDistributionSetFilter(@NotNull DistributionSetFilter distributionSetFilter, @NotNull Pageable pageable);
/**
* Retrieves {@link DistributionSet}s by filtering on the given parameters.
*
* @param tagId of the tag the DS are assigned to
* @param pageable page parameter
* @param distributionSetFilter has details of filters to be applied.
* @return the page of found {@link DistributionSet}
* @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 tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<DistributionSet> findByDistributionSetFilter(@NotNull Pageable pageable,
@NotNull DistributionSetFilter distributionSetFilter);
Page<DistributionSet> findByTag(long tagId, @NotNull Pageable pageable);
/**
* Retrieves {@link DistributionSet}s by filtering on the given parameters.
*
* @param rsqlParam rsql query string
* @param tagId of the tag the DS are assigned to
* @param pageable page parameter
* @return the page of found {@link DistributionSet}
* @throws EntityNotFoundException of distribution set tag with given ID does not exist
*/
@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.
*
* @param complete to <code>true</code> for counting only completed distribution sets or <code>false</code> for only incomplete ones
* nor <code>null</code> to count both.
* @return count of all found {@link DistributionSet}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countByCompleted(Boolean complete);
/**
* Counts all {@link DistributionSet}s in repository based on given filter.
@@ -289,41 +335,15 @@ public interface DistributionSetManagement
long countByDistributionSetFilter(@NotNull DistributionSetFilter distributionSetFilter);
/**
* Retrieves {@link DistributionSet}s by filtering on the given parameters.
* Count all {@link DistributionSet}s in the repository that are not marked
* as deleted.
*
* @param pageable page parameter
* @param tagId of the tag the DS are assigned to
* @return the page of found {@link DistributionSet}
* @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 tag with given ID does not exist
* @param typeId to look for
* @return number of {@link DistributionSet}s
* @throws EntityNotFoundException if type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSet> findByTag(@NotNull Pageable pageable, long tagId);
/**
* Retrieves {@link DistributionSet}s by filtering on the given parameters.
*
* @param pageable page parameter
* @param rsqlParam rsql query string
* @param tagId of the tag the DS are assigned to
* @return the page of found {@link DistributionSet}
* @throws EntityNotFoundException of distribution set tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSet> findByRsqlAndTag(@NotNull Pageable pageable, @NotNull String rsqlParam, long tagId);
/**
* 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> getMetaDataByDistributionSetId(long id, @NotEmpty String key);
long countByTypeId(long typeId);
/**
* Checks if a {@link DistributionSet} is currently in use by a target in
@@ -335,43 +355,6 @@ public interface DistributionSetManagement
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
boolean isInUse(long id);
/**
* Unassigns a {@link SoftwareModule} form an existing
* {@link DistributionSet}.
*
* @param id to get unassigned form
* @param moduleId to be unassigned
* @return the updated {@link DistributionSet}.
* @throws EntityNotFoundException if given module or DS does not exist
* @throws EntityReadOnlyException if use tries to change the {@link DistributionSet} s while
* the DS is already in use.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSet unassignSoftwareModule(long id, long moduleId);
/**
* Updates a distribution set meta data value if corresponding entry exists.
*
* @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
* @throws EntityNotFoundException in case the meta data entry does not exists and cannot be
* updated
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSetMetadata updateMetaData(long id, @NotNull MetaData metadata);
/**
* Count all {@link DistributionSet}s in the repository that are not marked
* as deleted.
*
* @param typeId to look for
* @return number of {@link DistributionSet}s
* @throws EntityNotFoundException if type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countByTypeId(long typeId);
/**
* Count all {@link org.eclipse.hawkbit.repository.model.Rollout}s by status for
* Distribution Set.
@@ -402,18 +385,10 @@ public interface DistributionSetManagement
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countAutoAssignmentsForDistributionSet(@NotNull Long id);
/**
* Sets the specified {@link DistributionSet} as invalidated.
*
* @param distributionSet the ID of the {@link DistributionSet} to be set to invalid
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void invalidate(DistributionSet distributionSet);
/**
* Toggles {@link DistributionSetTag} assignment to given
* {@link DistributionSet}s by means that if some (or all) of the targets in
* the list have the {@link Tag} not yet assigned, they will be. Only if all
* the list have the {@link org.eclipse.hawkbit.repository.model.Tag} not yet assigned, they will be. Only if all
* of theme have the tag already assigned they will be removed instead.
*
* @param ids to toggle for
@@ -438,4 +413,4 @@ public interface DistributionSetManagement
@Deprecated(forRemoval = true)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSet unassignTag(long id, long tagId);
}
}

View File

@@ -31,16 +31,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
*/
public interface DistributionSetTagManagement extends RepositoryManagement<DistributionSetTag, TagCreate, TagUpdate> {
/**
* Deletes {@link DistributionSetTag} by given
* {@link DistributionSetTag#getName()}.
*
* @param tagName to be deleted
* @throws EntityNotFoundException if tag with given name does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void delete(@NotEmpty String tagName);
/**
* Find {@link DistributionSet} based on given name.
*
@@ -48,7 +38,7 @@ public interface DistributionSetTagManagement extends RepositoryManagement<Distr
* @return {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSetTag> getByName(@NotEmpty String name);
Optional<DistributionSetTag> findByName(@NotEmpty String name);
/**
* Finds all {@link TargetTag} assigned to given {@link Target}.
@@ -60,4 +50,14 @@ public interface DistributionSetTagManagement extends RepositoryManagement<Distr
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetTag> findByDistributionSet(@NotNull Pageable pageable, long distributionSetId);
}
/**
* Deletes {@link DistributionSetTag} by given
* {@link DistributionSetTag#getName()}.
*
* @param tagName to be deleted
* @throws EntityNotFoundException if tag with given name does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void delete(@NotEmpty String tagName);
}

View File

@@ -32,10 +32,10 @@ public interface DistributionSetTypeManagement
extends RepositoryManagement<DistributionSetType, DistributionSetTypeCreate, DistributionSetTypeUpdate> {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSetType> getByKey(@NotEmpty String key);
Optional<DistributionSetType> findByKey(@NotEmpty String key);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<DistributionSetType> getByName(@NotEmpty String name);
Optional<DistributionSetType> findByName(@NotEmpty String name);
/**
* Assigns {@link DistributionSetType#getMandatoryModuleTypes()}.

View File

@@ -43,8 +43,7 @@ public interface RepositoryManagement<T, C, U> {
*
* @param creates to create
* @return created Entity
* @throws ConstraintViolationException if fields are not filled as specified. Check
* {@link BaseEntity} for field constraints.
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link BaseEntity} for field constraints.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<T> create(@NotNull @Valid Collection<C> creates);
@@ -54,8 +53,7 @@ public interface RepositoryManagement<T, C, U> {
*
* @param create to create
* @return created Entity
* @throws ConstraintViolationException if fields are not filled as specified. Check
* {@link BaseEntity} for field constraints.
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link BaseEntity} for field constraints.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
T create(@NotNull @Valid C create);
@@ -65,22 +63,13 @@ public interface RepositoryManagement<T, C, U> {
*
* @param update to update
* @return updated Entity
* @throws EntityReadOnlyException if the {@link BaseEntity} cannot be updated (e.g. is already
* in use)
* @throws EntityNotFoundException in case the {@link BaseEntity} does not exists and cannot be
* updated
* @throws ConstraintViolationException if fields are not filled as specified. Check
* {@link BaseEntity} for field constraints.
* @throws EntityReadOnlyException if the {@link BaseEntity} cannot be updated (e.g. is already in use)
* @throws EntityNotFoundException in case the {@link BaseEntity} does not exist and cannot be updated
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link BaseEntity} for field constraints.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
T update(@NotNull @Valid U update);
/**
* @return number of {@link BaseEntity}s in the repository.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long count();
/**
* Deletes or marks as delete in case the {@link BaseEntity} is in use.
*
@@ -91,9 +80,8 @@ public interface RepositoryManagement<T, C, U> {
void delete(long id);
/**
* Delete {@link BaseEntity}s by their IDs. That is either a soft delete of
* the entities have been linked to another entity before or a hard delete
* if not.
* Delete {@link BaseEntity}s by their IDs. That is either a soft delete of the entities have been linked to another entity before or a hard
* delete if not.
*
* @param ids to be deleted
* @throws EntityNotFoundException if (at least one) given distribution set does not exist
@@ -110,21 +98,11 @@ public interface RepositoryManagement<T, C, U> {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<T> get(@NotEmpty Collection<Long> ids);
/**
* Verifies that {@link BaseEntity} with given ID exists in the repository.
*
* @param id of entity to check existence
* @return <code>true</code> if entity with given ID exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
boolean exists(long id);
/**
* Retrieve {@link BaseEntity}
*
* @param id to search for
* @return {@link BaseEntity} in the repository with given
* {@link BaseEntity#getId()}
* @return {@link BaseEntity} in the repository with given {@link BaseEntity#getId()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<T> get(long id);
@@ -141,13 +119,28 @@ public interface RepositoryManagement<T, C, U> {
/**
* Retrieves all {@link BaseEntity}s with a given specification.
*
* @param pageable pagination parameter
* @param rsqlParam filter definition in RSQL syntax
* @param pageable pagination parameter
* @return the found {@link BaseEntity}s
* @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
* @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_REPOSITORY)
Page<T> findByRsql(@NotNull Pageable pageable, @NotNull String rsqlParam);
}
Page<T> findByRsql(@NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Verifies that {@link BaseEntity} with given ID exists in the repository.
*
* @param id of entity to check existence
* @return <code>true</code> if entity with given ID exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
boolean exists(long id);
/**
* @return number of {@link BaseEntity}s in the repository.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long count();
}

View File

@@ -40,170 +40,54 @@ import org.springframework.security.access.prepost.PreAuthorize;
/**
* Service for managing {@link SoftwareModule}s.
*/
public interface SoftwareModuleManagement
extends RepositoryManagement<SoftwareModule, SoftwareModuleCreate, SoftwareModuleUpdate> {
public interface SoftwareModuleManagement extends RepositoryManagement<SoftwareModule, SoftwareModuleCreate, SoftwareModuleUpdate> {
/**
* Creates a list of software module meta data entries.
* Creates a list of software module meta-data entries.
*
* @param metadata the meta data entries to create
* @return the updated or created software module meta data entries
* @throws EntityAlreadyExistsException in case one of the meta data entry already exists for the
* specific key
* @param metadata the meta-data entries to create
* @return the updated or created software module meta-data entries
* @throws EntityAlreadyExistsException in case one of the meta-data entry already exists for the specific key
* @throws EntityNotFoundException if software module with given ID does not exist
* @throws AssignmentQuotaExceededException if the maximum number of {@link SoftwareModuleMetadata} entries is exceeded for the addressed
* {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<SoftwareModuleMetadata> putMetaData(@NotNull @Valid Collection<SoftwareModuleMetadataCreate> metadata);
/**
* Creates or updates a single software module meta-data entry.
*
* @param metadata the meta-data entry to create
* @return the updated or created software module meta-data entry
* @throws EntityAlreadyExistsException in case the meta-data entry already exists for the specific key
* @throws EntityNotFoundException if software module with given ID does not exist
* @throws AssignmentQuotaExceededException if the maximum number of {@link SoftwareModuleMetadata}
* entries is exceeded for the addressed {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<SoftwareModuleMetadata> createMetaData(@NotNull @Valid Collection<SoftwareModuleMetadataCreate> metadata);
SoftwareModuleMetadata updateMetaData(@NotNull @Valid SoftwareModuleMetadataCreate metadata);
/**
* Creates or updates a single software module meta data entry.
* Updates a distribution set meta-data value if corresponding entry exists.
*
* @param metadata the meta data entry to create
* @return the updated or created software module meta data entry
* @throws EntityAlreadyExistsException in case the meta data entry already exists for the specific
* key
* @throws EntityNotFoundException if software module with given ID does not exist
* @throws AssignmentQuotaExceededException if the maximum number of {@link SoftwareModuleMetadata}
* entries is exceeded for the addressed {@link SoftwareModule}
* @param update the meta-data entry to be updated
* @return the updated meta-data entry
* @throws EntityNotFoundException in case the meta-data entry does not exist and cannot be updated
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata createMetaData(@NotNull @Valid SoftwareModuleMetadataCreate metadata);
SoftwareModuleMetadata updateMetaData(@NotNull @Valid SoftwareModuleMetadataUpdate update);
/**
* Deletes a software module meta data entry.
* Deletes a software module meta-data entry.
*
* @param id where meta data has to be deleted
* @param key of the metda data element
* @param id where meta-data has to be deleted
* @param key of the meta-data element
* @throws EntityNotFoundException of module or metadata entry does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteMetaData(long id, @NotEmpty String key);
/**
* Returns all modules assigned to given {@link DistributionSet}.
*
* @param pageable the page request to page the result set
* @param distributionSetId to search for
* @return all {@link SoftwareModule}s that are assigned to given
* {@link DistributionSet}.
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModule> findByAssignedTo(@NotNull Pageable pageable, long distributionSetId);
/**
* Returns count of all modules assigned to given {@link DistributionSet}.
*
* @param distributionSetId to search for
* @return count of {@link SoftwareModule}s that are assigned to given
* {@link DistributionSet}.
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countByAssignedTo(long distributionSetId);
/**
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* and {@link SoftwareModule#getType()} that are not marked as deleted.
*
* @param pageable page parameter
* @param searchText to be filtered as "like" on {@link SoftwareModule#getName()}
* @param typeId to be filtered as "like" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
* @throws EntityNotFoundException if given software module type does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findByTextAndType(@NotNull Pageable pageable, String searchText, Long typeId);
/**
* Retrieves {@link SoftwareModule} by their name AND version AND type..
*
* @param name of the {@link SoftwareModule}
* @param version of the {@link SoftwareModule}
* @param typeId of the {@link SoftwareModule}
* @return the found {@link SoftwareModule}
* @throws EntityNotFoundException if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<SoftwareModule> getByNameAndVersionAndType(@NotEmpty String name, @NotEmpty String version, long typeId);
/**
* Finds a single software module meta data by its id.
*
* @param id where meta data has to be found
* @param key of the meta data element
* @return the found SoftwareModuleMetadata or {@code null} if not exits
* @throws EntityNotFoundException is module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<SoftwareModuleMetadata> getMetaDataBySoftwareModuleId(long id, @NotEmpty String key);
/**
* Finds all meta data by the given software module id.
*
* @param pageable the page request to page the result
* @param id the software module id to retrieve the meta data from
* @return a paged result of all meta data entries for a given software
* module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(@NotNull Pageable pageable, long id);
/**
* Counts all meta data by the given software module id.
*
* @param id the software module id to retrieve the meta data count from
* @return count of all meta data entries for a given software module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countMetaDataBySoftwareModuleId(long id);
/**
* Finds all meta data by the given software module id where
* {@link SoftwareModuleMetadata#isTargetVisible()}.
*
* @param pageable the page request to page the result
* @param id the software module id to retrieve the meta data from
* @return a paged result of all meta data entries for a given software
* module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleIdAndTargetVisible(@NotNull Pageable pageable, long id);
/**
* Finds all meta data by the given software module id.
*
* @param pageable the page request to page the result
* @param id the software module id to retrieve the meta data from
* @param rsqlParam filter definition in RSQL syntax
* @return a paged result of all meta data entries for a given software
* module 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 if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findMetaDataByRsql(@NotNull Pageable pageable, long id, @NotNull String rsqlParam);
/**
* Retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType}
* .
*
* @param pageable page parameters
* @param typeId to be filtered on
* @return the found {@link SoftwareModule}s
* @throws EntityNotFoundException if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findByType(@NotNull Pageable pageable, long typeId);
/**
* Locks a software module.
*
@@ -225,16 +109,120 @@ public interface SoftwareModuleManagement
void unlock(long id);
/**
* Updates a distribution set meta data value if corresponding entry exists.
* Returns all modules assigned to given {@link DistributionSet}.
*
* @param update the meta data entry to be updated
* @return the updated meta data entry
* @throws EntityNotFoundException in case the meta data entry does not exists and cannot be
* updated
* @param distributionSetId to search for
* @param pageable the page request to page the result set
* @return all {@link SoftwareModule}s that are assigned to given {@link DistributionSet}.
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata updateMetaData(@NotNull @Valid SoftwareModuleMetadataUpdate update);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModule> findByAssignedTo(long distributionSetId, @NotNull Pageable pageable);
/**
* Filter {@link SoftwareModule}s with given {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* and {@link SoftwareModule#getType()} that are not marked as deleted.
*
* @param searchText to be filtered as "like" on {@link SoftwareModule#getName()}
* @param typeId to be filtered as "like" on {@link SoftwareModule#getType()}
* @param pageable page parameter
* @return the page of found {@link SoftwareModule}
* @throws EntityNotFoundException if given software module type does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findByTextAndType(String searchText, Long typeId, @NotNull Pageable pageable);
/**
* Retrieves {@link SoftwareModule} by their name AND version AND type.
*
* @param name of the {@link SoftwareModule}
* @param version of the {@link SoftwareModule}
* @param typeId of the {@link SoftwareModule}
* @return the found {@link SoftwareModule}
* @throws EntityNotFoundException if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<SoftwareModule> findByNameAndVersionAndType(@NotEmpty String name, @NotEmpty String version, long typeId);
/**
* Finds a single software module meta-data by its id.
*
* @param id where meta-data has to be found
* @param key of the meta-data element
* @return the found SoftwareModuleMetadata or {@code null} if not exits
* @throws EntityNotFoundException is module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(long id, @NotEmpty String key);
/**
* Finds all meta-data by the given software module id.
*
* @param pageable the page request to page the result
* @param id the software module id to retrieve the meta-data from
* @return a paged result of all meta-data entries for a given software module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(@NotNull Pageable pageable, long id);
/**
* Finds all meta-data by the given software module id where {@link SoftwareModuleMetadata#isTargetVisible()}.
*
* @param pageable the page request to page the result
* @param id the software module id to retrieve the meta-data from
* @return a paged result of all meta-data entries for a given software module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleIdAndTargetVisible(@NotNull Pageable pageable, long id);
/**
* Finds all meta-data by the given software module id.
*
* @param id the software module id to retrieve the meta-data from
* @param rsqlParam filter definition in RSQL syntax
* @param pageable the page request to page the result
* @return a paged result of all meta-data entries for a given software module 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 if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleMetadata> findMetaDataByRsql(long id, @NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType}
*
* @param typeId to be filtered on
* @param pageable page parameters
* @return the found {@link SoftwareModule}s
* @throws EntityNotFoundException if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findByType(long typeId, @NotNull Pageable pageable);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Map<Long, List<SoftwareModuleMetadata>> findMetaDataBySoftwareModuleIdsAndTargetVisible(Collection<Long> moduleIds);
/**
* Returns count of all modules assigned to given {@link DistributionSet}.
*
* @param distributionSetId to search for
* @return count of {@link SoftwareModule}s that are assigned to given {@link DistributionSet}.
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countByAssignedTo(long distributionSetId);
/**
* Counts all meta-data by the given software module id.
*
* @param id the software module id to retrieve the meta-data count from
* @return count of all meta-data entries for a given software module id
* @throws EntityNotFoundException if software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countMetaDataBySoftwareModuleId(long id);
}

View File

@@ -30,12 +30,12 @@ public interface SoftwareModuleTypeManagement
* @return {@link SoftwareModuleType} in the repository with given {@link SoftwareModuleType#getKey()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<SoftwareModuleType> getByKey(@NotEmpty String key);
Optional<SoftwareModuleType> findByKey(@NotEmpty String key);
/**
* @param name to search for
* @return all {@link SoftwareModuleType}s in the repository with given {@link SoftwareModuleType#getName()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<SoftwareModuleType> getByName(@NotEmpty String name);
Optional<SoftwareModuleType> findByName(@NotEmpty String name);
}