Completed management separation.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-05-19 11:16:26 +02:00
parent 3c0d5396b0
commit 3e5330a5e6
77 changed files with 2095 additions and 1792 deletions

View File

@@ -12,8 +12,8 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.hawkbit.aspects.ExceptionMappingAspectHandler;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.jpa.SystemManagement;
import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder;
import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder;

View File

@@ -277,13 +277,11 @@ public interface ArtifactManagement {
SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id);
/**
* Loads {@link org.eclipse.hawkbit.artifact.server.json.model.Artifact}
* from store for given {@link LocalArtifact}.
* Loads {@link DbArtifact} from store for given {@link LocalArtifact}.
*
* @param artifact
* to search for
* @return loaded
* {@link org.eclipse.hawkbit.artifact.server.json.model.Artifact}
* @return loaded {@link DbArtifact}
*
* @throws GridFSDBFileNotFoundException
* if file could not be found in store

View File

@@ -43,16 +43,6 @@ public interface ControllerManagement {
String SERVER_MESSAGE_PREFIX = "Update Server: ";
/**
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
* . No state changes.
*
* @param statusMessage
* to add to the action
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
void addInformationalActionStatus(@NotNull ActionStatus statusMessage);
/**
* Adds an {@link ActionStatus} for a cancel {@link Action} including
* potential state changes for the target and the {@link Action} itself.
@@ -68,6 +58,16 @@ public interface ControllerManagement {
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Action addCancelActionStatus(@NotNull ActionStatus actionStatus);
/**
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
* . No state changes.
*
* @param statusMessage
* to add to the action
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
void addInformationalActionStatus(@NotNull ActionStatus statusMessage);
/**
* Adds an {@link ActionStatus} entry for an update {@link Action} including
* potential state changes for the target and the {@link Action} itself.
@@ -133,14 +133,14 @@ public interface ControllerManagement {
List<SoftwareModule> findSoftwareModulesByDistributionSet(@NotNull DistributionSet distributionSet);
/**
* Retrieves last {@link UpdateAction} for a download of an artifact of
* given module and target.
* Retrieves last {@link Action} for a download of an artifact of given
* module and target.
*
* @param controllerId
* to look for
* @param module
* that should be assigned to the target
* @return last {@link UpdateAction} for given combination
* @return last {@link Action} for given combination
*
* @throws EntityNotFoundException
* if action for given combination could not be found

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
import javax.validation.constraints.NotNull;
@@ -99,7 +100,7 @@ public interface DeploymentManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET)
DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID,
@NotEmpty List<TargetWithActionType> targets);
@NotEmpty Collection<TargetWithActionType> targets);
// TODO document: why are rollouts in the signature ? can all the parameters
// be null or the list empty?
@@ -123,7 +124,7 @@ public interface DeploymentManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET)
DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID,
@NotEmpty List<TargetWithActionType> targets, Rollout rollout, RolloutGroup rolloutGroup);
@NotEmpty Collection<TargetWithActionType> targets, Rollout rollout, RolloutGroup rolloutGroup);
/**
* method assigns the {@link DistributionSet} to all {@link Target}s by
@@ -210,7 +211,7 @@ public interface DeploymentManagement {
* the roll out group for this action
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
void createScheduledAction(List<Target> targets, DistributionSet distributionSet, ActionType actionType,
void createScheduledAction(Collection<Target> targets, DistributionSet distributionSet, ActionType actionType,
long forcedTime, Rollout rollout, RolloutGroup rolloutGroup);
/**

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository;
import java.util.Collections;
import java.util.List;
import org.eclipse.hawkbit.repository.jpa.TargetManagement;
import org.eclipse.hawkbit.repository.model.AssignmentResult;
import org.eclipse.hawkbit.repository.model.Target;
@@ -53,11 +52,6 @@ public class DistributionSetAssignmentResult extends AssignmentResult<Target> {
this.targetManagement = targetManagement;
}
@Override
public List<Target> getAssignedEntity() {
return targetManagement.findTargetByControllerID(assignedTargets);
}
/**
* @return the actionIds
*/
@@ -65,4 +59,9 @@ public class DistributionSetAssignmentResult extends AssignmentResult<Target> {
return actions;
}
@Override
public List<Target> getAssignedEntity() {
return targetManagement.findTargetByControllerID(assignedTargets);
}
}

View File

