Feature add optional name to thing created (#888)

* First implementation pushed because of debugging purpose

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Add name field and tests regarding name field functionality in THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* SonarQube realted changes in name field functionality in THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Add name field and tests regarding name field functionality in UPDATE_ATTRIBUTES

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Adapt documentation due to name field in THING_CREATED and UPDATE_ATTRIBUTES

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Add integration tests regarding name field functionality in THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Reformat after finding format bug regarding THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Reformat after finding the real format bug regarding THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Reformat regarding THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Use constant in THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Format in THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Resolving peer review comments regarding THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Resolving peer review comments (organize imports) regarding THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Refactoring regarding THING_CREATED

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Refactoring due to peer review

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Refactoring due to peer review

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Excluding UPDATE_ATTRIBUTES changes and provide functionality of updating the name property in THING_CREATED message

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Refactoring due to peer review

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Refactoring due to peer review

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Fix SonarQube finding

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Merge master into current branch

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>

* Fix peer review findings

Signed-off-by: Ammar Bikic <ammar.bikic@bosch-si.com>
This commit is contained in:
Ammar Bikic
2019-10-24 12:13:35 +02:00
committed by Dominic Schabel
parent b50a82fc0f
commit af0f7ceb5a
10 changed files with 525 additions and 388 deletions

View File

@@ -46,19 +46,19 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface ControllerManagement {
/**
* Adds an {@link ActionStatus} for a cancel {@link Action} including
* potential state changes for the target and the {@link Action} itself.
* Adds an {@link ActionStatus} for a cancel {@link Action} including potential
* state changes for the target and the {@link Action} itself.
*
* @param create
* to be added
* @return the updated {@link Action}
*
*
* @throws EntityAlreadyExistsException
* if a given entity already exists
*
* @throws QuotaExceededException
* if more than the allowed number of status entries or messages
* per entry are inserted
* if more than the allowed number of status entries or messages per
* entry are inserted
* @throws EntityNotFoundException
* if given action does not exist
* @throws ConstraintViolationException
@@ -93,8 +93,8 @@ public interface ControllerManagement {
@NotNull Collection<Long> moduleId);
/**
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
* . No state changes.
* Simple addition of a new {@link ActionStatus} entry to the {@link Action} .
* No state changes.
*
* @param create
* to add to the action
@@ -102,8 +102,8 @@ public interface ControllerManagement {
* @return created {@link ActionStatus} entity
*
* @throws QuotaExceededException
* if more than the allowed number of status entries or messages
* per entry are inserted
* if more than the allowed number of status entries or messages per
* entry are inserted
* @throws EntityNotFoundException
* if given action does not exist
* @throws ConstraintViolationException
@@ -124,8 +124,8 @@ public interface ControllerManagement {
* @throws EntityAlreadyExistsException
* if a given entity already exists
* @throws QuotaExceededException
* if more than the allowed number of status entries or messages
* per entry are inserted
* if more than the allowed number of status entries or messages per
* entry are inserted
* @throws EntityNotFoundException
* if action status not exist
* @throws ConstraintViolationException
@@ -140,7 +140,7 @@ public interface ControllerManagement {
* {@link Target}.
*
* For performance reasons this method does not throw
* {@link EntityNotFoundException} in case target with given controllerId
* {@link EntityNotFoundException} in case target with given controlelrId
* does not exist but will return an {@link Optional#empty()} instead.
*
* @param controllerId
@@ -152,8 +152,8 @@ public interface ControllerManagement {
Optional<Action> findOldestActiveActionByTarget(@NotEmpty String controllerId);
/**
* Retrieves all active actions which are assigned to the target with the
* given controller ID.
* Retrieves all active actions which are assigned to the target with the given
* controller ID.
*
* @param pageable
* pagination parameter
@@ -165,8 +165,7 @@ public interface ControllerManagement {
Page<Action> findActiveActionsByTarget(@NotNull Pageable pageable, @NotEmpty String controllerId);
/**
* Get the {@link Action} entity for given actionId with all lazy
* attributes.
* Get the {@link Action} entity for given actionId with all lazy attributes.
*
* @param actionId
* to be id of the action
@@ -176,8 +175,7 @@ public interface ControllerManagement {
Optional<Action> findActionWithDetails(long actionId);
/**
* Retrieves all the {@link ActionStatus} entries of the given
* {@link Action}.
* Retrieves all the {@link ActionStatus} entries of the given {@link Action}.
*
* @param pageReq
* pagination parameter
@@ -192,11 +190,10 @@ public interface ControllerManagement {
Page<ActionStatus> findActionStatusByAction(@NotNull Pageable pageReq, long actionId);
/**
* Register new target in the repository (plug-and-play) and in case it
* already exists updates {@link Target#getAddress()} and
* Register new target in the repository (plug-and-play) and in case it already
* exists updates {@link Target#getAddress()} and
* {@link Target#getLastTargetQuery()} and switches if
* {@link TargetUpdateStatus#UNKNOWN} to
* {@link TargetUpdateStatus#REGISTERED}.
* {@link TargetUpdateStatus#UNKNOWN} to {@link TargetUpdateStatus#REGISTERED}.
*
* @param controllerId
* reference
@@ -208,14 +205,31 @@ public interface ControllerManagement {
Target findOrRegisterTargetIfItDoesNotExist(@NotEmpty String controllerId, @NotNull URI address);
/**
* Retrieves last {@link Action} for a download of an artifact of given
* module and target if exists and is not canceled.
* Register new target in the repository (plug-and-play) and in case it already
* exists updates {@link Target#getAddress()} and
* {@link Target#getLastTargetQuery()} and {@link Target#getName()} and switches if
* {@link TargetUpdateStatus#UNKNOWN} to {@link TargetUpdateStatus#REGISTERED}.
*
* @param controllerId
* reference
* @param address
* the client IP address of the target, might be {@code null}
* @param name
* the name of the target
* @return target reference
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Target findOrRegisterTargetIfItDoesNotExist(@NotEmpty String controllerId, @NotNull URI address, String name);
/**
* Retrieves last {@link Action} for a download of an artifact of given module
* and target if exists and is not canceled.
*
* @param controllerId
* to look for
* @param moduleId
* of the the {@link SoftwareModule} that should be assigned to
* the target
* of the the {@link SoftwareModule} that should be assigned to the
* target
* @return last {@link Action} for given combination
*
* @throws EntityNotFoundException
@@ -253,18 +267,18 @@ public interface ControllerManagement {
int getMaintenanceWindowPollCount();
/**
* Returns polling time based on the maintenance window for an action.
* Server will reduce the polling interval as the start time for maintenance
* window approaches, so that at least these many attempts are made between
* current polling until start of maintenance window. Poll time keeps
* reducing with MinPollingTime as lower limit
* {@link TenantConfigurationKey#MIN_POLLING_TIME_INTERVAL}. After the start
* of maintenance window, it resets to default
* Returns polling time based on the maintenance window for an action. Server
* will reduce the polling interval as the start time for maintenance window
* approaches, so that at least these many attempts are made between current
* polling until start of maintenance window. Poll time keeps reducing with
* MinPollingTime as lower limit
* {@link TenantConfigurationKey#MIN_POLLING_TIME_INTERVAL}. After the start of
* maintenance window, it resets to default
* {@link TenantConfigurationKey#POLLING_TIME_INTERVAL}.
*
* @param actionId
* id the {@link Action} for which polling time is calculated
* based on it having maintenance window or not
* id the {@link Action} for which polling time is calculated based
* on it having maintenance window or not
*
* @return current {@link TenantConfigurationKey#POLLING_TIME_INTERVAL}.
*/
@@ -272,20 +286,20 @@ public interface ControllerManagement {
String getPollingTimeForAction(long actionId);
/**
* Checks if a given target has currently or has even been assigned to the
* given artifact through the action history list. This can e.g. indicate if
* a target is allowed to download a given artifact because it has currently
* assigned or had ever been assigned to the target and so it's visible to a
* specific target e.g. for downloading.
* Checks if a given target has currently or has even been assigned to the given
* artifact through the action history list. This can e.g. indicate if a target
* is allowed to download a given artifact because it has currently assigned or
* had ever been assigned to the target and so it's visible to a specific target
* e.g. for downloading.
*
* @param controllerId
* the ID of the target to check
* @param sha1Hash
* of the artifact to verify if the given target had even been
* assigned to
* @return {@code true} if the given target has currently or had ever a
* relation to the given artifact through the action history,
* otherwise {@code false}
* @return {@code true} if the given target has currently or had ever a relation
* to the given artifact through the action history, otherwise
* {@code false}
*
* @throws EntityNotFoundException
* if target with given ID does not exist
@@ -294,20 +308,20 @@ public interface ControllerManagement {
boolean hasTargetArtifactAssigned(@NotEmpty String controllerId, @NotEmpty String sha1Hash);
/**
* Checks if a given target has currently or has even been assigned to the
* given artifact through the action history list. This can e.g. indicate if
* a target is allowed to download a given artifact because it has currently
* assigned or had ever been assigned to the target and so it's visible to a
* specific target e.g. for downloading.
* Checks if a given target has currently or has even been assigned to the given
* artifact through the action history list. This can e.g. indicate if a target
* is allowed to download a given artifact because it has currently assigned or
* had ever been assigned to the target and so it's visible to a specific target
* e.g. for downloading.
*
* @param targetId
* the ID of the target to check
* @param sha1Hash
* of the artifact to verify if the given target had even been
* assigned to
* @return {@code true} if the given target has currently or had ever a
* relation to the given artifact through the action history,
* otherwise {@code false}
* @return {@code true} if the given target has currently or had ever a relation
* to the given artifact through the action history, otherwise
* {@code false}
*
* @throws EntityNotFoundException
* if target with given ID does not exist
@@ -316,8 +330,8 @@ public interface ControllerManagement {
boolean hasTargetArtifactAssigned(long targetId, @NotEmpty String sha1Hash);
/**
* Registers retrieved status for given {@link Target} and {@link Action} if
* it does not exist yet.
* Registers retrieved status for given {@link Target} and {@link Action} if it
* does not exist yet.
*
* @param actionId
* to the handle status for
@@ -371,9 +385,8 @@ public interface ControllerManagement {
Optional<Target> getByControllerId(@NotEmpty String controllerId);
/**
* Finds {@link Target} based on given ID returns found Target without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible.
* Finds {@link Target} based on given ID returns found Target without details,
* i.e. NO {@link Target#getTags()} and {@link Target#getActions()} possible.
*
* @param targetId
* to look for.
@@ -385,21 +398,20 @@ public interface ControllerManagement {
Optional<Target> get(long targetId);
/**
* Retrieves the specified number of messages from action history of the
* given {@link Action} based on messageCount. Regardless of the value of
* Retrieves the specified number of messages from action history of the given
* {@link Action} based on messageCount. Regardless of the value of
* messageCount, in order to restrict resource utilisation by controllers,
* maximum number of messages that are retrieved from database is limited by
* {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}. messageCount
* less then zero, retrieves the maximum allowed number of action status
* messages from history; messageCount equal zero, does not retrieve any
* message; and messageCount larger then zero, retrieves the specified
* number of messages, limited by maximum allowed number. A controller sends
* the feedback for an {@link ActionStatus} as a list of messages; while
* returning the messages, even though the messages from multiple
* {@link ActionStatus} are retrieved in descending order by the reported
* time ({@link ActionStatus#getOccurredAt()}), i.e. latest ActionStatus
* first, the sub-ordering of messages from within single
* {@link ActionStatus} is unspecified.
* {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}. messageCount less
* then zero, retrieves the maximum allowed number of action status messages
* from history; messageCount equal zero, does not retrieve any message; and
* messageCount larger then zero, retrieves the specified number of messages,
* limited by maximum allowed number. A controller sends the feedback for an
* {@link ActionStatus} as a list of messages; while returning the messages,
* even though the messages from multiple {@link ActionStatus} are retrieved in
* descending order by the reported time ({@link ActionStatus#getOccurredAt()}),
* i.e. latest ActionStatus first, the sub-ordering of messages from within
* single {@link ActionStatus} is unspecified.
*
* @param actionId
* to be filtered on
@@ -412,10 +424,10 @@ public interface ControllerManagement {
List<String> getActionHistoryMessages(long actionId, int messageCount);
/**
* Cancels given {@link Action} for this {@link Target}. However, it might
* be possible that the controller will continue to work on the
* cancellation. The controller needs to acknowledge or reject the
* cancellation using {@link DdiRootController#postCancelActionFeedback}.
* Cancels given {@link Action} for this {@link Target}. However, it might be
* possible that the controller will continue to work on the cancellation. The
* controller needs to acknowledge or reject the cancellation using
* {@link DdiRootController#postCancelActionFeedback}.
*
* @param actionId
* to be canceled
@@ -442,9 +454,8 @@ public interface ControllerManagement {
void updateActionExternalRef(long actionId, @NotEmpty String externalRef);
/**
* Retrieves list of {@link Action}s which matches the provided
* externalRefs.
*
* Retrieves list of {@link Action}s which matches the provided externalRefs.
*
* @param externalRefs
* for which the actions need to be fetched.
* @return list of {@link Action}s matching the externalRefs.