Merge pull request #294 from bsinno/fix_memory_optimization

Performance and memory optimisation
This commit is contained in:
Kai Zimmermann
2016-09-27 11:12:37 +02:00
committed by GitHub
114 changed files with 974 additions and 1103 deletions

View File

@@ -9,8 +9,8 @@
package org.eclipse.hawkbit.ui.artifacts.details;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,6 +46,7 @@ import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.server.FontAwesome;
import com.vaadin.shared.ui.label.ContentMode;
@@ -207,8 +208,7 @@ public class ArtifactDetailsLayout extends VerticalLayout {
}
private Container createArtifactLazyQueryContainer() {
final Map<String, Object> queryConfiguration = new HashMap<>();
return getArtifactLazyQueryContainer(queryConfiguration);
return getArtifactLazyQueryContainer(Collections.emptyMap());
}
private LazyQueryContainer getArtifactLazyQueryContainer(final Map<String, Object> queryConfig) {
@@ -429,9 +429,12 @@ public class ArtifactDetailsLayout extends VerticalLayout {
titleOfArtifactDetails.setContentMode(ContentMode.HTML);
}
}
final Map<String, Object> queryConfiguration = new HashMap<>();
final Map<String, Object> queryConfiguration;
if (baseSwModuleId != null) {
queryConfiguration = Maps.newHashMapWithExpectedSize(1);
queryConfiguration.put(SPUIDefinitions.BY_BASE_SOFTWARE_MODULE, baseSwModuleId);
} else {
queryConfiguration = Collections.emptyMap();
}
final LazyQueryContainer artifactContainer = getArtifactLazyQueryContainer(queryConfiguration);
artifactDetailsTable.setContainerDataSource(artifactContainer);

View File

@@ -9,13 +9,13 @@
package org.eclipse.hawkbit.ui.artifacts.event;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import com.google.common.collect.Maps;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.Component;
@@ -54,7 +54,7 @@ public class UploadViewAcceptCriteria extends AbstractAcceptCriteria {
}
private static Map<String, List<String>> createDropConfigurations() {
final Map<String, List<String>> config = new HashMap<>();
final Map<String, List<String>> config = Maps.newHashMapWithExpectedSize(1);
// Delete drop area droppable components
config.put(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID, Arrays.asList(
UIComponentIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE, UIComponentIdProvider.UPLOAD_TYPE_BUTTON_PREFIX));
@@ -63,7 +63,7 @@ public class UploadViewAcceptCriteria extends AbstractAcceptCriteria {
}
private static Map<String, Object> createDropHintConfigurations() {
final Map<String, Object> config = new HashMap<>();
final Map<String, Object> config = Maps.newHashMapWithExpectedSize(2);
config.put(UIComponentIdProvider.UPLOAD_TYPE_BUTTON_PREFIX, UploadArtifactUIEvent.SOFTWARE_TYPE_DRAG_START);
config.put(UIComponentIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE, UploadArtifactUIEvent.SOFTWARE_DRAG_START);
return config;

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.ui.artifacts.footer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -21,11 +20,12 @@ import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout;
import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
@@ -64,7 +64,7 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind
@Override
protected Map<String, ConfirmationTab> getConfimrationTabs() {
final Map<String, ConfirmationTab> tabs = new HashMap<>();
final Map<String, ConfirmationTab> tabs = Maps.newHashMapWithExpectedSize(2);
if (!artifactUploadState.getDeleteSofwareModules().isEmpty()) {
tabs.put(i18n.get("caption.delete.swmodule.accordion.tab"), createSMDeleteConfirmationTab());
}

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.ui.artifacts.smtable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,11 +24,11 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
import org.eclipse.hawkbit.ui.distributions.smtable.SwMetadataPopupLayout;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.TableColumn;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
@@ -37,6 +36,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.event.dd.DragAndDropEvent;
@@ -97,7 +97,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable<SoftwareModul
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(2);
artifactUploadState.getSoftwareModuleFilters().getSearchText()
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));

View File

@@ -32,11 +32,11 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -572,6 +572,9 @@ public class UploadConfirmationWindow implements Button.ClickListener {
}
// Exception squid:S3655 - Optional access is checked in
// checkIfArtifactDetailsDispalyed subroutine
@SuppressWarnings("squid:S3655")
private void processArtifactUpload() {
final List<String> itemIds = (List<String>) uploadDetailsTable.getItemIds();
if (preUploadValidation(itemIds)) {
@@ -593,6 +596,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
}
refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId());
}
if (refreshArtifactDetailsLayout) {
uploadLayout.refreshArtifactDetailsLayout(artifactUploadState.getSelectedBaseSoftwareModule().get());
}

View File

