hawkBit repository uses Optional on single entity find/get requests (#435)

* Repo returns optionals.
* Improved exception handling for collection usage in repo queries.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-02-16 10:09:14 +01:00
committed by GitHub
parent d21af83804
commit 804522f966
232 changed files with 2104 additions and 2377 deletions

View File

@@ -9,17 +9,17 @@
package org.eclipse.hawkbit.repository;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
import org.eclipse.hawkbit.repository.model.Artifact;
@@ -119,7 +119,8 @@ public interface ArtifactManagement {
* of the {@link Artifact} that has to be deleted.
* @throws ArtifactDeleteFailedException
* if deletion failed (MongoDB is not available)
*
* @throws EntityNotFoundException
* if artifact with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteArtifact(@NotNull Long id);
@@ -129,12 +130,11 @@ public interface ArtifactManagement {
*
* @param id
* to search for
* @return found {@link Artifact} or <code>null</code> is it could not be
* found.
* @return found {@link Artifact}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
Artifact findArtifact(@NotNull Long id);
Optional<Artifact> findArtifact(@NotNull Long id);
/**
* Find by artifact by software module id and filename.
@@ -143,11 +143,11 @@ public interface ArtifactManagement {
* file name
* @param softwareModuleId
* software module id.
* @return Artifact if artifact present
* @return found {@link Artifact}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
List<Artifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
Optional<Artifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
/**
* Find all local artifact by sha1 and return the first artifact.
@@ -158,7 +158,7 @@ public interface ArtifactManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
Artifact findFirstArtifactBySHA1(@NotNull String sha1);
Optional<Artifact> findFirstArtifactBySHA1(@NotNull String sha1);
/**
* Searches for {@link Artifact} with given file name.
@@ -169,7 +169,7 @@ public interface ArtifactManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
List<Artifact> findArtifactByFilename(@NotNull String filename);
Optional<Artifact> findArtifactByFilename(@NotNull String filename);
/**
* Get local artifact for a base software module.

View File

@@ -106,6 +106,9 @@ public interface ControllerManagement {
* @throws TooManyStatusEntriesException
* if more than the allowed number of status entries are
* inserted
*
* @throws EntityNotFoundException
* if action status not exist
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Action addUpdateActionStatus(@NotNull ActionStatusCreate create);
@@ -117,9 +120,6 @@ public interface ControllerManagement {
* @param controllerId
* identifies the target to retrieve the actions from
* @return a list of actions assigned to given target which are active
*
* @throws EntityNotFoundException
* if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Optional<Action> findOldestActiveActionByTarget(@NotNull String controllerId);
@@ -133,7 +133,7 @@ public interface ControllerManagement {
* @return the corresponding {@link Action}
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Action findActionWithDetails(@NotNull Long actionId);
Optional<Action> findActionWithDetails(@NotNull Long actionId);
/**
* register new target in the repository (plug-and-play).
@@ -149,19 +149,19 @@ public interface ControllerManagement {
/**
* Retrieves last {@link Action} for a download of an artifact of given
* module and target.
* module and target if exists and is not canceled.
*
* @param controllerId
* to look for
* @param module
* that should be assigned to the target
* @param moduleId
* of the the {@link SoftwareModule} that should be assigned to
* the target
* @return last {@link Action} for given combination
*
* @throws EntityNotFoundException
* if action for given combination could not be found
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Action getActionForDownloadByTargetAndSoftwareModule(@NotEmpty String controllerId, @NotNull SoftwareModule module);
Optional<Action> getActionForDownloadByTargetAndSoftwareModule(@NotEmpty String controllerId,
@NotNull Long moduleId);
/**
* @return current {@link TenantConfigurationKey#POLLING_TIME_INTERVAL}.
@@ -271,7 +271,7 @@ public interface ControllerManagement {
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
Target findByControllerId(@NotEmpty String controllerId);
Optional<Target> findByControllerId(@NotEmpty String controllerId);
/**
* Finds {@link Target} based on given ID returns found Target without
@@ -285,6 +285,6 @@ public interface ControllerManagement {
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
Target findByTargetId(@NotNull Long targetId);
Optional<Target> findByTargetId(@NotNull Long targetId);
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotNull;
@@ -123,12 +124,11 @@ public interface DeploymentManagement {
* @param actionId
* to be canceled
*
* @return generated {@link Action} or <code>null</code> if not active on
* given {@link Target}.
* @return canceled {@link Action}
*
* @throws CancelActionNotAllowedException
* in case the given action is not active or is already a cancel
* action
*
* @throws EntityNotFoundException
* if action with given ID does not exist
*/
@@ -181,9 +181,10 @@ public interface DeploymentManagement {
* @param actionId
* to be id of the action
* @return the corresponding {@link Action}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Action findAction(@NotNull Long actionId);
Optional<Action> findAction(@NotNull Long actionId);
/**
* Retrieves all {@link Action}s from repository.
@@ -242,6 +243,7 @@ public interface DeploymentManagement {
* @param pageable
* the pageable request to limit, sort the actions
* @return a slice of actions found for a specific target
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Action> findActionsByTarget(@NotEmpty String controllerId, @NotNull Pageable pageable);
@@ -255,6 +257,9 @@ public interface DeploymentManagement {
* @param actionId
* to be filtered on
* @return the corresponding {@link Page} of {@link ActionStatus}
*
* @throws EntityNotFoundException
* if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<ActionStatus> findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Long actionId);
@@ -268,6 +273,9 @@ public interface DeploymentManagement {
* @param actionId
* the {@link Action} to retrieve the {@link ActionStatus} from
* @return a page of {@link ActionStatus} by a speciifc {@link Action}
*
* @throws EntityNotFoundException
* if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<ActionStatus> findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Long actionId);
@@ -292,7 +300,7 @@ public interface DeploymentManagement {
* @return the corresponding {@link Action}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Action findActionWithDetails(@NotNull Long actionId);
Optional<Action> findActionWithDetails(@NotNull Long actionId);
/**
* Retrieves all active {@link Action}s of a specific target ordered by
@@ -325,8 +333,8 @@ public interface DeploymentManagement {
* @param actionId
* to be canceled
*
* @return generated {@link Action} or <code>null</code> if not active on
* {@link Target}.
* @return quite {@link Action}
*
* @throws CancelActionNotAllowedException
* in case the given action is not active
*
@@ -343,6 +351,9 @@ public interface DeploymentManagement {
* @param actionId
* the ID of the action
* @return the updated or the found {@link Action}
*
* @throws EntityNotFoundException
* if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
Action forceTargetAction(@NotNull Long actionId);

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotNull;
@@ -60,7 +61,7 @@ public interface DistributionSetManagement {
* @return the updated {@link DistributionSet}.
*
* @throws EntityNotFoundException
* if given module does not exist
* if (at least one) given module does not exist
*
* @throws EntityReadOnlyException
* if use tries to change the {@link DistributionSet} s while
@@ -86,7 +87,8 @@ public interface DistributionSetManagement {
* @return list of assigned ds
*
* @throws EntityNotFoundException
* if tag with given ID does not exist
* 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> dsIds, @NotNull Long tagId);
@@ -108,6 +110,9 @@ public interface DistributionSetManagement {
* 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 countDistributionSetsByType(@NotNull Long typeId);
@@ -214,9 +219,13 @@ public interface DistributionSetManagement {
* result means that they cannot be assigned anymore to any targets. (define
* e.g. findByDeletedFalse())
* </p>
*
*
* @param setId
* to delete
*
* @throws EntityNotFoundException
* if given {@link DistributionSet} does not exist
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteDistributionSet(@NotNull Long setId);
@@ -228,6 +237,9 @@ public interface DistributionSetManagement {
*
* @param dsIds
* to be deleted
*
* @throws EntityNotFoundException
* if (at least one) given distribution set does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteDistributionSet(@NotEmpty Collection<Long> dsIds);
@@ -264,9 +276,12 @@ public interface DistributionSetManagement {
* @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 findDistributionSetByAction(@NotNull Long actionId);
Optional<DistributionSet> findDistributionSetByAction(@NotNull Long actionId);
/**
* Find {@link DistributionSet} based on given ID without details, e.g.
@@ -274,10 +289,11 @@ public interface DistributionSetManagement {
*
* @param distid
* to look for.
* @return {@link DistributionSet} or <code>null</code> if it does not exist
* @return {@link DistributionSet}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSet findDistributionSetById(@NotNull Long distid);
Optional<DistributionSet> findDistributionSetById(@NotNull Long distid);
/**
* Find {@link DistributionSet} based on given ID including (lazy loaded)
@@ -288,10 +304,10 @@ public interface DistributionSetManagement {
*
* @param distid
* to look for.
* @return {@link DistributionSet} or <code>null</code> if it does not exist
* @return {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSet findDistributionSetByIdWithDetails(@NotNull Long distid);
Optional<DistributionSet> findDistributionSetByIdWithDetails(@NotNull Long distid);
/**
* Find distribution set by name and version.
@@ -303,7 +319,8 @@ public interface DistributionSetManagement {
* @return the page with the found {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSet findDistributionSetByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version);
Optional<DistributionSet> findDistributionSetByNameAndVersion(@NotEmpty String distributionName,
@NotEmpty String version);
/**
* finds all meta data by the given distribution set id.
@@ -314,21 +331,14 @@ public interface DistributionSetManagement {
* the page request to page the result
* @return a paged result of all meta data entries for a given distribution
* set id
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId,
@NotNull Pageable pageable);
/**
* Finds all meta data by the given distribution set id.
*
* @param distributionSetId
* the distribution set id to retrieve the meta data from
* @return list of distributionSetMetadata for a given distribution set Id.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId);
/**
* finds all meta data by the given distribution set id.
*
@@ -346,6 +356,9 @@ public interface DistributionSetManagement {
* 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> findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId,
@@ -449,27 +462,27 @@ public interface DistributionSetManagement {
/**
* @param id
* as {@link DistributionSetType#getId()}
* @return {@link DistributionSetType} if found or <code>null</code> if not
* @return {@link DistributionSetType}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetType findDistributionSetTypeById(@NotNull Long id);
Optional<DistributionSetType> findDistributionSetTypeById(@NotNull Long id);
/**
* @param key
* as {@link DistributionSetType#getKey()}
* @return {@link DistributionSetType} if found or <code>null</code> if not
* @return {@link DistributionSetType}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetType findDistributionSetTypeByKey(@NotEmpty String key);
Optional<DistributionSetType> findDistributionSetTypeByKey(@NotEmpty String key);
/**
* @param name
* as {@link DistributionSetType#getName()}
* @return {@link DistributionSetType} if found or <code>null</code> if not
* @return {@link DistributionSetType}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetType findDistributionSetTypeByName(@NotEmpty String name);
Optional<DistributionSetType> findDistributionSetTypeByName(@NotEmpty String name);
/**
* @param pageable
@@ -506,11 +519,9 @@ public interface DistributionSetManagement {
* @param key
* of the meta data element
* @return the found DistributionSetMetadata or {@code null} if not exits
* @throws EntityNotFoundException
* in case the meta data does not exists for the given key
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetMetadata findDistributionSetMetadata(@NotNull Long setId, @NotEmpty String key);
Optional<DistributionSetMetadata> findDistributionSetMetadata(@NotNull Long setId, @NotEmpty String key);
/**
* Checks if a {@link DistributionSet} is currently in use by a target in
@@ -536,6 +547,9 @@ public interface DistributionSetManagement {
* to toggle
* @return {@link DistributionSetTagAssignmentResult} with all meta data of
* the assignment outcome.
*
* @throws EntityNotFoundException
* if given tag does not exist or (at least one) module
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<Long> dsIds, @NotNull String tagName);
@@ -715,6 +729,6 @@ public interface DistributionSetManagement {
* @return the found {@link DistributionSet}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSet> findDistributionSetAllById(@NotNull Collection<Long> ids);
List<DistributionSet> findDistributionSetAllById(@NotEmpty Collection<Long> ids);
}

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository;
import java.util.Optional;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
@@ -67,9 +69,10 @@ public interface RolloutGroupManagement {
* the ID of the rollout group to find
* @return the found {@link RolloutGroup} by its ID or {@code null} if it
* does not exists
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
RolloutGroup findRolloutGroupById(@NotNull Long rolloutGroupId);
Optional<RolloutGroup> findRolloutGroupById(@NotNull Long rolloutGroupId);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
@@ -151,9 +154,10 @@ public interface RolloutGroupManagement {
* @param rolloutGroupId
* rollout group id
* @return rolloutGroup with details of targets count for different statuses
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId);
Optional<RolloutGroup> findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId);
/**
* Count targets of rollout group.

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository;
import java.util.List;
import java.util.concurrent.Future;
import java.util.Optional;
import javax.validation.constraints.NotNull;
@@ -45,8 +45,8 @@ public interface RolloutManagement {
/**
* Checking running rollouts. Rollouts which are checked updating the
* lastCheck to indicate that the current instance
* is handling the specific rollout. This code should run as system-code.
* lastCheck to indicate that the current instance is handling the specific
* rollout. This code should run as system-code.
*
* <pre>
* {@code
@@ -58,9 +58,8 @@ public interface RolloutManagement {
* }
* </pre>
*
* This method is intended to be called by a scheduler.
* And must be running in an transaction so it's
* splitted from the scheduler.
* This method is intended to be called by a scheduler. And must be running
* in an transaction so it's splitted from the scheduler.
*
* Rollouts which are currently running are investigated, by means the
* error- and finish condition of running groups in this rollout are
@@ -292,7 +291,7 @@ public interface RolloutManagement {
* not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutById(@NotNull Long rolloutId);
Optional<Rollout> findRolloutById(@NotNull Long rolloutId);
/**
* Retrieves a specific rollout by its name.
@@ -303,7 +302,7 @@ public interface RolloutManagement {
* does not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutByName(@NotNull String rolloutName);
Optional<Rollout> findRolloutByName(@NotEmpty String rolloutName);
/**
* Get count of targets in different status in rollout.
@@ -311,10 +310,21 @@ public interface RolloutManagement {
* @param rolloutId
* rollout id
* @return rollout details of targets count for different statuses
*
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutWithDetailedStatus(@NotNull Long rolloutId);
Optional<Rollout> findRolloutWithDetailedStatus(@NotNull Long rolloutId);
/**
* Checks if rollout with given ID exists.
*
* @param rolloutId
* rollout id
*
* @return <code>true</code> if rollout exists
*/
boolean exists(@NotNull Long rolloutId);
/***
* Get finished percentage details for a specified group which is in running
@@ -378,7 +388,7 @@ public interface RolloutManagement {
* all actions are created and the first group is started. The rollout
* itself will be then also in {@link RolloutStatus#RUNNING}.
*
* @param rollout
* @param rolloutId
* the rollout to be started
*
* @return started rollout
@@ -390,7 +400,7 @@ public interface RolloutManagement {
* ready rollouts can be started.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
Rollout startRollout(@NotNull Long rollout);
Rollout startRollout(@NotNull Long rolloutId);
/**
* Update rollout details.
@@ -399,6 +409,10 @@ public interface RolloutManagement {
* rollout to be updated
*
* @return Rollout updated rollout
*
* @throws EntityNotFoundException
* if rollout or DS with given IDs do not exist
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
Rollout updateRollout(@NotNull RolloutUpdate update);

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotNull;
@@ -50,6 +51,9 @@ public interface SoftwareManagement {
* @param typeId
* to filter the result by type
* @return number of found {@link SoftwareModule}s
*
* @throws EntityNotFoundException
* if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModuleByFilters(String searchText, Long typeId);
@@ -77,6 +81,9 @@ public interface SoftwareManagement {
* @return SoftwareModule
* @throws EntityAlreadyExistsException
* if a given entity already exists
*
* @throws EntityNotFoundException
* of given software module type does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<SoftwareModule> createSoftwareModule(@NotNull Collection<SoftwareModuleCreate> creates);
@@ -88,6 +95,9 @@ public interface SoftwareManagement {
* @return SoftwareModule
* @throws EntityAlreadyExistsException
* if a given entity already exists
*
* @throws EntityNotFoundException
* of given software module type does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
SoftwareModule createSoftwareModule(@NotNull SoftwareModuleCreate create);
@@ -103,6 +113,8 @@ public interface SoftwareManagement {
* @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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<SoftwareModuleMetadata> createSoftwareModuleMetadata(@NotNull Long moduleId,
@@ -119,6 +131,8 @@ public interface SoftwareManagement {
* @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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull Long moduleId, @NotNull MetaData metadata);
@@ -159,6 +173,9 @@ public interface SoftwareManagement {
* where meta data has to be deleted
* @param key
* of the metda data element
*
* @throws EntityNotFoundException
* of module or metadata entry does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
@@ -168,6 +185,9 @@ public interface SoftwareManagement {
*
* @param moduleIds
* of the Software Modules to be deleted
*
* @throws EntityNotFoundException
* if (at least one) module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModules(@NotNull Collection<Long> moduleIds);
@@ -179,7 +199,7 @@ public interface SoftwareManagement {
* to delete
*
* @throws EntityNotFoundException
* not found is type with giben ID does not exist
* not found is type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModuleType(@NotNull Long typeId);
@@ -191,6 +211,9 @@ public interface SoftwareManagement {
* 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> findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull Long setId);
@@ -207,6 +230,9 @@ public interface SoftwareManagement {
* @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> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, Long typeId);
@@ -227,12 +253,12 @@ public interface SoftwareManagement {
*
* @param id
* to search for
* @return the found {@link SoftwareModule}s or <code>null</code> if not
* found.
* @return the found {@link SoftwareModule}s
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
SoftwareModule findSoftwareModuleById(@NotNull Long id);
Optional<SoftwareModule> findSoftwareModuleById(@NotNull Long id);
/**
* retrieves {@link SoftwareModule} by their name AND version AND type..
@@ -243,10 +269,13 @@ public interface SoftwareManagement {
* of the {@link SoftwareModule}
* @param typeId
* of the {@link SoftwareModule}
* @return the found {@link SoftwareModule} or <code>null</code>
* @return the found {@link SoftwareModule}
*
* @throws EntityNotFoundException
* if software module type with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
Optional<SoftwareModule> findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
@NotNull Long typeId);
/**
@@ -257,11 +286,9 @@ public interface SoftwareManagement {
* @param key
* of the meta data element
* @return the found SoftwareModuleMetadata or {@code null} if not exits
* @throws EntityNotFoundException
* in case the meta data does not exists for the given key
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
Optional<SoftwareModuleMetadata> findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
/**
* finds all meta data by the given software module id.
@@ -272,6 +299,9 @@ public interface SoftwareManagement {
* the page request to page the result
* @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> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long swId,
@@ -294,6 +324,8 @@ public interface SoftwareManagement {
* 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> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId,
@@ -318,6 +350,9 @@ public interface SoftwareManagement {
* @param typeId
* filtered as "equal" 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<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
@@ -371,6 +406,9 @@ public interface SoftwareManagement {
* @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> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull Long typeId);
@@ -383,7 +421,7 @@ public interface SoftwareManagement {
* {@link SoftwareModuleType#getId()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id);
Optional<SoftwareModuleType> findSoftwareModuleTypeById(@NotNull Long id);
/**
*
@@ -393,7 +431,7 @@ public interface SoftwareManagement {
* {@link SoftwareModuleType#getKey()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeByKey(@NotEmpty String key);
Optional<SoftwareModuleType> findSoftwareModuleTypeByKey(@NotEmpty String key);
/**
*
@@ -403,7 +441,7 @@ public interface SoftwareManagement {
* {@link SoftwareModuleType#getName()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name);
Optional<SoftwareModuleType> findSoftwareModuleTypeByName(@NotNull String name);
/**
* @param pageable
@@ -443,6 +481,9 @@ public interface SoftwareManagement {
* if given module does not exist
*
* @return the saved Entity.
*
* @throws EntityNotFoundException
* if fiven {@link SoftwareModule} does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModule updateSoftwareModule(@NotNull SoftwareModuleUpdate update);
@@ -455,8 +496,8 @@ public interface SoftwareManagement {
* @param metadata
* 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
@@ -492,6 +533,9 @@ public interface SoftwareManagement {
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
* @return result of all meta data entries for a given software module id.
*
* @throws EntityNotFoundException
* of software module with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId);

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotNull;
@@ -102,6 +103,9 @@ public interface TagManagement {
*
* @param tagName
* to be deleted
*
* @throws EntityNotFoundException
* if tag with given name does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteDistributionSetTag(@NotEmpty String tagName);
@@ -111,6 +115,9 @@ public interface TagManagement {
*
* @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 deleteTargetTag(@NotEmpty String targetTagName);
@@ -150,12 +157,6 @@ public interface TagManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetTag> findAllDistributionSetTags(@NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* @return all {@link TargetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<TargetTag> findAllTargetTags();
/**
* returns all {@link TargetTag}s.
*
@@ -190,41 +191,40 @@ public interface TagManagement {
*
* @param name
* to look for.
* @return {@link DistributionSet} or <code>null</code> if it does not exist
* @return {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetTag findDistributionSetTag(@NotEmpty String name);
Optional<DistributionSetTag> findDistributionSetTag(@NotEmpty String name);
/**
* Finds {@link DistributionSetTag} by given id.
*
* @param id
* to search for
* @return the found {@link DistributionSetTag}s or <code>null</code> if not
* found.
* @return the found {@link DistributionSetTag}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetTag findDistributionSetTagById(@NotNull Long id);
Optional<DistributionSetTag> findDistributionSetTagById(@NotNull Long id);
/**
* Find {@link TargetTag} based on given Name.
*
* @param name
* to look for.
* @return {@link TargetTag} or <code>null</code> if it does not exist
* @return {@link TargetTag}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetTag findTargetTag(@NotEmpty String name);
Optional<TargetTag> findTargetTag(@NotEmpty String name);
/**
* Finds {@link TargetTag} by given id.
*
* @param id
* to search for
* @return the found {@link TargetTag}s or <code>null</code> if not found.
* @return the found {@link TargetTag}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetTag findTargetTagById(@NotNull Long id);
Optional<TargetTag> findTargetTagById(@NotNull Long id);
/**
* Updates an existing {@link DistributionSetTag}.

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository;
import java.util.Optional;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
@@ -42,6 +44,9 @@ public interface TargetFilterQueryManagement {
*
* @param targetFilterQueryId
* IDs of target filter query to be deleted
*
* @throws EntityNotFoundException
* if filter with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId);
@@ -118,7 +123,7 @@ public interface TargetFilterQueryManagement {
* @return the page with the found {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<TargetFilterQuery> findTargetFilterQueryByQuery(@NotNull Pageable pageable, String query);
Page<TargetFilterQuery> findTargetFilterQueryByQuery(@NotNull Pageable pageable, @NotNull String query);
/**
* Retrieves all target filter query which {@link TargetFilterQuery}.
@@ -159,7 +164,7 @@ public interface TargetFilterQueryManagement {
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetFilterQuery findTargetFilterQueryById(@NotNull Long targetFilterQueryId);
Optional<TargetFilterQuery> findTargetFilterQueryById(@NotNull Long targetFilterQueryId);
/**
* Find target filter query by name.
@@ -170,7 +175,7 @@ public interface TargetFilterQueryManagement {
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetFilterQuery findTargetFilterQueryByName(@NotNull String targetFilterQueryName);
Optional<TargetFilterQuery> findTargetFilterQueryByName(@NotNull String targetFilterQueryName);
/**
* updates the {@link TargetFilterQuery}.

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotNull;
@@ -64,6 +65,9 @@ public interface TargetManagement {
* to search for
*
* @return number of found {@link Target}s.
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
@@ -94,6 +98,9 @@ public interface TargetManagement {
* flag to select targets with no tag assigned
*
* @return the found number {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByFilters(Collection<TargetUpdateStatus> status, Boolean overdueState, String searchText,
@@ -106,6 +113,9 @@ public interface TargetManagement {
* @param distId
* to search for
* @return number of found {@link Target}s.
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
@@ -175,10 +185,13 @@ public interface TargetManagement {
*
* @param targetIDs
* the IDs of the targets to be deleted
*
* @throws EntityNotFoundException
* if (at least one) of the given target IDs does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargets(@NotEmpty Collection<Long> targetIDs);
/**
* Deletes target with the given IDs.
*
@@ -203,10 +216,13 @@ public interface TargetManagement {
* @param rsqlParam
* filter definition in RSQL syntax
* @return a page of the found {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, Long distributionSetId,
@NotNull String rsqlParam);
Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
@NotNull Long distributionSetId, @NotNull String rsqlParam);
/**
* Counts all targets for all the given parameter {@link TargetFilterQuery}
@@ -218,6 +234,9 @@ public interface TargetManagement {
* @param rsqlParam
* filter definition in RSQL syntax
* @return the count of found {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetsByTargetFilterQueryAndNonDS(@NotNull Long distributionSetId, @NotNull String rsqlParam);
@@ -261,6 +280,9 @@ public interface TargetManagement {
* @param group
* the {@link RolloutGroup}
* @return the found {@link Target}s
*
* @throws EntityNotFoundException
* if rollout group with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findAllTargetsInRolloutGroupWithoutAction(@NotNull Pageable pageRequest, @NotNull Long group);
@@ -276,6 +298,9 @@ public interface TargetManagement {
* @param pageReq
* page parameter
* @return the found {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq);
@@ -297,7 +322,8 @@ public interface TargetManagement {
* given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull String rsqlParam,
@@ -322,10 +348,10 @@ public interface TargetManagement {
*
* @param controllerId
* to look for.
* @return {@link Target} or <code>null</code> if it does not exist
* @return {@link Target}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Target findTargetByControllerID(@NotEmpty String controllerId);
Optional<Target> findTargetByControllerID(@NotEmpty String controllerId);
/**
* Find {@link Target} based on given ID returns found Target with details,
@@ -337,10 +363,10 @@ public interface TargetManagement {
*
* @param controllerId
* to look for.
* @return {@link Target} or <code>null</code> if it does not exist
* @return {@link Target}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Target findTargetByControllerIDWithDetails(@NotEmpty String controllerId);
Optional<Target> findTargetByControllerIDWithDetails(@NotEmpty String controllerId);
/**
* Filter {@link Target}s for all the given parameters. If all parameters
@@ -369,6 +395,9 @@ public interface TargetManagement {
* flag to select targets with no tag assigned
*
* @return the found {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetByFilters(@NotNull Pageable pageable, Collection<TargetUpdateStatus> status,
@@ -385,6 +414,9 @@ public interface TargetManagement {
* @param pageReq
* page parameter
* @return the found {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByInstalledDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq);
@@ -407,6 +439,9 @@ public interface TargetManagement {
* given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, @NotNull String rsqlParam,
@@ -506,6 +541,9 @@ public interface TargetManagement {
* non-null value; filters are AND-gated
* @return a paged result {@link Page} of the {@link Target}s in a defined
* order.
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable,
@@ -546,6 +584,9 @@ public interface TargetManagement {
* @param tagName
* to toggle
* @return TagAssigmentResult with all meta data of the assignment outcome.
*
* @throws EntityNotFoundException
* if tag with given name does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<String> targetIds, @NotEmpty String tagName);
@@ -600,10 +641,10 @@ public interface TargetManagement {
*
* @param id
* to look for
* @return {@link Target} or <code>null</code> if it does not exist
* @return {@link Target}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Target findTargetById(Long id);
Optional<Target> findTargetById(Long id);
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}

View File

@@ -8,15 +8,17 @@
*/
package org.eclipse.hawkbit.repository.exception;
import java.util.Collection;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.MetaData;
/**
* the {@link EntityNotFoundException} is thrown when a entity is tried find but
* not found.
*
*
*
* the {@link EntityNotFoundException} is thrown when a entity queried but not
* found.
*/
public class EntityNotFoundException extends AbstractServerRtException {
@@ -58,7 +60,51 @@ public class EntityNotFoundException extends AbstractServerRtException {
* @param message
* of the exception
*/
public EntityNotFoundException(final String message) {
protected EntityNotFoundException(final String message) {
super(message, THIS_ERROR);
}
/**
* Parameterized constructor for {@link BaseEntity} not found.
*
* @param type
* of the entity that was not found
*
* @param enityId
* of the {@link BaseEntity}
*/
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Object enityId) {
this(type.getSimpleName() + " with given identifier {" + enityId + "} does not exist.");
}
/**
* Parameterized constructor for {@link MetaData} not found.
*
* @param type
* of the entity that was not found
* @param enityId
* of the {@link BaseEntity} the {@link MetaData} was for
* @param key
* for the {@link MetaData} entry
*/
public EntityNotFoundException(final Class<? extends MetaData> type, final Long enityId, final String key) {
this(type.getSimpleName() + " for given entity {" + enityId + "} and with key {" + key + "} does not exist.");
}
/**
* Parameterized constructor for a list of {@link BaseEntity}s not found.
*
* @param type
* of the entity that was not found
*
* @param expected
* collection of the {@link BaseEntity#getId()}s
* @param found
* collection of the {@link BaseEntity#getId()}s
*/
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Collection<Long> expected,
final Collection<Long> found) {
this(type.getSimpleName() + "s with given identifiers {" + expected.stream().filter(id -> !found.contains(id))
.map(String::valueOf).collect(Collectors.joining(",")) + "} do not exist.");
}
}

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.exception;
import java.lang.annotation.Target;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
* the {@link SoftwareModuleNotAssignedToTargetException} is thrown when a
* {@link SoftwareModule} is requested as part of an {@link Action} that has
* however never been assigned to the {@link Target}.
*/
public class SoftwareModuleNotAssignedToTargetException extends EntityNotFoundException {
private static final long serialVersionUID = 1L;
/**
* Constructor
*
* @param moduleId
* thats is not assigned to given {@link Target}
* @param controllerId
* of the {@link Target} where given {@link SoftwareModule} is
* not part of
*/
public SoftwareModuleNotAssignedToTargetException(final Long moduleId, final String controllerId) {
super("No assignment found for " + SoftwareModule.class.getSimpleName() + " with id {" + moduleId + "} to "
+ Target.class.getSimpleName() + " with id {" + controllerId + "}.");
}
}

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
/**
* the {@link SoftwareModuleTypeNotInDistributionSetTypeException} is thrown
* when a {@link SoftwareModuleType} is requested as part of a
* {@link DistributionSetType} but actually neither
* {@link DistributionSetType#getMandatoryModuleTypes()} or
* {@link DistributionSetType#getOptionalModuleTypes()}.
*/
public class SoftwareModuleTypeNotInDistributionSetTypeException extends EntityNotFoundException {
private static final long serialVersionUID = 1L;
/**
* Constructor
*
* @param moduleTypeId
* thats is not part of given {@link DistributionSetType}
* @param distributionSetTypeId
* of the {@link DistributionSetType} where given
* {@link SoftwareModuleType} is not part of
*/
public SoftwareModuleTypeNotInDistributionSetTypeException(final Long moduleTypeId,
final Long distributionSetTypeId) {
super(SoftwareModuleType.class.getSimpleName() + " with id {" + moduleTypeId + "} is not part of "
+ DistributionSetType.class.getSimpleName() + " with id {" + distributionSetTypeId + "}.");
}
}

View File

@@ -12,10 +12,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Operations to be executed by the target. Usually a software update. Other
* supported actions are the cancellation of a running update action or a
* refresh request for target attributes.
*
* Update operations to be executed by the target.
*/
public interface Action extends TenantAwareBaseEntity {

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository.model;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
@@ -57,10 +58,10 @@ public interface DistributionSet extends NamedVersionedEntity {
*
* @param type
* to search for
* @return SoftwareModule of given type or <code>null</code> if not found.
* @return SoftwareModule of given type
*/
default SoftwareModule findFirstModuleByType(final SoftwareModuleType type) {
return getModules().stream().filter(module -> module.getType().equals(type)).findFirst().orElse(null);
default Optional<SoftwareModule> findFirstModuleByType(final SoftwareModuleType type) {
return getModules().stream().filter(module -> module.getType().equals(type)).findAny();
}
/**

View File

@@ -73,7 +73,7 @@ public interface DistributionSetType extends NamedEntity {
*/
default boolean containsMandatoryModuleType(final Long softwareModuleTypeId) {
return getMandatoryModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId))
.findFirst().isPresent();
.findAny().isPresent();
}
/**
@@ -98,7 +98,7 @@ public interface DistributionSetType extends NamedEntity {
*/
default boolean containsOptionalModuleType(final Long softwareModuleTypeId) {
return getOptionalModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId))
.findFirst().isPresent();
.findAny().isPresent();
}
/**

View File

@@ -23,11 +23,7 @@ public interface SoftwareModule extends NamedVersionedEntity {
* @return found {@link Artifact}
*/
default Optional<Artifact> getArtifact(final Long artifactId) {
if (getArtifacts().isEmpty()) {
return Optional.empty();
}
return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst();
return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findAny();
}
/**
@@ -36,12 +32,8 @@ public interface SoftwareModule extends NamedVersionedEntity {
* @return found {@link Artifact}
*/
default Optional<Artifact> getArtifactByFilename(final String fileName) {
if (getArtifacts().isEmpty()) {
return Optional.empty();
}
return getArtifacts().stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim()))
.findFirst();
.findAny();
}
/**

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.lang.reflect.Method;