Fix issues from static code analysis

Signed-off-by: Marcel Mager (INST-IOT/ESB) <Marcel.Mager@bosch-si.com>
This commit is contained in:
Marcel Mager (INST-IOT/ESB)
2016-09-22 10:28:08 +02:00
parent b790072d1f
commit 07a158534f
8 changed files with 215 additions and 83 deletions

View File

@@ -0,0 +1,151 @@
package org.eclipse.hawkbit.repository;
import java.util.Collection;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
/**
* Encapsulates a set of filters that may be specified (optionally). Properties
* that are not specified (e.g. <code>null</code> for simple properties) When
* applied, these filters are AND-gated.
*
*/
public class FilterParams {
Collection<TargetUpdateStatus> filterByStatus;
Boolean overdueState;
String filterBySearchText;
Boolean selectTargetWithNoTag;
String[] filterByTagNames;
Long filterByDistributionId;
public FilterParams(Long filterByDistributionId, Collection<TargetUpdateStatus> filterByStatus,
Boolean overdueState, String filterBySearchText, Boolean selectTargetWithNoTag,
String... filterByTagNames) {
this.filterByStatus = filterByStatus;
this.overdueState = overdueState;
this.filterBySearchText = filterBySearchText;
this.filterByDistributionId = filterByDistributionId;
this.selectTargetWithNoTag = selectTargetWithNoTag;
this.filterByTagNames = filterByTagNames;
}
/**
* Gets {@link DistributionSet#getId()} to filter the result. <br>
* If set to <code>null</code> this filter is disabled.
*
* @return {@link DistributionSet#getId()} to filter the result
*/
public Long getFilterByDistributionId() {
return filterByDistributionId;
}
/**
* Sets {@link DistributionSet#getId()} to filter the result.
*
* @param filterByDistributionId
*/
public void setFilterByDistributionId(Long filterByDistributionId) {
this.filterByDistributionId = filterByDistributionId;
}
/**
* Gets a collection of target states to filter for. <br>
* If set to <code>null</code> this filter is disabled.
*
* @return collection of target states to filter for
*/
public Collection<TargetUpdateStatus> getFilterByStatus() {
return filterByStatus;
}
/**
* Sets the collection of target states to filter for.
*
* @param filterByStatus
*/
public void setFilterByStatus(Collection<TargetUpdateStatus> filterByStatus) {
this.filterByStatus = filterByStatus;
}
/**
* Gets the flag for overdue filter; if set to <code>true</code>, the
* overdue filter is activated. Overdued targets a targets that did not
* respond during the configured intervals: poll_itvl + overdue_itvl. <br>
* If set to <code>null</code> this filter is disabled.
*
* @return flag for overdue filter activation
*/
public Boolean getOverdueState() {
return overdueState;
}
/**
* Sets the flag for overdue filter; if set to <code>true</code>, the
* overdue filter is activated.
*
* @param overdueState
*/
public void setOverdueState(Boolean overdueState) {
this.overdueState = overdueState;
}
/**
* Gets the search text to filter for. This is used to find targets having
* the text anywhere in name or description <br>
* If set to <code>null</code> this filter is disabled.
*
* @return the search text to filter for
*/
public String getFilterBySearchText() {
return filterBySearchText;
}
/**
* Sets the search text to filter for.
*
* @param filterBySearchText
*/
public void setFilterBySearchText(String filterBySearchText) {
this.filterBySearchText = filterBySearchText;
}
/**
* Gets the flag indicating if tagging filter is used. <br>
* If set to <code>null</code> this filter is disabled.
*
* @return the flag indicating if tagging filter is used
*/
public Boolean getSelectTargetWithNoTag() {
return selectTargetWithNoTag;
}
/**
* Sets the flag indicating if tagging filter is used.
*
* @param selectTargetWithNoTag
*/
public void setSelectTargetWithNoTag(Boolean selectTargetWithNoTag) {
this.selectTargetWithNoTag = selectTargetWithNoTag;
}
/**
* Gets the tags that are used to filter for. The activation of this filter
* is done by {@link #setSelectTargetWithNoTag(Boolean)}.
*
* @return the tags that are used to filter for
*/
public String[] getFilterByTagNames() {
return filterByTagNames;
}
/**
* Sets the tags that are used to filter for.
*
* @param filterByTagNames
*/
public void setFilterByTagNames(String[] filterByTagNames) {
this.filterByTagNames = filterByTagNames;
}
}