@@ -34,10 +34,10 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.eclipse.hawkbit.util.SPInfo;
import org.slf4j.Logger;
@@ -254,6 +254,11 @@ public class UploadLayout extends VerticalLayout {
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
// selected software module at the time of file drop is
// considered for upload
if (!artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
return;
}
final SoftwareModule selectedSw = artifactUploadState.getSelectedBaseSoftwareModule().get();
// reset the flag
hasDirectory = Boolean.FALSE;

View File

@@ -12,7 +12,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -28,11 +27,12 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorderWithIcon;
import org.eclipse.hawkbit.ui.layouts.AbstractCreateUpdateTagLayout;
import org.eclipse.hawkbit.ui.management.targettable.TargetAddUpdateWindowLayout;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroupItemComponent;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.vaadin.data.Container.ItemSetChangeEvent;
import com.vaadin.data.Container.ItemSetChangeListener;
@@ -129,8 +129,8 @@ public class CommonDialogWindow extends Window {
this.helpLink = helpLink;
this.closeListener = closeListener;
this.cancelButtonClickListener = cancelButtonClickListener;
this.orginalValues = new HashMap<>();
this.allComponents = getAllComponents(layout);
this.orginalValues = Maps.newHashMapWithExpectedSize(allComponents.size());
this.i18n = i18n;
init();
}

View File

@@ -30,8 +30,8 @@ import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import com.google.gwt.thirdparty.guava.common.collect.Iterables;
import com.google.gwt.thirdparty.guava.common.collect.Sets;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.event.Transferable;

View File

@@ -93,7 +93,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
private VerticalLayout tagsLayout;
private final Map<String, StringBuilder> assignedSWModule = new HashMap<>();
private Map<String, StringBuilder> assignedSWModule;
/**
* softwareLayout Initialize the component.
@@ -144,6 +144,10 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
}
if (null != softwareModuleIdNameList) {
if (assignedSWModule == null) {
assignedSWModule = new HashMap<>();
}
for (final SoftwareModuleIdName swIdName : softwareModuleIdNameList) {
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(swIdName.getId());
if (assignedSWModule.containsKey(softwareModule.getType().getName())) {
@@ -169,9 +173,11 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
}
private Button assignSoftModuleButton(final String softwareModuleName) {
if (getPermissionChecker().hasUpdateDistributionPermission() && distributionSetManagement
.findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId())
.getAssignedTargets().isEmpty()) {
if (getPermissionChecker().hasUpdateDistributionPermission()
&& manageDistUIState.getLastSelectedDistribution().isPresent()
&& distributionSetManagement
.findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId())
.getAssignedTargets().isEmpty()) {
final Button reassignSoftModule = SPUIComponentProvider.getButton(softwareModuleName, "", "", "", true,
FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class);
reassignSoftModule.setEnabled(false);
@@ -186,6 +192,9 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
@SuppressWarnings("unchecked")
private void updateSoftwareModule(final SoftwareModule module) {
if (assignedSWModule == null) {
assignedSWModule = new HashMap<>();
}
softwareModuleTable.getContainerDataSource().getItemIds();
if (assignedSWModule.containsKey(module.getType().getName())) {
@@ -363,7 +372,9 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS
|| saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ALL_ASSIGNMENTS)
&& getSelectedBaseEntity() != null) {
assignedSWModule.clear();
if (assignedSWModule != null) {
assignedSWModule.clear();
}
setSelectedBaseEntity(
distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId()));
UI.getCurrent().access(() -> populateModule());
@@ -375,7 +386,9 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet
if (saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ASSIGNMENT
|| saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ALL_ASSIGNMENTS
|| saveActionWindowEvent == SaveActionWindowEvent.DELETE_ALL_SOFWARE) {
assignedSWModule.clear();
if (assignedSWModule != null) {
assignedSWModule.clear();
}
showUnsavedAssignment();
}
}

View File

@@ -57,6 +57,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.event.dd.DragAndDropEvent;
@@ -167,7 +168,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(2);
manageDistUIState.getManageDistFilters().getSearchText()
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
@@ -530,7 +531,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable<Distribution
return manageMetadataBtn;
}
private void showMetadataDetails(final Long itemId) {
private void showMetadataDetails(final Long itemId) {
final DistributionSet ds = distributionSetManagement.findDistributionSetByIdWithDetails(itemId);
UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null));
}

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.ui.distributions.event;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +16,7 @@ import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import com.google.common.collect.Maps;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.Component;
@@ -66,7 +66,7 @@ public class DistributionsViewAcceptCriteria extends AbstractAcceptCriteria {
}
private static Map<String, List<String>> createDropConfigurations() {
final Map<String, List<String>> config = new HashMap<>();
final Map<String, List<String>> config = Maps.newHashMapWithExpectedSize(2);
// Delete drop area droppable components
config.put(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID,
@@ -82,7 +82,7 @@ public class DistributionsViewAcceptCriteria extends AbstractAcceptCriteria {
}
private static Map<String, Object> createDropHintConfigurations() {
final Map<String, Object> config = new HashMap<>();
final Map<String, Object> config = Maps.newHashMapWithExpectedSize(4);
config.put(SPUIDefinitions.DISTRIBUTION_TYPE_ID_PREFIXS, DragEvent.DISTRIBUTION_TYPE_DRAG);
config.put(UIComponentIdProvider.DIST_TABLE_ID, DragEvent.DISTRIBUTION_DRAG);
config.put(UIComponentIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE, DragEvent.SOFTWAREMODULE_DRAG);

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.ui.distributions.footer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -37,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
@@ -90,7 +90,7 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW
@Override
protected Map<String, ConfirmationTab> getConfimrationTabs() {
final Map<String, ConfirmationTab> tabs = new HashMap<>();
final Map<String, ConfirmationTab> tabs = Maps.newHashMapWithExpectedSize(5);
/* Create tab for SW Modules delete */
if (!manageDistUIState.getDeleteSofwareModulesList().isEmpty()) {
tabs.put(i18n.get("caption.delete.swmodule.accordion.tab"), createSMDeleteConfirmationTab());
@@ -112,7 +112,6 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW
}
/* Create tab for Assign Software Module */
if (!manageDistUIState.getAssignedList().isEmpty()) {
tabs.put(i18n.get("caption.assign.dist.accordion.tab"), createAssignSWModuleConfirmationTab());
}

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.ui.distributions.smtable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -40,6 +39,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.event.dd.DragAndDropEvent;
@@ -143,7 +143,7 @@ public class SwModuleTable extends AbstractNamedVersionTable<SoftwareModule, Lon
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(3);
manageDistUIState.getSoftwareModuleFilters().getSearchText()
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));

View File