@@ -16,32 +16,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
* Holds distribution set filter parameters.
*/
public final class DistributionSetFilter {
private final Boolean isDeleted;
private final Boolean isComplete;
private final DistributionSetType type;
private final String searchText;
private final Boolean selectDSWithNoTag;
private final Collection<String> tagNames;
private final String assignedTargetId;
private final String installedTargetId;
/**
* Parametric constructor.
*
* @param builder
* DistributionSetFilterBuilder
*/
public DistributionSetFilter(final DistributionSetFilterBuilder builder) {
this.isDeleted = builder.isDeleted;
this.isComplete = builder.isComplete;
this.type = builder.type;
this.searchText = builder.searchText;
this.selectDSWithNoTag = builder.selectDSWithNoTag;
this.tagNames = builder.tagNames;
this.assignedTargetId = builder.assignedTargetId;
this.installedTargetId = builder.installedTargetId;
}
/**
*
* Distribution set filter builder.
@@ -68,8 +42,13 @@ public final class DistributionSetFilter {
return new DistributionSetFilter(this);
}
public DistributionSetFilterBuilder setIsDeleted(final Boolean isDeleted) {
this.isDeleted = isDeleted;
public DistributionSetFilterBuilder setAssignedTargetId(final String assignedTargetId) {
this.assignedTargetId = assignedTargetId;
return this;
}
public DistributionSetFilterBuilder setInstalledTargetId(final String installedTargetId) {
this.installedTargetId = installedTargetId;
return this;
}
@@ -78,8 +57,8 @@ public final class DistributionSetFilter {
return this;
}
public DistributionSetFilterBuilder setType(final DistributionSetType type) {
this.type = type;
public DistributionSetFilterBuilder setIsDeleted(final Boolean isDeleted) {
this.isDeleted = isDeleted;
return this;
}
@@ -98,28 +77,53 @@ public final class DistributionSetFilter {
return this;
}
public DistributionSetFilterBuilder setAssignedTargetId(final String assignedTargetId) {
this.assignedTargetId = assignedTargetId;
return this;
}
public DistributionSetFilterBuilder setInstalledTargetId(final String installedTargetId) {
this.installedTargetId = installedTargetId;
public DistributionSetFilterBuilder setType(final DistributionSetType type) {
this.type = type;
return this;
}
}
private final Boolean isDeleted;
private final Boolean isComplete;
private final DistributionSetType type;
private final String searchText;
private final Boolean selectDSWithNoTag;
private final Collection<String> tagNames;
private final String assignedTargetId;
public Boolean getIsDeleted() {
return isDeleted;
private final String installedTargetId;
/**
* Parametric constructor.
*
* @param builder
* DistributionSetFilterBuilder
*/
public DistributionSetFilter(final DistributionSetFilterBuilder builder) {
this.isDeleted = builder.isDeleted;
this.isComplete = builder.isComplete;
this.type = builder.type;
this.searchText = builder.searchText;
this.selectDSWithNoTag = builder.selectDSWithNoTag;
this.tagNames = builder.tagNames;
this.assignedTargetId = builder.assignedTargetId;
this.installedTargetId = builder.installedTargetId;
}
public String getAssignedTargetId() {
return assignedTargetId;
}
public String getInstalledTargetId() {
return installedTargetId;
}
public Boolean getIsComplete() {
return isComplete;
}
public DistributionSetType getType() {
return type;
public Boolean getIsDeleted() {
return isDeleted;
}
public String getSearchText() {
@@ -134,12 +138,8 @@ public final class DistributionSetFilter {
return tagNames;
}
public String getAssignedTargetId() {
return assignedTargetId;
}
public String getInstalledTargetId() {
return installedTargetId;
public DistributionSetType getType() {
return type;
}
}

View File

@@ -41,6 +41,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
/**
* Management service for {@link DistributionSet}s.
*
*/
public interface DistributionSetManagement {
// TODO rename/document the whole with details thing (document what the

View File

@@ -32,15 +32,81 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface ReportManagement {
/**
* Generates a report of all targets of their current update status count.
* For each {@link TargetUpdateStatus} an total count of targets which are
* in this status currently.
* Data base format.
*
* @return a data report series which contains the target count for each
* target update status
*
*
* @param <T>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DataReportSeries<TargetUpdateStatus> targetStatus();
public interface DateType<T> {
/**
* @param s
* @return T
*/
T format(String s);
/**
* h2 format.
*
* @return String
*/
String h2Format();
/**
* mysql format.
*
* @return String
*/
String mySqlFormat();
}
/**
* Return DateTypes.
*/
public static final class DateTypes implements Serializable {
private static final long serialVersionUID = 1L;
private static final PerMonth PER_MONTH = new PerMonth();
/**
* @return PerMonth
*/
public static PerMonth perMonth() {
return PER_MONTH;
}
private DateTypes() {
}
}
/**
* Gives the date format based on DB H2 or mySql.
*
*
*
*/
public static final class PerMonth implements DateType<LocalDate>, Serializable {
private static final long serialVersionUID = 1L;
private static final String DATE_PATTERN = "yyyy-MM";
@Override
public LocalDate format(final String s) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
final YearMonth ym = YearMonth.parse(s, formatter);
return ym.atDay(1);
}
@Override
public String h2Format() {
return DATE_PATTERN;
}
@Override
public String mySqlFormat() {
return "%Y-%m";
}
}
/**
* Generates a report of the top x distribution set assigned usage as a list
@@ -81,22 +147,6 @@ public interface ReportManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<InnerOuterDataReportSeries<String>> distributionUsageInstalled(int topXEntries);
/**
* Generates report for target created over period.
*
* @param dateType
* {@link PerMonth}
* @param from
* start date
* @param to
* end date
* @return <T> DataReportSeries<T> ListReportSeries list of target created
* count
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
<T extends Serializable> DataReportSeries<T> targetsCreatedOverPeriod(@NotNull DateType<T> dateType,
@NotNull LocalDateTime from, @NotNull LocalDateTime to);
/**
* Generates report for feedback over period.
*
@@ -113,6 +163,22 @@ public interface ReportManagement {
<T extends Serializable> DataReportSeries<T> feedbackReceivedOverTime(@NotNull DateType<T> dateType,
@NotNull LocalDateTime from, @NotNull LocalDateTime to);
/**
* Generates report for target created over period.
*
* @param dateType
* {@link PerMonth}
* @param from
* start date
* @param to
* end date
* @return <T> DataReportSeries<T> ListReportSeries list of target created
* count
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
<T extends Serializable> DataReportSeries<T> targetsCreatedOverPeriod(@NotNull DateType<T> dateType,
@NotNull LocalDateTime from, @NotNull LocalDateTime to);
/**
* Generates a report as a {@link ListReportSeries} targets polled based on
* the {@link TargetStatus#getLastTargetQuery()} within an hour, day, week,
@@ -130,80 +196,14 @@ public interface ReportManagement {
DataReportSeries<SeriesTime> targetsLastPoll();
/**
* Return DateTypes.
* Generates a report of all targets of their current update status count.
* For each {@link TargetUpdateStatus} an total count of targets which are
* in this status currently.
*
* @return a data report series which contains the target count for each
* target update status
*/
public static final class DateTypes implements Serializable {
private static final long serialVersionUID = 1L;
private static final PerMonth PER_MONTH = new PerMonth();
private DateTypes() {
}
/**
* @return PerMonth
*/
public static PerMonth perMonth() {
return PER_MONTH;
}
}
/**
* Data base format.
*
*
*
* @param <T>
*/
public interface DateType<T> {
/**
* @param s
* @return T
*/
T format(String s);
/**
* h2 format.
*
* @return String
*/
String h2Format();
/**
* mysql format.
*
* @return String
*/
String mySqlFormat();
}
/**
* Gives the date format based on DB H2 or mySql.
*
*
*
*/
public static final class PerMonth implements DateType<LocalDate>, Serializable {
private static final long serialVersionUID = 1L;
private static final String DATE_PATTERN = "yyyy-MM";
@Override
public LocalDate format(final String s) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
final YearMonth ym = YearMonth.parse(s, formatter);
return ym.atDay(1);
}
@Override
public String h2Format() {
return DATE_PATTERN;
}
@Override
public String mySqlFormat() {
return "%Y-%m";
}
}
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DataReportSeries<TargetUpdateStatus> targetStatus();
}

View File

@@ -27,47 +27,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
*/
public interface RolloutGroupManagement {
/**
* Retrieves a single {@link RolloutGroup} by its ID.
*
* @param rolloutGroupId
* 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);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout}.
*
* @param rolloutId
* the ID of the rollout to filter the {@link RolloutGroup}s
* @param page
* the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable page);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout} and the given {@link Specification}.
*
* @param rolloutId
* the ID of the rollout to filter the {@link RolloutGroup}s
* @param specification
* the specification to filter the result set based on attributes
* of the {@link RolloutGroup}
* @param page
* the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findRolloutGroupsAll(@NotNull Rollout rollout,
@NotNull Specification<RolloutGroup> specification, @NotNull Pageable page);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout} with the detailed status.
@@ -81,47 +40,6 @@ public interface RolloutGroupManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable page);
/**
* Get count of targets in different status in rollout group.
*
* @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);
// TODO discuss: target read perm missing?
/**
* Get targets of specified rollout group.
*
* @param rolloutGroup
* rollout group
* @param specification
* the specification for filtering the targets of a rollout group
* @param page
* the page request to sort and limit the result
*
* @return Page<Target> list of targets of a rollout group
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Target> findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup,
@NotNull Specification<Target> specification, @NotNull Pageable page);
// TODO discuss: target read perm missing?
/**
* Get targets of specified rollout group.
*
* @param rolloutGroup
* rollout group
* @param page
* the page request to sort and limit the result
*
* @return Page<Target> list of targets of a rollout group
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Target> findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page);
// TODO discuss: target read perm missing?
/**
*
@@ -141,4 +59,86 @@ public interface RolloutGroupManagement {
Page<TargetWithActionStatus> findAllTargetsWithActionStatus(@NotNull PageRequest pageRequest,
@NotNull RolloutGroup rolloutGroup);
/**
* Retrieves a single {@link RolloutGroup} by its ID.
*
* @param rolloutGroupId
* 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);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout} and the given {@link Specification}.
*
* @param rolloutId
* the ID of the rollout to filter the {@link RolloutGroup}s
* @param specification
* the specification to filter the result set based on attributes
* of the {@link RolloutGroup}
* @param page
* the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findRolloutGroupsAll(@NotNull Rollout rollout,
@NotNull Specification<RolloutGroup> specification, @NotNull Pageable page);
/**
* Retrieves a page of {@link RolloutGroup}s filtered by a given
* {@link Rollout}.
*
* @param rolloutId
* the ID of the rollout to filter the {@link RolloutGroup}s
* @param page
* the page request to sort and limit the result
* @return a page of found {@link RolloutGroup}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<RolloutGroup> findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable page);
// TODO discuss: target read perm missing?
/**
* Get targets of specified rollout group.
*
* @param rolloutGroup
* rollout group
* @param page
* the page request to sort and limit the result
*
* @return Page<Target> list of targets of a rollout group
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Target> findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page);
// TODO discuss: target read perm missing?
/**
* Get targets of specified rollout group.
*
* @param rolloutGroup
* rollout group
* @param specification
* the specification for filtering the targets of a rollout group
* @param page
* the page request to sort and limit the result
*
* @return Page<Target> list of targets of a rollout group
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Target> findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup,
@NotNull Specification<Target> specification, @NotNull Pageable page);
/**
* Get count of targets in different status in rollout group.
*
* @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);
}

View File

@@ -33,38 +33,54 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface RolloutManagement {
/**
* Retrieves all rollouts.
* Checking running rollouts. Rollouts which are checked updating the
* {@link Rollout#setLastCheck(long)} to indicate that the current instance
* is handling the specific rollout. This code should run as system-code.
*
* @param page
* the page request to sort and limit the result
* @return a page of found rollouts
* <pre>
* {@code
* SystemSecurityContext.runAsSystem(new Callable<Void>() {
* public Void call() throws Exception {
* //run system-code
* }
* });
* }
* </pre>
*
* This method is attend to be called by a scheduler.
* {@link RolloutScheduler}. 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
* evaluated.
*
* @param delayBetweenChecks
* the time in milliseconds of the delay between the further and
* this check. This check is only applied if the last check is
* less than (lastcheck-delay).
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Rollout> findAll(@NotNull Pageable page);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
void checkRunningRollouts(long delayBetweenChecks);
/**
* Retrieves all rollouts found by the given specification.
* Counts all {@link Rollout}s in the repository.
*
* @param specification
* the specification to filter rollouts
* @param page
* the page request to sort and limit the result
* @return a page of found rollouts
* @return number of roll outs
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Rollout> findAllWithDetailedStatusByPredicate(@NotNull Specification<Rollout> specification,
@NotNull Pageable page);
Long countRolloutsAll();
/**
* Retrieves a specific rollout by its ID.
* Count rollouts by given text in name or description.
*
* @param rolloutId
* the ID of the rollout to retrieve
* @return the founded rollout or {@code null} if rollout with given ID does
* not exists
* @param searchText
* name or description
* @return total count rollouts for specified filter text.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutById(@NotNull Long rolloutId);
Long countRolloutsAllByFilters(@NotEmpty String searchText);
/**
* Persists a new rollout entity. The filter within the
@@ -131,6 +147,138 @@ public interface RolloutManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
Rollout createRolloutAsync(@NotNull Rollout rollout, int amountGroup, @NotNull RolloutGroupConditions conditions);
/**
* Retrieves all rollouts.
*
* @param page
* the page request to sort and limit the result
* @return a page of found rollouts
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Rollout> findAll(@NotNull Pageable page);
/**
* Get count of targets in different status in rollout.
*
* @param page
* the page request to sort and limit the result
* @return a list of rollouts with details of targets count for different
* statuses
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Rollout> findAllRolloutsWithDetailedStatus(@NotNull Pageable page);
/**
* Retrieves all rollouts found by the given specification.
*
* @param specification
* the specification to filter rollouts
* @param page
* the page request to sort and limit the result
* @return a page of found rollouts
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Rollout> findAllWithDetailedStatusByPredicate(@NotNull Specification<Rollout> specification,
@NotNull Pageable page);
/**
* Finds rollouts by given text in name or description.
*
* @param pageable
* the page request to sort and limit the result
* @param searchText
* search text which matches name or description of rollout
* @return the founded rollout or {@code null} if rollout with given ID does
* not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Slice<Rollout> findRolloutByFilters(@NotNull Pageable pageable, @NotEmpty String searchText);
/**
* Retrieves a specific rollout by its ID.
*
* @param rolloutId
* the ID of the rollout to retrieve
* @return the founded rollout or {@code null} if rollout with given ID does
* not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutById(@NotNull Long rolloutId);
/**
* Retrieves a specific rollout by its name.
*
* @param rolloutName
* the name of the rollout to retrieve
* @return the founded rollout or {@code null} if rollout with given name
* does not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutByName(@NotNull String rolloutName);
/**
* Get count of targets in different status in rollout.
*
* @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);
/***
* Get finished percentage details for a specified group which is in running
* state.
*
* @param rolloutId
* the ID of the {@link Rollout}
* @param rolloutGroup
* the ID of the {@link RolloutGroup}
* @return percentage finished
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup);
/**
* Pauses a rollout which is currently running. The Rollout switches
* {@link RolloutStatus#PAUSED}. {@link RolloutGroup}s which are currently
* running will be untouched. {@link RolloutGroup}s which are
* {@link RolloutGroupStatus#SCHEDULED} will not be started and keep in
* {@link RolloutGroupStatus#SCHEDULED} state until the rollout is
* {@link RolloutManagement#resumeRollout(Rollout)}.
*
* Switching the rollout status to {@link RolloutStatus#PAUSED} is
* sufficient due the {@link #checkRunningRollouts(long)} will not check
* this rollout anymore.
*
* @param rollout
* the rollout to be paused.
*
* @throws RolloutIllegalStateException
* if given rollout is not in {@link RolloutStatus#RUNNING}.
* Only running rollouts can be paused.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
void pauseRollout(@NotNull Rollout rollout);
/**
* Resumes a paused rollout. The rollout switches back to
* {@link RolloutStatus#RUNNING} state which is then picked up again by the
* {@link #checkRunningRollouts(long)}.
*
* @param rollout
* the rollout to be resumed
* @throws RolloutIllegalStateException
* if given rollout is not in {@link RolloutStatus#PAUSED}. Only
* paused rollouts can be resumed.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
void resumeRollout(@NotNull Rollout rollout);
/**
* Starts a rollout which has been created. The rollout must be in
* {@link RolloutStatus#READY} state. The according actions will be created
@@ -176,118 +324,6 @@ public interface RolloutManagement {
+ SpringEvalExpressions.IS_SYSTEM_CODE)
Rollout startRolloutAsync(@NotNull Rollout rollout);
/**
* Pauses a rollout which is currently running. The Rollout switches
* {@link RolloutStatus#PAUSED}. {@link RolloutGroup}s which are currently
* running will be untouched. {@link RolloutGroup}s which are
* {@link RolloutGroupStatus#SCHEDULED} will not be started and keep in
* {@link RolloutGroupStatus#SCHEDULED} state until the rollout is
* {@link RolloutManagement#resumeRollout(Rollout)}.
*
* Switching the rollout status to {@link RolloutStatus#PAUSED} is
* sufficient due the {@link #checkRunningRollouts(long)} will not check
* this rollout anymore.
*
* @param rollout
* the rollout to be paused.
*
* @throws RolloutIllegalStateException
* if given rollout is not in {@link RolloutStatus#RUNNING}.
* Only running rollouts can be paused.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
void pauseRollout(@NotNull Rollout rollout);
/**
* Resumes a paused rollout. The rollout switches back to
* {@link RolloutStatus#RUNNING} state which is then picked up again by the
* {@link #checkRunningRollouts(long)}.
*
* @param rollout
* the rollout to be resumed
* @throws RolloutIllegalStateException
* if given rollout is not in {@link RolloutStatus#PAUSED}. Only
* paused rollouts can be resumed.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
void resumeRollout(@NotNull Rollout rollout);
/**
* Checking running rollouts. Rollouts which are checked updating the
* {@link Rollout#setLastCheck(long)} to indicate that the current instance
* is handling the specific rollout. This code should run as system-code.
*
* <pre>
* {@code
* SystemSecurityContext.runAsSystem(new Callable<Void>() {
* public Void call() throws Exception {
* //run system-code
* }
* });
* }
* </pre>
*
* This method is attend to be called by a scheduler.
* {@link RolloutScheduler}. 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
* evaluated.
*
* @param delayBetweenChecks
* the time in milliseconds of the delay between the further and
* this check. This check is only applied if the last check is
* less than (lastcheck-delay).
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
void checkRunningRollouts(long delayBetweenChecks);
/**
* Counts all {@link Rollout}s in the repository.
*
* @return number of roll outs
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Long countRolloutsAll();
/**
* Count rollouts by given text in name or description.
*
* @param searchText
* name or description
* @return total count rollouts for specified filter text.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Long countRolloutsAllByFilters(@NotEmpty String searchText);
/**
* Finds rollouts by given text in name or description.
*
* @param pageable
* the page request to sort and limit the result
* @param searchText
* search text which matches name or description of rollout
* @return the founded rollout or {@code null} if rollout with given ID does
* not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Slice<Rollout> findRolloutByFilters(@NotNull Pageable pageable, @NotEmpty String searchText);
/**
* Retrieves a specific rollout by its name.
*
* @param rolloutName
* the name of the rollout to retrieve
* @return the founded rollout or {@code null} if rollout with given name
* does not exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Rollout findRolloutByName(@NotNull String rolloutName);
/**
* Update rollout details.
*
@@ -299,40 +335,4 @@ public interface RolloutManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
Rollout updateRollout(@NotNull Rollout rollout);
/**
* Get count of targets in different status in rollout.
*
* @param page
* the page request to sort and limit the result
* @return a list of rollouts with details of targets count for different
* statuses
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Page<Rollout> findAllRolloutsWithDetailedStatus(@NotNull Pageable page);
/**
* Get count of targets in different status in rollout.
*
* @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);
/***
* Get finished percentage details for a specified group which is in running
* state.
*
* @param rolloutId
* the ID of the {@link Rollout}
* @param rolloutGroup
* the ID of the {@link RolloutGroup}
* @return percentage finished
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup);
}

View File

@@ -18,12 +18,6 @@ import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties("hawkbit.rollout")
public class RolloutProperties {
private final Scheduler scheduler = new Scheduler();
public Scheduler getScheduler() {
return scheduler;
}
/**
* Rollout scheduler configuration.
*/
@@ -47,4 +41,10 @@ public class RolloutProperties {
}
private final Scheduler scheduler = new Scheduler();
public Scheduler getScheduler() {
return scheduler;
}
}

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
import java.util.List;
import org.eclipse.hawkbit.repository.jpa.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger;

View File

@@ -36,235 +36,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
*/
public interface SoftwareManagement {
/**
* Updates existing {@link SoftwareModule}. Update-able values are
* {@link SoftwareModule#getDescription()}
* {@link SoftwareModule#getVendor()}.
*
* @param sm
* to update
*
* @return the saved {@link Entity}.
*
* @throws NullPointerException
* of {@link SoftwareModule#getId()} is <code>null</code>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModule updateSoftwareModule(@NotNull SoftwareModule sm);
/**
* Updates existing {@link SoftwareModuleType}. Update-able value is
* {@link SoftwareModuleType#getDescription()} and
* {@link SoftwareModuleType#getColour()}.
*
* @param sm
* to update
* @return updated {@link Entity}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm);
/**
*
* @param swModule
* SoftwareModule to create
* @return SoftwareModule
* @throws EntityAlreadyExistsException
* if a given entity already exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
SoftwareModule createSoftwareModule(@NotNull SoftwareModule swModule);
/**
* Create {@link SoftwareModule}s in the repository.
*
* @param swModules
* {@link SoftwareModule}s to create
* @return SoftwareModule
* @throws EntityAlreadyExistsException
* if a given entity already exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<SoftwareModule> createSoftwareModule(@NotNull Iterable<SoftwareModule> swModules);
/**
* retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType}
* .
*
* @param pageable
* page parameters
* @param type
* to be filtered on
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type);
/**
* Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}.
*
* @param type
* to count
* @return number of found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModulesByType(@NotNull SoftwareModuleType type);
/**
* Finds {@link SoftwareModule} by given id.
*
* @param id
* to search for
* @return the found {@link SoftwareModule}s or <code>null</code> if not
* found.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
SoftwareModule findSoftwareModuleById(@NotNull Long id);
/**
* retrieves {@link SoftwareModule} by their name AND version AND type..
*
* @param name
* of the {@link SoftwareModule}
* @param version
* of the {@link SoftwareModule}
* @param type
* of the {@link SoftwareModule}
* @return the found {@link SoftwareModule} or <code>null</code>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
@NotNull SoftwareModuleType type);
/**
* Deletes the given {@link SoftwareModule} {@link Entity}.
*
* @param bsm
* is the {@link SoftwareModule} to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModule(@NotNull SoftwareModule bsm);
/**
* Deletes {@link SoftwareModule}s which is any if the given ids.
*
* @param ids
* of the Software Modules to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModules(@NotNull Iterable<Long> ids);
/**
* Retrieves all software modules. Deleted ones are filtered.
*
* @param pageable
* pagination parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModulesAll(@NotNull Pageable pageable);
/**
* Count all {@link SoftwareModule}s in the repository that are not marked
* as deleted.
*
* @return number of {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModulesAll();
/**
* Retrieves software module including details (
* {@link SoftwareModule#getArtifacts()}).
*
* @param id
* parameter
* @param isDeleted
* parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id);
/**
* Retrieves all {@link SoftwareModule}s with a given specification.
*
* @param spec
* the specification to filter the software modules
* @param pageable
* pagination parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModule> findSoftwareModulesByPredicate(@NotNull Specification<SoftwareModule> spec,
@NotNull Pageable pageable);
/**
* Retrieves all {@link SoftwareModuleType}s with a given specification.
*
* @param spec
* the specification to filter the software modules types
* @param pageable
* pagination parameter
* @return the found {@link SoftwareModuleType}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleType> findSoftwareModuleTypesByPredicate(@NotNull Specification<SoftwareModuleType> spec,
@NotNull Pageable pageable);
/**
* Retrieves all software modules with a given list of ids
* {@link SoftwareModule#getId()}.
*
* @param ids
* to search for
* @return {@link List} of found {@link SoftwareModule}s
*/
List<SoftwareModule> findSoftwareModulesById(@NotEmpty Collection<Long> ids);
/**
* 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 type
* to be filtered as "like" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText,
SoftwareModuleType type);
/**
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* search text and {@link SoftwareModule#getType()} that are not marked as
* deleted and sort them by means of given distribution set related modules
* on top of the list.
*
* After that the modules are sorted by {@link SoftwareModule#getName()} and
* {@link SoftwareModule#getVersion()} in ascending order.
*
* @param pageable
* page parameter
* @param orderByDistributionId
* the ID of distribution set to be ordered on top
* @param searchText
* filtered as "like" on {@link SoftwareModule#getName()}
* @param type
* filtered as "equal" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<CustomSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
@NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText,
SoftwareModuleType type);
/**
* Counts {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
@@ -280,12 +51,23 @@ public interface SoftwareManagement {
Long countSoftwareModuleByFilters(String searchText, SoftwareModuleType type);
/**
* @param pageable
* parameter
* @return all {@link SoftwareModuleType}s in the repository.
* Count all {@link SoftwareModule}s in the repository that are not marked
* as deleted.
*
* @return number of {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleType> findSoftwareModuleTypesAll(@NotNull Pageable pageable);
Long countSoftwareModulesAll();
/**
* Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}.
*
* @param type
* to count
* @return number of found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModulesByType(@NotNull SoftwareModuleType type);
/**
* @return number of {@link SoftwareModuleType}s in the repository.
@@ -294,34 +76,63 @@ public interface SoftwareManagement {
Long countSoftwareModuleTypesAll();
/**
* Create {@link SoftwareModule}s in the repository.
*
* @param key
* to search for
* @return {@link SoftwareModuleType} in the repository with given
* {@link SoftwareModuleType#getKey()}
* @param swModules
* {@link SoftwareModule}s to create
* @return SoftwareModule
* @throws EntityAlreadyExistsException
* if a given entity already exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull String key);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<SoftwareModule> createSoftwareModule(@NotNull Collection<SoftwareModule> swModules);
/**
*
* @param id
* to search for
* @return {@link SoftwareModuleType} in the repository with given
* {@link SoftwareModuleType#getId()}
* @param swModule
* SoftwareModule to create
* @return SoftwareModule
* @throws EntityAlreadyExistsException
* if a given entity already exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
SoftwareModule createSoftwareModule(@NotNull SoftwareModule swModule);
/**
* creates a list of software module meta data entries.
*
* @param name
* to search for
* @return all {@link SoftwareModuleType}s in the repository with given
* {@link SoftwareModuleType#getName()}
* @param metadata
* the meta data entries to create or update
* @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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<SoftwareModuleMetadata> createSoftwareModuleMetadata(@NotNull Collection<SoftwareModuleMetadata> metadata);
/**
* creates or updates a single software module meta data entry.
*
* @param metadata
* the meta data entry to create or update
* @return the updated or created software module meta data entry
* @throws EntityAlreadyExistsException
* in case the meta data entry already exists for the specific
* key
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata);
/**
* Creates multiple {@link SoftwareModuleType}s.
*
* @param types
* to create
* @return created {@link Entity}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<SoftwareModuleType> createSoftwareModuleType(@NotNull final Collection<SoftwareModuleType> types);
/**
* Creates new {@link SoftwareModuleType}.
@@ -334,14 +145,31 @@ public interface SoftwareManagement {
SoftwareModuleType createSoftwareModuleType(@NotNull SoftwareModuleType type);
/**
* Creates multiple {@link SoftwareModuleType}s.
* Deletes the given {@link SoftwareModule} {@link Entity}.
*
* @param types
* to create
* @return created {@link Entity}
* @param bsm
* is the {@link SoftwareModule} to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<SoftwareModuleType> createSoftwareModuleType(@NotNull final Collection<SoftwareModuleType> types);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModule(@NotNull SoftwareModule bsm);
/**
* deletes a software module meta data entry.
*
* @param id
* the ID of the software module meta data to delete
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id);
/**
* Deletes {@link SoftwareModule}s which is any if the given ids.
*
* @param ids
* of the Software Modules to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModules(@NotNull Collection<Long> ids);
/**
* Deletes or marks as delete in case the type is in use.
@@ -378,52 +206,61 @@ public interface SoftwareManagement {
@NotNull SoftwareModuleType type);
/**
* creates or updates a single software module meta data entry.
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* and {@link SoftwareModule#getType()} that are not marked as deleted.
*
* @param metadata
* the meta data entry to create or update
* @return the updated or created software module meta data entry
* @throws EntityAlreadyExistsException
* in case the meta data entry already exists for the specific
* key
* @param pageable
* page parameter
* @param searchText
* to be filtered as "like" on {@link SoftwareModule#getName()}
* @param type
* to be filtered as "like" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText,
SoftwareModuleType type);
/**
* creates a list of software module meta data entries.
*
* @param metadata
* the meta data entries to create or update
* @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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<SoftwareModuleMetadata> createSoftwareModuleMetadata(@NotNull Collection<SoftwareModuleMetadata> metadata);
/**
* updates a distribution set meta data value if corresponding entry exists.
*
* @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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata);
/**
* deletes a software module meta data entry.
* Finds {@link SoftwareModule} by given id.
*
* @param id
* the ID of the software module meta data to delete
* to search for
* @return the found {@link SoftwareModule}s or <code>null</code> if not
* found.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
SoftwareModule findSoftwareModuleById(@NotNull Long id);
/**
* retrieves {@link SoftwareModule} by their name AND version AND type..
*
* @param name
* of the {@link SoftwareModule}
* @param version
* of the {@link SoftwareModule}
* @param type
* of the {@link SoftwareModule}
* @return the found {@link SoftwareModule} or <code>null</code>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
@NotNull SoftwareModuleType type);
/**
* finds a single software module meta data by its id.
*
* @param id
* the id of the software module meta data containing the meta
* data key and the ID of the software module
* @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 SwMetadataCompositeKey id);
/**
* finds all meta data by the given software module id.
@@ -456,16 +293,179 @@ public interface SoftwareManagement {
@NotNull Specification<SoftwareModuleMetadata> spec, @NotNull Pageable pageable);
/**
* finds a single software module meta data by its id.
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
* search text and {@link SoftwareModule#getType()} that are not marked as
* deleted and sort them by means of given distribution set related modules
* on top of the list.
*
* After that the modules are sorted by {@link SoftwareModule#getName()} and
* {@link SoftwareModule#getVersion()} in ascending order.
*
* @param id
* the id of the software module meta data containing the meta
* data key and the ID of the software module
* @return the found SoftwareModuleMetadata or {@code null} if not exits
* @throws EntityNotFoundException
* in case the meta data does not exists for the given key
* @param pageable
* page parameter
* @param orderByDistributionId
* the ID of distribution set to be ordered on top
* @param searchText
* filtered as "like" on {@link SoftwareModule#getName()}
* @param type
* filtered as "equal" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id);
Slice<CustomSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
@NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText,
SoftwareModuleType type);
/**
* Retrieves all software modules. Deleted ones are filtered.
*
* @param pageable
* pagination parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModulesAll(@NotNull Pageable pageable);
/**
* Retrieves all software modules with a given list of ids
* {@link SoftwareModule#getId()}.
*
* @param ids
* to search for
* @return {@link List} of found {@link SoftwareModule}s
*/
List<SoftwareModule> findSoftwareModulesById(@NotEmpty Collection<Long> ids);
/**
* Retrieves all {@link SoftwareModule}s with a given specification.
*
* @param spec
* the specification to filter the software modules
* @param pageable
* pagination parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModule> findSoftwareModulesByPredicate(@NotNull Specification<SoftwareModule> spec,
@NotNull Pageable pageable);
/**
* retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType}
* .
*
* @param pageable
* page parameters
* @param type
* to be filtered on
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type);
/**
*
* @param id
* to search for
* @return {@link SoftwareModuleType} in the repository with given
* {@link SoftwareModuleType#getId()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id);
/**
*
* @param key
* to search for
* @return {@link SoftwareModuleType} in the repository with given
* {@link SoftwareModuleType#getKey()}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull 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)
SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name);
/**
* @param pageable
* parameter
* @return all {@link SoftwareModuleType}s in the repository.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleType> findSoftwareModuleTypesAll(@NotNull Pageable pageable);
/**
* Retrieves all {@link SoftwareModuleType}s with a given specification.
*
* @param spec
* the specification to filter the software modules types
* @param pageable
* pagination parameter
* @return the found {@link SoftwareModuleType}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModuleType> findSoftwareModuleTypesByPredicate(@NotNull Specification<SoftwareModuleType> spec,
@NotNull Pageable pageable);
/**
* Retrieves software module including details (
* {@link SoftwareModule#getArtifacts()}).
*
* @param id
* parameter
* @param isDeleted
* parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id);
/**
* Updates existing {@link SoftwareModule}. Update-able values are
* {@link SoftwareModule#getDescription()}
* {@link SoftwareModule#getVendor()}.
*
* @param sm
* to update
*
* @return the saved {@link Entity}.
*
* @throws NullPointerException
* of {@link SoftwareModule#getId()} is <code>null</code>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModule updateSoftwareModule(@NotNull SoftwareModule sm);
/**
* updates a distribution set meta data value if corresponding entry exists.
*
* @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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata);
/**
* Updates existing {@link SoftwareModuleType}. Update-able value is
* {@link SoftwareModuleType#getDescription()} and
* {@link SoftwareModuleType#getColour()}.
*
* @param sm
* to update
* @return updated {@link Entity}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm);
}

View File

@@ -0,0 +1,93 @@
/**
* 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;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.report.model.SystemUsageReport;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.security.access.prepost.PreAuthorize;
/**
* Central system management operations of the update server.
*
*/
public interface SystemManagement {
/**
* Checks if a specific tenant exists. The tenant will not be created lazy.
*
* @return {@code true} in case the tenant exits or {@code false} if not
*/
String currentTenant();
/**
* Deletes all data related to a given tenant.
*
* @param tenant
* to delete
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
void deleteTenant(@NotNull String tenant);
/**
*
* @return list of all tenant names in the system.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
List<String> findTenants();
/**
* Calculated system usage statistics, both overall for the entire system
* and per tenant;
*
* @return SystemUsageReport of the current system
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
SystemUsageReport getSystemUsageStatistics();
/**
* @return {@link TenantMetaData} of {@link TenantAware#getCurrentTenant()}
*/
TenantMetaData getTenantMetadata();
// TODO figure out why this is necessary and clean this up
@Bean
KeyGenerator currentTenantKeyGenerator();
/**
* Returns {@link TenantMetaData} of given and current tenant.
*
* DISCLAIMER: this variant is used during initial login (where the tenant
* is not yet in the session). Please user {@link #getTenantMetadata()} for
* regular requests.
*
* @param tenant
* to retrieve data for
* @return {@link TenantMetaData} of given tenant
*/
TenantMetaData getTenantMetadata(@NotNull String tenant);
/**
* Update call for {@link TenantMetaData}.
*
* @param metaData
* to update
* @return updated {@link TenantMetaData} entity
*/
TenantMetaData updateTenantMetadata(@NotNull TenantMetaData metaData);
}

View File

@@ -0,0 +1,236 @@
/**
* 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;
import java.util.Collection;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.prepost.PreAuthorize;
/**
* Management service for {@link Tag}s.
*
*/
public interface TagManagement {
/**
* count {@link TargetTag}s.
*
* @return size of {@link TargetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
long countTargetTags();
/**
* Creates a {@link DistributionSet}.
*
* @param distributionSetTag
* to be created.
* @return the new {@link DistributionSet}
* @throws EntityAlreadyExistsException
* if distributionSetTag already exists
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
DistributionSetTag createDistributionSetTag(@NotNull DistributionSetTag distributionSetTag);
/**
* Creates multiple {@link DistributionSetTag}s.
*
* @param distributionSetTags
* to be created
* @return the new {@link DistributionSetTag}
* @throws EntityAlreadyExistsException
* if a given entity already exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<DistributionSetTag> createDistributionSetTags(@NotNull Collection<DistributionSetTag> distributionSetTags);
/**
* Creates a new {@link TargetTag}.
*
* @param targetTag
* to be created
*
* @return the new created {@link TargetTag}
*
* @throws EntityAlreadyExistsException
* if given object already exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
TargetTag createTargetTag(@NotNull TargetTag targetTag);
/**
* created multiple {@link TargetTag}s.
*
* @param targetTags
* to be created
* @return the new created {@link TargetTag}s
*
* @throws EntityAlreadyExistsException
* if given object has already an ID.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
List<TargetTag> createTargetTags(@NotNull Iterable<TargetTag> targetTags);
/**
* Deletes {@link DistributionSetTag} by given
* {@link DistributionSetTag#getName()}.
*
* @param tagName
* to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteDistributionSetTag(@NotEmpty String tagName);
/**
* Deletes {@link TargetTag} with given name.
*
* @param targetTagName
* tag name of the {@link TargetTag} to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargetTag(@NotEmpty String targetTagName);
/**
*
* @return all {@link DistributionSetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<DistributionSetTag> findAllDistributionSetTags();
/**
* returns all {@link DistributionSetTag}s.
*
* @param pageReq
* page parameter
* @return all {@link DistributionSetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetTag> findAllDistributionSetTags(@NotNull Pageable pageReq);
/**
* Retrieves all DistributionSet tags based on the given specification.
*
* @param spec
* the specification for the query
* @param pageable
* pagination parameter
* @return the found {@link DistributionSetTag}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<DistributionSetTag> findAllDistributionSetTags(@NotNull Specification<DistributionSetTag> spec,
@NotNull Pageable pageable);
/**
* @return all {@link TargetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<TargetTag> findAllTargetTags();
/**
* returns all {@link TargetTag}s.
*
* @param pageReq
* page parameter
*
* @return all {@link TargetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<TargetTag> findAllTargetTags(@NotNull Pageable pageReq);
/**
* Retrieves all target tags based on the given specification.
*
* @param spec
* the specification for the query
* @param pageable
* pagination parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<TargetTag> findAllTargetTags(@NotNull Specification<TargetTag> spec, @NotNull Pageable pageable);
/**
* Find {@link DistributionSet} based on given name.
*
* @param name
* to look for.
* @return {@link DistributionSet} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
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.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
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
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
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.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetTag findTargetTagById(@NotNull Long id);
/**
* Updates an existing {@link DistributionSetTag}.
*
* @param distributionSetTag
* to be updated
* @return the updated {@link DistributionSet}
* @throws NullPointerException
* of {@link DistributionSetTag#getName()} is <code>null</code>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSetTag updateDistributionSetTag(@NotNull DistributionSetTag distributionSetTag);
/**
* updates the {@link TargetTag}.
*
* @param targetTag
* the {@link TargetTag} with updated values
* @return the updated {@link TargetTag}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTag updateTargetTag(@NotNull TargetTag targetTag);
}

View File

@@ -0,0 +1,99 @@
/**
* 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;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
/**
* Management service for {@link TargetFilterQuery}s.
*
*/
public interface TargetFilterQueryManagement {
/**
* creating new {@link TargetFilterQuery}.
*
* @param customTargetFilter
* @return the created {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
TargetFilterQuery createTargetFilterQuery(@NotNull TargetFilterQuery customTargetFilter);
/**
* Delete target filter query.
*
* @param targetFilterQueryId
* IDs of target filter query to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId);
/**
*
* Retrieves all target filter query{@link TargetFilterQuery}.
*
* @param pageable
* pagination parameter
* @return the found {@link TargetFilterQuery}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<TargetFilterQuery> findAllTargetFilterQuery(@NotNull Pageable pageable);
/**
* Retrieves all target filter query which {@link TargetFilterQuery}.
*
*
* @param pageable
* pagination parameter
* @param name
* target filter query name
* @return the page with the found {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<TargetFilterQuery> findTargetFilterQueryByFilters(@NotNull Pageable pageable, String name);
/**
* Find target filter query by id.
*
* @param targetFilterQueryId
* Target filter query id
* @return the found {@link TargetFilterQuery}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetFilterQuery findTargetFilterQueryById(@NotNull Long targetFilterQueryId);
/**
* Find target filter query by name.
*
* @param targetFilterQueryName
* Target filter query name
* @return the found {@link TargetFilterQuery}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
TargetFilterQuery findTargetFilterQueryByName(@NotNull String targetFilterQueryName);
/**
* updates the {@link TargetFilterQuery}.
*
* @param targetFilterQuery
* to be updated
* @return the updated {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery);
}

View File

@@ -0,0 +1,604 @@
/**
* 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;
import java.net.URI;
import java.util.Collection;
import java.util.List;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.prepost.PreAuthorize;
/**
* Management service for {@link Target}s.
*
*/
public interface TargetManagement {
/**
* Assign a {@link TargetTag} assignment to given {@link Target}s.
*
* @param targetIds
* to assign for
* @param tag
* to assign
* @return list of assigned targets
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
List<Target> assignTag(@NotEmpty Collection<String> targetIds, @NotNull TargetTag tag);
/**
* Counts number of targets with given
* {@link Target#getAssignedDistributionSet()}.
*
* @param distId
* to search for
*
* @return number of found {@link Target}s.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByAssignedDistributionSet(@NotNull Long distId);
/**
* Count {@link Target}s for all the given filter parameters.
*
* @param status
* find targets having on of these {@link TargetUpdateStatus}s.
* Set to <code>null</code> in case this is not required.
* @param searchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param tagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found number {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByFilters(Collection<TargetUpdateStatus> status, String searchText,
Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, String... tagNames);
/**
* Counts number of targets with given
* {@link TargetInfo#getInstalledDistributionSet()}.
*
* @param distId
* to search for
* @return number of found {@link Target}s.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByInstalledDistributionSet(@NotNull Long distId);
/**
* Count {@link TargetFilterQuery}s for given target filter query.
*
* @param targetFilterQuery
* {link TargetFilterQuery}
* @return the found number {@link TargetFilterQuery}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByTargetFilterQuery(@NotEmpty String targetFilterQuery);
/**
* Count {@link TargetFilterQuery}s for given filter parameter.
*
* @param targetFilterQuery
* {link TargetFilterQuery}
* @return the found number {@link TargetFilterQuery}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery);
/**
* Counts all {@link Target}s in the repository.
*
* @return number of targets
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetsAll();
/**
* creating a new {@link Target}.
*
* @param target
* to be created
* @return the created {@link Target}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
Target createTarget(@NotNull Target target);
/**
* creating new {@link Target}s including poll status data. useful
* especially in plug and play scenarios.
*
* @param target
* to be created *
* @param status
* of the target
* @param lastTargetQuery
* if a plug and play case
* @param address
* if a plug and play case
*
* @throws EntityAlreadyExistsException
* if {@link Target} with given {@link Target#getControllerId()}
* already exists.
*
* @return created {@link Target}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
Target createTarget(@NotNull Target target, @NotNull TargetUpdateStatus status, Long lastTargetQuery, URI address);
/**
* creates multiple {@link Target}s. If some of the given {@link Target}s
* already exists in the DB a {@link EntityAlreadyExistsException} is
* thrown. {@link Target}s contain all objects of the parameter targets,
* including duplicates.
*
* @param targets
* to be created.
* @return the created {@link Target}s
*
* @throws EntityAlreadyExistsException
* of one of the given targets already exist.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
List<Target> createTargets(@NotNull Collection<Target> targets);
/**
* creating a new {@link Target} including poll status data. useful
* especially in plug and play scenarios.
*
* @param targets
* to be created *
* @param status
* of the target
* @param lastTargetQuery
* if a plug and play case
* @param address
* if a plug and play case
*
* @return newly created target
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
List<Target> createTargets(@NotNull Collection<Target> targets, @NotNull TargetUpdateStatus status,
Long lastTargetQuery, URI address);
/**
* Deletes all targets with the given IDs.
*
* @param targetIDs
* the technical IDs of the targets to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargets(@NotEmpty Long... targetIDs);
/**
* finds all {@link Target#getControllerId()} which are currently in the
* database.
*
* @return all IDs of all {@link Target} in the system
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<TargetIdName> findAllTargetIds();
/**
* Finds all targets for all the given parameters but returns not the full
* target but {@link TargetIdName}.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
*
* @param filterByStatus
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param filterBySearchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param filterByTagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<TargetIdName> findAllTargetIdsByFilters(@NotNull Pageable pageRequest,
Collection<TargetUpdateStatus> filterByStatus, String filterBySearchText,
Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, String... filterByTagNames);
/**
* Finds all targets for all the given parameter {@link TargetFilterQuery}
* and returns not the full target but {@link TargetIdName}.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
* @param targetFilterQuery
* {@link TargetFilterQuery}
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<TargetIdName> findAllTargetIdsByTargetFilterQuery(@NotNull Pageable pageRequest,
@NotNull TargetFilterQuery targetFilterQuery);
/**
* retrieves {@link Target}s by the assigned {@link DistributionSet} without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible.
*
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
* @param pageReq
* page parameter
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq);
/**
* Retrieves {@link Target}s by the assigned {@link DistributionSet} without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible including additional filtering based on the given {@code spec}.
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
* @param spec
* the specification to filter the result set
* @param pageReq
* page parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByAssignedDistributionSet(@NotNull Long distributionSetID,
@NotNull Specification<Target> spec, @NotNull Pageable pageReq);
/**
* Find {@link Target} based on given ID returns found Target without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible.
*
* @param controllerIDs
* to look for.
* @return List of found{@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> findTargetByControllerID(@NotEmpty Collection<String> controllerIDs);
/**
* Find {@link Target} based on given ID returns found Target without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible.
*
* @param controllerId
* to look for.
* @return {@link Target} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Target findTargetByControllerID(@NotEmpty String controllerId);
/**
* Find {@link Target} based on given ID returns found Target with details,
* i.e. {@link Target#getTags()} and {@link Target#getActions()} are
* possible.
*
* Note: try to use {@link #findTargetByControllerID(String)} as much as
* possible.
*
* @param controllerId
* to look for.
* @return {@link Target} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Target findTargetByControllerIDWithDetails(@NotEmpty String controllerId);
/**
* Filter {@link Target}s for all the given parameters. If all parameters
* except pageable are null, all available {@link Target}s are returned.
*
* @param pageable
* page parameters
* @param status
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param searchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param tagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetByFilters(@NotNull Pageable pageable, Collection<TargetUpdateStatus> status,
String searchText, Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag,
String... tagNames);
/**
* retrieves {@link Target}s by the installed {@link DistributionSet}without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible.
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
* @param pageReq
* page parameter
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByInstalledDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq);
/**
* retrieves {@link Target}s by the installed {@link DistributionSet}without
* details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()}
* possible including additional filtering based on the given {@code spec}.
*
* @param distributionSetId
* the ID of the {@link DistributionSet}
* @param spec
* the specification to filter the result
* @param pageable
* page parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findTargetByInstalledDistributionSet(@NotNull Long distributionSetId,
@NotNull Specification<Target> spec, @NotNull Pageable pageable);
/**
* Retrieves the {@link Target} which have a certain
* {@link TargetUpdateStatus} without details, i.e. NO
* {@link Target#getTags()} and {@link Target#getActions()} possible.
*
* @param pageable
* page parameter
* @param status
* the {@link TargetUpdateStatus} to be filtered on
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findTargetByUpdateStatus(@NotNull Pageable pageable, @NotNull TargetUpdateStatus status);
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActions()} possible
*
* @param pageable
* pagination parameter
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetsAll(@NotNull Pageable pageable);
/**
* Retrieves all targets based on the given specification.
*
* @param spec
* the specification for the query
* @param pageable
* pagination parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findTargetsAll(@NotNull Specification<Target> spec, @NotNull Pageable pageable);
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActions()} possible based on
* {@link TargetFilterQuery#getQuery()}
*
* @param targetFilterQuery
* in string notation
* @param pageable
* pagination parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable);
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActions()} possible based on
* {@link TargetFilterQuery#getQuery()}
*
* @param targetFilterQuery
* the specification for the query
* @param pageable
* pagination parameter
*
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetsAll(@NotNull TargetFilterQuery targetFilterQuery, @NotNull Pageable pageable);
/**
* method retrieves all {@link Target}s from the repo in the following
* order:
* <p>
* 1) {@link Target}s which have the given {@link DistributionSet} as
* {@link Target#getTargetInfo()}
* {@link TargetInfo#getInstalledDistributionSet()}
* <p>
* 2) {@link Target}s which have the given {@link DistributionSet} as
* {@link Target#getAssignedDistributionSet()}
* <p>
* 3) {@link Target}s which have no connection to the given
* {@link DistributionSet}.
*
* @param pageable
* the page request to page the result set
* @param orderByDistributionId
* {@link DistributionSet#getId()} to be ordered by
* @param filterByDistributionId
* {@link DistributionSet#getId()} to be filter the result. Set
* to <code>null</code> in case this is not required.
* @param filterByStatus
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param filterBySearchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param filterByTagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
* @return a paged result {@link Page} of the {@link Target}s in a defined
* order.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable,
@NotNull Long orderByDistributionId, Long filterByDistributionId,
Collection<TargetUpdateStatus> filterByStatus, String filterBySearchText, Boolean selectTargetWithNoTag,
String... filterByTagNames);
/**
* retrieves a list of {@link Target}s by their controller ID with details,
* i.e. {@link Target#getTags()} are possible.
*
* Note: try to use {@link #findTargetByControllerID(String)} as much as
* possible.
*
* @param controllerIDs
* {@link Target}s Names parameter
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> findTargetsByControllerIDsWithTags(@NotNull List<String> controllerIDs);
/**
* Find targets by tag name.
*
* @param tagName
* tag name
* @return list of matching targets
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> findTargetsByTag(@NotEmpty String tagName);
/**
* Toggles {@link TargetTag} assignment to given {@link Target}s by means
* that if some (or all) of the targets in the list have the {@link Tag} not
* yet assigned, they will be. If all of theme have the tag already assigned
* they will be removed instead.
*
* @param targetIds
* to toggle for
* @param tagName
* to toggle
* @return TagAssigmentResult with all meta data of the assignment outcome.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<String> targetIds, @NotEmpty String tagName);
/**
* {@link Entity} based method call for
* {@link #toggleTagAssignment(Collection, String)}.
*
* @param targets
* to toggle for
* @param tag
* to toggle
* @return TagAssigmentResult with all meta data of the assignment outcome.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<Target> targets, @NotNull TargetTag tag);
/**
* Un-assign all {@link Target} from a given {@link TargetTag} .
*
* @param tag
* to un-assign all targets
* @return list of unassigned targets
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
List<Target> unAssignAllTargetsByTag(@NotNull TargetTag tag);
/**
* Un-assign a {@link TargetTag} assignment to given {@link Target}.
*
* @param controllerID
* to un-assign for
* @param targetTag
* to un-assign
* @return the unassigned target or <null> if no target is unassigned
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
Target unAssignTag(@NotEmpty String controllerID, @NotNull TargetTag targetTag);
/**
* updates the {@link Target}.
*
* @param target
* to be updated
* @return the updated {@link Target}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
Target updateTarget(@NotNull Target target);
/**
* updates multiple {@link Target}s.
*
* @param targets
* to be updated
* @return the updated {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
List<Target> updateTargets(@NotNull Iterable<Target> targets);
}

View File

@@ -23,6 +23,74 @@ import org.springframework.security.access.prepost.PreAuthorize;
*/
public interface TenantConfigurationManagement {
/**
* Adds or updates a specific configuration for a specific tenant.
*
*
* @param configurationKey
* the key of the configuration
* @param value
* the configuration value which will be written into the
* database.
* @return the configuration value which was just written into the database.
* @throws TenantConfigurationValidatorException
* if the {@code propertyType} and the value in general does not
* match the expected type and format defined by the Key
* @throws ConversionFailedException
* if the property cannot be converted to the given
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION)
<T> TenantConfigurationValue<T> addOrUpdateConfiguration(TenantConfigurationKey configurationKey, T value);
/**
* Build the tenant configuration by the given key
*
* @param configurationKey
* the key
* @param propertyType
* the property type
* @param tenantConfiguration
* the configuration
* @return <null> if no default value is set and no database value available
* or returns the tenant configuration value
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
<T> TenantConfigurationValue<T> buildTenantConfigurationValueByKey(TenantConfigurationKey configurationKey,
Class<T> propertyType, TenantConfiguration tenantConfiguration);
/**
* Deletes a specific configuration for the current tenant. Does nothing in
* case there is no tenant specific configuration value.
*
* @param configurationKey
* the configuration key to be deleted
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION)
void deleteConfiguration(TenantConfigurationKey configurationKey);
/**
* Retrieves a configuration value from the e.g. tenant overwritten
* configuration values or in case the tenant does not a have a specific
* configuration the global default value hold in the {@link Environment}.
*
* @param configurationKey
* the key of the configuration
* @return the converted configuration value either from the tenant specific
* configuration stored or from the fall back default values or
* {@code null} in case key has not been configured and not default
* value exists
* @throws TenantConfigurationValidatorException
* if the {@code propertyType} and the value in general does not
* match the expected type and format defined by the Key
* @throws ConversionFailedException
* if the property cannot be converted to the given
* {@code propertyType}
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
TenantConfigurationValue<?> getConfigurationValue(TenantConfigurationKey configurationKey);
/**
* Retrieves a configuration value from the e.g. tenant overwritten
* configuration values or in case the tenant does not a have a specific
@@ -51,45 +119,6 @@ public interface TenantConfigurationManagement {
<T> TenantConfigurationValue<T> getConfigurationValue(TenantConfigurationKey configurationKey,
Class<T> propertyType);
/**
* Build the tenant configuration by the given key
*
* @param configurationKey
* the key
* @param propertyType
* the property type
* @param tenantConfiguration
* the configuration
* @return <null> if no default value is set and no database value available
* or returns the tenant configuration value
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
<T> TenantConfigurationValue<T> buildTenantConfigurationValueByKey(TenantConfigurationKey configurationKey,
Class<T> propertyType, TenantConfiguration tenantConfiguration);
/**
* Retrieves a configuration value from the e.g. tenant overwritten
* configuration values or in case the tenant does not a have a specific
* configuration the global default value hold in the {@link Environment}.
*
* @param configurationKey
* the key of the configuration
* @return the converted configuration value either from the tenant specific
* configuration stored or from the fall back default values or
* {@code null} in case key has not been configured and not default
* value exists
* @throws TenantConfigurationValidatorException
* if the {@code propertyType} and the value in general does not
* match the expected type and format defined by the Key
* @throws ConversionFailedException
* if the property cannot be converted to the given
* {@code propertyType}
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
TenantConfigurationValue<?> getConfigurationValue(TenantConfigurationKey configurationKey);
/**
* returns the global configuration property either defined in the property
* file or an default value otherwise.
@@ -114,33 +143,4 @@ public interface TenantConfigurationManagement {
+ SpringEvalExpressions.IS_SYSTEM_CODE)
<T> T getGlobalConfigurationValue(TenantConfigurationKey configurationKey, Class<T> propertyType);
/**
* Adds or updates a specific configuration for a specific tenant.
*
*
* @param configurationKey
* the key of the configuration
* @param value
* the configuration value which will be written into the
* database.
* @return the configuration value which was just written into the database.
* @throws TenantConfigurationValidatorException
* if the {@code propertyType} and the value in general does not
* match the expected type and format defined by the Key
* @throws ConversionFailedException
* if the property cannot be converted to the given
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION)
<T> TenantConfigurationValue<T> addOrUpdateConfiguration(TenantConfigurationKey configurationKey, T value);
/**
* Deletes a specific configuration for the current tenant. Does nothing in
* case there is no tenant specific configuration value.
*
* @param configurationKey
* the configuration key to be deleted
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION)
void deleteConfiguration(TenantConfigurationKey configurationKey);
}

View File

@@ -0,0 +1,33 @@
/**
* 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;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.report.model.TenantUsage;
import org.springframework.security.access.prepost.PreAuthorize;
/**
* Management service for statistics of a single tenant.
*
*/
public interface TenantStatsManagement {
/**
* Service for stats of a single tenant. Opens a new transaction and as a
* result can an be used for multiple tenants, i.e. to allow in one session
* to collect data of all tenants in the system.
*
* @param tenant
* to collect for
* @return collected statistics
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
TenantUsage getStatsOfTenant(String tenant);
}

View File

@@ -14,6 +14,7 @@ import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.Target;

View File

@@ -19,6 +19,7 @@ import javax.persistence.criteria.Root;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException;

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository.jpa;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -33,6 +34,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent;
import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
@@ -75,7 +77,7 @@ import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
/**
* JPA implementation for DeploymentManagement.
* JPA implementation for {@link DeploymentManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
@@ -156,7 +158,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Transactional(isolation = Isolation.READ_COMMITTED)
@CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true)
public DistributionSetAssignmentResult assignDistributionSet(final Long dsID,
final List<TargetWithActionType> targets) {
final Collection<TargetWithActionType> targets) {
final DistributionSet set = distributoinSetRepository.findOne(dsID);
if (set == null) {
throw new EntityNotFoundException(
@@ -171,7 +173,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Transactional(isolation = Isolation.READ_COMMITTED)
@CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true)
public DistributionSetAssignmentResult assignDistributionSet(final Long dsID,
final List<TargetWithActionType> targets, final Rollout rollout, final RolloutGroup rolloutGroup) {
final Collection<TargetWithActionType> targets, final Rollout rollout, final RolloutGroup rolloutGroup) {
final DistributionSet set = distributoinSetRepository.findOne(dsID);
if (set == null) {
throw new EntityNotFoundException(
@@ -200,7 +202,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
* {@link DistributionSetType}.
*/
private DistributionSetAssignmentResult assignDistributionSetToTargets(@NotNull final DistributionSet set,
final List<TargetWithActionType> targetsWithActionType, final Rollout rollout,
final Collection<TargetWithActionType> targetsWithActionType, final Rollout rollout,
final RolloutGroup rolloutGroup) {
if (!set.isComplete()) {
@@ -456,7 +458,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_COMMITTED)
public void createScheduledAction(final List<Target> targets, final DistributionSet distributionSet,
public void createScheduledAction(final Collection<Target> targets, final DistributionSet distributionSet,
final ActionType actionType, final long forcedTime, final Rollout rollout,
final RolloutGroup rolloutGroup) {
// cancel all current scheduled actions for this target. E.g. an action

View File

@@ -27,6 +27,8 @@ import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.repository.DistributionSetFilter;
import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityLockedException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -59,7 +61,7 @@ import com.google.common.base.Strings;
import com.google.common.eventbus.EventBus;
/**
* Business facade for managing the {@link DistributionSet}s.
* JPA implementation of {@link DistributionSetManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)

View File

@@ -51,7 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
* Service layer for generating hawkBit reports.
* JPA implementation of {@link ReportManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)

View File

@@ -40,15 +40,13 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
* RolloutGroupManagement to control rollout groups. This service secures all
* the functionality based on the {@link PreAuthorize} annotation on methods.
* JPA implementation of {@link RolloutGroupManagement}.
*/
@Validated
@Service

View File

@@ -20,6 +20,7 @@ import javax.persistence.EntityManager;
import org.eclipse.hawkbit.cache.CacheWriteNotify;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
@@ -52,7 +53,6 @@ import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
@@ -65,9 +65,7 @@ import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
/**
* RolloutManagement to control rollouts e.g. like creating, starting, resuming
* and pausing rollouts. This service secures all the functionality based on the
* {@link PreAuthorize} annotation on methods.
* JPA implementation of {@link RolloutManagement}.
*/
@Validated
@Service

View File

@@ -59,7 +59,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.Sets;
/**
* JPA implementation of SoftwareManagement.
* JPA implementation of {@link SoftwareManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
@@ -148,7 +148,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public List<SoftwareModule> createSoftwareModule(final Iterable<SoftwareModule> swModules) {
public List<SoftwareModule> createSoftwareModule(final Collection<SoftwareModule> swModules) {
swModules.forEach(swModule -> {
if (null != swModule.getId()) {
throw new EntityAlreadyExistsException();
@@ -222,7 +222,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void deleteSoftwareModules(final Iterable<Long> ids) {
public void deleteSoftwareModules(final Collection<Long> ids) {
final List<SoftwareModule> swModulesToDelete = softwareModuleRepository.findByIdIn(ids);
final Set<Long> assignedModuleIds = new HashSet<>();
swModulesToDelete.forEach(swModule -> {

View File

@@ -14,11 +14,11 @@ import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.cache.TenancyCacheManager;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.report.model.SystemUsageReport;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantStatsManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -33,7 +33,6 @@ import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@@ -41,13 +40,13 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
* Central system management operations of the SP server.
* JPA implementation of {@link SystemManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
@Validated
@Service
public class SystemManagement {
public class JpaSystemManagement implements SystemManagement {
@Autowired
private EntityManager entityManager;
@@ -107,14 +106,7 @@ public class SystemManagement {
private final ThreadLocal<String> createInitialTenant = new ThreadLocal<>();
/**
* Calculated system usage statistics, both overall for the entire system
* and per tenant;
*
* @return SystemUsageReport of the current system
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
@Override
public SystemUsageReport getSystemUsageStatistics() {
BigDecimal sumOfArtifacts = (BigDecimal) entityManager
@@ -156,35 +148,18 @@ public class SystemManagement {
}));
}
/**
* Registers the key generator for the {@link #currentTenant()} method
* because this key generator is aware of the {@link #createInitialTenant}
* thread local in case we are currently creating a tenant and insert the
* default distribution set types.
*
* @return the {@link CurrentTenantKeyGenerator}
*/
@Bean
@Override
@Transactional(propagation = Propagation.SUPPORTS)
public CurrentTenantKeyGenerator currentTenantKeyGenerator() {
@Bean
public KeyGenerator currentTenantKeyGenerator() {
return new CurrentTenantKeyGenerator();
}
/**
* Returns {@link TenantMetaData} of given and current tenant.
*
* DISCLAIMER: this variant is used during initial login (where the tenant
* is not yet in the session). Please user {@link #getTenantMetadata()} for
* regular requests.
*
* @param tenant
* @return
*/
@Override
@Cacheable(value = "tenantMetadata", key = "#tenant.toUpperCase()")
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
@NotNull
public TenantMetaData getTenantMetadata(@NotNull final String tenant) {
public TenantMetaData getTenantMetadata(final String tenant) {
final TenantMetaData result = tenantMetaDataRepository.findByTenantIgnoreCase(tenant);
// Create if it does not exist
@@ -201,28 +176,16 @@ public class SystemManagement {
return result;
}
/**
*
* @return list of all tenant names in the system.
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
@Override
public List<String> findTenants() {
return tenantMetaDataRepository.findAll().stream().map(md -> md.getTenant()).collect(Collectors.toList());
}
/**
* Deletes all data related to a given tenant.
*
* @param tenant
* to delete
*/
@Override
@CacheEvict(value = { "tenantMetadata" }, key = "#tenant.toUpperCase()")
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
public void deleteTenant(@NotNull final String tenant) {
public void deleteTenant(final String tenant) {
cacheManager.evictCaches(tenant);
cacheManager.getCache("currentTenant").evict(currentTenantKeyGenerator().generate(null, null));
tenantAware.runAsTenant(tenant, () -> {
@@ -246,13 +209,10 @@ public class SystemManagement {
});
}
/**
* @return {@link TenantMetaData} of {@link TenantAware#getCurrentTenant()}
*/
@Override
@Cacheable(value = "tenantMetadata", keyGenerator = "tenantKeyGenerator")
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
@NotNull
public TenantMetaData getTenantMetadata() {
if (tenantAware.getCurrentTenant() == null) {
throw new IllegalStateException("Tenant not set");
@@ -261,13 +221,7 @@ public class SystemManagement {
return getTenantMetadata(tenantAware.getCurrentTenant());
}
/**
* Checks if a specific tenant exists. The tenant will not be created lazy.
*
* @param tenant
* the tenant to check
* @return {@code true} in case the tenant exits or {@code false} if not
*/
@Override
@Cacheable(value = "currentTenant", keyGenerator = "currentTenantKeyGenerator")
// set transaction to not supported, due we call this in
// BaseEntity#prePersist methods
@@ -290,18 +244,11 @@ public class SystemManagement {
return initialTenantCreation;
}
/**
* Update call for {@link TenantMetaData}.
*
* @param metaData
* to update
* @return updated {@link TenantMetaData} entity
*/
@Override
@CachePut(value = "tenantMetadata", key = "#metaData.tenant.toUpperCase()")
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
@NotNull
public TenantMetaData updateTenantMetadata(@NotNull final TenantMetaData metaData) {
public TenantMetaData updateTenantMetadata(final TenantMetaData metaData) {
if (!tenantMetaDataRepository.exists(metaData.getId())) {
throw new EntityNotFoundException("Metadata does not exist: " + metaData.getId());
}
@@ -340,7 +287,7 @@ public class SystemManagement {
* currently created and not the one currently in the {@link TenantAware}.
*
*/
private class CurrentTenantKeyGenerator implements KeyGenerator {
public class CurrentTenantKeyGenerator implements KeyGenerator {
@Override
// Exception squid:S923 - override
@SuppressWarnings({ "squid:S923" })

View File

@@ -10,11 +10,10 @@ package org.eclipse.hawkbit.repository.jpa;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent;
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent;
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent;
@@ -22,21 +21,18 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent;
import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent;
import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent;
import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@@ -45,13 +41,13 @@ import org.springframework.validation.annotation.Validated;
import com.google.common.eventbus.EventBus;
/**
* Management service class for {@link Tag}s.
* JP>A implementation of {@link TagManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
@Validated
@Service
public class TagManagement {
public class JpaTagManagement implements TagManagement {
@Autowired
private TargetTagRepository targetTagRepository;
@@ -74,34 +70,14 @@ public class TagManagement {
@Autowired
private AfterTransactionCommitExecutor afterCommit;
/**
* Find {@link TargetTag} based on given Name.
*
* @param name
* to look for.
* @return {@link TargetTag} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public TargetTag findTargetTag(@NotEmpty final String name) {
@Override
public TargetTag findTargetTag(final String name) {
return targetTagRepository.findByNameEquals(name);
}
/**
* Creates a new {@link TargetTag}.
*
* @param targetTag
* to be created
*
* @return the new created {@link TargetTag}
*
* @throws EntityAlreadyExistsException
* if given object already exists
*/
@Modifying
@Override
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
public TargetTag createTargetTag(@NotNull final TargetTag targetTag) {
public TargetTag createTargetTag(final TargetTag targetTag) {
if (null != targetTag.getId()) {
throw new EntityAlreadyExistsException();
}
@@ -118,21 +94,10 @@ public class TagManagement {
return save;
}
/**
* created multiple {@link TargetTag}s.
*
* @param targetTags
* to be created
* @return the new created {@link TargetTag}s
*
* @throws EntityAlreadyExistsException
* if given object has already an ID.
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
public List<TargetTag> createTargetTags(@NotNull final Iterable<TargetTag> targetTags) {
public List<TargetTag> createTargetTags(final Iterable<TargetTag> targetTags) {
targetTags.forEach(tag -> {
if (tag.getId() != null) {
throw new EntityAlreadyExistsException();
@@ -144,16 +109,10 @@ public class TagManagement {
return save;
}
/**
* Deletes {@link TargetTag} with given name.
*
* @param targetTagName
* tag name of the {@link TargetTag} to be deleted
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
public void deleteTargetTag(@NotEmpty final String targetTagName) {
public void deleteTargetTag(final String targetTagName) {
final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName);
final List<Target> changed = new LinkedList<>();
@@ -172,54 +131,25 @@ public class TagManagement {
}
/**
* returns all {@link TargetTag}s.
*
* @return all {@link TargetTag}s
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public List<TargetTag> findAllTargetTags() {
return targetTagRepository.findAll();
}
/**
* Retrieves all target tags based on the given specification.
*
* @param spec
* the specification for the query
* @param pageable
* pagination parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<TargetTag> findAllTargetTags(@NotNull final Specification<TargetTag> spec,
@NotNull final Pageable pageable) {
@Override
public Page<TargetTag> findAllTargetTags(final Specification<TargetTag> spec, final Pageable pageable) {
return targetTagRepository.findAll(spec, pageable);
}
/**
* count {@link TargetTag}s.
*
* @return size of {@link TargetTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public long countTargetTags() {
return targetTagRepository.count();
}
/**
* updates the {@link TargetTag}.
*
* @param targetTag
* the {@link TargetTag}
* @return the new {@link TargetTag}
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public TargetTag updateTargetTag(@NotNull final TargetTag targetTag) {
public TargetTag updateTargetTag(final TargetTag targetTag) {
checkNotNull(targetTag.getName());
checkNotNull(targetTag.getId());
final TargetTag save = targetTagRepository.save(targetTag);
@@ -227,32 +157,15 @@ public class TagManagement {
return save;
}
/**
* Find {@link DistributionSet} based on given name.
*
* @param name
* to look for.
* @return {@link DistributionSet} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public DistributionSetTag findDistributionSetTag(@NotEmpty final String name) {
@Override
public DistributionSetTag findDistributionSetTag(final String name) {
return distributionSetTagRepository.findByNameEquals(name);
}
/**
* Creates a {@link DistributionSet}.
*
* @param distributionSetTag
* to be created.
* @return the new {@link DistributionSet}
* @throws EntityAlreadyExistsException
* if distributionSetTag already exists
*
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
public DistributionSetTag createDistributionSetTag(@NotNull final DistributionSetTag distributionSetTag) {
public DistributionSetTag createDistributionSetTag(final DistributionSetTag distributionSetTag) {
if (null != distributionSetTag.getId()) {
throw new EntityAlreadyExistsException();
}
@@ -268,20 +181,11 @@ public class TagManagement {
return save;
}
/**
* Creates multiple {@link DistributionSetTag}s.
*
* @param distributionSetTags
* to be created
* @return the new {@link DistributionSetTag}
* @throws EntityAlreadyExistsException
* if a given entity already exists
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
public List<DistributionSetTag> createDistributionSetTags(
@NotNull final Iterable<DistributionSetTag> distributionSetTags) {
final Collection<DistributionSetTag> distributionSetTags) {
for (final DistributionSetTag dsTag : distributionSetTags) {
if (dsTag.getId() != null) {
throw new EntityAlreadyExistsException();
@@ -294,17 +198,10 @@ public class TagManagement {
return save;
}
/**
* Deletes {@link DistributionSetTag} by given
* {@link DistributionSetTag#getName()}.
*
* @param tagNames
* to be deleted
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
public void deleteDistributionSetTag(@NotEmpty final String tagName) {
public void deleteDistributionSetTag(final String tagName) {
final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName);
final List<DistributionSet> changed = new LinkedList<>();
@@ -321,20 +218,10 @@ public class TagManagement {
afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagDeletedEvent(tag)));
}
/**
* Updates an existing {@link DistributionSetTag}.
*
* @param distributionSetTag
* to be updated
* @return the updated {@link DistributionSet}
* @throws NullPointerException
* of {@link DistributionSetTag#getName()} is <code>null</code>
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
public DistributionSetTag updateDistributionSetTag(@NotNull final DistributionSetTag distributionSetTag) {
public DistributionSetTag updateDistributionSetTag(final DistributionSetTag distributionSetTag) {
checkNotNull(distributionSetTag.getName());
checkNotNull(distributionSetTag.getId());
final DistributionSetTag save = distributionSetTagRepository.save(distributionSetTag);
@@ -343,80 +230,34 @@ public class TagManagement {
return save;
}
/**
* returns all {@link DistributionTag}s.
*
* @return all {@link DistributionTag}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
@Override
public List<DistributionSetTag> findAllDistributionSetTags() {
return distributionSetTagRepository.findAll();
}
/**
* Finds {@link TargetTag} by given id.
*
* @param id
* to search for
* @return the found {@link TargetTag}s or <code>null</code> if not found.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public TargetTag findTargetTagById(@NotNull final Long id) {
@Override
public TargetTag findTargetTagById(final Long id) {
return targetTagRepository.findOne(id);
}
/**
* Finds {@link DistributionSetTag} by given id.
*
* @param id
* to search for
* @return the found {@link DistributionSetTag}s or <code>null</code> if not
* found.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public DistributionSetTag findDistributionSetTagById(@NotNull final Long id) {
@Override
public DistributionSetTag findDistributionSetTagById(final Long id) {
return distributionSetTagRepository.findOne(id);
}
/**
* returns all {@link TargetTag}s.
*
* @param pageReq
* page parameter
*
* @return all {@link TargetTag}s
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<TargetTag> findAllTargetTags(@NotNull final Pageable pageReq) {
@Override
public Page<TargetTag> findAllTargetTags(final Pageable pageReq) {
return targetTagRepository.findAll(pageReq);
}
/**
* returns all {@link DistributionSetTag}s.
*
* @param pageReq
* page parameter
* @return all {@link DistributionSetTag}s
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public Page<DistributionSetTag> findAllDistributionSetTags(@NotNull final Pageable pageReq) {
@Override
public Page<DistributionSetTag> findAllDistributionSetTags(final Pageable pageReq) {
return distributionSetTagRepository.findAll(pageReq);
}
/**
* Retrieves all DistributionSet tags based on the given specification.
*
* @param spec
* the specification for the query
* @param pageable
* pagination parameter
* @return the found {@link DistributionSetTag}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<DistributionSetTag> findAllDistributionSetTags(@NotNull final Specification<DistributionSetTag> spec,
@NotNull final Pageable pageable) {
@Override
public Page<DistributionSetTag> findAllDistributionSetTags(final Specification<DistributionSetTag> spec,
final Pageable pageable) {
return distributionSetTagRepository.findAll(spec, pageable);
}

View File

@@ -11,9 +11,7 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder;
@@ -24,7 +22,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@@ -34,28 +31,21 @@ import org.springframework.validation.annotation.Validated;
import com.google.common.base.Strings;
/**
* Business service facade for managing {@link TargetFilterQuery}s.
* JPA implementation of {@link TargetFilterQueryManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
@Validated
@Service
public class TargetFilterQueryManagement {
public class JpaTargetFilterQueryManagement implements TargetFilterQueryManagement {
@Autowired
private TargetFilterQueryRepository targetFilterQueryRepository;
/**
* creating new {@link TargetFilterQuery}.
*
* @param customTargetFilter
* @return the created {@link TargetFilterQuery}
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
public TargetFilterQuery createTargetFilterQuery(@NotNull final TargetFilterQuery customTargetFilter) {
public TargetFilterQuery createTargetFilterQuery(final TargetFilterQuery customTargetFilter) {
if (targetFilterQueryRepository.findByName(customTargetFilter.getName()) != null) {
throw new EntityAlreadyExistsException(customTargetFilter.getName());
@@ -63,44 +53,20 @@ public class TargetFilterQueryManagement {
return targetFilterQueryRepository.save(customTargetFilter);
}
/**
* Delete target filter query.
*
* @param targetFilterQueryId
* IDs of target filter query to be deleted
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
public void deleteTargetFilterQuery(@NotNull final Long targetFilterQueryId) {
public void deleteTargetFilterQuery(final Long targetFilterQueryId) {
targetFilterQueryRepository.delete(targetFilterQueryId);
}
/**
*
* Retrieves all target filter query{@link TargetFilterQuery}.
*
* @param pageable
* pagination parameter
* @return the found {@link TargetFilterQuery}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<TargetFilterQuery> findAllTargetFilterQuery(@NotNull final Pageable pageable) {
@Override
public Page<TargetFilterQuery> findAllTargetFilterQuery(final Pageable pageable) {
return targetFilterQueryRepository.findAll(pageable);
}
/**
* Retrieves all target filter query which {@link TargetFilterQuery}.
*
*
* @param pageable
* pagination parameter
* @param name
* target filter query name
* @return the page with the found {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<TargetFilterQuery> findTargetFilterQueryByFilters(@NotNull final Pageable pageable, final String name) {
@Override
public Page<TargetFilterQuery> findTargetFilterQueryByFilters(final Pageable pageable, final String name) {
final List<Specification<TargetFilterQuery>> specList = new ArrayList<>();
if (!Strings.isNullOrEmpty(name)) {
specList.add(TargetFilterQuerySpecification.likeName(name));
@@ -108,15 +74,7 @@ public class TargetFilterQueryManagement {
return findTargetFilterQueryByCriteriaAPI(pageable, specList);
}
/**
*
* @param pageable
* pagination parameter
* @param specList
* list of @link {@link Specification}
* @return the page with the found {@link TargetFilterQuery}
*/
private Page<TargetFilterQuery> findTargetFilterQueryByCriteriaAPI(@NotNull final Pageable pageable,
private Page<TargetFilterQuery> findTargetFilterQueryByCriteriaAPI(final Pageable pageable,
final List<Specification<TargetFilterQuery>> specList) {
if (specList == null || specList.isEmpty()) {
return targetFilterQueryRepository.findAll(pageable);
@@ -126,44 +84,20 @@ public class TargetFilterQueryManagement {
return targetFilterQueryRepository.findAll(specs, pageable);
}
/**
* Find target filter query by name.
*
* @param targetFilterQueryName
* Target filter query name
* @return the found {@link TargetFilterQuery}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public TargetFilterQuery findTargetFilterQueryByName(@NotNull final String targetFilterQueryName) {
@Override
public TargetFilterQuery findTargetFilterQueryByName(final String targetFilterQueryName) {
return targetFilterQueryRepository.findByName(targetFilterQueryName);
}
/**
* Find target filter query by id.
*
* @param targetFilterQueryId
* Target filter query id
* @return the found {@link TargetFilterQuery}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public TargetFilterQuery findTargetFilterQueryById(@NotNull final Long targetFilterQueryId) {
@Override
public TargetFilterQuery findTargetFilterQueryById(final Long targetFilterQueryId) {
return targetFilterQueryRepository.findOne(targetFilterQueryId);
}
/**
* updates the {@link TargetFilterQuery}.
*
* @param targetFilterQuery
* to be updated
* @return the updated {@link TargetFilterQuery}
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public TargetFilterQuery updateTargetFilterQuery(@NotNull final TargetFilterQuery targetFilterQuery) {
public TargetFilterQuery updateTargetFilterQuery(final TargetFilterQuery targetFilterQuery) {
Assert.notNull(targetFilterQuery.getId());
return targetFilterQueryRepository.save(targetFilterQuery);
}

View File

@@ -17,7 +17,6 @@ import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PreDestroy;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@@ -27,17 +26,14 @@ import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.Constants;
import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent;
import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSet_;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetIdName;
@@ -50,7 +46,6 @@ import org.eclipse.hawkbit.repository.model.Target_;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder;
import org.eclipse.hawkbit.repository.specifications.TargetSpecifications;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
@@ -61,7 +56,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@@ -73,13 +67,13 @@ import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
/**
* Business service facade for managing {@link Target}s.
* JPA implementation of {@link TargetManagement}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
@Validated
@Service
public class TargetManagement {
public class JpaTargetManagement implements TargetManagement {
@Autowired
private EntityManager entityManager;
@@ -102,34 +96,13 @@ public class TargetManagement {
@Autowired
private AfterTransactionCommitExecutor afterCommit;
/**
* Find {@link Target} based on given ID returns found Target without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible.
*
* @param controllerId
* to look for.
* @return {@link Target} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Target findTargetByControllerID(@NotEmpty final String controllerId) {
@Override
public Target findTargetByControllerID(final String controllerId) {
return targetRepository.findByControllerId(controllerId);
}
/**
* Find {@link Target} based on given ID returns found Target with details,
* i.e. {@link Target#getTags()} and {@link Target#getActiveActions()} are
* possible.
*
* Note: try to use {@link #findTargetByControllerID(String)} as much as
* possible.
*
* @param controllerId
* to look for.
* @return {@link Target} or <code>null</code> if it does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Target findTargetByControllerIDWithDetails(@NotEmpty final String controllerId) {
@Override
public Target findTargetByControllerIDWithDetails(final String controllerId) {
final Target result = targetRepository.findByControllerId(controllerId);
// load lazy relations
if (result != null) {
@@ -146,40 +119,18 @@ public class TargetManagement {
return result;
}
/**
* Find {@link Target} based on given ID returns found Target without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible.
*
* @param controllerIDs
* to look for.
* @return List of found{@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<Target> findTargetByControllerID(@NotEmpty final Collection<String> controllerIDs) {
@Override
public List<Target> findTargetByControllerID(final Collection<String> controllerIDs) {
return targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndAssignedInJoin(controllerIDs));
}
/**
* Counts all {@link Target}s in the repository.
*
* @return number of targets
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public Long countTargetsAll() {
return targetRepository.count();
}
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActiveActions()} possible
*
* @param pageable
* pagination parameter
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Slice<Target> findTargetsAll(@NotNull final Pageable pageable) {
@Override
public Slice<Target> findTargetsAll(final Pageable pageable) {
// workarround - no join fetch allowed that is why we need specification
// instead of query for
// count() of Pageable
@@ -192,113 +143,50 @@ public class TargetManagement {
return criteriaNoCountDao.findAll(spec, pageable, Target.class);
}
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActiveActions()} possible based on
* {@link TargetFilterQuery#getQuery()}
*
* @param targetFilterQuery
* @param pageable
* @return
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Slice<Target> findTargetsAll(@NotNull final TargetFilterQuery targetFilterQuery,
@NotNull final Pageable pageable) {
@Override
public Slice<Target> findTargetsAll(final TargetFilterQuery targetFilterQuery, final Pageable pageable) {
return findTargetsAll(RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class), pageable);
}
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActiveActions()} possible based on
* {@link TargetFilterQuery#getQuery()}
*
* @param targetFilterQuery
* @param pageable
* @return
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Slice<Target> findTargetsAll(@NotNull final String targetFilterQuery, @NotNull final Pageable pageable) {
@Override
public Slice<Target> findTargetsAll(final String targetFilterQuery, final Pageable pageable) {
return findTargetsAll(RSQLUtility.parse(targetFilterQuery, TargetFields.class), pageable);
}
/**
* Retrieves all targets based on the given specification.
*
* @param spec
* the specification for the query
* @param pageable
* pagination parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<Target> findTargetsAll(@NotNull final Specification<Target> spec, @NotNull final Pageable pageable) {
@Override
public Page<Target> findTargetsAll(final Specification<Target> spec, final Pageable pageable) {
return targetRepository.findAll(spec, pageable);
}
/**
* retrieves a list of {@link Target}s by their controller ID with details,
* i.e. {@link Target#getTags()} are possible.
*
* Note: try to use {@link #findTargetByControllerID(String)} as much as
* possible.
*
* @param controllerIDs
* {@link Target}s Names parameter
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<Target> findTargetsByControllerIDsWithTags(@NotNull final List<String> controllerIDs) {
@Override
public List<Target> findTargetsByControllerIDsWithTags(final List<String> controllerIDs) {
final List<List<String>> partition = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT);
return partition.stream()
.map(ids -> targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(ids)))
.flatMap(t -> t.stream()).collect(Collectors.toList());
}
/**
* updates the {@link Target}.
*
* @param target
* to be updated
* @return the updated {@link Target}
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
public Target updateTarget(@NotNull final Target target) {
public Target updateTarget(final Target target) {
Assert.notNull(target.getId());
target.setNew(false);
return targetRepository.save(target);
}
/**
* updates multiple {@link Target}s.
*
* @param targets
* to be updated
* @return the updated {@link Target}s
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
public List<Target> updateTargets(@NotNull final List<Target> targets) {
public List<Target> updateTargets(final Iterable<Target> targets) {
targets.forEach(target -> target.setNew(false));
return targetRepository.save(targets);
}
/**
* Deletes all targets with the given IDs.
*
* @param targetIDs
* the technical IDs of the targets to be deleted
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
public void deleteTargets(@NotEmpty final Long... targetIDs) {
public void deleteTargets(final Long... targetIDs) {
// we need to select the target IDs first to check the if the targetIDs
// belonging to the
// tenant! Delete statement are not automatically enhanced with the
@@ -312,81 +200,25 @@ public class TargetManagement {
}
}
/**
* retrieves {@link Target}s by the assigned {@link DistributionSet} without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible.
*
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
* @param pageReq
* page parameter
* @return the found {@link Target}s
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
public Page<Target> findTargetByAssignedDistributionSet(@NotNull final Long distributionSetID,
@NotNull final Pageable pageReq) {
@Override
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final Pageable pageReq) {
return targetRepository.findByAssignedDistributionSetId(pageReq, distributionSetID);
}
/**
* Retrieves {@link Target}s by the assigned {@link DistributionSet} without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible including additional filtering
* based on the given {@code spec}.
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
* @param spec
* the specification to filter the result set
* @param pageReq
* page parameter
* @return the found {@link Target}s, never {@code null}
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
public Page<Target> findTargetByAssignedDistributionSet(@NotNull final Long distributionSetID,
final Specification<Target> spec, @NotNull final Pageable pageReq) {
@Override
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID,
final Specification<Target> spec, final Pageable pageReq) {
return targetRepository.findAll((Specification<Target>) (root, query, cb) -> cb.and(
TargetSpecifications.hasAssignedDistributionSet(distributionSetID).toPredicate(root, query, cb),
spec.toPredicate(root, query, cb)), pageReq);
}
/**
* retrieves {@link Target}s by the installed {@link DistributionSet}without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible.
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
* @param pageReq
* page parameter
* @return the found {@link Target}s
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
public Page<Target> findTargetByInstalledDistributionSet(@NotNull final Long distributionSetID,
@NotNull final Pageable pageReq) {
@Override
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetID, final Pageable pageReq) {
return targetRepository.findByTargetInfoInstalledDistributionSetId(pageReq, distributionSetID);
}
/**
* retrieves {@link Target}s by the installed {@link DistributionSet}without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible including additional filtering
* based on the given {@code spec}.
*
* @param distributionSetId
* the ID of the {@link DistributionSet}
* @param spec
* the specification to filter the result
* @param pageable
* page parameter
* @return the found {@link Target}s, never {@code null}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
@Override
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetId,
final Specification<Target> spec, final Pageable pageable) {
return targetRepository.findAll((Specification<Target>) (root, query, cb) -> cb.and(
@@ -394,82 +226,21 @@ public class TargetManagement {
spec.toPredicate(root, query, cb)), pageable);
}
/**
* Retrieves the {@link Target} which have a certain
* {@link TargetUpdateStatus} without details, i.e. NO
* {@link Target#getTags()} and {@link Target#getActiveActions()} possible.
*
* @param pageable
* page parameter
* @param status
* the {@link TargetUpdateStatus} to be filtered on
* @return the found {@link Target}s
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<Target> findTargetByUpdateStatus(@NotNull final Pageable pageable,
@NotNull final TargetUpdateStatus status) {
@Override
public Page<Target> findTargetByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) {
return targetRepository.findByTargetInfoUpdateStatus(pageable, status);
}
/**
* Filter {@link Target}s for all the given parameters. If all parameters
* except pageable are null, all available {@link Target}s are returned.
*
* @param pageable
* page parameters
* @param status
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param searchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param tagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Slice<Target> findTargetByFilters(@NotNull final Pageable pageable,
final Collection<TargetUpdateStatus> status, final String searchText,
final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag,
final String... tagNames) {
@Override
public Slice<Target> findTargetByFilters(final Pageable pageable, final Collection<TargetUpdateStatus> status,
final String searchText, final Long installedOrAssignedDistributionSetId,
final Boolean selectTargetWithNoTag, final String... tagNames) {
final List<Specification<Target>> specList = buildSpecificationList(status, searchText,
installedOrAssignedDistributionSetId, selectTargetWithNoTag, true, tagNames);
return findByCriteriaAPI(pageable, specList);
}
/**
* Count {@link Target}s for all the given filter parameters.
*
* @param status
* find targets having on of these {@link TargetUpdateStatus}s.
* Set to <code>null</code> in case this is not required.
* @param searchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param tagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found number {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public Long countTargetByFilters(final Collection<TargetUpdateStatus> status, final String searchText,
final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag,
final String... tagNames) {
@@ -498,15 +269,6 @@ public class TargetManagement {
return specList;
}
/**
* executes findAll with the given {@link Target} {@link Specification}s.
*
* @param pageable
* paging parameter
* @param specList
* list of @link {@link Specification}
* @return the page with the found {@link Target}
*/
private Slice<Target> findByCriteriaAPI(final Pageable pageable, final List<Specification<Target>> specList) {
if (specList == null || specList.isEmpty()) {
return criteriaNoCountDao.findAll(pageable, Target.class);
@@ -522,44 +284,18 @@ public class TargetManagement {
return targetRepository.count(SpecificationsBuilder.combineWithAnd(specList));
}
/**
* {@link Entity} based method call for
* {@link #toggleTagAssignment(Collection, String)}.
*
* @param targets
* to toggle for
* @param tag
* to toggle
* @return TagAssigmentResult with all metadata of the assignment outcome.
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final List<Target> targets,
@NotNull final TargetTag tag) {
public TargetTagAssignmentResult toggleTagAssignment(final Collection<Target> targets, final TargetTag tag) {
return toggleTagAssignment(
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());
}
/**
* Toggles {@link TargetTag} assignment to given {@link Target}s by means
* that if some (or all) of the targets in the list have the {@link Tag} not
* yet assigned, they will be. If all of theme have the tag already assigned
* they will be removed instead.
*
* @param targetIds
* to toggle for
* @param tagName
* to toogle
* @return TagAssigmentResult with all metadata of the assigment outcome.
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection<String> targetIds,
@NotNull final String tagName) {
public TargetTagAssignmentResult toggleTagAssignment(final Collection<String> targetIds, final String tagName) {
final TargetTag tag = targetTagRepository.findByNameEquals(tagName);
final List<Target> alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName, targetIds);
final List<Target> allTargets = targetRepository
@@ -588,20 +324,10 @@ public class TargetManagement {
return result;
}
/**
* Assign a {@link TargetTag} assignment to given {@link Target}s.
*
* @param targetIds
* to assign for
* @param tagName
* to assign
* @return list of assigned targets
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public List<Target> assignTag(@NotEmpty final Collection<String> targetIds, @NotNull final TargetTag tag) {
public List<Target> assignTag(final Collection<String> targetIds, final TargetTag tag) {
final List<Target> allTargets = targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(targetIds));
@@ -617,7 +343,7 @@ public class TargetManagement {
return save;
}
private List<Target> unAssignTag(@NotEmpty final Collection<Target> targets, @NotNull final TargetTag tag) {
private List<Target> unAssignTag(final Collection<Target> targets, final TargetTag tag) {
targets.forEach(target -> target.getTags().remove(tag));
final List<Target> save = targetRepository.save(targets);
@@ -629,83 +355,26 @@ public class TargetManagement {
return save;
}
/**
* Unassign all {@link Target} from a given {@link TargetTag} .
*
* @param tag
* to unassign all targets
* @return list of unassigned targets
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public List<Target> unAssignAllTargetsByTag(@NotNull final TargetTag tag) {
public List<Target> unAssignAllTargetsByTag(final TargetTag tag) {
return unAssignTag(tag.getAssignedToTargets(), tag);
}
/**
* Unassign a {@link TargetTag} assignment to given {@link Target}.
*
* @param controllerID
* to unassign for
* @param targetTag
* to unassign
* @return the unassigned target or <null> if no target is unassigned
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
public Target unAssignTag(@NotNull final String controllerID, @NotNull final TargetTag targetTag) {
public Target unAssignTag(final String controllerID, final TargetTag targetTag) {
final List<Target> allTargets = targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID)));
final List<Target> unAssignTag = unAssignTag(allTargets, targetTag);
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
}
/**
* method retrieves all {@link Target}s from the repo in the following
* order:
* <p>
* 1) {@link Target}s which have the given {@link DistributionSet} as
* {@link Target#getTargetStatus()}
* {@link TargetStatus#getInstalledDistributionSet()}
* <p>
* 2) {@link Target}s which have the given {@link DistributionSet} as
* {@link Target#getAssignedDistributionSet()}
* <p>
* 3) {@link Target}s which have no connection to the given
* {@link DistributionSet}.
*
* @param pageable
* the page request to page the result set
* @param orderByDistributionId
* {@link DistributionSet#getId()} to be ordered by
* @param filterByDistributionId
* {@link DistributionSet#getId()} to be filter the result. Set
* to <code>null</code> in case this is not required.
* @param filterByStatus
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param filterBySearchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param filterByTagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
* @return a paged result {@link Page} of the {@link Target}s in a defined
* order.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull final Pageable pageable,
@NotNull final Long orderByDistributionId, final Long filterByDistributionId,
@Override
public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable,
final Long orderByDistributionId, final Long filterByDistributionId,
final Collection<TargetUpdateStatus> filterByStatus, final String filterBySearchText,
final Boolean selectTargetWithNoTag, final String... filterByTagNames) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
@@ -756,9 +425,6 @@ public class TargetManagement {
return new SliceImpl<>(resultList, pageable, hasNext);
}
/**
* @param specifications
*/
private static Predicate[] specificationsToPredicate(final List<Specification<Target>> specifications,
final Root<Target> root, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
final Predicate[] predicates = new Predicate[specifications.size()];
@@ -768,40 +434,17 @@ public class TargetManagement {
return predicates;
}
/**
* Counts number of targets with given
* {@link Target#getAssignedDistributionSet()}.
*
* @param distId
* to search for
*
* @return number of found {@link Target}s.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public Long countTargetByAssignedDistributionSet(final Long distId) {
return targetRepository.countByAssignedDistributionSetId(distId);
}
/**
* Counts number of targets with given
* {@link TargetStatus#getInstalledDistributionSet()}.
*
* @param distId
* to search for
* @return number of found {@link Target}s.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public Long countTargetByInstalledDistributionSet(final Long distId) {
return targetRepository.countByTargetInfoInstalledDistributionSetId(distId);
}
/**
* finds all {@link Target#getControllerId()} which are currently in the
* database.
*
* @return all IDs of all {@link Target} in the system
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public List<TargetIdName> findAllTargetIds() {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<TargetIdName> query = cb.createQuery(TargetIdName.class);
@@ -811,34 +454,8 @@ public class TargetManagement {
}
/**
* Finds all targets for all the given parameters but returns not the full
* target but {@link TargetIdName}.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
*
* @param filterByStatus
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param filterBySearchText
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param filterByTagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<TargetIdName> findAllTargetIdsByFilters(@NotNull final Pageable pageRequest,
@Override
public List<TargetIdName> findAllTargetIdsByFilters(final Pageable pageRequest,
final Collection<TargetUpdateStatus> filterByStatus, final String filterBySearchText,
final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag,
final String... filterByTagNames) {
@@ -871,19 +488,9 @@ public class TargetManagement {
.collect(Collectors.toList());
}
/**
* Finds all targets for all the given parameter {@link TargetFilterQuery}
* and returns not the full target but {@link TargetIdName}.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
* @param targetFilterQuery
* {@link TargetFilterQuery}
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
@Override
public List<TargetIdName> findAllTargetIdsByTargetFilterQuery(final Pageable pageRequest,
@NotNull final TargetFilterQuery targetFilterQuery) {
final TargetFilterQuery targetFilterQuery) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
final Root<Target> targetRoot = query.from(Target.class);
@@ -918,31 +525,12 @@ public class TargetManagement {
eventBus.unregister(this);
}
/**
* creating new {@link Target}s including poll status data. useful
* especially in plug and play scenarios.
*
* @param target
* to be created *
* @param status
* of the target
* @param lastTargetQuery
* if a plug and play case
* @param address
* if a plug and play case
*
* @throws EntityAlreadyExistsException
*
* @return
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
@CacheEvict(value = { "targetsCreatedOverPeriod" }, allEntries = true)
public Target createTarget(@NotNull final Target target, @NotNull final TargetUpdateStatus status,
final Long lastTargetQuery, final URI address) {
public Target createTarget(final Target target, final TargetUpdateStatus status, final Long lastTargetQuery,
final URI address) {
if (targetRepository.findByControllerId(target.getControllerId()) != null) {
throw new EntityAlreadyExistsException(target.getControllerId());
@@ -965,43 +553,18 @@ public class TargetManagement {
}
/**
* creating a new {@link Target}.
*
* @param target
* to be created
* @return the created {@link Target}
*
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
@CacheEvict(value = { "targetsCreatedOverPeriod" }, allEntries = true)
public Target createTarget(@NotNull final Target target) {
public Target createTarget(final Target target) {
return createTarget(target, TargetUpdateStatus.UNKNOWN, null, null);
}
/**
* creates multiple {@link Target}s. If some of the given {@link Target}s
* already exists in the DB a {@link EntityAlreadyExistsException} is
* thrown. {@link Target}s contain all objects of the parameter targets,
* including duplicates.
*
* @param targets
* to be created.
* @return the created {@link Target}s
*
* @throws {@link
* EntityAlreadyExistsException} of one of the given targets
* already exist.
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
public List<Target> createTargets(@NotNull final List<Target> targets) {
public List<Target> createTargets(final Collection<Target> targets) {
if (!targets.isEmpty() && targetRepository.countByControllerIdIn(
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())) > 0) {
throw new EntityAlreadyExistsException();
@@ -1014,27 +577,11 @@ public class TargetManagement {
return savedTargets;
}
/**
* creating a new {@link Target} including poll status data. useful
* especially in plug and play scenarios.
*
* @param targets
* to be created *
* @param status
* of the target
* @param lastTargetQuery
* if a plug and play case
* @param address
* if a plug and play case
*
* @return newly created target
*/
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET)
public List<Target> createTargets(@NotNull final Collection<Target> targets,
@NotNull final TargetUpdateStatus status, final long lastTargetQuery, final URI address) {
public List<Target> createTargets(final Collection<Target> targets, final TargetUpdateStatus status,
final Long lastTargetQuery, final URI address) {
if (targetRepository.countByControllerIdIn(
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())) > 0) {
throw new EntityAlreadyExistsException();
@@ -1047,42 +594,20 @@ public class TargetManagement {
return savedTargets;
}
/**
* Find targets by tag name.
*
* @param tagName
* tag name
* @return list of matching targets
*/
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<Target> findTargetsByTag(@NotNull final String tagName) {
@Override
public List<Target> findTargetsByTag(final String tagName) {
final TargetTag tag = targetTagRepository.findByNameEquals(tagName);
return targetRepository.findByTag(tag);
}
/**
* Count {@link TargetFilterQuery}s for given filter parameter.
*
* @param targetFilterQuery
* {link TargetFilterQuery}
* @return the found number {@link TargetFilterQuery}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Long countTargetByTargetFilterQuery(@NotNull final TargetFilterQuery targetFilterQuery) {
@Override
public Long countTargetByTargetFilterQuery(final TargetFilterQuery targetFilterQuery) {
final Specification<Target> specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
return targetRepository.count(specs);
}
/**
* Count {@link TargetFilterQuery}s for given target filter query.
*
* @param targetFilterQuery
* {link TargetFilterQuery}
* @return the found number {@link TargetFilterQuery}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Long countTargetByTargetFilterQuery(@NotNull final String targetFilterQuery) {
@Override
public Long countTargetByTargetFilterQuery(final String targetFilterQuery) {
final Specification<Target> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class);
return targetRepository.count(specs);
}

View File

@@ -10,10 +10,9 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.Optional;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.report.model.TenantUsage;
import org.eclipse.hawkbit.repository.TenantStatsManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@@ -21,12 +20,12 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
* Management service for stats of a single tenant.
* Management service for statistics of a single tenant.
*
*/
@Validated
@Service
public class TenantStatsManagement {
public class JpaTenantStatsManagement implements TenantStatsManagement {
@Autowired
private TargetRepository targetRepository;
@@ -37,17 +36,8 @@ public class TenantStatsManagement {
@Autowired
private ActionRepository actionRepository;
/**
* Service for stats of a single tenant. Opens a new transaction and as a
* result can an be used for multiple tenants, i.e. to allow in one session
* to collect data of all tenants in the system.
*
* @param tenant
* to collect for
* @return collected statistics
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED)
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
public TenantUsage getStatsOfTenant(final String tenant) {
final TenantUsage result = new TenantUsage(tenant);

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.model.helper;
import org.eclipse.hawkbit.repository.jpa.SystemManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.springframework.beans.factory.annotation.Autowired;
/**

View File

@@ -23,6 +23,10 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.jpa.ActionRepository;
import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository;
@@ -36,11 +40,7 @@ import org.eclipse.hawkbit.repository.jpa.RolloutRepository;
import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository;
import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository;
import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository;
import org.eclipse.hawkbit.repository.jpa.SystemManagement;
import org.eclipse.hawkbit.repository.jpa.TagManagement;
import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository;
import org.eclipse.hawkbit.repository.jpa.TargetManagement;
import org.eclipse.hawkbit.repository.jpa.TargetRepository;
import org.eclipse.hawkbit.repository.jpa.TargetTagRepository;
import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository;

View File

@@ -19,7 +19,7 @@ import org.apache.commons.io.IOUtils;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.jpa.TargetManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;

View File

@@ -21,7 +21,6 @@ import org.eclipse.hawkbit.AbstractIntegrationTest;
import org.eclipse.hawkbit.TestDataUtil;
import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.TagManagement;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;

View File

@@ -13,7 +13,6 @@ import static org.junit.Assert.fail;
import org.eclipse.hawkbit.AbstractIntegrationTest;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.junit.Test;

View File

@@ -31,8 +31,8 @@ import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.jpa.TagManagement;
import org.eclipse.hawkbit.repository.jpa.TargetManagement;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;