Skip to content

Commit

Permalink
Feature target type filter (#1197)
Browse files Browse the repository at this point in the history
* Added Target type filter with drag and drop support

Signed-off-by: Anand kumar <[email protected]>

* Removed the unused enums and target type filter button class

Signed-off-by: Anand kumar <[email protected]>

* Resolved merge conflicts

Signed-off-by: Anand kumar <[email protected]>

* Fixed java doc issue with the method link in the comment

Signed-off-by: Anand kumar <[email protected]>

* Fixed the IN query overflow for target Type assignment

Signed-off-by: Anand kumar <[email protected]>

* Fixed Review comments

Signed-off-by: Anand kumar <[email protected]>
  • Loading branch information
aktivk authored Oct 27, 2021
1 parent dea6fa3 commit 70779d1
Show file tree
Hide file tree
Showing 38 changed files with 1,404 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ public boolean isMap() {
public String getFieldName() {
return fieldName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public class FilterParams {
private final Boolean selectTargetWithNoTag;
private final String[] filterByTagNames;
private final Long filterByDistributionId;
private final Boolean selectTargetWithNoTargetType;
private final Long filterByTargetType;

/**
* Constructor.
* Constructor for the filter parameters of a Simple Filter.
*
* @param filterByInstalledOrAssignedDistributionSetId
* if set, a filter is added for the given
Expand All @@ -56,6 +58,34 @@ public FilterParams(final Collection<TargetUpdateStatus> filterByStatus, final B
this.filterByDistributionId = filterByInstalledOrAssignedDistributionSetId;
this.selectTargetWithNoTag = selectTargetWithNoTag;
this.filterByTagNames = filterByTagNames;
this.selectTargetWithNoTargetType = false;
this.filterByTargetType = null;

}

/**
* Constructor for the filter parameters of a Type Filter.
*
* @param filterBySearchText
* if set, a filter is added for the given search text
* @param filterByInstalledOrAssignedDistributionSetId
* if set, a filter is added for the given
* {@link DistributionSet#getId()}
* @param selectTargetWithNoType
* if true, a filter is added with no type
* @param filterByType
* if set, a filter is added for the given target type
*/
public FilterParams(final String filterBySearchText, final Long filterByInstalledOrAssignedDistributionSetId,
final Boolean selectTargetWithNoType, final Long filterByType) {
this.filterBySearchText = filterBySearchText;
this.filterByDistributionId = filterByInstalledOrAssignedDistributionSetId;
this.filterByStatus = null;
this.overdueState = null;
this.selectTargetWithNoTag = false;
this.filterByTagNames = null;
this.selectTargetWithNoTargetType = selectTargetWithNoType;
this.filterByTargetType = filterByType;
}

/**
Expand Down Expand Up @@ -120,4 +150,23 @@ public Boolean getSelectTargetWithNoTag() {
public String[] getFilterByTagNames() {
return filterByTagNames;
}

/**
* Gets the flag indicating if no target type filter is used. <br>
* If set to <code>false</code> this filter is disabled.
*
* @return the flag indicating if no target type filter is used
*/
public Boolean getSelectTargetWithNoTargetType() {
return selectTargetWithNoTargetType;
}

/**
* Gets the target type
*
* @return the target type that are used to filter for
*/
public Long getFilterByTargetType() {
return filterByTargetType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
*/
package org.eclipse.hawkbit.repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.builder.TargetCreate;
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
Expand All @@ -35,12 +27,22 @@
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.TargetTypeAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* Management service for {@link Target}s.
*
Expand Down Expand Up @@ -106,11 +108,29 @@ public interface TargetManagement {
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*
* @deprecated this method {@link TargetManagement#countByFilters(FilterParams)} should be used instead.
*/
@Deprecated
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
long countByFilters(Collection<TargetUpdateStatus> status, Boolean overdueState, String searchText,
Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, String... tagNames);

/**
* Count {@link Target}s for all the given filter parameters.
*
* @param filterParams
* the filters to apply; only filters are enabled that have
* non-null value; filters are AND-gated
*
* @return the found number {@link Target}s
*
* @throws EntityNotFoundException
* if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
long countByFilters(@NotNull final FilterParams filterParams);

/**
* Counts number of targets with given with given distribution set Id
*
Expand Down Expand Up @@ -607,6 +627,38 @@ Slice<Target> findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageabl
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection<String> controllerIds, @NotEmpty String tagName);


/**
* Initiates {@link TargetType} assignment to given {@link Target}s. If some
* targets in the list have the {@link TargetType} not yet assigned, they will
* get assigned. If all targets are already of that type, there will be no
* un-assignment.
*
* @param controllerIds
* to set the type to
* @param typeId
* to assign targets to
* @return {@link TargetTypeAssignmentResult} with all meta data of the
* assignment outcome.
*
* @throws EntityNotFoundException
* if target type with given id does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTypeAssignmentResult assignType(@NotEmpty Collection<String> controllerIds, @NotNull Long typeId);

/**
* Initiates {@link TargetType} un-assignment to given {@link Target}s. The type
* of the targets will be set to {@code null}
*
* @param controllerIds
* to remove the type from
* @return {@link TargetTypeAssignmentResult} with all meta data of the
* assignment outcome.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTypeAssignmentResult unAssignType(@NotEmpty Collection<String> controllerIds);

/**
* Un-assign a {@link TargetTag} assignment to given {@link Target}.
*
Expand Down Expand Up @@ -638,6 +690,8 @@ Slice<Target> findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageabl
*
* @param controllerID
* to un-assign for
* @param targetTypeId
* Target type id
* @return the unassigned target
*
* @throws EntityNotFoundException
Expand Down Expand Up @@ -854,4 +908,5 @@ Page<TargetMetadata> findMetaDataByControllerIdAndRsql(@NotNull Pageable pageabl
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
TargetMetadata updateMetadata(@NotEmpty String controllerId, @NotNull MetaData metadata);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2021 Bosch.IO 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.model;

import java.util.List;

/**
* Result object for {@link TargetType} assignments.
*
*/
public class TargetTypeAssignmentResult extends AbstractAssignmentResult<Target> {

private final TargetType targetType;

/**
* Constructor.
*
* @param alreadyAssigned
* count of already assigned (ignored) elements
* @param assigned
* {@link List} of assigned {@link Target}s.
* @param unassigned
* {@link List} of unassigned {@link Target}s.
* @param targetType
* the assigned or unassigned tag
*/
public TargetTypeAssignmentResult(final int alreadyAssigned, final List<? extends Target> assigned,
final List<? extends Target> unassigned, final TargetType targetType) {
super(alreadyAssigned, assigned, unassigned);
this.targetType = targetType;
}

public TargetType getTargetType() {
return targetType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.hawkbit.repository.event.remote.TargetFilterQueryDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetTypeDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.TenantConfigurationDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
Expand All @@ -53,6 +54,8 @@
import org.eclipse.hawkbit.repository.event.remote.entity.TargetFilterQueryUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTypeCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTypeUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TenantConfigurationCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TenantConfigurationUpdatedEvent;
Expand Down Expand Up @@ -150,6 +153,11 @@ public class EventType {

// rollout stopped due to invalidated distribution set
TYPES.put(43, RolloutStoppedEvent.class);

// target type
TYPES.put(44, TargetTypeCreatedEvent.class);
TYPES.put(45, TargetTypeUpdatedEvent.class);
TYPES.put(46, TargetTypeDeletedEvent.class);
}

private int value;
Expand Down
Loading

0 comments on commit 70779d1

Please sign in to comment.