@@ -13,8 +13,7 @@ import static org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.Sof
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.SW_MODULE_TYPE_TABLE_ID;
import static org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions.VAR_NAME;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent;
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
@@ -59,10 +58,9 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons {
@Override
protected LazyQueryContainer createButtonsLazyQueryContainer() {
final Map<String, Object> queryConfig = new HashMap<>();
final BeanQueryFactory<SoftwareModuleTypeBeanQuery> typeQF = new BeanQueryFactory<>(
SoftwareModuleTypeBeanQuery.class);
typeQF.setQueryConfiguration(queryConfig);
typeQF.setQueryConfiguration(Collections.emptyMap());
return new LazyQueryContainer(new LazyQueryDefinition(true, 20, VAR_NAME), typeQF);
}

View File

@@ -52,7 +52,7 @@ public class ManageDistUIState implements ManagmentEntityState<DistributionSetId
private Set<Long> selectedSoftwareModules = emptySet();
private Set<String> selectedDeleteDistSetTypes = new HashSet<>();
private final Set<String> selectedDeleteDistSetTypes = new HashSet<>();
private Set<String> selectedDeleteSWModuleTypes = new HashSet<>();
@@ -201,10 +201,6 @@ public class ManageDistUIState implements ManagmentEntityState<DistributionSetId
return selectedDeleteDistSetTypes;
}
public void setSelectedDeleteDistSetTypes(final Set<String> selectedDeleteDistSetTypes) {
this.selectedDeleteDistSetTypes = selectedDeleteDistSetTypes;
}
public Set<String> getSelectedDeleteSWModuleTypes() {
return selectedDeleteSWModuleTypes;
}

View File

@@ -1,27 +0,0 @@
/**
* 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.ui.filter;
/**
* A filter expression interface definition to implement the UI filter
* mechanism. The filter expression can evaluate if e.g. Targets should
* currently be added to the target list or if the current enabled filtered will
* filter the target and not show the newly created target.
*
*/
@FunctionalInterface
public interface FilterExpression {
/**
* @return {@code true} if the expression evaluate that it should be
* filtered and not shown on the UI, otherwise {@code false}
*/
boolean doFilter();
}

View File