View File

@@ -480,36 +480,15 @@ public interface TargetManagement {
* the page request to page the result set * the page request to page the result set
* @param orderByDistributionId * @param orderByDistributionId
* {@link DistributionSet#getId()} to be ordered by * {@link DistributionSet#getId()} to be ordered by
* @param filterByDistributionId * @param filterParams
* {@link DistributionSet#getId()} to be filter the result. Set * the filters to apply; only filters are enabled that have
* to <code>null</code> in case this is not required. * non-null value; filters are AND-gated
* @param filterByStatus
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
* @param overdueState
* find targets that are overdue (targets that did not respond
* during the configured intervals: poll_itvl + overdue_itvl).
* @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 * @return a paged result {@link Page} of the {@link Target}s in a defined
* order. * order.
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable, Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable,
@NotNull Long orderByDistributionId, Long filterByDistributionId, @NotNull Long orderByDistributionId, FilterParams filterParams);
Collection<TargetUpdateStatus> filterByStatus, Boolean overdueState, String filterBySearchText,
Boolean selectTargetWithNoTag, String... filterByTagNames);
/** /**
* retrieves a list of {@link Target}s by their controller ID with details, * retrieves a list of {@link Target}s by their controller ID with details,

View File

@@ -27,6 +27,7 @@ import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.eclipse.hawkbit.repository.FilterParams;
import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent;
@@ -281,8 +282,10 @@ public class JpaTargetManagement implements TargetManagement {
public Slice<Target> findTargetByFilters(final Pageable pageable, final Collection<TargetUpdateStatus> status, public Slice<Target> findTargetByFilters(final Pageable pageable, final Collection<TargetUpdateStatus> status,
final Boolean overdueState, final String searchText, final Long installedOrAssignedDistributionSetId, final Boolean overdueState, final String searchText, final Long installedOrAssignedDistributionSetId,
final Boolean selectTargetWithNoTag, final String... tagNames) { final Boolean selectTargetWithNoTag, final String... tagNames) {
final List<Specification<JpaTarget>> specList = buildSpecificationList(status, overdueState, searchText, final List<Specification<JpaTarget>> specList = buildSpecificationList(
installedOrAssignedDistributionSetId, selectTargetWithNoTag, true, tagNames); new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText,
selectTargetWithNoTag, tagNames),
true);
return findByCriteriaAPI(pageable, specList); return findByCriteriaAPI(pageable, specList);
} }
@@ -290,31 +293,35 @@ public class JpaTargetManagement implements TargetManagement {
public Long countTargetByFilters(final Collection<TargetUpdateStatus> status, final Boolean overdueState, public Long countTargetByFilters(final Collection<TargetUpdateStatus> status, final Boolean overdueState,
final String searchText, final Long installedOrAssignedDistributionSetId, final String searchText, final Long installedOrAssignedDistributionSetId,
final Boolean selectTargetWithNoTag, final String... tagNames) { final Boolean selectTargetWithNoTag, final String... tagNames) {
final List<Specification<JpaTarget>> specList = buildSpecificationList(status, overdueState, searchText, final List<Specification<JpaTarget>> specList = buildSpecificationList(
installedOrAssignedDistributionSetId, selectTargetWithNoTag, true, tagNames); new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText,
selectTargetWithNoTag, tagNames),
true);
return countByCriteriaAPI(specList); return countByCriteriaAPI(specList);
} }
private static List<Specification<JpaTarget>> buildSpecificationList(final Collection<TargetUpdateStatus> status, private static List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams,
final Boolean overdueState, final String searchText, final Long installedOrAssignedDistributionSetId, final boolean fetch) {
final Boolean selectTargetWithNoTag, final boolean fetch, final String... tagNames) {
final List<Specification<JpaTarget>> specList = new ArrayList<>(); final List<Specification<JpaTarget>> specList = new ArrayList<>();
if (status != null && !status.isEmpty()) { if (filterParams.getFilterByStatus() != null && !filterParams.getFilterByStatus().isEmpty()) {
specList.add(TargetSpecifications.hasTargetUpdateStatus(status, fetch)); specList.add(TargetSpecifications.hasTargetUpdateStatus(filterParams.getFilterByStatus(), fetch));
} }
if (overdueState != null) { if (filterParams.getOverdueState() != null) {
specList.add( specList.add(
TargetSpecifications.isOverdue(new TimestampCalculator().calculateOverdueTimestamp())); TargetSpecifications.isOverdue(new TimestampCalculator().calculateOverdueTimestamp()));
} }
if (installedOrAssignedDistributionSetId != null) { if (filterParams.getFilterByDistributionId() != null) {
specList.add( specList.add(
TargetSpecifications.hasInstalledOrAssignedDistributionSet(installedOrAssignedDistributionSetId)); TargetSpecifications
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
} }
if (!Strings.isNullOrEmpty(searchText)) { if (!Strings.isNullOrEmpty(filterParams.getFilterBySearchText())) {
specList.add(TargetSpecifications.likeNameOrDescriptionOrIp(searchText)); specList.add(TargetSpecifications.likeNameOrDescriptionOrIp(filterParams.getFilterBySearchText()));
} }
if (selectTargetWithNoTag != null && (selectTargetWithNoTag || (tagNames != null && tagNames.length > 0))) { if (filterParams.getSelectTargetWithNoTag() != null && (filterParams.getSelectTargetWithNoTag()
specList.add(TargetSpecifications.hasTags(tagNames, selectTargetWithNoTag)); || (filterParams.getFilterByTagNames() != null && filterParams.getFilterByTagNames().length > 0))) {
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),
filterParams.getSelectTargetWithNoTag()));
} }
return specList; return specList;
} }
@@ -428,10 +435,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable, public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable,
final Long orderByDistributionId, final Long filterByDistributionId, final Long orderByDistributionId, final FilterParams filterParams) {
final Collection<TargetUpdateStatus> filterByStatus, final Boolean overdueState,
final String filterBySearchText,
final Boolean selectTargetWithNoTag, final String... filterByTagNames) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class); final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class);
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class); final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
@@ -454,8 +459,7 @@ public class JpaTargetManagement implements TargetManagement {
// build the specifications and then to predicates necessary by the // build the specifications and then to predicates necessary by the
// given filters // given filters
final Predicate[] specificationsForMultiSelect = specificationsToPredicate( final Predicate[] specificationsForMultiSelect = specificationsToPredicate(
buildSpecificationList(filterByStatus, overdueState, filterBySearchText, filterByDistributionId, buildSpecificationList(filterParams, true),
selectTargetWithNoTag, true, filterByTagNames),
targetRoot, query, cb); targetRoot, query, cb);
// if we have some predicates then add it to the where clause of the // if we have some predicates then add it to the where clause of the
@@ -529,9 +533,9 @@ public class JpaTargetManagement implements TargetManagement {
targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name), targetRoot.get(sortProperty)); targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name), targetRoot.get(sortProperty));
final Predicate[] specificationsForMultiSelect = specificationsToPredicate( final Predicate[] specificationsForMultiSelect = specificationsToPredicate(
buildSpecificationList(filterByStatus, overdueState, filterBySearchText, buildSpecificationList(new FilterParams(installedOrAssignedDistributionSetId, filterByStatus,
installedOrAssignedDistributionSetId, overdueState, filterBySearchText,
selectTargetWithNoTag, false, filterByTagNames), selectTargetWithNoTag, filterByTagNames), false),
targetRoot, multiselect, cb); targetRoot, multiselect, cb);
// if we have some predicates then add it to the where clause of the // if we have some predicates then add it to the where clause of the

View File

@@ -13,6 +13,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
* <p> * <p>
* This is used in context of string replacement. * This is used in context of string replacement.
*/ */
@FunctionalInterface
public interface VirtualPropertyLookup { public interface VirtualPropertyLookup {
/** /**

View File

@@ -50,9 +50,9 @@ public class VirtualPropertyResolver implements VirtualPropertyLookup {
public String lookup(String rhs) { public String lookup(String rhs) {
String resolved = null; String resolved = null;
if ("now_ts".equals(rhs.toLowerCase())) { if ("now_ts".equalsIgnoreCase(rhs)) {
resolved = String.valueOf(Instant.now().toEpochMilli()); resolved = String.valueOf(Instant.now().toEpochMilli());
} else if ("overdue_ts".equals(rhs.toLowerCase())) { } else if ("overdue_ts".equalsIgnoreCase(rhs)) {
resolved = String.valueOf(getTimestampCalculator().calculateOverdueTimestamp()); resolved = String.valueOf(getTimestampCalculator().calculateOverdueTimestamp());
} }
return resolved; return resolved;

View File

@@ -16,21 +16,16 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.eclipse.hawkbit.ControllerPollProperties; import org.eclipse.hawkbit.repository.FilterParams;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
@@ -39,7 +34,6 @@ import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Slice; import org.springframework.data.domain.Slice;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@@ -746,7 +740,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed"); targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed");
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(), final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
null, null, null, null, Boolean.FALSE, new String[0]); new FilterParams(null, null, null, null, Boolean.FALSE, new String[0]));
final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId());
@@ -801,7 +795,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed"); targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed");
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(), final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
null, null, Boolean.TRUE, null, Boolean.FALSE, new String[0]); new FilterParams(null, null, Boolean.TRUE, null, Boolean.FALSE, new String[0]));
final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId());

View File

@@ -11,14 +11,14 @@ package org.eclipse.hawkbit.ui.management.targettable;
import static org.apache.commons.lang3.ArrayUtils.isEmpty; import static org.apache.commons.lang3.ArrayUtils.isEmpty;
import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.isNotNullOrEmpty; import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.isNotNullOrEmpty;
import static org.eclipse.hawkbit.ui.utils.SPUIDefinitions.TARGET_TABLE_CREATE_AT_SORT_ORDER; import static org.eclipse.hawkbit.ui.utils.SPUIDefinitions.TARGET_TABLE_CREATE_AT_SORT_ORDER;
import static org.springframework.data.domain.Sort.Direction.ASC; import static org.springframework.data.domain.Sort.Direction.*;
import static org.springframework.data.domain.Sort.Direction.DESC;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.hawkbit.repository.FilterParams;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -40,6 +40,7 @@ import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
import org.vaadin.addons.lazyquerycontainer.QueryDefinition; import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.primitives.Booleans;
/** /**
* Simple implementation of generics bean query which dynamically loads a batch * Simple implementation of generics bean query which dynamically loads a batch
@@ -115,7 +116,7 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
if (pinnedDistId != null) { if (pinnedDistId != null) {
targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet( targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet(
new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId, new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId,
distributionId, status, overdueState, searchText, noTagClicked, targetTags); new FilterParams(distributionId, status, overdueState, searchText, noTagClicked, targetTags));
} else if (null != targetFilterQuery) { } else if (null != targetFilterQuery) {
targetBeans = getTargetManagement().findTargetsAll(targetFilterQuery, targetBeans = getTargetManagement().findTargetsAll(targetFilterQuery,
new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort));
@@ -185,8 +186,9 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
} }
private Boolean anyFilterSelected() { private Boolean anyFilterSelected() {
if (status == null && distributionId == null && Strings.isNullOrEmpty(searchText) && !isTagSelected() int enabledFiltersCount = Booleans.countTrue(status != null, distributionId != null,
&& !isOverdueFilterEnabled()) { !Strings.isNullOrEmpty(searchText), isTagSelected(), isOverdueFilterEnabled());
if (enabledFiltersCount == 0) {
return false; return false;
} }
return true; return true;

View File

@@ -8,14 +8,7 @@
*/ */
package org.eclipse.hawkbit.ui.management.targettable; package org.eclipse.hawkbit.ui.management.targettable;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.FILTER_BY_DISTRIBUTION; import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.*;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.FILTER_BY_TAG;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.FILTER_BY_TARGET_FILTER_QUERY;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.FILTER_BY_TEXT;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.REMOVE_FILTER_BY_DISTRIBUTION;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.REMOVE_FILTER_BY_TAG;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.REMOVE_FILTER_BY_TARGET_FILTER_QUERY;
import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.REMOVE_FILTER_BY_TEXT;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -26,6 +19,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.FilterParams;
import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
@@ -63,11 +57,11 @@ import org.eclipse.hawkbit.ui.management.state.TargetTableFilters;
import org.eclipse.hawkbit.ui.utils.AssignInstalledDSTooltipGenerator; import org.eclipse.hawkbit.ui.utils.AssignInstalledDSTooltipGenerator;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.TableColumn; import org.eclipse.hawkbit.ui.utils.TableColumn;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -902,26 +896,33 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
pinnedDistId = managementUIState.getTargetTableFilters().getPinnedDistId().get(); pinnedDistId = managementUIState.getTargetTableFilters().getPinnedDistId().get();
} }
final long size = getTargetsCountWithFilter(totalTargetsCount, status, overdueState, targetTags, distributionId, final long size = getTargetsCountWithFilter(totalTargetsCount, pinnedDistId,
searchText, noTagClicked, pinnedDistId); new FilterParams(distributionId, status, overdueState, searchText, noTagClicked, targetTags));
if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) { if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) {
managementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES); managementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES);
} }
} }
private long getTargetsCountWithFilter(final long totalTargetsCount, final Collection<TargetUpdateStatus> status, private long getTargetsCountWithFilter(final long totalTargetsCount,
final Boolean overdueState, final String[] targetTags, final Long distributionId, final String searchText, // final Collection<TargetUpdateStatus> status,
final Boolean noTagClicked, final Long pinnedDistId) { // final Boolean overdueState, final String[] targetTags, final Long
// distributionId, final String searchText,
// final Boolean noTagClicked
final Long pinnedDistId, final FilterParams filterParams) {
final long size; final long size;
if (managementUIState.getTargetTableFilters().getTargetFilterQuery().isPresent()) { if (managementUIState.getTargetTableFilters().getTargetFilterQuery().isPresent()) {
size = targetManagement.countTargetByTargetFilterQuery( size = targetManagement.countTargetByTargetFilterQuery(
managementUIState.getTargetTableFilters().getTargetFilterQuery().get()); managementUIState.getTargetTableFilters().getTargetFilterQuery().get());
} else if (!anyFilterSelected(status, pinnedDistId, noTagClicked, targetTags, searchText)) { } else if (!anyFilterSelected(filterParams.getFilterByStatus(), pinnedDistId,
filterParams.getSelectTargetWithNoTag(), filterParams.getFilterByTagNames(),
filterParams.getFilterBySearchText())) {
size = totalTargetsCount; size = totalTargetsCount;
} else { } else {
size = targetManagement.countTargetByFilters(status, overdueState, searchText, distributionId, noTagClicked, size = targetManagement.countTargetByFilters(filterParams.getFilterByStatus(),
targetTags); filterParams.getOverdueState(), filterParams.getFilterBySearchText(),
filterParams.getFilterByDistributionId(), filterParams.getSelectTargetWithNoTag(),
filterParams.getFilterByTagNames());
} }
return size; return size;
} }