@@ -1,77 +0,0 @@
/**
* 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.ui.filter;
import java.util.Arrays;
import java.util.List;
/**
* {@link Filters} which provides the functionality to combine
* {@link FilterExpression}s.
*
*
*
* @see FilterExpression
*
*/
public final class Filters {
/**
* private.
*/
private Filters() {
}
/**
* Combines the given filter to an or-expression and evaluate them.
*
* @param expressions
* the expressions to combine with an or-filter
* @return an or-combined filter expression
*/
public static FilterExpression or(final List<FilterExpression> expressions) {
return or(expressions.toArray(new FilterExpression[expressions.size()]));
}
/**
* Combines the given filter to an or-expression and evaluate them.
*
* @param expressions
* the expressions to combine with an or-filter
* @return an or-combined filter expression
*/
public static FilterExpression or(final FilterExpression... expressions) {
return new OrFilterExpression(expressions);
}
private static final class OrFilterExpression implements FilterExpression {
private final FilterExpression[] expresssions;
private OrFilterExpression(final FilterExpression[] expresssions) {
this.expresssions = Arrays.copyOf(expresssions, expresssions.length);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate()
*/
@Override
public boolean doFilter() {
for (final FilterExpression filterExpression : expresssions) {
if (filterExpression.doFilter()) {
return true;
}
}
return false;
}
}
}

View File

@@ -1,48 +0,0 @@
/**
* 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.ui.filter.target;
import java.util.Optional;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.ui.filter.FilterExpression;
/**
* Checks if custom target filter is applied.
*
*/
public class CustomTargetFilter implements FilterExpression {
private final Optional<TargetFilterQuery> targetFilterQuery;
/**
* Initialize.
*
* @param targetFilterQuery
* custom target filter applied
*/
public CustomTargetFilter(final Optional<TargetFilterQuery> targetFilterQuery) {
this.targetFilterQuery = targetFilterQuery;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.ui.filter.FilterExpression#doFilter()
*/
@Override
public boolean doFilter() {
if (!targetFilterQuery.isPresent()) {
return false;
}
return true;
}
}

View File

@@ -1,67 +0,0 @@
/**
* Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved.
*/
package org.eclipse.hawkbit.ui.filter.target;
import java.net.URI;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.ui.filter.FilterExpression;
/**
*
*
*
*/
public class TargetSearchTextFilter implements FilterExpression {
private final Target target;
private final String searchTextUpper;
/**
* @param target
* the target to check against the search text
* @param searchText
* the search text check against the given target
*/
public TargetSearchTextFilter(final Target target, final String searchText) {
this.target = target;
this.searchTextUpper = searchText.toUpperCase();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate()
*/
@Override
public boolean doFilter() {
return !(descriptionIgnoreCase() || nameIgnoreCase() || controllerIdIgnoreCase() || ipAddressIgnoreCase());
}
private boolean descriptionIgnoreCase() {
if (target.getDescription() == null) {
return false;
}
return target.getDescription().toUpperCase().contains(searchTextUpper);
}
private boolean nameIgnoreCase() {
if (target.getName() == null) {
return false;
}
return target.getName().toUpperCase().contains(searchTextUpper);
}
private boolean controllerIdIgnoreCase() {
return target.getControllerId().toUpperCase().contains(searchTextUpper);
}
private boolean ipAddressIgnoreCase() {
final URI targetAddress = target.getTargetInfo().getAddress();
if (targetAddress == null || targetAddress.getHost() == null) {
return false;
}
return targetAddress.getHost().toUpperCase().contains(searchTextUpper);
}
}

View File

@@ -1,42 +0,0 @@
/**
* Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved.
*/
package org.eclipse.hawkbit.ui.filter.target;
import java.util.List;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.ui.filter.FilterExpression;
/**
*
*
*
*/
public class TargetStatusFilter implements FilterExpression {
private final List<TargetUpdateStatus> targetUpdateStatus;
/**
* @param target
* the target to check the update status against
* @param updateStatus
* the target update status to check against the given target
*/
public TargetStatusFilter(final List<TargetUpdateStatus> updateStatus) {
this.targetUpdateStatus = updateStatus;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate()
*/
@Override
public boolean doFilter() {
if (targetUpdateStatus.isEmpty()) {
return false;
}
return true;
}
}

View File

@@ -1,54 +0,0 @@
/**
* Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved.
*/
package org.eclipse.hawkbit.ui.filter.target;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.ui.filter.FilterExpression;
import org.springframework.util.CollectionUtils;
/**
*
*
*
*/
public class TargetTagFilter implements FilterExpression {
private final Target target;
private final Collection<String> tags;
private final boolean noTag;
/**
* @param target
* the target to check the filter against
* @param tags
* the tags to check the target against it
* @param noTag
* {@code true} indicates that targets which have no tags should
* not be filtered, otherwise {@code false}
*/
public TargetTagFilter(final Target target, final Collection<String> tags, final boolean noTag) {
this.target = target;
this.tags = tags;
this.noTag = noTag;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate()
*/
@Override
public boolean doFilter() {
final List<String> targetTags = target.getTags().stream().map(targetTag -> targetTag.getName())
.collect(Collectors.toList());
if (targetTags.isEmpty() || (noTag && targetTags.isEmpty())) {
return false;
}
return !CollectionUtils.containsAny(targetTags, tags);
}
}

View File

@@ -26,9 +26,9 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder;
import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent;
import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState;
import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -136,7 +136,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
private LayoutClickListener nameLayoutClickListner;
private boolean validationFailed = false;
private boolean validationFailed;
/**
* Initialize the Campaign Status History Header.
@@ -509,6 +509,10 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
}
private void updateCustomFilter() {
if (!filterManagementUIState.getTfQuery().isPresent()) {
return;
}
final TargetFilterQuery targetFilterQuery = filterManagementUIState.getTfQuery().get();
targetFilterQuery.setName(nameTextField.getValue());
targetFilterQuery.setQuery(queryTextField.getValue());

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.filtermanagement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -37,6 +36,7 @@ import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.vaadin.data.Item;
import com.vaadin.server.FontAwesome;
import com.vaadin.shared.ui.label.ContentMode;
@@ -142,7 +142,7 @@ public class CreateOrUpdateFilterTable extends Table {
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(2);
if (!Strings.isNullOrEmpty(filterManagementUIState.getFilterQueryValue())) {
queryConfig.put(SPUIDefinitions.FILTER_BY_QUERY, filterManagementUIState.getFilterQueryValue());
}

View File

@@ -38,6 +38,7 @@ import org.vaadin.spring.events.EventBus;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.server.FontAwesome;
@@ -128,7 +129,7 @@ public class TargetFilterTable extends Table {
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(1);
filterManagementUIState.getCustomFilterSearchText()
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
return queryConfig;

View File

@@ -8,9 +8,8 @@
*/
package org.eclipse.hawkbit.ui.management.dstable;
import java.util.HashMap;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct;
@@ -178,10 +177,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
* @return
*/
private LazyQueryContainer getDistSetTypeLazyQueryContainer() {
final Map<String, Object> queryConfig = new HashMap<>();
final BeanQueryFactory<DistributionSetTypeBeanQuery> dtQF = new BeanQueryFactory<>(
DistributionSetTypeBeanQuery.class);
dtQF.setQueryConfiguration(queryConfig);
dtQF.setQueryConfiguration(Collections.emptyMap());
final LazyQueryContainer disttypeContainer = new LazyQueryContainer(
new LazyQueryDefinition(true, SPUIDefinitions.DIST_TYPE_SIZE, SPUILabelDefinitions.VAR_NAME), dtQF);

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.ui.management.dstable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -43,11 +42,11 @@ import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent;
import org.eclipse.hawkbit.ui.management.event.SaveActionWindowEvent;
import org.eclipse.hawkbit.ui.management.state.ManagementUIState;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.TableColumn;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
@@ -56,6 +55,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.event.dd.DragAndDropEvent;
@@ -240,7 +240,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(4);
managementUIState.getDistributionTableFilters().getSearchText()
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
managementUIState.getDistributionTableFilters().getPinnedTargetId()
@@ -525,6 +525,10 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
}
private void styleDistributionTableOnPinning() {
if (!managementUIState.getDistributionTableFilters().getPinnedTargetId().isPresent()) {
return;
}
final Target targetObj = targetService.findTargetByControllerIDWithDetails(
managementUIState.getDistributionTableFilters().getPinnedTargetId().get());

View File

@@ -8,8 +8,7 @@
*/
package org.eclipse.hawkbit.ui.management.dstag;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent;
@@ -101,9 +100,8 @@ public class DistributionTagButtons extends AbstractFilterButtons {
@Override
protected LazyQueryContainer createButtonsLazyQueryContainer() {
final Map<String, Object> queryConfig = new HashMap<>();
final BeanQueryFactory<DistributionTagBeanQuery> tagQF = new BeanQueryFactory<>(DistributionTagBeanQuery.class);
tagQF.setQueryConfiguration(queryConfig);
tagQF.setQueryConfiguration(Collections.emptyMap());
return HawkbitCommonUtil.createDSLazyQueryContainer(
new BeanQueryFactory<DistributionTagBeanQuery>(DistributionTagBeanQuery.class));

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.ui.management.event;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +16,7 @@ import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import com.google.common.collect.Maps;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.Component;
@@ -67,7 +67,7 @@ public class ManagementViewAcceptCriteria extends AbstractAcceptCriteria {
}
private static Map<String, List<String>> createDropConfigurations() {
final Map<String, List<String>> config = new HashMap<>();
final Map<String, List<String>> config = Maps.newHashMapWithExpectedSize(6);
// Delete drop area acceptable components
config.put(UIComponentIdProvider.DELETE_BUTTON_WRAPPER_ID,
@@ -94,7 +94,7 @@ public class ManagementViewAcceptCriteria extends AbstractAcceptCriteria {
}
private static Map<String, Object> createDropHintConfigurations() {
final Map<String, Object> config = new HashMap<>();
final Map<String, Object> config = Maps.newHashMapWithExpectedSize(4);
config.put(SPUIDefinitions.TARGET_TAG_ID_PREFIXS, DragEvent.TARGET_TAG_DRAG);
config.put(UIComponentIdProvider.TARGET_TABLE_ID, DragEvent.TARGET_DRAG);
config.put(UIComponentIdProvider.DIST_TABLE_ID, DragEvent.DISTRIBUTION_DRAG);

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.management.footer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -39,6 +38,7 @@ import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Maps;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.FontAwesome;
@@ -88,7 +88,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin
@Override
protected Map<String, ConfirmationTab> getConfimrationTabs() {
final Map<String, ConfirmationTab> tabs = new HashMap<>();
final Map<String, ConfirmationTab> tabs = Maps.newHashMapWithExpectedSize(3);
if (!managementUIState.getDeletedDistributionList().isEmpty()) {
tabs.put(i18n.get("caption.delete.dist.accordion.tab"), createDeletedDistributionTab());
}
@@ -150,7 +150,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin
? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime()
: RepositoryModelConstants.NO_FORCE_TIME;
final Map<Long, ArrayList<TargetIdName>> saveAssignedList = new HashMap<>();
final Map<Long, ArrayList<TargetIdName>> saveAssignedList = Maps.newHashMapWithExpectedSize(itemIds.size());
int successAssignmentCount = 0;
int duplicateAssignmentCount = 0;

View File

@@ -87,10 +87,9 @@ public class ManagementUIState implements ManagmentEntityState<DistributionSetId
private boolean customFilterSelected;
private boolean bulkUploadWindowMinimised;
private DistributionSetIdName lastSelectedDistribution;
/**
* @return the lastSelectedDistribution
*/
@@ -98,12 +97,10 @@ public class ManagementUIState implements ManagmentEntityState<DistributionSetId
return Optional.ofNullable(lastSelectedDistribution);
}
public void setLastSelectedDistribution(final DistributionSetIdName value) {
this.lastSelectedDistribution = value;
}
/**
* @return the bulkUploadWindowMinimised
*/

View File

@@ -9,12 +9,9 @@
package org.eclipse.hawkbit.ui.management.targettable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.ui.UiProperties;
@@ -40,6 +37,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
import org.vaadin.spring.events.EventBus;
import org.vaadin.tokenfield.TokenField;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.server.FontAwesome;
import com.vaadin.shared.ui.combobox.FilteringMode;
@@ -112,12 +110,6 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
buildLayout();
setImmediate(true);
setCompositionRoot(mainLayout);
eventBus.subscribe(this);
}
@PreDestroy
void destroy() {
eventBus.unsubscribe(this);
}
protected void onStartOfUpload() {
@@ -242,7 +234,7 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
*/
private Container createContainer() {
final Map<String, Object> queryConfiguration = new HashMap<>();
final Map<String, Object> queryConfiguration = Maps.newHashMapWithExpectedSize(2);
final List<String> list = new ArrayList<>();
queryConfiguration.put(SPUIDefinitions.FILTER_BY_NO_TAG,

View File

@@ -19,10 +19,10 @@ import static org.eclipse.hawkbit.ui.management.event.TargetFilterEvent.REMOVE_F
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -43,12 +43,6 @@ import org.eclipse.hawkbit.ui.common.ManagmentEntityState;
import org.eclipse.hawkbit.ui.common.UserDetailsFormatter;
import org.eclipse.hawkbit.ui.common.table.AbstractTable;
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
import org.eclipse.hawkbit.ui.filter.FilterExpression;
import org.eclipse.hawkbit.ui.filter.Filters;
import org.eclipse.hawkbit.ui.filter.target.CustomTargetFilter;
import org.eclipse.hawkbit.ui.filter.target.TargetSearchTextFilter;
import org.eclipse.hawkbit.ui.filter.target.TargetStatusFilter;
import org.eclipse.hawkbit.ui.filter.target.TargetTagFilter;
import org.eclipse.hawkbit.ui.management.event.DragEvent;
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
import org.eclipse.hawkbit.ui.management.event.ManagementViewAcceptCriteria;
@@ -78,6 +72,7 @@ import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.event.dd.DragAndDropEvent;
@@ -140,11 +135,14 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
if (TargetCreatedEvent.class.isInstance(firstEvent)) {
onTargetCreatedEvents();
} else if (TargetInfoUpdateEvent.class.isInstance(firstEvent)) {
onTargetInfoUpdateEvents((List<TargetInfoUpdateEvent>) events);
onTargetUpdateEvents(((List<TargetInfoUpdateEvent>) events).stream()
.map(targetInfoUpdateEvent -> targetInfoUpdateEvent.getEntity().getTarget())
.collect(Collectors.toList()));
} else if (TargetDeletedEvent.class.isInstance(firstEvent)) {
onTargetDeletedEvent((List<TargetDeletedEvent>) events);
} else if (TargetUpdatedEvent.class.isInstance(firstEvent)) {
onTargetUpdateEvents((List<TargetUpdatedEvent>) events);
onTargetUpdateEvents(((List<TargetUpdatedEvent>) events).stream()
.map(targetInfoUpdateEvent -> targetInfoUpdateEvent.getEntity()).collect(Collectors.toList()));
}
}
@@ -348,7 +346,7 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
}
private Map<String, Object> prepareQueryConfigFilters() {
final Map<String, Object> queryConfig = new HashMap<>();
final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(7);
managementUIState.getTargetTableFilters().getSearchText()
.ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
managementUIState.getTargetTableFilters().getDistributionSet()
@@ -746,16 +744,17 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
}
@SuppressWarnings("unchecked")
private void updateVisibleItemOnEvent(final TargetInfo targetInfo, final Target target,
final TargetIdName targetIdName) {
private void updateVisibleItemOnEvent(final TargetInfo targetInfo) {
final Target target = targetInfo.getTarget();
final TargetIdName targetIdName = target.getTargetIdName();
final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource();
final Item item = targetContainer.getItem(targetIdName);
item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(target.getName());
if (targetInfo != null) {
item.getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP)
.setValue(HawkbitCommonUtil.getPollStatusToolTip(targetInfo.getPollStatus(), i18n));
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(targetInfo.getUpdateStatus());
}
item.getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP)
.setValue(HawkbitCommonUtil.getPollStatusToolTip(targetInfo.getPollStatus(), i18n));
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(targetInfo.getUpdateStatus());
}
private boolean isLastSelectedTarget(final TargetIdName targetIdName) {
@@ -767,62 +766,30 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
* EventListener method which is called by the event bus to notify about a
* list of {@link TargetInfoUpdateEvent}.
*
* @param targetInfoUpdateEvents
* list of target info update event
* @param updatedTargets
* list of updated targets
*/
private void onTargetInfoUpdateEvents(final List<TargetInfoUpdateEvent> targetInfoUpdateEvents) {
private void onTargetUpdateEvents(final List<Target> updatedTargets) {
@SuppressWarnings("unchecked")
final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds();
boolean shoulTargetsUpdated = false;
Target lastSelectedTarget = null;
for (final TargetInfoUpdateEvent targetInfoUpdateEvent : targetInfoUpdateEvents) {
final TargetInfo targetInfo = targetInfoUpdateEvent.getEntity();
final Target target = targetInfo.getTarget();
final TargetIdName targetIdName = target.getTargetIdName();
if (Filters.or(getTargetTableFilters(target)).doFilter()) {
shoulTargetsUpdated = true;
} else {
if (visibleItemIds.contains(targetIdName)) {
updateVisibleItemOnEvent(targetInfo, target, targetIdName);
}
}
// workaround until push is available for action history, re-select
// the updated target so the action history gets refreshed.
if (isLastSelectedTarget(targetIdName)) {
lastSelectedTarget = target;
}
}
if (shoulTargetsUpdated) {
refreshTargets();
}
if (lastSelectedTarget != null) {
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, lastSelectedTarget));
}
}
private void onTargetUpdateEvents(final List<TargetUpdatedEvent> events) {
final List<Object> visibleItemIds = (List<Object>) getVisibleItemIds();
boolean shoulTargetsUpdated = false;
Target lastSelectedTarget = null;
for (final TargetUpdatedEvent targetUpdatedEvent : events) {
final Target target = targetUpdatedEvent.getEntity();
final TargetIdName targetIdName = target.getTargetIdName();
if (Filters.or(getTargetTableFilters(target)).doFilter()) {
shoulTargetsUpdated = true;
} else {
if (visibleItemIds.contains(targetIdName)) {
updateVisibleItemOnEvent(null, target, targetIdName);
}
}
if (isLastSelectedTarget(targetIdName)) {
lastSelectedTarget = target;
}
}
if (shoulTargetsUpdated) {
if (isFilterEnabled()) {
LOG.debug("Filter enabled on UI {}. Refresh targets from database.", getUI().getUIId());
refreshTargets();
} else {
updatedTargets.stream().filter(target -> visibleItemIds.contains(target.getTargetIdName()))
.forEach(target -> updateVisibleItemOnEvent(target.getTargetInfo()));
}
if (lastSelectedTarget != null) {
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, lastSelectedTarget));
// workaround until push is available for action
// history, re-select
// the updated target so the action history gets
// refreshed.
final Optional<Target> selected = updatedTargets.stream()
.filter(target -> isLastSelectedTarget(target.getTargetIdName())).findAny();
if (selected.isPresent()) {
LOG.debug("Selected element has changed on UI {}. Reselect to update action history.", getUI().getUIId());
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, selected.get()));
}
}
@@ -830,17 +797,11 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> {
refreshTargets();
}
private List<FilterExpression> getTargetTableFilters(final Target target) {
private boolean isFilterEnabled() {
final TargetTableFilters targetTableFilters = managementUIState.getTargetTableFilters();
final List<FilterExpression> filters = new ArrayList<>();
if (targetTableFilters.getSearchText().isPresent()) {
filters.add(new TargetSearchTextFilter(target, targetTableFilters.getSearchText().get()));
}
filters.add(new TargetStatusFilter(targetTableFilters.getClickedStatusTargetTags()));
filters.add(new TargetTagFilter(target, targetTableFilters.getClickedTargetTags(),
targetTableFilters.isNoTagSelected()));
filters.add(new CustomTargetFilter(targetTableFilters.getTargetFilterQuery()));
return filters;
return targetTableFilters.getSearchText().isPresent() || !targetTableFilters.getClickedTargetTags().isEmpty()
|| !targetTableFilters.getClickedStatusTargetTags().isEmpty()
|| targetTableFilters.getTargetFilterQuery().isPresent();
}
/**

View File

@@ -9,9 +9,8 @@
package org.eclipse.hawkbit.ui.management.targettag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.PreDestroy;
@@ -102,8 +101,7 @@ public class TargetFilterQueryButtons extends Table {
protected LazyQueryContainer createButtonsLazyQueryContainer() {
final BeanQueryFactory<TargetFilterBeanQuery> queryFactory = new BeanQueryFactory<>(
TargetFilterBeanQuery.class);
final Map<String, Object> queryConfig = new HashMap<>();
queryFactory.setQueryConfiguration(queryConfig);
queryFactory.setQueryConfiguration(Collections.emptyMap());
return new LazyQueryContainer(new LazyQueryDefinition(true, 20, "id"), queryFactory);
}

View File

@@ -8,11 +8,11 @@
*/
package org.eclipse.hawkbit.ui.push;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
import org.eclipse.hawkbit.eventbus.event.Event;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.ui.UIEventProvider;
import org.slf4j.Logger;
@@ -57,10 +58,11 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
private static final Logger LOG = LoggerFactory.getLogger(DelayedEventBusPushStrategy.class);
private static final int BLOCK_SIZE = 10_000;
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
private final BlockingDeque<org.eclipse.hawkbit.eventbus.event.Event> queue = new LinkedBlockingDeque<>(BLOCK_SIZE);
private final ScheduledExecutorService executorService;
private final BlockingDeque<Event> queue = new LinkedBlockingDeque<>(BLOCK_SIZE);
private final EventBus.SessionEventBus eventBus;
private final com.google.common.eventbus.EventBus systemEventBus;
private int uiid = -1;
private ScheduledFuture<?> jobHandle;
@@ -68,15 +70,20 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
/**
* Constructor.
*
*
* @param executorService
* for scheduled execution of event forwarding to the UI
* @param eventBus
* the session event bus to where the events should be dispatched
* @param systemEventBus
* the system event bus where to retrieve the events from the
* back-end
* @param eventProvider
* for event delegation to UI
*/
public DelayedEventBusPushStrategy(final SessionEventBus eventBus,
public DelayedEventBusPushStrategy(final ScheduledExecutorService executorService, final SessionEventBus eventBus,
final com.google.common.eventbus.EventBus systemEventBus, final UIEventProvider eventProvider) {
this.executorService = executorService;
this.eventBus = eventBus;
this.systemEventBus = systemEventBus;
this.eventProvider = eventProvider;
@@ -92,7 +99,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
*/
@Subscribe
@AllowConcurrentEvents
public void dispatch(final org.eclipse.hawkbit.eventbus.event.Event event) {
public void dispatch(final Event event) {
// to dispatch too many events which are not interested on the UI
if (!isEventProvided(event)) {
LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event);
@@ -100,19 +107,24 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
}
if (!queue.offer(event)) {
LOG.warn("Deque limit is reached, cannot add more events!!! Dropped event is {}", event);
LOG.trace("Deque limit is reached, cannot add more events for UI {}! Dropped event is {}", uiid, event);
return;
}
}
private boolean isEventProvided(final org.eclipse.hawkbit.eventbus.event.Event event) {
private boolean isEventProvided(final Event event) {
return eventProvider.getSingleEvents().contains(event.getClass())
|| eventProvider.getBulkEvents().contains(event.getClass());
}
@Override
public void init(final UI vaadinUI) {
LOG.debug("Initialize delayed event push strategy");
uiid = vaadinUI.getUIId();
LOG.info("Initialize delayed event push strategy for UI {}", uiid);
if (vaadinUI.getSession() == null) {
LOG.error("Vaadin session of UI {} is null! Event push disabled!", uiid);
}
jobHandle = executorService.scheduleWithFixedDelay(new DispatchRunnable(vaadinUI, vaadinUI.getSession()), 500,
2000, TimeUnit.MILLISECONDS);
systemEventBus.register(this);
@@ -120,10 +132,9 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
@Override
public void clean() {
LOG.debug("Cleanup resources");
jobHandle.cancel(true);
LOG.info("Cleanup delayed event push strategy for UI", uiid);
systemEventBus.unregister(this);
executorService.shutdownNow();
jobHandle.cancel(true);
queue.clear();
}
@@ -138,8 +149,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
* @return {@code true} if the event can be dispatched to the UI otherwise
* {@code false}
*/
protected boolean eventSecurityCheck(final SecurityContext userContext,
final org.eclipse.hawkbit.eventbus.event.Event event) {
protected static boolean eventSecurityCheck(final SecurityContext userContext, final Event event) {
if (userContext == null || userContext.getAuthentication() == null) {
return false;
}
@@ -163,43 +173,39 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
@Override
public void run() {
LOG.debug("UI EventBus aggregator started");
LOG.debug("UI EventBus aggregator started for UI {}", vaadinUI.getUIId());
final long timestamp = System.currentTimeMillis();
final List<org.eclipse.hawkbit.eventbus.event.Event> events = new LinkedList<>();
for (int i = 0; i < BLOCK_SIZE; i++) {
final org.eclipse.hawkbit.eventbus.event.Event pollEvent = queue.poll();
if (pollEvent == null) {
continue;
}
events.add(pollEvent);
final int size = queue.size();
if (size <= 0) {
LOG.debug("UI EventBus aggregator for UI {} has nothing to do.", vaadinUI.getUIId());
return;
}
final List<Event> events = new ArrayList<>(size);
final int eventsSize = queue.drainTo(events);
if (events.isEmpty()) {
LOG.debug("UI EventBus aggregator for UI {} has nothing to do.", vaadinUI.getUIId());
return;
}
if (vaadinSession == null) {
return;
}
LOG.debug("UI EventBus aggregator session: {}", vaadinSession);
final WrappedSession wrappedSession = vaadinSession.getSession();
if (wrappedSession == null) {
return;
}
final int eventsSize = events.size();
LOG.debug("UI EventBus aggregator dispatches {} events for session {} for UI {}", eventsSize, vaadinSession,
vaadinUI.getUIId());
doDispatch(events, wrappedSession);
LOG.debug("UI EventBus aggregator done with sending {} events in {} ms", eventsSize,
System.currentTimeMillis() - timestamp);
LOG.debug("UI EventBus aggregator done with sending {} events in {} ms for UI {}", eventsSize,
System.currentTimeMillis() - timestamp, vaadinUI.getUIId());
}
private void doDispatch(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
final WrappedSession wrappedSession) {
private void doDispatch(final List<Event> events, final WrappedSession wrappedSession) {
final SecurityContext userContext = (SecurityContext) wrappedSession
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
final SecurityContext oldContext = SecurityContextHolder.getContext();
@@ -210,25 +216,24 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
if (vaadinSession.getState() != State.OPEN) {
return;
}
LOG.debug("UI EventBus aggregator of UI {} got lock on session.", vaadinUI.getUIId());
fowardSingleEvents(events, userContext);
fowardBulkEvents(events, userContext);
});
LOG.debug("UI EventBus aggregator of UI {} left lock on session.", vaadinUI.getUIId());
}).get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Wait for Vaadin session for UI {} interrupted!", vaadinUI.getUIId(), e);
} finally {
SecurityContextHolder.setContext(oldContext);
}
}
private void fowardBulkEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
final SecurityContext userContext) {
private void fowardBulkEvents(final List<Event> events, final SecurityContext userContext) {
final Set<Class<?>> filterBulkEvenTypes = eventProvider.getFilteredBulkEventsType(events);
publishBulkEvent(events, userContext, filterBulkEvenTypes);
}
private void publishBulkEvent(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
final SecurityContext userContext, final Set<Class<?>> filterBulkEvenTypes) {
for (final Class<?> bulkType : filterBulkEvenTypes) {
final List<org.eclipse.hawkbit.eventbus.event.Event> listBulkEvents = events.stream()
.filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event)
final List<Event> listBulkEvents = events.stream()
.filter(event -> DelayedEventBusPushStrategy.eventSecurityCheck(userContext, event)
&& bulkType.isInstance(event))
.collect(Collectors.toList());
if (!listBulkEvents.isEmpty()) {
@@ -237,10 +242,9 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy {
}
}
private void fowardSingleEvents(final List<org.eclipse.hawkbit.eventbus.event.Event> events,
final SecurityContext userContext) {
private void fowardSingleEvents(final List<Event> events, final SecurityContext userContext) {
events.stream()
.filter(event -> DelayedEventBusPushStrategy.this.eventSecurityCheck(userContext, event)
.filter(event -> DelayedEventBusPushStrategy.eventSecurityCheck(userContext, event)
&& eventProvider.getSingleEvents().contains(event.getClass()))
.forEach(event -> eventBus.publish(vaadinUI, event));
}

View File

@@ -21,7 +21,6 @@ import static org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions.VAR_TOTAL_TARGET
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -57,6 +56,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.collect.Maps;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.converter.Converter;
@@ -495,7 +495,8 @@ public class RolloutListGrid extends AbstractGrid {
* Contains all expected rollout status per column to enable or disable
* the button.
*/
private static final Map<String, RolloutStatus> EXPECTED_ROLLOUT_STATUS_ENABLE_BUTTON = new HashMap<>();
private static final Map<String, RolloutStatus> EXPECTED_ROLLOUT_STATUS_ENABLE_BUTTON = Maps
.newHashMapWithExpectedSize(2);
private final Container.Indexed containerDataSource;
static {

View File

@@ -9,8 +9,8 @@
package org.eclipse.hawkbit.ui.utils;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
@@ -435,8 +435,7 @@ public final class HawkbitCommonUtil {
*/
public static LazyQueryContainer createLazyQueryContainer(
final BeanQueryFactory<? extends AbstractBeanQuery<?>> queryFactory) {
final Map<String, Object> queryConfig = new HashMap<>();
queryFactory.setQueryConfiguration(queryConfig);
queryFactory.setQueryConfiguration(Collections.emptyMap());
return new LazyQueryContainer(new LazyQueryDefinition(true, 20, SPUILabelDefinitions.VAR_NAME), queryFactory);
}
@@ -448,8 +447,7 @@ public final class HawkbitCommonUtil {
*/
public static LazyQueryContainer createDSLazyQueryContainer(
final BeanQueryFactory<? extends AbstractBeanQuery<?>> queryFactory) {
final Map<String, Object> queryConfig = new HashMap<>();
queryFactory.setQueryConfiguration(queryConfig);
queryFactory.setQueryConfiguration(Collections.emptyMap());
return new LazyQueryContainer(new LazyQueryDefinition(true, 20, "tagIdName"), queryFactory);
}

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.utils;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
@@ -19,6 +18,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.eclipse.hawkbit.repository.model.BaseEntity;
import com.google.common.collect.Maps;
import com.vaadin.server.WebBrowser;
/**
@@ -32,7 +32,7 @@ import com.vaadin.server.WebBrowser;
public final class SPDateTimeUtil {
private static final String DURATION_FORMAT = "y','M','d','H','m','s";
private static final Map<Integer, CalendarI18N> DURATION_I18N = new HashMap<>();
private static final Map<Integer, CalendarI18N> DURATION_I18N = Maps.newHashMapWithExpectedSize(6);
static {
DURATION_I18N.put(0, CalendarI18N.YEAR);