From 4e2fd2befdf833fb94b4c79fa6c7e2a766d8b817 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 14:33:51 +0200 Subject: [PATCH 01/69] Add missing TargetTagDeletedEvent Signed-off-by: SirWayne --- .../main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java index 12bcaacbc..842cfcab5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; /** * The default hawkbit event provider. @@ -34,6 +35,7 @@ public class HawkbitEventProvider implements UIEventProvider { SINGLE_EVENTS.add(TargetTagCreatedBulkEvent.class); SINGLE_EVENTS.add(DistributionSetTagCreatedBulkEvent.class); SINGLE_EVENTS.add(DistributionSetTagDeletedEvent.class); + SINGLE_EVENTS.add(TargetTagDeletedEvent.class); SINGLE_EVENTS.add(DistributionSetTagUpdateEvent.class); SINGLE_EVENTS.add(RolloutGroupChangeEvent.class); SINGLE_EVENTS.add(RolloutChangeEvent.class); From a7d0306e75299387b693eb87901f27d4d9a424df Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 8 Apr 2016 05:37:21 +0200 Subject: [PATCH 02/69] Removed unnecessary transaction exceptions. Signed-off-by: Kai Zimmermann --- .../MultiTenantJpaTransactionManager.java | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java index 7b97f5037..1a519ea5b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit; import javax.persistence.EntityManager; import javax.transaction.Transaction; -import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -38,38 +37,31 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { protected void doBegin(final Object transaction, final TransactionDefinition definition) { super.doBegin(transaction, definition); + // ignore transactions on tenant independent calls + if (isTenantManagement(definition) && isCurrentTenantKeyGenerator(definition)) { + return; + } + final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager .getResource(getEntityManagerFactory()); final EntityManager em = emHolder.getEntityManager(); - if (notTenantManagement(definition) && notCurrentTenantKeyGenerator(definition) - && notRolloutScheduler(definition) && notGetOrCreateTenantMetadata(definition)) { - - final String currentTenant = tenantAware.getCurrentTenant(); - if (currentTenant == null) { - throw new TenantNotExistException("Tenant Unknown. Canceling transaction."); - } - - em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); + final String currentTenant = tenantAware.getCurrentTenant(); + if (currentTenant == null) { + throw new TenantNotExistException("Tenant Unknown. Canceling transaction."); } + + em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); + } - private boolean notGetOrCreateTenantMetadata(final TransactionDefinition definition) { - return !definition.getName() - .startsWith(SystemManagement.class.getCanonicalName() + ".getOrCreateTenantMetadata"); - } - - private boolean notRolloutScheduler(final TransactionDefinition definition) { - return !definition.getName().startsWith(RolloutManagement.class.getCanonicalName() + ".rolloutScheduler"); - } - - private boolean notCurrentTenantKeyGenerator(final TransactionDefinition definition) { - return !definition.getName() + private boolean isCurrentTenantKeyGenerator(final TransactionDefinition definition) { + return definition.getName() .startsWith(SystemManagement.class.getCanonicalName() + ".currentTenantKeyGenerator"); } - private boolean notTenantManagement(final TransactionDefinition definition) { - return !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant") + private boolean isTenantManagement(final TransactionDefinition definition) { + return definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant") && !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants"); } } From e3de03206d540bea56b5bc1b70edc6d915798fc5 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 8 Apr 2016 05:59:34 +0200 Subject: [PATCH 03/69] Fixed condition --- .../main/java/org/eclipse/hawkbit/ui/HawkbitUI.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java index f4c26a960..4acd6e887 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java @@ -48,15 +48,13 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; /** - * Vaadin management UI. - * - * - * + * hawkBit Management UI. * */ -@SuppressWarnings("serial") @Title("hawkBit Update Server") public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { + private static final long serialVersionUID = 1L; + private static final Logger LOG = LoggerFactory.getLogger(HawkbitUI.class); private static final String EMPTY_VIEW = ""; @@ -154,6 +152,8 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { } final Navigator navigator = new Navigator(this, content); navigator.addViewChangeListener(new ViewChangeListener() { + private static final long serialVersionUID = 1L; + @Override public boolean beforeViewChange(final ViewChangeEvent event) { return true; @@ -233,6 +233,7 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { } private class ManagementViewProvider implements ViewProvider { + private static final long serialVersionUID = 1L; @Override public String getViewName(final String viewAndParameters) { From 0c800d31490bf66810b382f7f6df22562f642261 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 8 Apr 2016 06:13:16 +0200 Subject: [PATCH 04/69] Fixed condition --- .../org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java index 1a519ea5b..ac6bc8806 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java @@ -38,7 +38,7 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { super.doBegin(transaction, definition); // ignore transactions on tenant independent calls - if (isTenantManagement(definition) && isCurrentTenantKeyGenerator(definition)) { + if (isTenantManagement(definition) || isCurrentTenantKeyGenerator(definition)) { return; } From cf8e4fd2fd55909a8fe66c43a2e59d422da1596e Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 8 Apr 2016 06:50:27 +0200 Subject: [PATCH 05/69] Revert "Fixed condition" This reverts commit e3de03206d540bea56b5bc1b70edc6d915798fc5. --- .../main/java/org/eclipse/hawkbit/ui/HawkbitUI.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java index 4acd6e887..f4c26a960 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java @@ -48,13 +48,15 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; /** - * hawkBit Management UI. + * Vaadin management UI. + * + * + * * */ +@SuppressWarnings("serial") @Title("hawkBit Update Server") public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { - private static final long serialVersionUID = 1L; - private static final Logger LOG = LoggerFactory.getLogger(HawkbitUI.class); private static final String EMPTY_VIEW = ""; @@ -152,8 +154,6 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { } final Navigator navigator = new Navigator(this, content); navigator.addViewChangeListener(new ViewChangeListener() { - private static final long serialVersionUID = 1L; - @Override public boolean beforeViewChange(final ViewChangeEvent event) { return true; @@ -233,7 +233,6 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { } private class ManagementViewProvider implements ViewProvider { - private static final long serialVersionUID = 1L; @Override public String getViewName(final String viewAndParameters) { From b3efcff49ec30233f27c87b7afb396917298cfd8 Mon Sep 17 00:00:00 2001 From: Asharani Date: Mon, 11 Apr 2016 11:21:46 +0530 Subject: [PATCH 06/69] Add documentation for client side debugging Signed-off-by: Asharani --- hawkbit-ui/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 hawkbit-ui/README.md diff --git a/hawkbit-ui/README.md b/hawkbit-ui/README.md new file mode 100644 index 000000000..f8e020648 --- /dev/null +++ b/hawkbit-ui/README.md @@ -0,0 +1,34 @@ +# hawkBit User Interface + +The application with user interface to create and manage rollouts. + +## Debugging client-side code +### Debug usings SuperDevMode +The SuperDevMode can be used to debug client side code without any browser plugin. + +#### Using SuperDevMode with chrome : + +- Add required maven dependencies + - Add vaadin-client-compiler dependency + - Add jetty dependencies (version : 8.1x) +- Set redirect property in the AppWidgetSet.gwt.xml module descriptor as follows + - < set-configuration-property name="devModeRedirectEnabled" value="true" /> +- Create launch configuration for the SuperDevMode + - The main class to execute should be com.google.gwt.dev.codeserver.CodeServer. + - Add fully-qualified class name of widgetset (org.eclipse.hawkbit.ui.AppWidgetSet) as parameter +- Enable debug in chrome + - Chrome inspector window ▸ Click on settings icon ▸ Scripts ▸ Enable source maps option +- Run the SuperDevMode Code Server with the launch configuration created above +- Open http://localhost:8080/UI/?debug .Click on "SuperDev" button in debug console (Alternatively can directly add ?superdevmode parameter to URL) +- Widgetset is compiled and you can see the java code files loaded in 'Chrome inspector window ▸ Source tab' + + +#### Using SuperDevMode with Eclipse : + +- Install the plugin from http://sdbg.github.io/p2 +- Start the server and Super Dev Mode as mentioned above +- Create a new launch configuration in Eclipse + - Type is "Launch Chrome" + - http://localhost:8080/UI/?superdevmode +- Launch the new configuration in debug mode +- Now breakpoints in eclipse can be set \ No newline at end of file From 2bf328402cbcb57fbbafc060a2947be4f1d63e6b Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Mon, 11 Apr 2016 12:41:16 +0200 Subject: [PATCH 07/69] Send DMF message only in case of DMF sim. Signed-off-by: Kai Zimmermann --- .../org/eclipse/hawkbit/simulator/SimulationController.java | 5 ++++- .../java/org/eclipse/hawkbit/simulator/SimulatorStartup.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java index 426860d8b..649d88477 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java @@ -86,7 +86,10 @@ public class SimulationController { final String deviceId = name + i; repository.add(deviceFactory.createSimulatedDevice(deviceId, tenant, protocol, pollDelay, new URL(endpoint), gatewayToken)); - spSenderService.createOrUpdateThing(tenant, deviceId); + + if (protocol == Protocol.DMF_AMQP) { + spSenderService.createOrUpdateThing(tenant, deviceId); + } } return ResponseEntity.ok("Updated " + amount + " DMF connected targets!"); diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java index 60f3055bd..b772bae1f 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.simulator; import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +53,9 @@ public class SimulatorStartup implements ApplicationListener Date: Mon, 11 Apr 2016 15:05:02 +0200 Subject: [PATCH 08/69] Fix null handling for all drag and drop table Signed-off-by: SirWayne --- .../footer/SMDeleteActionsLayout.java | 13 ++-- .../ui/common/table/AbstractTable.java | 25 +++++++ .../dstable/DistributionSetTable.java | 13 ++-- .../footer/DSDeleteActionsLayout.java | 21 ++---- .../management/dstable/DistributionTable.java | 14 ++-- .../event/DistributionTagDropEvent.java | 21 +++--- .../footer/DeleteActionsLayout.java | 69 ++++++++----------- .../management/targettable/TargetTable.java | 11 +-- .../targettable/TargetTableHeader.java | 12 +--- .../targettag/TargetTagFilterButtons.java | 39 +++++------ 10 files changed, 105 insertions(+), 133 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index ee2fc356f..4cb28c2c3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -8,16 +8,15 @@ */ package org.eclipse.hawkbit.ui.artifacts.footer; -import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -155,13 +154,9 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { private void addToDeleteList(final Table sourceTable, final TableTransferable transferable) { @SuppressWarnings("unchecked") - final Set swModuleSelected = (Set) sourceTable.getValue(); - final Set swModuleIdNameSet = new HashSet<>(); - if (!swModuleSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - swModuleIdNameSet.add((Long) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - swModuleIdNameSet.addAll(swModuleSelected); - } + final AbstractTable swTable = (AbstractTable) sourceTable; + final Set swModuleIdNameSet = swTable.getDeletedEntityByTransferable(transferable); + swModuleIdNameSet.forEach(id -> { final String swModuleName = (String) sourceTable.getContainerDataSource().getItem(id) .getItemProperty(SPUILabelDefinitions.NAME_VERSION).getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index eb1951d27..0737f42c8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.common.table; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -231,6 +232,30 @@ public abstract class AbstractTable extends Table { } } + /** + * Return the entity which should be deleted by a transferable + * + * @param transferable + * the table transferable + * @return set of entities id which will deleted + */ + @SuppressWarnings("unchecked") + public Set getDeletedEntityByTransferable(final TableTransferable transferable) { + final Set selectedEntities = (Set) getTableValue(this); + final Set ids = new HashSet<>(); + final Object tranferableData = transferable.getData(SPUIDefinitions.ITEMID); + if (tranferableData == null) { + return ids; + } + + if (!selectedEntities.contains(tranferableData)) { + ids.add((I) tranferableData); + } else { + ids.addAll(selectedEntities); + } + return ids; + } + protected abstract E findEntityByTableValue(I lastSelectedId); protected abstract void publishEntityAfterValueChange(E selectedLastEntity); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 1cd89b30f..b5d614243 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; @@ -208,17 +209,11 @@ public class DistributionSetTable extends AbstractNamedVersionTable softwareModuleSelected = (Set) source.getValue(); - final Set softwareModulesIdList = new HashSet<>(); - - if (!softwareModuleSelected.contains(transferable.getData("itemId"))) { - softwareModulesIdList.add((Long) transferable.getData("itemId")); - } else { - softwareModulesIdList.addAll(softwareModuleSelected); - } + final AbstractTable source = (AbstractTable) transferable.getSourceComponent(); + final Set softwareModulesIdList = source.getDeletedEntityByTransferable(transferable); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index dba8155db..5bc1627a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; @@ -188,13 +189,8 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { @SuppressWarnings("unchecked") - final Set distSelected = (Set) sourceTable.getValue(); - final Set distributionIdNameSet = new HashSet<>(); - if (!distSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - distributionIdNameSet.add((DistributionSetIdName) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - distributionIdNameSet.addAll(distSelected); - } + final AbstractTable table = (AbstractTable) sourceTable; + final Set distributionIdNameSet = table.getDeletedEntityByTransferable(transferable); /* * Flags to identify whether all dropped distributions are already in * the deleted list (or) some distributions are already in the deleted @@ -224,15 +220,10 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { } private void addToSWDeleteList(final Table sourceTable, final TableTransferable transferable) { - @SuppressWarnings("unchecked") - final Set swModuleSelected = (Set) sourceTable.getValue(); - final Set swModuleIdNameSet = new HashSet<>(); - if (!swModuleSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - swModuleIdNameSet.add((Long) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - swModuleIdNameSet.addAll(swModuleSelected); - } + final AbstractTable swTable = (AbstractTable) sourceTable; + final Set swModuleIdNameSet = swTable.getDeletedEntityByTransferable(transferable); + swModuleIdNameSet.forEach(id -> { final String swModuleName = (String) sourceTable.getContainerDataSource().getItem(id) .getItemProperty(SPUILabelDefinitions.NAME_VERSION).getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 1b856277e..0df1b0ea5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -26,6 +26,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; @@ -350,17 +351,12 @@ public class DistributionTable extends AbstractNamedVersionTable targetsSelected = getTableValue(source); - final Set targetDetailsList = new HashSet<>(); - - if (!targetsSelected.contains(transferable.getData("itemId"))) { - targetDetailsList.add((TargetIdName) transferable.getData("itemId")); - } else { - targetDetailsList.addAll(targetsSelected); - } + final AbstractTable source = (AbstractTable) transferable + .getSourceComponent(); + final Set targetDetailsList = source.getDeletedEntityByTransferable(transferable); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java index 5b1e09282..97ba7ea6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.event; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -17,6 +16,7 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.state.DistributionTableFilters; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -127,28 +127,25 @@ public class DistributionTagDropEvent implements DropHandler { return true; } + @SuppressWarnings("unchecked") private void processDistributionDrop(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); - final Table source = transferable.getSourceComponent(); + final AbstractTable source = (AbstractTable) transferable + .getSourceComponent(); - @SuppressWarnings("unchecked") - final Set distSelected = (Set) source.getValue(); - final Set distributionList = new HashSet<>(); - if (!distSelected.contains(transferable.getData(ITEMID))) { - distributionList.add(((DistributionSetIdName) transferable.getData(ITEMID)).getId()); - } else { - distributionList.addAll(distSelected.stream().map(t -> t.getId()).collect(Collectors.toList())); - } + final Set distSelected = source.getDeletedEntityByTransferable(transferable); + final Set distributionList = distSelected.stream().map(entity -> entity.getId()) + .collect(Collectors.toSet()); final String distTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); final List tagsClickedList = distFilterParameters.getDistSetTags(); - final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, - distTagName); + final DistributionSetTagAssignmentResult result = distributionSetManagement + .toggleTagAssignment(distributionList, distTagName); notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n)); if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 678a5704f..0466e6076 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.footer; -import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.repository.TagManagement; @@ -257,15 +256,10 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } } + @SuppressWarnings("unchecked") private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { - final Set distSelected = AbstractTable.getTableValue(sourceTable); - final Set distributionIdNameSet = new HashSet<>(); - - if (!distSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - distributionIdNameSet.add((DistributionSetIdName) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - distributionIdNameSet.addAll(distSelected); - } + final AbstractTable distTable = (AbstractTable) sourceTable; + final Set distributionIdNameSet = distTable.getDeletedEntityByTransferable(transferable); final DistributionSetIdName dsInBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload() .getDsNameAndVersion(); @@ -273,31 +267,31 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { distributionIdNameSet.remove(dsInBulkUpload); } - if (!distributionIdNameSet.isEmpty()) { - + if (distributionIdNameSet.isEmpty()) { + return; + } + /* + * Flags to identify whether all dropped distributions are already in + * the deleted list (or) some distributions are already in the deleted + * distribution list. + */ + final int existingDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); + managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); + final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); + if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { /* - * Flags to identify whether all dropped distributions are already - * in the deleted list (or) some distributions are already in the - * deleted distribution list. + * No new distributions are added, all distributions dropped now are + * already available in the delete list. Hence display warning + * message accordingly. */ - final int existingDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); - managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); - final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); - if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { - /* - * No new distributions are added, all distributions dropped now - * are already available in the delete list. Hence display - * warning message accordingly. - */ - notification.displayValidationError(i18n.get("message.targets.already.deleted")); - } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { - /* - * Not the all distributions dropped now are added to the delete - * list. There are some distributions are already there in the - * delete list. Hence display warning message accordingly. - */ - notification.displayValidationError(i18n.get("message.dist.deleted.pending")); - } + notification.displayValidationError(i18n.get("message.targets.already.deleted")); + } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { + /* + * Not the all distributions dropped now are added to the delete + * list. There are some distributions are already there in the + * delete list. Hence display warning message accordingly. + */ + notification.displayValidationError(i18n.get("message.dist.deleted.pending")); } } @@ -311,15 +305,10 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { return false; } + @SuppressWarnings("unchecked") private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { - final Set targetSelected = AbstractTable.getTableValue(sourceTable); - - final Set targetIdNameSet = new HashSet<>(); - if (!targetSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { - targetIdNameSet.add((TargetIdName) transferable.getData(SPUIDefinitions.ITEMID)); - } else { - targetIdNameSet.addAll(targetSelected); - } + final AbstractTable targetTable = (AbstractTable) sourceTable; + final Set targetIdNameSet = targetTable.getDeletedEntityByTransferable(transferable); /* * Flags to identify whether all dropped targets are already in the diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index e73bf2e4a..1307e27d3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -632,16 +632,11 @@ public class TargetTable extends AbstractTable implements return true; } + @SuppressWarnings("unchecked") private static Set getDraggedDistributionSet(final TableTransferable transferable, final Table source) { - final Set distSelected = getTableValue(source); - final Set distributionIdSet = new HashSet<>(); - if (!distSelected.contains(transferable.getData(ITEMID))) { - distributionIdSet.add((DistributionSetIdName) transferable.getData(ITEMID)); - } else { - distributionIdSet.addAll(distSelected); - } - return distributionIdSet; + final AbstractTable distTable = (AbstractTable) source; + return distTable.getDeletedEntityByTransferable(transferable); } private Boolean validateDragAndDropWrapper(final Component compsource) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index cb00c2338..158d57878 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -378,16 +378,10 @@ public class TargetTableHeader extends AbstractTableHeader { return isValid; } + @SuppressWarnings("unchecked") private Set getDropppedDistributionDetails(final TableTransferable transferable) { - final Set distSelected = AbstractTable.getTableValue(transferable.getSourceComponent()); - final Set distributionIdSet = new HashSet<>(); - if (!distSelected.contains(transferable.getData("itemId"))) { - distributionIdSet.add((DistributionSetIdName) transferable.getData("itemId")); - } else { - distributionIdSet.addAll(distSelected); - } - - return distributionIdSet; + final AbstractTable distTable = (AbstractTable) transferable.getSourceComponent(); + return distTable.getDeletedEntityByTransferable(transferable); } private void addFilterTextField(final DistributionSetIdName distributionSetIdName) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index c60ab37ca..671d332de 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.targettag; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -212,36 +211,32 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { return true; } + @SuppressWarnings("unchecked") private void processTargetDrop(final DragAndDropEvent event) { - final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); - final Table source = transferable.getSourceComponent(); + final AbstractTable targetTable = (AbstractTable) transferable + .getSourceComponent(); - final Set targetSelected = AbstractTable.getTableValue(source); - final Set targetList = new HashSet<>(); - if (transferable.getData(ITEMID) != null) { - if (!targetSelected.contains(transferable.getData(ITEMID))) { - targetList.add(((TargetIdName) transferable.getData(ITEMID)).getControllerId()); - } else { - targetList.addAll(targetSelected.stream().map(t -> t.getControllerId()).collect(Collectors.toList())); - } + final Set targetSelected = targetTable.getDeletedEntityByTransferable(transferable); + final Set targetList = targetSelected.stream().map(t -> t.getControllerId()) + .collect(Collectors.toSet()); - final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), - SPUIDefinitions.TARGET_TAG_ID_PREFIXS); + final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), + SPUIDefinitions.TARGET_TAG_ID_PREFIXS); - final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); + final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); - final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); - notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); + final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); + notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); - if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { - eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); - } - if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() && tagsClickedList.contains(targTagName)) { - eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); - } + if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { + eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); } + if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() && tagsClickedList.contains(targTagName)) { + eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); + } + } private boolean validateIfSourceisTargetTable(final Table source) { From c4fd082098b01228cd0e719cd94743ac87b594bc Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 09:39:07 +0200 Subject: [PATCH 09/69] fix the lookup of artifacts with the same lookup key, e.g. SHA1 hash if multiple artifacts with key exists for different software modules Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerService.java | 14 +++-- .../repository/ControllerManagement.java | 27 +++++++++ .../specifications/ActionSpecifications.java | 60 +++++++++++++++++++ 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 41e70f91f..e05ddf71d 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -166,6 +166,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource); if (localArtifact == null) { + LOG.info("target {} requested file resource which does not exists to download", + secruityToken.getControllerId(), fileResource); throw new EntityNotFoundException(); } @@ -175,10 +177,14 @@ public class AmqpMessageHandlerService extends BaseAmqpService { // assigned to this controller. Otherwise no controllerId is set = // anonymous download if (secruityToken.getControllerId() != null) { - final Action action = controllerManagement.getActionForDownloadByTargetAndSoftwareModule( - secruityToken.getControllerId(), localArtifact.getSoftwareModule()); - LOG.info("Found action for download authentication request action: {}, resource: {}", action, - secruityToken.getFileResource()); + LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", + secruityToken.getControllerId(), localArtifact); + if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { + LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + throw new EntityNotFoundException(); + } + LOG.info("download security check for target {} and artifact {} granted", + secruityToken.getControllerId(), localArtifact); } final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact)); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 0bb94bd72..9510ae899 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -28,12 +28,14 @@ import org.eclipse.hawkbit.repository.model.Action.Status; 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.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.repository.specifications.ActionSpecifications; import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; @@ -166,6 +168,31 @@ public class ControllerManagement { return action.get(0); } + /** + * Checks if a given target has currently or has even been assigned to the + * given artifact through the action history list. This can e.g. indicate if + * a target is allowed to download a given artifact because it has currently + * assigned or had ever been assigned to the target and so it's visible to a + * specific target e.g. for downloading. + * + * @param targetId + * the ID of the target to check + * @param localArtifact + * the artifact to verify if the given target had even been + * assigned to + * @return {@code true} if the given target has currently or had ever a + * relation to the given artifact through the action history, + * otherwise {@code false} + */ + public boolean hasTargetArtifactAssigned(@NotNull final String targetId, + @NotNull final LocalArtifact localArtifact) { + final Target target = targetRepository.findByControllerId(targetId); + if (target == null) { + return false; + } + return actionRepository.count(ActionSpecifications.hasTargetArtifactAssigned(target, localArtifact)) > 0; + } + /** * Refreshes the time of the last time the controller has been connected to * the server. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java new file mode 100644 index 000000000..ef8c97e22 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.specifications; + +import javax.persistence.criteria.Join; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.SetJoin; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action_; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSet_; +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.LocalArtifact_; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModule_; +import org.eclipse.hawkbit.repository.model.Target; +import org.springframework.data.jpa.domain.Specification; + +/** + * Utility class for {@link Action}s {@link Specification}s. The class provides + * Spring Data JPQL Specifications. + * + */ +public class ActionSpecifications { + + private ActionSpecifications() { + // utility class + } + + /** + * Specification which joins all necessary tables to retrieve the dependency + * between a target and a local file assignment through the assigen action + * of the target. All actions are included, not only active actions. + * + * @param target + * the target to verfiy if the given artifact is currently + * assigned or had been assigned + * @param localArtifact + * the local artifact to check wherever the target had ever been + * assigned + * @return a specification to use with spring JPA + */ + public static Specification hasTargetArtifactAssigned(final Target target, + final LocalArtifact localArtifact) { + return (actionRoot, query, cb) -> { + final Join dsJoin = actionRoot.join(Action_.distributionSet); + final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); + final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); + return cb.and(cb.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), + cb.equal(actionRoot.get(Action_.target), target)); + }; + } +} From 0b5286299c7a2453a635f8a7d64eac33cb99d46d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 10:03:19 +0200 Subject: [PATCH 10/69] fix unit tests after changing the lookup way Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 930ca02ad..0faa0a8a6 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -313,11 +313,9 @@ public class AmqpMessageHandlerServiceTest { // mock final LocalArtifact localArtifactMock = mock(LocalArtifact.class); - final Action actionMock = mock(Action.class); final DbArtifact dbArtifactMock = mock(DbArtifact.class); when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock); - when(controllerManagementMock.getActionForDownloadByTargetAndSoftwareModule(anyObject(), anyObject())) - .thenReturn(actionMock); + when(controllerManagementMock.hasTargetArtifactAssigned(anyObject(), anyObject())).thenReturn(true); when(artifactManagementMock.loadLocalArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock); when(dbArtifactMock.getArtifactId()).thenReturn("artifactId"); when(dbArtifactMock.getSize()).thenReturn(1L); From b11a0bac5db51e38685d77ca15669e4042069ba4 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 12:18:59 +0200 Subject: [PATCH 11/69] reduce method cyclomatic complexity by extracting security check into own method Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerService.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index e05ddf71d..47807cd4d 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -171,21 +171,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { throw new EntityNotFoundException(); } - // check action for this download purposes, the method will throw an - // EntityNotFoundException in case the controller is not allowed to - // download this file because it's not assigned to an action and not - // assigned to this controller. Otherwise no controllerId is set = - // anonymous download - if (secruityToken.getControllerId() != null) { - LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", - secruityToken.getControllerId(), localArtifact); - if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { - LOG.info("target {} tried to download artifact {} which is not assigned to the target"); - throw new EntityNotFoundException(); - } - LOG.info("download security check for target {} and artifact {} granted", - secruityToken.getControllerId(), localArtifact); - } + checkIfArtifactIsAssignedToTarget(secruityToken, localArtifact); final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact)); if (artifact == null) { @@ -219,6 +205,25 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return getMessageConverter().toMessage(authentificationResponse, messageProperties); } + private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, + final LocalArtifact localArtifact) { + // check action for this download purposes, the method will throw an + // EntityNotFoundException in case the controller is not allowed to + // download this file because it's not assigned to an action and not + // assigned to this controller. Otherwise no controllerId is set = + // anonymous download + if (secruityToken.getControllerId() != null) { + LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", + secruityToken.getControllerId(), localArtifact); + if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { + LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + throw new EntityNotFoundException(); + } + LOG.info("download security check for target {} and artifact {} granted", secruityToken.getControllerId(), + localArtifact); + } + } + private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { if (fileResource.getSha1() != null) { return artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1()); From d91922dc048cb3119561135ff60f0e9da8f24997 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 12 Apr 2016 13:37:07 +0200 Subject: [PATCH 12/69] Update the entity before call the super method Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 59 ++++++++----------- .../table/AbstractNamedVersionTable.java | 2 +- .../dstable/DistributionSetTable.java | 12 ++-- .../distributions/smtable/SwModuleTable.java | 20 ++++--- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index f101c94a7..237634398 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -9,7 +9,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -25,7 +24,6 @@ import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -44,6 +42,8 @@ import com.vaadin.ui.UI; /** * Header of Software module table. + * + * * */ @SpringComponent @@ -129,22 +129,6 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable getTableVisibleColumns() { - final List columnList = super.getTableVisibleColumns(); - if (!isMaximized()) { - return columnList; - } - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); - return columnList; + protected void updateEntity(final SoftwareModule baseEntity, final Item item) { + final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), + baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); + item.getItemProperty("swId").setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); + super.updateEntity(baseEntity, item); } @Override @@ -203,6 +180,22 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable Date: Tue, 12 Apr 2016 13:42:57 +0200 Subject: [PATCH 13/69] Update the entity before call the super method Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 237634398..478438891 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -24,6 +25,7 @@ import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.TableColumn; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -42,8 +44,6 @@ import com.vaadin.ui.UI; /** * Header of Software module table. - * - * * */ @SpringComponent @@ -129,6 +129,22 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable getTableVisibleColumns() { + final List columnList = super.getTableVisibleColumns(); + if (!isMaximized()) { + return columnList; + } + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); + return columnList; + } + @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -180,22 +207,6 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable Date: Tue, 12 Apr 2016 14:35:59 +0200 Subject: [PATCH 14/69] source code improvements Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerService.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 47807cd4d..994ef244a 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -205,23 +205,32 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return getMessageConverter().toMessage(authentificationResponse, messageProperties); } + /** + * check action for this download purposes, the method will throw an + * EntityNotFoundException in case the controller is not allowed to download + * this file because it's not assigned to an action and not assigned to this + * controller. Otherwise no controllerId is set = anonymous download + * + * @param secruityToken + * the security token which holds the target ID to check on + * @param localArtifact + * the local artifact to verify if the given target is allowed to + * download this artifact + */ private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, final LocalArtifact localArtifact) { - // check action for this download purposes, the method will throw an - // EntityNotFoundException in case the controller is not allowed to - // download this file because it's not assigned to an action and not - // assigned to this controller. Otherwise no controllerId is set = - // anonymous download - if (secruityToken.getControllerId() != null) { - LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", - secruityToken.getControllerId(), localArtifact); - if (!controllerManagement.hasTargetArtifactAssigned(secruityToken.getControllerId(), localArtifact)) { - LOG.info("target {} tried to download artifact {} which is not assigned to the target"); - throw new EntityNotFoundException(); - } - LOG.info("download security check for target {} and artifact {} granted", secruityToken.getControllerId(), - localArtifact); + final String controllerId = secruityToken.getControllerId(); + if (controllerId == null) { + LOG.info("anonymous download no authentication check for artifact {}", localArtifact); + return; } + LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", + controllerId, localArtifact); + if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) { + LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + throw new EntityNotFoundException(); + } + LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact); } private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { From cc8c6743415be5b01cd80cffd8da669611acd547 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 15:47:21 +0200 Subject: [PATCH 15/69] correct usage of logging, missing parameters Signed-off-by: Michael Hirsch --- .../org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 994ef244a..2ee0a0f45 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -227,7 +227,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", controllerId, localArtifact); if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) { - LOG.info("target {} tried to download artifact {} which is not assigned to the target"); + LOG.info("target {} tried to download artifact {} which is not assigned to the target", controllerId, + localArtifact); throw new EntityNotFoundException(); } LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact); From 30e8230b8aaa55e1e3834c1d9eeed019454d5f99 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 15:48:19 +0200 Subject: [PATCH 16/69] correct usage of logging, missing parameters Signed-off-by: Michael Hirsch --- .../org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 2ee0a0f45..447a8ffca 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -166,7 +166,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource); if (localArtifact == null) { - LOG.info("target {} requested file resource which does not exists to download", + LOG.info("target {} requested file resource {} which does not exists to download", secruityToken.getControllerId(), fileResource); throw new EntityNotFoundException(); } From d903be57b7a9913c29db8e8729efa88f5fab4666 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 15:50:48 +0200 Subject: [PATCH 17/69] use correct mock parameters to ensure test Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 0faa0a8a6..19a7be3bc 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -315,7 +315,8 @@ public class AmqpMessageHandlerServiceTest { final LocalArtifact localArtifactMock = mock(LocalArtifact.class); final DbArtifact dbArtifactMock = mock(DbArtifact.class); when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock); - when(controllerManagementMock.hasTargetArtifactAssigned(anyObject(), anyObject())).thenReturn(true); + when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), localArtifactMock)) + .thenReturn(true); when(artifactManagementMock.loadLocalArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock); when(dbArtifactMock.getArtifactId()).thenReturn("artifactId"); when(dbArtifactMock.getSize()).thenReturn(1L); From d704ef99fd1a3ee0f8152f933ee7c9f8ed610901 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 12 Apr 2016 16:22:43 +0200 Subject: [PATCH 18/69] source code hygiene, better method naming and variable naming Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/repository/ControllerManagement.java | 2 +- .../repository/specifications/ActionSpecifications.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 9510ae899..dc097a7e3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -190,7 +190,7 @@ public class ControllerManagement { if (target == null) { return false; } - return actionRepository.count(ActionSpecifications.hasTargetArtifactAssigned(target, localArtifact)) > 0; + return actionRepository.count(ActionSpecifications.hasTargetAssignedArtifact(target, localArtifact)) > 0; } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java index ef8c97e22..1ac3afb67 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java @@ -47,14 +47,14 @@ public class ActionSpecifications { * assigned * @return a specification to use with spring JPA */ - public static Specification hasTargetArtifactAssigned(final Target target, + public static Specification hasTargetAssignedArtifact(final Target target, final LocalArtifact localArtifact) { - return (actionRoot, query, cb) -> { + return (actionRoot, query, criteriaBuilder) -> { final Join dsJoin = actionRoot.join(Action_.distributionSet); final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); - return cb.and(cb.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), - cb.equal(actionRoot.get(Action_.target), target)); + return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), + criteriaBuilder.equal(actionRoot.get(Action_.target), target)); }; } } From 67fd24e66846a6f4d7e02a805a72773572ef07d4 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Wed, 13 Apr 2016 12:46:30 +0530 Subject: [PATCH 19/69] Rollout management issues Signed-off-by: venu1278 --- .../client/CustomObjectRendererConnector.java | 25 + .../client/LinkRendererConnector.java | 29 - .../client/renderers/CustomObject.java | 39 + .../renderers/CustomObjectRenederer.java | 52 + .../client/renderers/LinkRenderer.java | 42 - .../renderers/CustomObjectRenderer.java | 42 + .../renderers/LinkRenderer.java | 37 - .../ui/rollout/rollout/ProxyRollout.java | 194 +-- .../ui/rollout/rollout/RolloutBeanQuery.java | 4 +- .../ui/rollout/rollout/RolloutListGrid.java | 1116 +++++++++-------- .../rolloutgroup/ProxyRolloutGroup.java | 11 + .../rolloutgroup/RolloutGroupBeanQuery.java | 3 + .../rolloutgroup/RolloutGroupListGrid.java | 624 ++++----- .../themes/hawkbit/customstyles/rollout.scss | 18 +- 14 files changed, 1232 insertions(+), 1004 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java new file mode 100644 index 000000000..b209ab82c --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java @@ -0,0 +1,25 @@ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; + +import com.google.web.bindery.event.shared.HandlerRegistration; +import com.vaadin.client.connectors.ClickableRendererConnector; +import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; +import com.vaadin.shared.ui.Connect; + +import elemental.json.JsonObject; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer.class) +public class CustomObjectRendererConnector extends ClickableRendererConnector { + private static final long serialVersionUID = 7734682321931830566L; + + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer) super.getRenderer(); + } + + @Override + protected HandlerRegistration addClickHandler( + RendererClickHandler handler) { + return getRenderer().addClickHandler(handler); + } +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java deleted file mode 100644 index bc48d64d7..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java +++ /dev/null @@ -1,29 +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.customrenderers.client; - -import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; - -import com.vaadin.client.connectors.ButtonRendererConnector; -import com.vaadin.shared.ui.Connect; - -/** - * - * A connector for {@link LinkRenderer}. - * - */ -@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer.class) -public class LinkRendererConnector extends ButtonRendererConnector { - private static final long serialVersionUID = 7987417436367399331L; - - @Override - public org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer getRenderer() { - return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer) super.getRenderer(); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java new file mode 100644 index 000000000..85b5d9404 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java @@ -0,0 +1,39 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import java.io.Serializable; + +public class CustomObject implements Serializable { + private static final long serialVersionUID = -5018181529953620263L; + + private String name; + + private String status; + + public CustomObject(){ + + } + + public CustomObject(String name, String status) { + super(); + this.name = name; + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStatus() { + return status; + } + + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java new file mode 100644 index 000000000..a6a527f2a --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -0,0 +1,52 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import com.google.gwt.core.shared.GWT; +import com.vaadin.client.renderers.ClickableRenderer; +import com.vaadin.client.ui.VButton; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class CustomObjectRenederer extends ClickableRenderer { + + @Override + public VButton createWidget() { + VButton b = GWT.create(VButton.class); + b.addClickHandler(this); + b.setStylePrimaryName("v-nativebutton"); + return b; + } + + @Override + public void render(RendererCellReference cell, CustomObject text, VButton button) { + final String creating = "CREATING"; + button.setText(text.getName()); + applystyle(button); + // this is to allow the button to disappear, if the text is null + button.setVisible(text.getName() != null); + button.getElement().setId(new StringBuilder("link").append(".").append(text.getName()).toString()); + /* + * checking Rollout Status for applying button style. If Rollout status + * is not "CREATING", then the Rollout button is applying hyperlink + * style + */ + final boolean isStatusCreate = text.getStatus() != null && creating.equalsIgnoreCase(text.getStatus()); + if (isStatusCreate) { + button.addStyleName(getStyle("boldhide")); + button.setEnabled(false); + } else { + button.setEnabled(true); + } + } + + private void applystyle(VButton button) { + button.setStyleName(VButton.CLASSNAME); + button.addStyleName(getStyle("borderless")); + button.addStyleName(getStyle("small")); + button.addStyleName(getStyle("on-focus-no-border")); + button.addStyleName(getStyle("link")); + } + + private String getStyle(final String style) { + return new StringBuilder(style).append(" ").append(VButton.CLASSNAME).append("-").append(style).toString(); + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java deleted file mode 100644 index 0abe4044b..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java +++ /dev/null @@ -1,42 +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.customrenderers.client.renderers; - -import com.google.gwt.user.client.ui.Button; -import com.vaadin.client.renderers.ButtonRenderer; -import com.vaadin.client.ui.VButton; -import com.vaadin.client.widget.grid.RendererCellReference; - -/** - * - * Renders link with provided text. - * - */ -public class LinkRenderer extends ButtonRenderer { - @Override - public void render(RendererCellReference cell, String text, Button button) { - button.setText(text); - applystyle(button); - // this is to allow the button to disappear, if the text is null - button.setVisible(text != null); - button.getElement().setId(new StringBuilder("link").append(".").append(text).toString()); - } - - private void applystyle(Button button) { - button.setStyleName(VButton.CLASSNAME); - button.addStyleName(getStyle("borderless")); - button.addStyleName(getStyle("small")); - button.addStyleName(getStyle("on-focus-no-border")); - button.addStyleName(getStyle("link")); - } - - private String getStyle(final String style) { - return new StringBuilder(style).append(" ").append(VButton.CLASSNAME).append("-").append(style).toString(); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java new file mode 100644 index 000000000..c2a7606a3 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java @@ -0,0 +1,42 @@ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; + +import com.vaadin.ui.renderers.ClickableRenderer; + +import elemental.json.JsonValue; + +public class CustomObjectRenderer extends ClickableRenderer { + + /** + * + */ + private static final long serialVersionUID = -8754180585906263554L; + + /** + * Creates a new image renderer. + */ + public CustomObjectRenderer() { + super(CustomObject.class, null); + } + + public CustomObjectRenderer(Class presentationType) { + super(presentationType); + } + + /** + * Creates a new image renderer and adds the given click listener to it. + * + * @param listener + * the click listener to register + */ + public CustomObjectRenderer(RendererClickListener listener) { + this(); + addClickListener(listener); + } + + @Override + public JsonValue encode(CustomObject resource) { + return super.encode(resource, CustomObject.class); + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java deleted file mode 100644 index d913ca380..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java +++ /dev/null @@ -1,37 +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.customrenderers.renderers; - -import com.vaadin.ui.renderers.ButtonRenderer; - -/** - * - * Renders link with provided text. - * - */ -public class LinkRenderer extends ButtonRenderer { - private static final long serialVersionUID = -1242995370043404892L; - - /** - * Intialise link renderer. - */ - public LinkRenderer() { - super(); - } - - /** - * Intialise link renderer with {@link RendererClickListener} - * - * @param listener - * RendererClickListener - */ - public LinkRenderer(RendererClickListener listener) { - super(listener); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index b1309f8b9..36cb7ddee 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import com.vaadin.server.FontAwesome; @@ -18,113 +19,122 @@ import com.vaadin.server.FontAwesome; */ public class ProxyRollout extends Rollout { - private static final long serialVersionUID = 4539849939617681918L; + private static final long serialVersionUID = 4539849939617681918L; - private String distributionSetNameVersion; + private String distributionSetNameVersion; - private String createdDate; + private String createdDate; - private String modifiedDate; + private String modifiedDate; - private Long numberOfGroups; + private Long numberOfGroups; - private Boolean isActionRecieved = Boolean.FALSE; + private Boolean isActionRecieved = Boolean.FALSE; - private String totalTargetsCount; - - /** - * @return the distributionSetNameVersion - */ - public String getDistributionSetNameVersion() { - return distributionSetNameVersion; - } + private String totalTargetsCount; - /** - * @param distributionSetNameVersion - * the distributionSetNameVersion to set - */ - public void setDistributionSetNameVersion(final String distributionSetNameVersion) { - this.distributionSetNameVersion = distributionSetNameVersion; - } + private CustomObject customObject; - /** - * @return the numberOfGroups - */ - public Long getNumberOfGroups() { - return numberOfGroups; - } + public CustomObject getCustomObject() { + return customObject; + } - /** - * @param numberOfGroups - * the numberOfGroups to set - */ - public void setNumberOfGroups(final Long numberOfGroups) { - this.numberOfGroups = numberOfGroups; - } + public void setCustomObject(CustomObject customObject) { + this.customObject = customObject; + } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @return the distributionSetNameVersion + */ + public String getDistributionSetNameVersion() { + return distributionSetNameVersion; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @param distributionSetNameVersion + * the distributionSetNameVersion to set + */ + public void setDistributionSetNameVersion(final String distributionSetNameVersion) { + this.distributionSetNameVersion = distributionSetNameVersion; + } - /** - * @return the modifiedDate - */ - public String getModifiedDate() { - return modifiedDate; - } + /** + * @return the numberOfGroups + */ + public Long getNumberOfGroups() { + return numberOfGroups; + } - /** - * @param modifiedDate - * the modifiedDate to set - */ - public void setModifiedDate(final String modifiedDate) { - this.modifiedDate = modifiedDate; - } + /** + * @param numberOfGroups + * the numberOfGroups to set + */ + public void setNumberOfGroups(final Long numberOfGroups) { + this.numberOfGroups = numberOfGroups; + } - /** - * @return the isActionRecieved - */ - public Boolean getIsActionRecieved() { - return isActionRecieved; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param isActionRecieved - * the isActionRecieved to set - */ - public void setIsActionRecieved(final Boolean isActionRecieved) { - this.isActionRecieved = isActionRecieved; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @return the totalTargetsCount - */ - public String getTotalTargetsCount() { - return totalTargetsCount; - } + /** + * @return the modifiedDate + */ + public String getModifiedDate() { + return modifiedDate; + } + + /** + * @param modifiedDate + * the modifiedDate to set + */ + public void setModifiedDate(final String modifiedDate) { + this.modifiedDate = modifiedDate; + } + + /** + * @return the isActionRecieved + */ + public Boolean getIsActionRecieved() { + return isActionRecieved; + } + + /** + * @param isActionRecieved + * the isActionRecieved to set + */ + public void setIsActionRecieved(final Boolean isActionRecieved) { + this.isActionRecieved = isActionRecieved; + } + + /** + * @return the totalTargetsCount + */ + public String getTotalTargetsCount() { + return totalTargetsCount; + } + + /** + * @param totalTargetsCount + * the totalTargetsCount to set + */ + public void setTotalTargetsCount(final String totalTargetsCount) { + this.totalTargetsCount = totalTargetsCount; + } + + public String getAction() { + return FontAwesome.CIRCLE_O.getHtml(); + } - /** - * @param totalTargetsCount - * the totalTargetsCount to set - */ - public void setTotalTargetsCount(final String totalTargetsCount) { - this.totalTargetsCount = totalTargetsCount; - } - - - public String getAction() { - return FontAwesome.CIRCLE_O.getHtml(); - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 5ab6f6a97..114d2e432 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -130,7 +131,8 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); - + proxyRollout.setCustomObject(new CustomObject(rollout.getName(), rollout.getStatus().toString())); + final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 9151f3932..6cf781c4b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -25,9 +25,10 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; -import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -58,6 +59,7 @@ import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.Button; import com.vaadin.ui.UI; import com.vaadin.ui.Window; import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; @@ -72,524 +74,598 @@ import com.vaadin.ui.renderers.HtmlRenderer; @ViewScope public class RolloutListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; - - private static final String UPDATE_OPTION = "Update"; - - private static final String RESUME_OPTION = "Resume"; - - private static final String PAUSE_OPTION = "Pause"; - - private static final String START_OPTION = "Start"; - - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; - - @Autowired - private UINotification uiNotification; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - switch (event) { - case FILTER_BY_TEXT: - case CREATE_ROLLOUT: - case UPDATE_ROLLOUT: - case SHOW_ROLLOUTS: - refreshGrid(); - break; - default: - return; - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the grid. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - if (!rolloutUIState.isShowRollOuts()) { - return; - } - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Long.valueOf(rollout.getRolloutGroups().size())); - } - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Integer.class, 0, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, - FontAwesome.CIRCLE_O.getHtml(), false, false); - - } - - @Override - protected void setColumnExpandRatio() { - getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - - setFrozenColumnCount(getColumns().size()); - } - - @Override - protected void setColumnHeaderNames() { - getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); - } - - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; - } - - @Override - protected void setColumnProperties() { - List columnList = new ArrayList<>(); - columnList.add(SPUILabelDefinitions.VAR_NAME); - columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ACTION); - - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } - - @Override - protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - - } - - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } - - @Override - protected void addColumnRenderes() { - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - - createRolloutStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); - - getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - getColumn(SPUILabelDefinitions.VAR_NAME).setRenderer(new LinkRenderer(event -> onClickOfRolloutName(event))); - } - - private void createRolloutStatusToFontMap() { - statusIconMap.put(RolloutStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutStatus.PAUSED, - new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); - statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); - statusIconMap.put(RolloutStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutStatus.STOPPED, - new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); - statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); - statusIconMap.put(RolloutStatus.ERROR_CREATING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.ERROR_STARTING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } - - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; - - @Override - public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } - - private void onClickOfRolloutName(RendererClickEvent event) { - rolloutUIState.setRolloutId((long) event.getItemId()); - final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - String ds = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); - rolloutUIState.setRolloutDistributionSet(ds); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private void onClickOfActionBtn(RendererClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); - contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - final Item row = getContainerDataSource().getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - - switch (rolloutStatus) { - case READY: - final ContextMenuItem startItem = context.addItem(START_OPTION); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - break; - case RUNNING: - final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - break; - case PAUSED: - final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - break; - case STARTING: - case CREATING: - case ERROR_CREATING: - case ERROR_STARTING: - // do not provide any action on these statuses - return context; - default: - break; - } - getUpdateMenuItem(context, rolloutId); - return context; - } - - - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { - // Add 'Update' option only if user has update permission - if (!permissionChecker.hasRolloutUpdatePermission()) { - return; - } - final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - - private String convertRolloutStatusToString(final RolloutStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - switch (contextMenuData.getAction()) { - case PAUSE: - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - break; - case RESUME: - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - break; - case START: - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - break; - case UPDATE: - onUpdate(contextMenuData); - break; - default: - break; - } - } - - private void onUpdate(final ContextMenuData contextMenuData) { - addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); - final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); - addTargetWindow.setCaption(i18n.get("caption.update.rollout")); - UI.getCurrent().addWindow(addTargetWindow); - addTargetWindow.setVisible(Boolean.TRUE); - } - - private void refreshGrid() { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - - public final class FontIconGenerator extends PropertyValueGenerator { - - private static final long serialVersionUID = 2544026030795375748L; - private final FontAwesome fontIcon; - - public FontIconGenerator(FontAwesome icon) { - this.fontIcon = icon; - } - - @Override - public String getValue(Item item, Object itemId, Object propertyId) { - return fontIcon.getHtml(); - } - - @Override - public Class getType() { - return String.class; - } - } - - private String getDescription(CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (SPUILabelDefinitions.VAR_NAME.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } - - enum ACTION { - PAUSE, RESUME, START, UPDATE - } - - /** - * Represents data of context menu item. - * - */ - public static class ContextMenuData { - - private Long rolloutId; - - private ACTION action; - - /** - * Set rollout if and action. - * - * @param rolloutId - * id of rollout - * @param action - * user action {@link ACTION} - */ - public ContextMenuData(final Long rolloutId, final ACTION action) { - this.action = action; - this.rolloutId = rolloutId; - } - - /** - * @return the rolloutId - */ - public Long getRolloutId() { - return rolloutId; - } - - /** - * @param rolloutId - * the rolloutId to set - */ - public void setRolloutId(final Long rolloutId) { - this.rolloutId = rolloutId; - } - - /** - * @return the action - */ - public ACTION getAction() { - return action; - } - - /** - * @param action - * the action to set - */ - public void setAction(final ACTION action) { - this.action = action; - } - } - - /** - * - * Converter to convert {@link RolloutStatus} to string. - * - */ - class RolloutStatusConverter implements Converter { - - private static final long serialVersionUID = -1217685750825632678L; - - @Override - public RolloutStatus convertToModel(final String value, final Class targetType, - final Locale locale) { - return null; - } - - @Override - public String convertToPresentation(final RolloutStatus value, final Class targetType, - final Locale locale) { - return convertRolloutStatusToString(value); - } - - @Override - public Class getModelType() { - return RolloutStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - /** - * Converter to convert {@link TotalTargetCountStatus} to formatted string - * with status and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { - - private static final long serialVersionUID = -5794528427855153924L; - - @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } - - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } + private static final long serialVersionUID = 4060904914954370524L; + + private static final String UPDATE_OPTION = "Update"; + + private static final String RESUME_OPTION = "Resume"; + + private static final String PAUSE_OPTION = "Pause"; + + private static final String START_OPTION = "Start"; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + + @Override + @PostConstruct + protected void init() { + super.init(); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + switch (event) { + case FILTER_BY_TEXT: + case CREATE_ROLLOUT: + case UPDATE_ROLLOUT: + case SHOW_ROLLOUTS: + refreshGrid(); + break; + default: + return; + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the grid. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (!rolloutUIState.isShowRollOuts()) { + return; + } + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); + item.getItemProperty("customObject").setValue(new CustomObject(rollout.getName(), rollout.getStatus().toString())); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + /*if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + }*/ + final int groupsCreated = rollout.getRolloutGroupsCreated(); + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); + } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, null, false, false); + // rolloutGridContainer.addContainerProperty("yes", Boolean.class, null, + // false, false); + // rolloutGridContainer.addContainerProperty("custom", + // CustomValue.class, + // null, false, false); + // rolloutGridContainer.addContainerProperty("buttonText", String.class, + // "", false, false); + + rolloutGridContainer.addContainerProperty("customObject", CustomObject.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + getColumn("customObject").setMinimumWidth(40); + getColumn("customObject").setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + // getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption("name"); + getColumn("customObject").setHeaderCaption("Name"); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + // columnList.add("yes"); + columnList.add("customObject"); + // columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void setHiddenColumns() { + List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), + new TotalTargetGroupsConverter()); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + + createRolloutStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); + + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + + /////////////// + // getColumn("customObject").setRenderer(new CustomObjectRenderer(event + // -> onClickOfRolloutName(event))); + CustomObjectRenderer cor = new CustomObjectRenderer(CustomObject.class); + cor.addClickListener(event -> onClickOfRolloutName(event)); + getColumn("customObject").setRenderer(cor); + + /////////////////////// + + // getColumn("custom").setRenderer(new CheckboxRenderer()); + // getColumn("buttonText").setRenderer(new + // MyButtonRenderer(event->x())); + } + + private void createRolloutStatusToFontMap() { + statusIconMap.put(RolloutStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutStatus.PAUSED, + new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); + statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); + statusIconMap.put(RolloutStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutStatus.STOPPED, + new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); + statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); + statusIconMap.put(RolloutStatus.ERROR_CREATING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.ERROR_STARTING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + private void onClickOfRolloutName(RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + + // final String rolloutName = + CustomObject customObject = (CustomObject) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty("customObject").getValue(); + rolloutUIState.setRolloutName(customObject.getName()); + String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + + switch (rolloutStatus) { + case READY: + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + break; + case RUNNING: + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + break; + case PAUSED: + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + break; + case STARTING: + case CREATING: + case ERROR_CREATING: + case ERROR_STARTING: + // do not provide any action on these statuses + return context; + default: + break; + } + getUpdateMenuItem(context, rolloutId); + return context; + } + + private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { + // Add 'Update' option only if user has update permission + if (!permissionChecker.hasRolloutUpdatePermission()) { + return; + } + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + StatusFontIcon statusFontIcon = statusIconMap.get(value); + if (statusFontIcon == null) { + return null; + } + String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + switch (contextMenuData.getAction()) { + case PAUSE: + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + break; + case RESUME: + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + break; + case START: + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + break; + case UPDATE: + onUpdate(contextMenuData); + break; + default: + break; + } + } + + private void onUpdate(final ContextMenuData contextMenuData) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + + private void refreshGrid() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(Item item, Object itemId, Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if ("customObject".equals(cell.getPropertyId())) { + return ((CustomObject) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } + + enum ACTION { + PAUSE, RESUME, START, UPDATE + } + + /** + * Represents data of context menu item. + * + */ + public static class ContextMenuData { + + private Long rolloutId; + + private ACTION action; + + /** + * Set rollout if and action. + * + * @param rolloutId + * id of rollout + * @param action + * user action {@link ACTION} + */ + public ContextMenuData(final Long rolloutId, final ACTION action) { + this.action = action; + this.rolloutId = rolloutId; + } + + /** + * @return the rolloutId + */ + public Long getRolloutId() { + return rolloutId; + } + + /** + * @param rolloutId + * the rolloutId to set + */ + public void setRolloutId(final Long rolloutId) { + this.rolloutId = rolloutId; + } + + /** + * @return the action + */ + public ACTION getAction() { + return action; + } + + /** + * @param action + * the action to set + */ + public void setAction(final ACTION action) { + this.action = action; + } + } + + /** + * + * Converter to convert {@link RolloutStatus} to string. + * + */ + class RolloutStatusConverter implements Converter { + + private static final long serialVersionUID = -1217685750825632678L; + + @Override + public RolloutStatus convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, final Class targetType, + final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * Converter to convert {@link TotalTargetCountStatus} to formatted string + * with status and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { + + private static final long serialVersionUID = -5794528427855153924L; + + @Override + public TotalTargetCountStatus convertToModel(String value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(TotalTargetCountStatus value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * + * Converter to convert 0 to empty , if total target groups is zero. + * + */ + + class TotalTargetGroupsConverter implements Converter { + + private static final long serialVersionUID = 6589305227035220369L; + + @Override + public Long convertToModel(String value, Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(Long value, Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + if (value == 0) { + return ""; + } + return value.toString(); + } + + @Override + public Class getModelType() { + return Long.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index bb802c123..3033ff02c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; /** * Proxy rollout group with suctome properties. @@ -39,6 +40,16 @@ public class ProxyRolloutGroup extends RolloutGroup { private Boolean isActionRecieved = Boolean.FALSE; private String totalTargetsCount; + + private CustomObject customObject; + + public CustomObject getCustomObject() { + return customObject; + } + + public void setCustomObject(CustomObject customObject) { + this.customObject = customObject; + } /** * @return the createdDate diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 0dabb18fc..1902a7d9d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -121,6 +122,8 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessCondition(rolloutGroup.getSuccessCondition()); proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); + + proxyRolloutGroup.setCustomObject(new CustomObject(rolloutGroup.getName(), null)); proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 44d945efd..4fc023759 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -20,13 +20,15 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; import org.eclipse.hawkbit.repository.RolloutGroupManagement; +import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; -import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -47,6 +49,7 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Container; import com.vaadin.data.Item; +import com.vaadin.data.util.GeneratedPropertyContainer; import com.vaadin.data.util.converter.Converter; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; @@ -62,335 +65,392 @@ import com.vaadin.ui.renderers.HtmlRenderer; @SpringComponent @ViewScope public class RolloutGroupListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; + private static final long serialVersionUID = 4060904914954370524L; - @Autowired - private I18N i18n; + @Autowired + private I18N i18n; - @Autowired - private transient EventBus.SessionEventBus eventBus; + @Autowired + private transient EventBus.SessionEventBus eventBus; - @Autowired - private transient RolloutGroupManagement rolloutGroupManagement; + @Autowired + private transient RolloutGroupManagement rolloutGroupManagement; - @Autowired - private transient RolloutUIState rolloutUIState; + @Autowired + private transient RolloutManagement rolloutManagement; - @Autowired - private transient SpPermissionChecker permissionChecker; + @Autowired + private transient RolloutUIState rolloutUIState; - private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); + @Autowired + private transient SpPermissionChecker permissionChecker; - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } + private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } + private final String name = "name"; - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { - return; - } - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } + @Override + @PostConstruct + protected void init() { + super.init(); + eventBus.subscribe(this); + } - /** - * - * Handles the RolloutGroupChangeEvent to refresh the item in the grid. - * - * - * @param rolloutGroupChangeEvent - * the event which contains the rollout group which has been - * change - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { - if (!rolloutUIState.isShowRolloutGroups()) { - return; - } - final RolloutGroup rolloutGroup = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutGroup.getId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setValue(rolloutGroup.getTotalTargetCountStatus()); - } + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { + return; + } + getLazyQueryContainer().refresh(); + } - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, - String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, - null, false, false); + /** + * + * Handles the RolloutGroupChangeEvent to refresh the item in the grid. + * + * + * @param rolloutGroupChangeEvent + * the event which contains the rollout group which has been + * change + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { + if (!rolloutUIState.isShowRolloutGroups()) { + return; + } + final RolloutGroup rolloutGroup = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); + final LazyQueryContainer rolloutContainer = getLazyQueryContainer(); + final Item item = rolloutContainer.getItem(rolloutGroup.getId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(rolloutGroup.getTotalTargetCountStatus()); + item.getItemProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setValue(calculateFinishedPercentage(rolloutGroup)); + } - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, - false, false); + private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { + return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, + rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); + } - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); + return new GeneratedPropertyContainer(new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf)); + } - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupGridContainer = getLazyQueryContainer(); + rolloutGroupGridContainer.addContainerProperty("customObject", CustomObject.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, + null, false, false); - } + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, + false, false); - @Override - protected void setColumnExpandRatio() { - getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(200); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + // addGeneratedProperties(); + } - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + /* + * private void addGeneratedProperties() { GeneratedPropertyContainer + * generatedPropertyContainer = (GeneratedPropertyContainer) + * getContainerDataSource(); // + * generatedPropertyContainer.addGeneratedProperty(SPUILabelDefinitions. + * VAR_NAME, // new PropertyValueGenerator() { // + * private static final long serialVersionUID = -9203261132281441831L; // + * // @Override // public CustomRollOutDetails getValue(Item item, Object + * itemId, Object // propertyId) { // CustomRollOutDetails + * customRollOutDetails = new // CustomRollOutDetails(); // + * customRollOutDetails.setRolloutName( // (String) // + * item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue().toString() + * ); // return customRollOutDetails; // } // // @Override // public + * Class getType() { // return + * CustomRollOutDetails.class; // } // }); + * + * } + */ - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); + @Override + protected void setColumnExpandRatio() { + /*getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(200);*/ + + getColumn("customObject").setMinimumWidth(40); + getColumn("customObject").setMaximumWidth(200); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); - setFrozenColumnCount(7); - } + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); - @Override - protected void setColumnHeaderNames() { - getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) - .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - } + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; - } + setFrozenColumnCount(7); + } - @Override - protected void setColumnProperties() { - List columnList = new ArrayList<>(); - columnList.add(SPUILabelDefinitions.VAR_NAME); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } + @Override + protected void setColumnHeaderNames() { + //getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); + getColumn("customObject").setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + } - @Override - protected void addColumnRenderes() { - createRolloutGroupStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), - new RolloutGroupStatusConverter()); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - if (permissionChecker.hasRolloutTargetsReadPermission()) { - getColumn(SPUILabelDefinitions.VAR_NAME) - .setRenderer(new LinkRenderer(event -> onClickOfRolloutGroupName(event))); - } - } + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; + } - @Override - protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - } + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + columnList.add("customObject"); + //columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } + @Override + protected void addColumnRenderes() { + createRolloutGroupStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new RolloutGroupStatusConverter()); - private void onClickOfRolloutGroupName(RendererClickEvent event) { - rolloutUIState - .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); - } + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + if (permissionChecker.hasRolloutTargetsReadPermission()) { + /* + * getColumn(SPUILabelDefinitions.VAR_NAME) .setRenderer(new + * LinkRenderer(event -> onClickOfRolloutGroupName(event))); + */ + CustomObjectRenderer cor = new CustomObjectRenderer(CustomObject.class); + cor.addClickListener(event -> onClickOfRolloutGroupName(event)); + getColumn("customObject").setRenderer(cor); - private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + } + } - } + @Override + protected void setHiddenColumns() { + List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + } - private void createRolloutGroupStatusToFontMap() { - statusIconMap.put(RolloutGroupStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutGroupStatus.SCHEDULED, - new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); - statusIconMap.put(RolloutGroupStatus.RUNNING, - new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); - statusIconMap.put(RolloutGroupStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutGroupStatus.ERROR, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } - private String getDescription(CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (SPUILabelDefinitions.VAR_NAME.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } + private void onClickOfRolloutGroupName(RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + StatusFontIcon statusFontIcon = statusIconMap.get(value); + if (statusFontIcon == null) { + return null; + } + String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); - @Override - public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, - SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } + } - /** - * - * Converts {@link TotalTargetCountStatus} into formatted string with status - * and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { + private void createRolloutGroupStatusToFontMap() { + statusIconMap.put(RolloutGroupStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutGroupStatus.SCHEDULED, + new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); + statusIconMap.put(RolloutGroupStatus.RUNNING, + new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); + statusIconMap.put(RolloutGroupStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutGroupStatus.ERROR, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } - private static final long serialVersionUID = -9205943894818450807L; + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if ("customObject".equals(cell.getPropertyId())) { + return ((CustomObject) cell.getProperty().getValue()).getName(); + // getNameToolTip(cell.getProperty().getValue().toString()); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } - @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } + private String getNameToolTip(final String text) { + String[] nameList = text.split(":"); + if (nameList[0].equalsIgnoreCase(name)) { + return nameList[1]; + } + return ""; + } - @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } + @Override + public String getStyle(final CellReference cellReference) { + String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } - @Override - public Class getPresentationType() { - return String.class; - } - } + private LazyQueryContainer getLazyQueryContainer() { + return ((LazyQueryContainer) (((GeneratedPropertyContainer) getContainerDataSource()).getWrappedContainer())); + } - /** - * - * Converts {@link RolloutGroupStatus} to string. - * - */ - class RolloutGroupStatusConverter implements Converter { + /** + * + * Converts {@link TotalTargetCountStatus} into formatted string with status + * and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { - private static final long serialVersionUID = 5448062736373292820L; + private static final long serialVersionUID = -9205943894818450807L; - @Override - public RolloutGroupStatus convertToModel(final String value, - final Class targetType, final Locale locale) { - return null; - } + @Override + public TotalTargetCountStatus convertToModel(String value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } - @Override - public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, - final Locale locale) { - return convertRolloutGroupStatusToString(value); - } + @Override + public String convertToPresentation(TotalTargetCountStatus value, Class targetType, + Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } - @Override - public Class getModelType() { - return RolloutGroupStatus.class; - } + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } - @Override - public Class getPresentationType() { - return String.class; - } + @Override + public Class getPresentationType() { + return String.class; + } + } - } + /** + * + * Converts {@link RolloutGroupStatus} to string. + * + */ + class RolloutGroupStatusConverter implements Converter { + + private static final long serialVersionUID = 5448062736373292820L; + + @Override + public RolloutGroupStatus convertToModel(final String value, + final Class targetType, final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, + final Locale locale) { + return convertRolloutGroupStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutGroupStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss index 712e04ec1..b9049068e 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss @@ -19,20 +19,32 @@ } } + .v-context-menu .v-context-menu-item-basic-icon-container{ height:0px !important; width:0px !important; } - .v-context-menu, .v-context-menu .v-context-menu-item-basic{ + .v-context-menu .v-context-menu-item-basic{ background-color: #feffff !important; border-radius: 4px; + font-family : $app-font-family; + font-size : $app-text-font-size; + font-weight : normal; + font-style : normal; } + + .v-context-menu{ + background-color: #feffff !important; + border-radius: 4px; + } + .v-context-menu .v-context-menu-item-basic:focus, .v-context-menu .v-context-menu-item-basic-submenu:focus, .v-context-menu .v-context-menu-item-basic-open { @include valo-gradient($color: $hawkbit-primary-color); background-color: $hawkbit-primary-color !important; color: #e8eef3; + height: 30px; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.05); } @@ -77,5 +89,9 @@ border-left: $v-grid-border-size solid $widget-border-color ; } + .v-button-boldhide{ + text-decoration:none; + } + } \ No newline at end of file From ee0fc266780c0090244c7cfcf5e24c31d0b875fd Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 14:10:28 +0200 Subject: [PATCH 20/69] TTL Signed-off-by: SirWayne --- .../simulator/amqp/AmqpProperties.java | 14 ++++ .../hawkbit/amqp/AmqpConfiguration.java | 30 ++++---- .../amqp/AmqpDeadletterProperties.java | 69 +++++++++++++++++++ 3 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java index f58355980..8fba3ac5b 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java @@ -39,6 +39,12 @@ public class AmqpProperties { */ private String deadLetterExchange = "simulator.deadletter"; + /** + * Message time to live (ttl) for the deadletter queue. Default ttl is 1 + * hour. + */ + private int deadLetterTtl = 60_000; + public String getReceiverConnectorQueueFromSp() { return receiverConnectorQueueFromSp; } @@ -70,4 +76,12 @@ public class AmqpProperties { public void setSenderForSpExchange(final String senderForSpExchange) { this.senderForSpExchange = senderForSpExchange; } + + public int getDeadLetterTtl() { + return deadLetterTtl; + } + + public void setDeadLetterTtl(final int deadLetterTtl) { + this.deadLetterTtl = deadLetterTtl; + } } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java index acbcb453b..1e25e3717 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java @@ -8,9 +8,6 @@ */ package org.eclipse.hawkbit.amqp; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.BindingBuilder; @@ -31,15 +28,29 @@ import org.springframework.context.annotation.Bean; * {@code amqp} to use a AMQP for communication with SP enabled devices. * */ -@EnableConfigurationProperties(AmqpProperties.class) +@EnableConfigurationProperties({ AmqpProperties.class, AmqpDeadletterProperties.class }) public class AmqpConfiguration { @Autowired protected AmqpProperties amqpProperties; + @Autowired + protected AmqpDeadletterProperties amqpDeadletterProperties; + @Autowired private ConnectionFactory connectionFactory; + // /** + // * Method to set the Jackson2JsonMessageConverter. + // * + // * @return the Jackson2JsonMessageConverter + // */ + // @Bean + // public RabbitAdmin rabbitAdmin(final RabbitAdmin rabbitAdmin) { + // rabbitAdmin.setIgnoreDeclarationExceptions(true); + // return rabbitAdmin; + // } + /** * Method to set the Jackson2JsonMessageConverter. * @@ -59,7 +70,8 @@ public class AmqpConfiguration { */ @Bean public Queue receiverQueue() { - return new Queue(amqpProperties.getReceiverQueue(), true, false, false, getDeadLetterExchangeArgs()); + return new Queue(amqpProperties.getReceiverQueue(), true, false, false, + amqpDeadletterProperties.getDeadLetterExchangeArgs(amqpProperties.getDeadLetterExchange())); } /** @@ -79,7 +91,7 @@ public class AmqpConfiguration { */ @Bean public Queue deadLetterQueue() { - return new Queue(amqpProperties.getDeadLetterQueue()); + return amqpDeadletterProperties.createDeadletterQueue(amqpProperties.getDeadLetterQueue()); } /** @@ -149,10 +161,4 @@ public class AmqpConfiguration { return containerFactory; } - private Map getDeadLetterExchangeArgs() { - final Map args = new HashMap<>(); - args.put("x-dead-letter-exchange", amqpProperties.getDeadLetterExchange()); - return args; - } - } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java new file mode 100644 index 000000000..8e988ff16 --- /dev/null +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java @@ -0,0 +1,69 @@ +/** + * 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.amqp; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.amqp.core.Queue; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Bean which holds the necessary properties for configuring the AMQP deadletter + * queue. + */ +@ConfigurationProperties("hawkbit.dmf.rabbitmq.deadLetter") +public class AmqpDeadletterProperties { + + /** + * Message time to live (ttl) for the deadletter queue. Default ttl is 3 + * weeks. + */ + private int ttl = 1_814_400_000; + + /** + * Return the deadletter arguments. + * + * @param exchange + * the deadletter exchange + * @return map which holds the properties + */ + public Map getDeadLetterExchangeArgs(final String exchange) { + final Map args = new HashMap<>(); + args.put("x-dead-letter-exchange", exchange); + return args; + } + + /** + * Create a deadletter queue with ttl for messages + * + * @param queueName + * the deadlette queue name + * @return the deadletter queue + */ + public Queue createDeadletterQueue(final String queueName) { + // getTTLArgs() + return new Queue(queueName, true, false, false, null); + } + + private Map getTTLArgs() { + final Map args = new HashMap<>(); + args.put("x-message-ttl", getTtl()); + return args; + } + + public int getTtl() { + return ttl; + } + + public void setTtl(final int ttl) { + this.ttl = ttl; + } + +} From b95b9c1ce6e52689fb68db0a64ffb0df0cde1a03 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 14:20:27 +0200 Subject: [PATCH 21/69] Move @SuppressWarnings("unchecked") to the right line and remove unused attributes Signed-off-by: SirWayne --- .../ui/distributions/dstable/DistributionSetTable.java | 7 +------ .../ui/management/event/DistributionTagDropEvent.java | 4 +--- .../hawkbit/ui/management/footer/DeleteActionsLayout.java | 4 ++-- .../hawkbit/ui/management/targettable/TargetTable.java | 6 +++--- .../ui/management/targettable/TargetTableHeader.java | 3 +-- .../ui/management/targettag/TargetTagFilterButtons.java | 4 +--- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index b5d614243..4a7b74ece 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -209,9 +209,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable source = (AbstractTable) transferable.getSourceComponent(); final Set softwareModulesIdList = source.getDeletedEntityByTransferable(transferable); @@ -224,11 +224,6 @@ public class DistributionSetTable extends AbstractNamedVersionTable softwareModulesIdList, final Item item) { final Long distId = (Long) item.getItemProperty("id").getValue(); final String distName = (String) item.getItemProperty("name").getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java index 97ba7ea6c..2b6acbf68 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java @@ -68,8 +68,6 @@ public class DistributionTagDropEvent implements DropHandler { @Autowired private ManagementViewAcceptCriteria managementViewAcceptCriteria; - private static final String ITEMID = "itemId"; - @Override public void drop(final DragAndDropEvent event) { if (validate(event) && isNoTagAssigned(event)) { @@ -127,12 +125,12 @@ public class DistributionTagDropEvent implements DropHandler { return true; } - @SuppressWarnings("unchecked") private void processDistributionDrop(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); + @SuppressWarnings("unchecked") final AbstractTable source = (AbstractTable) transferable .getSourceComponent(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 0466e6076..7db48636b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -256,8 +256,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } } - @SuppressWarnings("unchecked") private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { + @SuppressWarnings("unchecked") final AbstractTable distTable = (AbstractTable) sourceTable; final Set distributionIdNameSet = distTable.getDeletedEntityByTransferable(transferable); @@ -305,8 +305,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { return false; } - @SuppressWarnings("unchecked") private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { + @SuppressWarnings("unchecked") final AbstractTable targetTable = (AbstractTable) sourceTable; final Set targetIdNameSet = targetTable.getDeletedEntityByTransferable(transferable); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 1307e27d3..3b9c18952 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -107,7 +107,6 @@ public class TargetTable extends AbstractTable implements private static final long serialVersionUID = -2300392868806614568L; private static final int PROPERTY_DEPT = 3; - private static final String ITEMID = "itemId"; private static final String ACTION_NOT_ALLOWED_MSG = "message.action.not.allowed"; @Autowired @@ -632,9 +631,9 @@ public class TargetTable extends AbstractTable implements return true; } - @SuppressWarnings("unchecked") private static Set getDraggedDistributionSet(final TableTransferable transferable, final Table source) { + @SuppressWarnings("unchecked") final AbstractTable distTable = (AbstractTable) source; return distTable.getDeletedEntityByTransferable(transferable); } @@ -853,6 +852,7 @@ public class TargetTable extends AbstractTable implements eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.REFRESH_TARGETS)); } + @SuppressWarnings("unchecked") private void updateVisibleItemOnEvent(final TargetInfo targetInfo, final Target target, final TargetIdName targetIdName) { final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource(); @@ -875,8 +875,8 @@ public class TargetTable extends AbstractTable implements * @param targetInfoUpdateEvents * list of target info update event */ - @SuppressWarnings("unchecked") private void onTargetInfoUpdateEvents(final List targetInfoUpdateEvents) { + @SuppressWarnings("unchecked") final List visibleItemIds = (List) getVisibleItemIds(); boolean shoulTargetsUpdated = false; Target lastSelectedTarget = null; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index 158d57878..09c9bf499 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.targettable; -import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; @@ -378,8 +377,8 @@ public class TargetTableHeader extends AbstractTableHeader { return isValid; } - @SuppressWarnings("unchecked") private Set getDropppedDistributionDetails(final TableTransferable transferable) { + @SuppressWarnings("unchecked") final AbstractTable distTable = (AbstractTable) transferable.getSourceComponent(); return distTable.getDeletedEntityByTransferable(transferable); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 671d332de..4d96a4b7a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -78,8 +78,6 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { @Autowired private transient TargetManagement targetManagement; - private static final String ITEMID = "itemId"; - TargetTagFilterButtonClick filterButtonClickBehaviour; /** @@ -211,10 +209,10 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { return true; } - @SuppressWarnings("unchecked") private void processTargetDrop(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails targetDetails = event.getTargetDetails(); final TableTransferable transferable = (TableTransferable) event.getTransferable(); + @SuppressWarnings("unchecked") final AbstractTable targetTable = (AbstractTable) transferable .getSourceComponent(); From f70120d5461959e0fa7abc0bb4382e17885341f1 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 15:36:14 +0200 Subject: [PATCH 22/69] Set the id after the update Signed-off-by: SirWayne --- .../hawkbit/ui/distributions/dstable/DistributionSetTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 4e6be369d..998cd1de2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -471,9 +471,9 @@ public class DistributionSetTable extends AbstractNamedVersionTable Date: Wed, 13 Apr 2016 15:47:08 +0200 Subject: [PATCH 23/69] Version should be set after id Signed-off-by: SirWayne --- .../hawkbit/ui/common/table/AbstractNamedVersionTable.java | 2 +- .../hawkbit/ui/distributions/dstable/DistributionSetTable.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java index b14c69a51..3e215f77c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java @@ -40,8 +40,8 @@ public abstract class AbstractNamedVersionTable Date: Wed, 13 Apr 2016 16:52:12 +0200 Subject: [PATCH 24/69] Refactoring: Extract some staff to private methods Signed-off-by: SirWayne --- .../footer/DeleteActionsLayout.java | 51 +++++++------------ .../targettag/TargetTagFilterButtons.java | 32 +++++++++--- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 7db48636b..5435a8f74 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -270,27 +270,20 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { if (distributionIdNameSet.isEmpty()) { return; } - /* - * Flags to identify whether all dropped distributions are already in - * the deleted list (or) some distributions are already in the deleted - * distribution list. - */ + checkDeletedDistributionSets(distributionIdNameSet); + } + + private void checkDeletedDistributionSets(final Set distributionIdNameSet) { final int existingDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); + if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { - /* - * No new distributions are added, all distributions dropped now are - * already available in the delete list. Hence display warning - * message accordingly. - */ notification.displayValidationError(i18n.get("message.targets.already.deleted")); - } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { - /* - * Not the all distributions dropped now are added to the delete - * list. There are some distributions are already there in the - * delete list. Hence display warning message accordingly. - */ + return; + } + + if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { notification.displayValidationError(i18n.get("message.dist.deleted.pending")); } } @@ -310,28 +303,22 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { final AbstractTable targetTable = (AbstractTable) sourceTable; final Set targetIdNameSet = targetTable.getDeletedEntityByTransferable(transferable); - /* - * Flags to identify whether all dropped targets are already in the - * deleted list (or) some target are already in the deleted distribution - * list. - */ + checkDeletedTargets(targetIdNameSet); + } + + private void checkDeletedTargets(final Set targetIdNameSet) { final int existingDeletedTargetsSize = managementUIState.getDeletedTargetList().size(); managementUIState.getDeletedTargetList().addAll(targetIdNameSet); final int newDeletedTargetsSize = managementUIState.getDeletedTargetList().size(); + if (newDeletedTargetsSize == existingDeletedTargetsSize) { - /* - * No new targets are added, all targets dropped now are already - * available in the delete list. Hence display warning message - * accordingly. - */ notification.displayValidationError(i18n.get("message.targets.already.deleted")); - } else if (newDeletedTargetsSize - existingDeletedTargetsSize != targetIdNameSet.size()) { - /* - * Not the all targets dropped now are added to the delete list. - * There are some targets are already there in the delete list. - * Hence display warning message accordingly. - */ + return; + } + + if (newDeletedTargetsSize - existingDeletedTargetsSize != targetIdNameSet.size()) { notification.displayValidationError(i18n.get("message.target.deleted.pending")); + return; } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 4d96a4b7a..4e5246703 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -223,18 +223,33 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { final String targTagName = HawkbitCommonUtil.removePrefix(targetDetails.getTarget().getId(), SPUIDefinitions.TARGET_TAG_ID_PREFIXS); - final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); - final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); - if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { - eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); - } - if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() && tagsClickedList.contains(targTagName)) { - eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); - } + publishAssignTargetTagEvent(result); + publishUnAssignTargetTagEvent(targTagName, result); + + } + + private void publishUnAssignTargetTagEvent(final String targTagName, final TargetTagAssignmentResult result) { + final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); + final boolean isTargetTagUnAssigned = result.getUnassigned() >= 1 && !tagsClickedList.isEmpty() + && tagsClickedList.contains(targTagName); + + if (!isTargetTagUnAssigned) { + return; + } + eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); + } + + private void publishAssignTargetTagEvent(final TargetTagAssignmentResult result) { + final boolean isNewTargetTagAssigned = result.getAssigned() >= 1 + && managementUIState.getTargetTableFilters().isNoTagSelected(); + if (!isNewTargetTagAssigned) { + return; + } + eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); } private boolean validateIfSourceisTargetTable(final Table source) { @@ -281,6 +296,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { } } + @SuppressWarnings("unchecked") private void addNewTargetTag(final TargetTag newTargetTag) { final LazyQueryContainer targetTagContainer = (LazyQueryContainer) getContainerDataSource(); final Object addItem = targetTagContainer.addItem(); From 30ba98ff8e2d7fa7386460bfa2e25fa47dba2c52 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 17:27:49 +0200 Subject: [PATCH 25/69] TTL Signed-off-by: SirWayne --- .../eclipse/hawkbit/amqp/AmqpConfiguration.java | 17 +++++++---------- .../hawkbit/amqp/AmqpDeadletterProperties.java | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java index 1e25e3717..448206924 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java @@ -15,6 +15,7 @@ import org.springframework.amqp.core.FanoutExchange; import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; @@ -40,16 +41,12 @@ public class AmqpConfiguration { @Autowired private ConnectionFactory connectionFactory; - // /** - // * Method to set the Jackson2JsonMessageConverter. - // * - // * @return the Jackson2JsonMessageConverter - // */ - // @Bean - // public RabbitAdmin rabbitAdmin(final RabbitAdmin rabbitAdmin) { - // rabbitAdmin.setIgnoreDeclarationExceptions(true); - // return rabbitAdmin; - // } + @Bean + public RabbitAdmin rabbitAdmin() { + final RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); + rabbitAdmin.setIgnoreDeclarationExceptions(true); + return rabbitAdmin; + } /** * Method to set the Jackson2JsonMessageConverter. diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java index 8e988ff16..e9ad60a1c 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java @@ -48,8 +48,7 @@ public class AmqpDeadletterProperties { * @return the deadletter queue */ public Queue createDeadletterQueue(final String queueName) { - // getTTLArgs() - return new Queue(queueName, true, false, false, null); + return new Queue(queueName, true, false, false, getTTLArgs()); } private Map getTTLArgs() { From 4b6a6a4a4aadad54e374601308d94f7ae78aaf0c Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 13 Apr 2016 17:37:55 +0200 Subject: [PATCH 26/69] Refactoring: Extract some staff to private methods and remove duplicated code Signed-off-by: SirWayne --- .../footer/DeleteActionsLayout.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 5435a8f74..ad537e626 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -278,14 +278,27 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { managementUIState.getDeletedDistributionList().addAll(distributionIdNameSet); final int newDeletedDistributionsSize = managementUIState.getDeletedDistributionList().size(); - if (newDeletedDistributionsSize == existingDeletedDistributionsSize) { - notification.displayValidationError(i18n.get("message.targets.already.deleted")); + showAlreadyDeletedDistributionSetNotfication(existingDeletedDistributionsSize, newDeletedDistributionsSize, + "message.dists.already.deleted"); + showPendingDeletedNotifaction(distributionIdNameSet, existingDeletedDistributionsSize, + newDeletedDistributionsSize, "message.dist.deleted.pending"); + } + + private void showPendingDeletedNotifaction(final Set currentValues, final int existingDeletedSize, + final int newDeletedSize, final String messageKey) { + if (newDeletedSize - existingDeletedSize == currentValues.size()) { return; } + notification.displayValidationError(i18n.get(messageKey)); + } - if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { - notification.displayValidationError(i18n.get("message.dist.deleted.pending")); + private void showAlreadyDeletedDistributionSetNotfication(final int existingDeletedSize, final int newDeletedSize, + final String messageKey) { + + if (newDeletedSize != existingDeletedSize) { + return; } + notification.displayValidationError(i18n.get(messageKey)); } private boolean isDsInUseInBulkUpload(final Set distributionIdNameSet, @@ -311,15 +324,11 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { managementUIState.getDeletedTargetList().addAll(targetIdNameSet); final int newDeletedTargetsSize = managementUIState.getDeletedTargetList().size(); - if (newDeletedTargetsSize == existingDeletedTargetsSize) { - notification.displayValidationError(i18n.get("message.targets.already.deleted")); - return; - } + showAlreadyDeletedDistributionSetNotfication(existingDeletedTargetsSize, newDeletedTargetsSize, + "message.targets.already.deleted"); - if (newDeletedTargetsSize - existingDeletedTargetsSize != targetIdNameSet.size()) { - notification.displayValidationError(i18n.get("message.target.deleted.pending")); - return; - } + showPendingDeletedNotifaction(targetIdNameSet, existingDeletedTargetsSize, newDeletedTargetsSize, + "message.target.deleted.pending"); } private void updateActionCount() { From fc693f099451a69e48f5688d99474c337dddfc2f Mon Sep 17 00:00:00 2001 From: Asharani Murugesh Date: Thu, 14 Apr 2016 09:54:56 +0530 Subject: [PATCH 27/69] Corrected the typo as per review comment --- hawkbit-ui/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/README.md b/hawkbit-ui/README.md index f8e020648..e1c7d8ffc 100644 --- a/hawkbit-ui/README.md +++ b/hawkbit-ui/README.md @@ -3,7 +3,7 @@ The application with user interface to create and manage rollouts. ## Debugging client-side code -### Debug usings SuperDevMode +### Debug using SuperDevMode The SuperDevMode can be used to debug client side code without any browser plugin. #### Using SuperDevMode with chrome : @@ -31,4 +31,4 @@ The SuperDevMode can be used to debug client side code without any browser plugi - Type is "Launch Chrome" - http://localhost:8080/UI/?superdevmode - Launch the new configuration in debug mode -- Now breakpoints in eclipse can be set \ No newline at end of file +- Now breakpoints in eclipse can be set From c8e88239c2201c9940999b5e21548ffaa3472904 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Thu, 14 Apr 2016 14:49:49 +0530 Subject: [PATCH 28/69] Rollout management issues Signed-off-by: venu1278 --- .../client/CustomObjectRendererConnector.java | 9 +++++++++ .../customrenderers/client/renderers/CustomObject.java | 8 ++++++++ .../client/renderers/CustomObjectRenederer.java | 8 ++++++++ .../customrenderers/renderers/CustomObjectRenderer.java | 9 +++++++++ 4 files changed, 34 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java index b209ab82c..c79e81924 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java @@ -1,3 +1,12 @@ +/** + * 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.customrenderers.client; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java index 85b5d9404..f3a5c74c4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObject.java @@ -1,3 +1,11 @@ +/** + * 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.customrenderers.client.renderers; import java.io.Serializable; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java index a6a527f2a..7931e9f84 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -1,3 +1,11 @@ +/** + * 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.customrenderers.client.renderers; import com.google.gwt.core.shared.GWT; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java index c2a7606a3..ae555f897 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java @@ -1,3 +1,12 @@ +/** + * 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.customrenderers.renderers; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; From 2ca807916c0b5101dcb04396d0f5a2bf73f5043d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 14 Apr 2016 13:32:24 +0200 Subject: [PATCH 29/69] fix lookup by filename and not by ID because the ID is unique and the filename exists multiple times Signed-off-by: Michael Hirsch --- .../repository/specifications/ActionSpecifications.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java index 1ac3afb67..62e7167f1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java @@ -53,7 +53,8 @@ public class ActionSpecifications { final Join dsJoin = actionRoot.join(Action_.distributionSet); final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); - return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.id), localArtifact.getId()), + return criteriaBuilder.and( + criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.filename), localArtifact.getFilename()), criteriaBuilder.equal(actionRoot.get(Action_.target), target)); }; } From b9c389d8dbb93449b1a1a63e52f1b94ab175cbf9 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Fri, 15 Apr 2016 15:22:16 +0530 Subject: [PATCH 30/69] Rollout management issues Signed-off-by: venu1278 --- .../renderers/CustomObjectRenederer.java | 5 + .../renderers/CustomObjectRenderer.java | 20 +- .../ui/rollout/rollout/ProxyRollout.java | 2 +- .../ui/rollout/rollout/RolloutListGrid.java | 11 +- .../rolloutgroup/ProxyRolloutGroup.java | 316 +++++++++--------- 5 files changed, 187 insertions(+), 167 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java index 7931e9f84..262648178 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -13,6 +13,11 @@ import com.vaadin.client.renderers.ClickableRenderer; import com.vaadin.client.ui.VButton; import com.vaadin.client.widget.grid.RendererCellReference; +/** + * Renders button with provided CustomObject. + * Used to display button with link. + * + */ public class CustomObjectRenederer extends ClickableRenderer { @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java index ae555f897..02eca1bf9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/CustomObjectRenderer.java @@ -15,26 +15,36 @@ import com.vaadin.ui.renderers.ClickableRenderer; import elemental.json.JsonValue; +/** + * Renders button with provided CustomObject. + * Used to display button with link. + * + */ + public class CustomObjectRenderer extends ClickableRenderer { - /** - * - */ private static final long serialVersionUID = -8754180585906263554L; /** - * Creates a new image renderer. + * Creates a new custom object renderer. */ public CustomObjectRenderer() { super(CustomObject.class, null); } + + /** + * Initialize custom object renderer with {@link Class} + * + * @param presentationType + * Class + */ public CustomObjectRenderer(Class presentationType) { super(presentationType); } /** - * Creates a new image renderer and adds the given click listener to it. + * Creates a new custom object renderer and adds the given click listener to it. * * @param listener * the click listener to register diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 36cb7ddee..6649d7dcb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -14,7 +14,7 @@ import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; import com.vaadin.server.FontAwesome; /** - * Proxy rollout with suctome properties. + * Proxy rollout with custom properties. * */ public class ProxyRollout extends Rollout { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index f8da4b269..65f94aee6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -97,6 +97,10 @@ public class RolloutListGrid extends AbstractGrid { private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + /** + * Handles the RolloutEvent to refresh Grid. + * + */ @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final RolloutEvent event) { switch (event) { @@ -419,6 +423,9 @@ public class RolloutListGrid extends AbstractGrid { ((LazyQueryContainer) getContainerDataSource()).refresh(); } + /** + * Generator to generate fontIcon by String. + */ public final class FontIconGenerator extends PropertyValueGenerator { private static final long serialVersionUID = 2544026030795375748L; @@ -585,11 +592,9 @@ public class RolloutListGrid extends AbstractGrid { } /** - * - * Converter to convert 0 to empty , if total target groups is zero. + * Converter to convert 0 to empty, if total target groups is zero. * */ - class TotalTargetGroupsConverter implements Converter { private static final long serialVersionUID = 6589305227035220369L; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 3033ff02c..71fe2aa8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -12,36 +12,36 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; /** - * Proxy rollout group with suctome properties. + * Proxy rollout group with custom properties. * */ public class ProxyRolloutGroup extends RolloutGroup { - private static final long serialVersionUID = -2745056813306692356L; + private static final long serialVersionUID = -2745056813306692356L; - private String createdDate; + private String createdDate; - private String modifiedDate; + private String modifiedDate; - private String finishedPercentage; + private String finishedPercentage; - private Long runningTargetsCount; + private Long runningTargetsCount; - private Long scheduledTargetsCount; + private Long scheduledTargetsCount; - private Long cancelledTargetsCount; + private Long cancelledTargetsCount; - private Long errorTargetsCount; + private Long errorTargetsCount; - private Long finishedTargetsCount; + private Long finishedTargetsCount; - private Long notStartedTargetsCount; + private Long notStartedTargetsCount; - private Boolean isActionRecieved = Boolean.FALSE; + private Boolean isActionRecieved = Boolean.FALSE; - private String totalTargetsCount; - - private CustomObject customObject; + private String totalTargetsCount; + + private CustomObject customObject; public CustomObject getCustomObject() { return customObject; @@ -51,169 +51,169 @@ public class ProxyRolloutGroup extends RolloutGroup { this.customObject = customObject; } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @return the modifiedDate - */ - public String getModifiedDate() { - return modifiedDate; - } + /** + * @return the modifiedDate + */ + public String getModifiedDate() { + return modifiedDate; + } - /** - * @param modifiedDate - * the modifiedDate to set - */ - public void setModifiedDate(final String modifiedDate) { - this.modifiedDate = modifiedDate; - } + /** + * @param modifiedDate + * the modifiedDate to set + */ + public void setModifiedDate(final String modifiedDate) { + this.modifiedDate = modifiedDate; + } - /** - * @return the finishedPercentage - */ - public String getFinishedPercentage() { - return finishedPercentage; - } + /** + * @return the finishedPercentage + */ + public String getFinishedPercentage() { + return finishedPercentage; + } - /** - * @param finishedPercentage - * the finishedPercentage to set - */ - public void setFinishedPercentage(final String finishedPercentage) { - this.finishedPercentage = finishedPercentage; - } + /** + * @param finishedPercentage + * the finishedPercentage to set + */ + public void setFinishedPercentage(final String finishedPercentage) { + this.finishedPercentage = finishedPercentage; + } - /** - * @return the runningTargetsCount - */ - public Long getRunningTargetsCount() { - return runningTargetsCount; - } + /** + * @return the runningTargetsCount + */ + public Long getRunningTargetsCount() { + return runningTargetsCount; + } - /** - * @param runningTargetsCount - * the runningTargetsCount to set - */ - public void setRunningTargetsCount(final Long runningTargetsCount) { - this.runningTargetsCount = runningTargetsCount; - } + /** + * @param runningTargetsCount + * the runningTargetsCount to set + */ + public void setRunningTargetsCount(final Long runningTargetsCount) { + this.runningTargetsCount = runningTargetsCount; + } - /** - * @return the scheduledTargetsCount - */ - public Long getScheduledTargetsCount() { - return scheduledTargetsCount; - } + /** + * @return the scheduledTargetsCount + */ + public Long getScheduledTargetsCount() { + return scheduledTargetsCount; + } - /** - * @param scheduledTargetsCount - * the scheduledTargetsCount to set - */ - public void setScheduledTargetsCount(final Long scheduledTargetsCount) { - this.scheduledTargetsCount = scheduledTargetsCount; - } + /** + * @param scheduledTargetsCount + * the scheduledTargetsCount to set + */ + public void setScheduledTargetsCount(final Long scheduledTargetsCount) { + this.scheduledTargetsCount = scheduledTargetsCount; + } - /** - * @return the cancelledTargetsCount - */ - public Long getCancelledTargetsCount() { - return cancelledTargetsCount; - } + /** + * @return the cancelledTargetsCount + */ + public Long getCancelledTargetsCount() { + return cancelledTargetsCount; + } - /** - * @param cancelledTargetsCount - * the cancelledTargetsCount to set - */ - public void setCancelledTargetsCount(final Long cancelledTargetsCount) { - this.cancelledTargetsCount = cancelledTargetsCount; - } + /** + * @param cancelledTargetsCount + * the cancelledTargetsCount to set + */ + public void setCancelledTargetsCount(final Long cancelledTargetsCount) { + this.cancelledTargetsCount = cancelledTargetsCount; + } - /** - * @return the errorTargetsCount - */ - public Long getErrorTargetsCount() { - return errorTargetsCount; - } + /** + * @return the errorTargetsCount + */ + public Long getErrorTargetsCount() { + return errorTargetsCount; + } - /** - * @param errorTargetsCount - * the errorTargetsCount to set - */ - public void setErrorTargetsCount(final Long errorTargetsCount) { - this.errorTargetsCount = errorTargetsCount; - } + /** + * @param errorTargetsCount + * the errorTargetsCount to set + */ + public void setErrorTargetsCount(final Long errorTargetsCount) { + this.errorTargetsCount = errorTargetsCount; + } - /** - * @return the finishedTargetsCount - */ - public Long getFinishedTargetsCount() { - return finishedTargetsCount; - } + /** + * @return the finishedTargetsCount + */ + public Long getFinishedTargetsCount() { + return finishedTargetsCount; + } - /** - * @param finishedTargetsCount - * the finishedTargetsCount to set - */ - public void setFinishedTargetsCount(final Long finishedTargetsCount) { - this.finishedTargetsCount = finishedTargetsCount; - } + /** + * @param finishedTargetsCount + * the finishedTargetsCount to set + */ + public void setFinishedTargetsCount(final Long finishedTargetsCount) { + this.finishedTargetsCount = finishedTargetsCount; + } - /** - * @return the notStartedTargetsCount - */ - public Long getNotStartedTargetsCount() { - return notStartedTargetsCount; - } + /** + * @return the notStartedTargetsCount + */ + public Long getNotStartedTargetsCount() { + return notStartedTargetsCount; + } - /** - * @param notStartedTargetsCount - * the notStartedTargetsCount to set - */ - public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { - this.notStartedTargetsCount = notStartedTargetsCount; - } + /** + * @param notStartedTargetsCount + * the notStartedTargetsCount to set + */ + public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { + this.notStartedTargetsCount = notStartedTargetsCount; + } - /** - * @return the isActionRecieved - */ - public Boolean getIsActionRecieved() { - return isActionRecieved; - } + /** + * @return the isActionRecieved + */ + public Boolean getIsActionRecieved() { + return isActionRecieved; + } - /** - * @param isActionRecieved - * the isActionRecieved to set - */ - public void setIsActionRecieved(final Boolean isActionRecieved) { - this.isActionRecieved = isActionRecieved; - } + /** + * @param isActionRecieved + * the isActionRecieved to set + */ + public void setIsActionRecieved(final Boolean isActionRecieved) { + this.isActionRecieved = isActionRecieved; + } - /** - * @return the totalTargetsCount - */ - public String getTotalTargetsCount() { - return totalTargetsCount; - } + /** + * @return the totalTargetsCount + */ + public String getTotalTargetsCount() { + return totalTargetsCount; + } - /** - * @param totalTargetsCount - * the totalTargetsCount to set - */ - public void setTotalTargetsCount(final String totalTargetsCount) { - this.totalTargetsCount = totalTargetsCount; - } + /** + * @param totalTargetsCount + * the totalTargetsCount to set + */ + public void setTotalTargetsCount(final String totalTargetsCount) { + this.totalTargetsCount = totalTargetsCount; + } } From 536098c4c786752256e29aaacece0f7d11aa5acb Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 15 Apr 2016 17:40:03 +0200 Subject: [PATCH 31/69] Load and format the user details by a user detail formatter Signed-off-by: SirWayne --- .../smtable/BaseSwModuleBeanQuery.java | 5 +- .../ui/common/UserDetailsFormatter.java | 170 ++++++++++++++++++ .../AbstractTableDetailsLayout.java | 40 ++--- .../ui/common/table/AbstractTable.java | 6 +- .../dstable/ManageDistBeanQuery.java | 5 +- .../smtable/SwModuleBeanQuery.java | 5 +- .../CustomTargetBeanQuery.java | 5 +- .../TargetFilterBeanQuery.java | 5 +- .../dstable/DistributionBeanQuery.java | 5 +- .../targettable/TargetBeanQuery.java | 5 +- .../management/targettable/TargetTable.java | 3 +- .../hawkbit/ui/menu/DashboardMenu.java | 65 ++----- .../rollout/DistributionBeanQuery.java | 12 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 14 +- .../rolloutgroup/RolloutGroupBeanQuery.java | 5 +- .../RolloutGroupTargetsBeanQuery.java | 5 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 53 ------ .../hawkbit/ui/utils/SPDateTimeUtil.java | 23 ++- .../themes/hawkbit/customstyles/common.scss | 6 + 19 files changed, 272 insertions(+), 165 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index bb48c515a..29bea30eb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -101,8 +102,8 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery + */ + public static String loadAndFormatUsername(final String username) { + return loadAndFormatUsername(username, 50); + } + + /** + * Load user details by {@link BaseEntity#getCreatedBy()} and format the + * user name. Use {@link UserDetailsFormatter#loadAndFormatUsername(String)} + * + * @param baseEntity + * the entity + * @return the formatted 'created at user name' (max 100 characters) cannot + * be + */ + public static String loadAndFormatCreatedBy(final BaseEntity baseEntity) { + if (baseEntity == null || baseEntity.getCreatedBy() == null) { + return StringUtils.EMPTY; + } + + return loadAndFormatUsername(baseEntity.getCreatedBy()); + } + + /** + * Load user details by {@link BaseEntity#getLastModifiedBy()} and format + * the user name. Use + * {@link UserDetailsFormatter#loadAndFormatUsername(String)} + * + * @param baseEntity + * the entity + * @return the formatted 'last modefied by user name' (max 100 characters) + * cannot be + */ + public static String loadAndFormatLastModifiedBy(final BaseEntity baseEntity) { + if (baseEntity == null || baseEntity.getLastModifiedBy() == null) { + return StringUtils.EMPTY; + } + + return loadAndFormatUsername(baseEntity.getLastModifiedBy()); + } + + /** + * Load user details by the current session information and format the user + * name to max 12 characters. @see + * {@link UserDetailsFormatter#loadAndFormatUsername(String, int)} + * + * @param baseEntity + * the entity + * @return the formatted user name (max 12 characters) cannot be + */ + public static String loadAndFormatCurrentUsername() { + return loadAndFormatUsername(getCurrentUser().getUsername(), 6); + } + + /** + * Load user details by the user name and format the user name. If the + * loaded {@link UserDetails} is not a instance of a {@link UserPrincipal}, + * then just the {@link UserDetails#getUsername()} will return. + * + * If first and last name available, they will combined. Otherwise the + * {@link UserPrincipal#getLoginname()} will formatted. The formatted name + * is reduced to 100 characters. + * + * @param username + * the user name + * @param expectedNameLength + * the name size of each name part + * @return the formatted user name (max 2 * expectedNameLength characters) + * cannot be + */ + public static String loadAndFormatUsername(final String username, final int expectedNameLength) { + final UserDetails userDetails = loadUserByUsername(username); + if (!(userDetails instanceof UserPrincipal)) { + return userDetails.getUsername(); + } + + final UserPrincipal userPrincipal = (UserPrincipal) userDetails; + + final String trimmedFirstname = trimAndFormatDetail(userPrincipal.getFirstname(), expectedNameLength); + final String trimmedLastname = trimAndFormatDetail(userPrincipal.getLastname(), expectedNameLength); + + if (StringUtils.isEmpty(trimmedFirstname) && StringUtils.isEmpty(trimmedLastname)) { + return StringUtils.substring(userPrincipal.getLoginname(), 0, 2 * expectedNameLength); + } + return trimmedFirstname + DETAIL_SEPERATOR + trimmedLastname; + } + + /** + * Format the current tenant. The information is loaded by the current + * session information. + * + * @return the formatted user name (max 8 characters) can be + */ + public static String formatCurrentTenant() { + final UserDetails userDetails = getCurrentUser(); + if (!(userDetails instanceof UserPrincipal)) { + return null; + } + + final UserPrincipal userPrincipal = (UserPrincipal) userDetails; + return trimAndFormatDetail(userPrincipal.getTenant(), 8); + } + + private static UserDetails getCurrentUser() { + final SecurityContext context = (SecurityContext) VaadinService.getCurrentRequest().getWrappedSession() + .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); + return (UserDetails) context.getAuthentication().getPrincipal(); + } + + private static String trimAndFormatDetail(final String formatString, final int expectedDetailLength) { + final String detail = StringUtils.defaultIfEmpty(formatString, StringUtils.EMPTY); + final String trimmedDetail = StringUtils.substring(detail, 0, expectedDetailLength); + if (StringUtils.length(detail) > expectedDetailLength) { + return trimmedDetail + TRIM_APPENDIX; + } + return trimmedDetail; + } + + private static UserDetails loadUserByUsername(final String username) { + final UserDetailsService userDetailsService = SpringContextHelper.getBean(UserDetailsService.class); + try { + final UserDetails loadUserByUsername = userDetailsService.loadUserByUsername(username); + if (loadUserByUsername == null) { + throw new UsernameNotFoundException("User not found " + username); + } + return loadUserByUsername; + } catch (final UsernameNotFoundException e) { // NOSONAR + } + return new User(username, "", Collections.emptyList()); + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 969436904..b2df26179 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -213,22 +214,24 @@ public abstract class AbstractTableDetailsLayout extends populateDetailsWidget(); } - protected void updateLogLayout(final VerticalLayout changeLogLayout, final Long lastModifiedAt, - final String lastModifiedBy, final Long createdAt, final String createdBy, final I18N i18n) { - changeLogLayout.removeAllComponents(); - changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.at"), - createdAt == null ? "" : SPDateTimeUtil.getFormattedDate(createdAt))); + protected void populateLog() { + logLayout.removeAllComponents(); - changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.by"), - createdBy == null ? "" : HawkbitCommonUtil.getIMUser(createdBy))); + logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.at"), + SPDateTimeUtil.formatCreatedAt(selectedBaseEntity))); - if (null != lastModifiedAt) { - changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.date"), - SPDateTimeUtil.getFormattedDate(lastModifiedAt))); + logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.by"), + UserDetailsFormatter.loadAndFormatCreatedBy(selectedBaseEntity))); - changeLogLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.by"), - lastModifiedBy == null ? "" : HawkbitCommonUtil.getIMUser(lastModifiedBy))); + if (selectedBaseEntity == null || selectedBaseEntity.getLastModifiedAt() == null) { + return; } + + logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.date"), + SPDateTimeUtil.formatLastModifiedAt(selectedBaseEntity))); + + logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.by"), + UserDetailsFormatter.loadAndFormatLastModifiedBy(selectedBaseEntity))); } protected void updateDescriptionLayout(final String descriptionLabel, final String description) { @@ -320,19 +323,6 @@ public abstract class AbstractTableDetailsLayout extends return detailsLayout; } - public VerticalLayout getLogLayout() { - return logLayout; - } - - private void populateLog() { - if (selectedBaseEntity == null) { - updateLogLayout(getLogLayout(), null, StringUtils.EMPTY, null, null, i18n); - return; - } - updateLogLayout(getLogLayout(), selectedBaseEntity.getLastModifiedAt(), selectedBaseEntity.getLastModifiedBy(), - selectedBaseEntity.getCreatedAt(), selectedBaseEntity.getCreatedBy(), i18n); - } - private void populateDescription() { if (selectedBaseEntity != null) { updateDescriptionLayout(i18n.get("label.description"), selectedBaseEntity.getDescription()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 0737f42c8..2d9067de8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -20,7 +20,7 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.common.ManagmentEntityState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -212,9 +212,9 @@ public abstract class AbstractTable extends Table { item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(baseEntity.getId()); item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(baseEntity.getDescription()); item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) - .setValue(HawkbitCommonUtil.getIMUser(baseEntity.getCreatedBy())); + .setValue(UserDetailsFormatter.loadAndFormatCreatedBy(baseEntity)); item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(HawkbitCommonUtil.getIMUser(baseEntity.getLastModifiedBy())); + .setValue(UserDetailsFormatter.loadAndFormatLastModifiedBy(baseEntity)); item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) .setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getCreatedAt())); item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java index 60b547285..78410f29c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -113,8 +114,8 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); proxyDistribution.setDescription(distributionSet.getDescription()); - proxyDistribution.setCreatedByUser(HawkbitCommonUtil.getIMUser(distributionSet.getCreatedBy())); - proxyDistribution.setModifiedByUser(HawkbitCommonUtil.getIMUser(distributionSet.getLastModifiedBy())); + proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); + proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setIsComplete(distributionSet.isComplete()); proxyDistributions.add(proxyDistribution); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index 5419cc1bf..21ce01347 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -99,8 +100,8 @@ public class SwModuleBeanQuery extends AbstractBeanQuery proxyItem.setVersion(bean.getVersion()); proxyItem.setVendor(bean.getVendor()); proxyItem.setDescription(bean.getDescription()); - proxyItem.setCreatedByUser(HawkbitCommonUtil.getIMUser(bean.getCreatedBy())); - proxyItem.setModifiedByUser(HawkbitCommonUtil.getIMUser(bean.getLastModifiedBy())); + proxyItem.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(bean)); + proxyItem.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(bean)); proxyItem.setAssigned(customSoftwareModule.isAssigned()); proxyItem.setColour(bean.getType().getColour()); proxyItem.setTypeId(bean.getType().getId()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java index bf5fdbe54..2cc572245 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTarget; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -118,8 +119,8 @@ public class CustomTargetBeanQuery extends AbstractBeanQuery { prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); prxyTarget.setCreatedAt(targ.getCreatedAt()); - prxyTarget.setCreatedByUser(HawkbitCommonUtil.getIMUser(targ.getCreatedBy())); - prxyTarget.setModifiedByUser(HawkbitCommonUtil.getIMUser(targ.getLastModifiedBy())); + prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); + prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ)); final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); prxyTarget.setInstalledDistributionSet(installedDistributionSet); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java index 9c50640cd..4a2d6da6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java @@ -14,6 +14,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTargetFilter; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -93,9 +94,9 @@ public class TargetFilterBeanQuery extends AbstractBeanQuery proxyTarFilter.setName(tarFilterQuery.getName()); proxyTarFilter.setId(tarFilterQuery.getId()); proxyTarFilter.setCreatedDate(SPDateTimeUtil.getFormattedDate(tarFilterQuery.getCreatedAt())); - proxyTarFilter.setCreatedBy(HawkbitCommonUtil.getIMUser(tarFilterQuery.getCreatedBy())); + proxyTarFilter.setCreatedBy(UserDetailsFormatter.loadAndFormatCreatedBy(tarFilterQuery)); proxyTarFilter.setModifiedDate(SPDateTimeUtil.getFormattedDate(tarFilterQuery.getLastModifiedAt())); - proxyTarFilter.setLastModifiedBy(HawkbitCommonUtil.getIMUser(tarFilterQuery.getLastModifiedBy())); + proxyTarFilter.setLastModifiedBy(UserDetailsFormatter.loadAndFormatLastModifiedBy(tarFilterQuery)); proxyTarFilter.setQuery(tarFilterQuery.getQuery()); proxyTargetFilter.add(proxyTarFilter); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java index 7b49ddcb2..7909a3850 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilte import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -129,8 +130,8 @@ public class DistributionBeanQuery extends AbstractBeanQuery proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); proxyDistribution.setDescription(distributionSet.getDescription()); - proxyDistribution.setCreatedByUser(HawkbitCommonUtil.getIMUser(distributionSet.getCreatedBy())); - proxyDistribution.setModifiedByUser(HawkbitCommonUtil.getIMUser(distributionSet.getLastModifiedBy())); + proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); + proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setNameVersion( HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())); proxyDistributions.add(proxyDistribution); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index dac50ab0d..e96a9af8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTarget; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -130,8 +131,8 @@ public class TargetBeanQuery extends AbstractBeanQuery { prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); prxyTarget.setCreatedAt(targ.getCreatedAt()); - prxyTarget.setCreatedByUser(HawkbitCommonUtil.getIMUser(targ.getCreatedBy())); - prxyTarget.setModifiedByUser(HawkbitCommonUtil.getIMUser(targ.getLastModifiedBy())); + prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); + prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ)); if (pinnedDistId == null) { prxyTarget.setInstalledDistributionSet(null); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 3b9c18952..ea75b5d31 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; 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; @@ -739,7 +740,7 @@ public class TargetTable extends AbstractTable implements .setValue(updatedTarget.getTargetInfo().getLastTargetQuery()); item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(HawkbitCommonUtil.getIMUser(updatedTarget.getLastModifiedBy())); + .setValue(UserDetailsFormatter.loadAndFormatCreatedBy(updatedTarget)); item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) .setValue(SPDateTimeUtil.getFormattedDate(updatedTarget.getLastModifiedAt())); item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(updatedTarget.getDescription()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java index bbbba8cec..690cb51a2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java @@ -18,23 +18,20 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.HawkbitServerProperties; import org.eclipse.hawkbit.im.authentication.PermissionService; -import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.ui.UiProperties; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.menu.DashboardEvent.PostViewChangeEvent; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.web.context.HttpSessionSecurityContextRepository; import com.vaadin.server.FontAwesome; import com.vaadin.server.Page; import com.vaadin.server.ThemeResource; -import com.vaadin.server.VaadinService; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.UIScope; @@ -189,63 +186,27 @@ public final class DashboardMenu extends CustomComponent { return links; } - private UserDetails getCurrentUser() { - final SecurityContext context = (SecurityContext) VaadinService.getCurrentRequest().getWrappedSession() - .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); - return (UserDetails) context.getAuthentication().getPrincipal(); - } - private Component buildUserMenu() { final MenuBar settings = new MenuBar(); settings.addStyleName("user-menu"); - final UserDetails user = getCurrentUser(); + settings.setHtmlContentAllowed(true); final MenuItem settingsItem = settings.addItem("", new ThemeResource("images/profile-pic-57px.jpg"), null); - if (user instanceof UserPrincipal - && (((UserPrincipal) user).getFirstname() != null || ((UserPrincipal) user).getLastname() != null)) { - settingsItem.setText(trimTanent(((UserPrincipal) user).getTenant()) + "\n" - + concateFNameLName(((UserPrincipal) user).getFirstname(), ((UserPrincipal) user).getLastname())); - settingsItem.setDescription( - ((UserPrincipal) user).getFirstname() + " / " + ((UserPrincipal) user).getLastname()); - } else if (user instanceof UserPrincipal) { - if (((UserPrincipal) user).getLoginname().length() > 10) { - settingsItem.setText(trimTanent(((UserPrincipal) user).getTenant()) + "\n" - + ((UserPrincipal) user).getLoginname().substring(0, 10) + ".."); - } else { - settingsItem.setText( - trimTanent(((UserPrincipal) user).getTenant()) + "\n" + ((UserPrincipal) user).getLoginname()); - } - settingsItem.setDescription(((UserPrincipal) user).getLoginname()); - } else if (user != null) { - settingsItem.setText(user.getUsername()); - settingsItem.setDescription(user.getUsername()); + + final String formattedTenant = UserDetailsFormatter.formatCurrentTenant(); + final String formattedUsername = UserDetailsFormatter.loadAndFormatCurrentUsername(); + String tenantAndUsernameHtml = ""; + if (!StringUtils.isEmpty(formattedTenant)) { + tenantAndUsernameHtml += formattedTenant + "
"; } + tenantAndUsernameHtml += formattedUsername; + settingsItem.setText(tenantAndUsernameHtml); + settingsItem.setDescription(formattedUsername); + settingsItem.setStyleName("user-menuitem"); settingsItem.addItem("Sign Out", selectedItem -> Page.getCurrent().setLocation("/UI/logout")); return settings; } - private String concateFNameLName(final String fName, final String lName) { - final StringBuilder userName = new StringBuilder(); - if (fName != null && fName.length() > 6) { - userName.append(fName.substring(0, 6) + ".." + ", "); - } else { - userName.append(fName).append(", "); - } - if (lName != null && lName.length() > 6) { - userName.append(lName.substring(0, 6) + ".."); - } else { - userName.append(lName); - } - return userName.toString(); - } - - private String trimTanent(final String tanent) { - if (tanent != null && tanent.length() > 8) { - return tanent.substring(0, 8) + ".."; - } - return tanent; - } - private Component buildToggleButton() { final Button valoMenuToggleButton = new Button("Menu", (ClickListener) event -> { if (getCompositionRoot().getStyleName().contains(STYLE_VISIBLE)) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java index 74daf89d8..75d2741af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.DistributionSetFilter; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -62,7 +63,8 @@ public class DistributionBeanQuery extends AbstractBeanQuery sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); // Add sort for (int distId = 1; distId < sortPropertyIds.length; distId++) { - sort.and(new Sort(sortStates[distId] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[distId])); + sort.and(new Sort(sortStates[distId] ? Direction.ASC : Direction.DESC, + (String) sortPropertyIds[distId])); } } } @@ -103,8 +105,8 @@ public class DistributionBeanQuery extends AbstractBeanQuery final List proxyDistributions = new ArrayList<>(); for (final DistributionSet distributionSet : distBeans) { final ProxyDistribution proxyDistribution = new ProxyDistribution(); - proxyDistribution.setName(HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), - distributionSet.getVersion())); + proxyDistribution.setName( + HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())); proxyDistribution.setDescription(distributionSet.getDescription()); proxyDistribution.setDistId(distributionSet.getId()); proxyDistribution.setId(distributionSet.getId()); @@ -112,8 +114,8 @@ public class DistributionBeanQuery extends AbstractBeanQuery proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); proxyDistribution.setDescription(distributionSet.getDescription()); - proxyDistribution.setCreatedByUser(HawkbitCommonUtil.getIMUser(distributionSet.getCreatedBy())); - proxyDistribution.setModifiedByUser(HawkbitCommonUtil.getIMUser(distributionSet.getLastModifiedBy())); + proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); + proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setIsComplete(distributionSet.isComplete()); proxyDistributions.add(proxyDistribution); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 5ab6f6a97..624f18b2f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -119,14 +120,14 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setName(rollout.getName()); proxyRollout.setDescription(rollout.getDescription()); final DistributionSet distributionSet = rollout.getDistributionSet(); - proxyRollout.setDistributionSetNameVersion(HawkbitCommonUtil.getFormattedNameVersion( - distributionSet.getName(), distributionSet.getVersion())); + proxyRollout.setDistributionSetNameVersion( + HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())); proxyRollout.setDistributionSet(distributionSet); proxyRollout.setNumberOfGroups(Long.valueOf(rollout.getRolloutGroups().size())); proxyRollout.setCreatedDate(SPDateTimeUtil.getFormattedDate(rollout.getCreatedAt())); proxyRollout.setModifiedDate(SPDateTimeUtil.getFormattedDate(rollout.getLastModifiedAt())); - proxyRollout.setCreatedBy(HawkbitCommonUtil.getIMUser(rollout.getCreatedBy())); - proxyRollout.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rollout.getLastModifiedBy())); + proxyRollout.setCreatedBy(UserDetailsFormatter.loadAndFormatCreatedBy(rollout)); + proxyRollout.setLastModifiedBy(UserDetailsFormatter.loadAndFormatLastModifiedBy(rollout)); proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); @@ -134,7 +135,7 @@ public class RolloutBeanQuery extends AbstractBeanQuery { final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - + proxyRolloutList.add(proxyRollout); } return proxyRolloutList; @@ -148,7 +149,8 @@ public class RolloutBeanQuery extends AbstractBeanQuery { * .util.List, java.util.List, java.util.List) */ @Override - protected void saveBeans(final List arg0, final List arg1, final List arg2) { + protected void saveBeans(final List arg0, final List arg1, + final List arg2) { /** * CRUD operations on Target will be done through repository methods */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 0dabb18fc..8273ed436 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -110,8 +111,8 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setDescription(rolloutGroup.getDescription()); proxyRolloutGroup.setCreatedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getCreatedAt())); proxyRolloutGroup.setModifiedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getLastModifiedAt())); - proxyRolloutGroup.setCreatedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getCreatedBy())); - proxyRolloutGroup.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getLastModifiedBy())); + proxyRolloutGroup.setCreatedBy(UserDetailsFormatter.loadAndFormatCreatedBy(rolloutGroup)); + proxyRolloutGroup.setLastModifiedBy(UserDetailsFormatter.loadAndFormatLastModifiedBy(rolloutGroup)); proxyRolloutGroup.setId(rolloutGroup.getId()); proxyRolloutGroup.setStatus(rolloutGroup.getStatus()); proxyRolloutGroup.setErrorAction(rolloutGroup.getErrorAction()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java index 097e076be..685be685e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTarget; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -105,8 +106,8 @@ public class RolloutGroupTargetsBeanQuery extends AbstractBeanQuery prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); prxyTarget.setCreatedAt(targ.getCreatedAt()); - prxyTarget.setCreatedByUser(HawkbitCommonUtil.getIMUser(targ.getCreatedBy())); - prxyTarget.setModifiedByUser(HawkbitCommonUtil.getIMUser(targ.getLastModifiedBy())); + prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); + prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ)); if (targetWithActionStatus.getStatus() != null) { prxyTarget.setStatus(targetWithActionStatus.getStatus()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 117b5bcb8..bfc996087 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -20,7 +20,6 @@ import java.util.Map.Entry; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; -import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.NamedEntity; @@ -34,9 +33,6 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -605,31 +601,6 @@ public final class HawkbitCommonUtil { return requiredExtraWidth + minTableWidth; } - /** - * get formatted name - lastname,firstname. - * - * @param user - * user name - * @return String formatted name - */ - public static String getFormattedName(final UserDetails user) { - final StringBuilder formattedName = new StringBuilder(); - if (user instanceof UserPrincipal) { - if (trimAndNullIfEmpty(((UserPrincipal) user).getLastname()) != null) { - formattedName.append(((UserPrincipal) user).getLastname()); - } - if (trimAndNullIfEmpty(((UserPrincipal) user).getFirstname()) != null) { - if (formattedName.length() > 0) { - formattedName.append(", "); - } - formattedName.append(((UserPrincipal) user).getFirstname()); - } - } else if (user != null) { - formattedName.append(user.getUsername()); - } - return formattedName.toString(); - } - /** * get the Last sequence of string which is after last dot in String. * @@ -686,30 +657,6 @@ public final class HawkbitCommonUtil { return exeJS.toString(); } - /** - * Get IM User for user UUID. - * - * @param uuid - * @return imReslovedUser user details - */ - public static String getIMUser(final String uuid) { - // Get modifed user - String imReslovedUser = HawkbitCommonUtil.SP_STRING_SPACE; - if (HawkbitCommonUtil.trimAndNullIfEmpty(uuid) != null) { - final UserDetailsService idManagement = SpringContextHelper.getBean(UserDetailsService.class); - try { - imReslovedUser = HawkbitCommonUtil.getFormattedName(idManagement.loadUserByUsername(uuid)); - } catch (final UsernameNotFoundException e) { // NOSONAR - // nope not need to handle - } - // If Null display the UID - if (HawkbitCommonUtil.trimAndNullIfEmpty(imReslovedUser) == null) { - imReslovedUser = uuid; - } - } - return imReslovedUser; - } - /** * Get formatted label.Appends ellipses if content does not fit the label. * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java index 532dd010d..4712f2f20 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java @@ -15,7 +15,9 @@ import java.util.HashMap; import java.util.Map; import java.util.TimeZone; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DurationFormatUtils; +import org.eclipse.hawkbit.repository.model.BaseEntity; import com.vaadin.server.WebBrowser; @@ -80,14 +82,31 @@ public final class SPDateTimeUtil { * @param lastQueryDate * @return String formatted date */ - public static String getFormattedDate(final Long lastQueryDate) { + return formatDate(lastQueryDate, null); + } + + public static String formatCreatedAt(final BaseEntity baseEntity) { + if (baseEntity == null) { + return StringUtils.EMPTY; + } + return formatDate(baseEntity.getCreatedAt(), StringUtils.EMPTY); + } + + public static String formatLastModifiedAt(final BaseEntity baseEntity) { + if (baseEntity == null) { + return StringUtils.EMPTY; + } + return formatDate(baseEntity.getLastModifiedAt(), StringUtils.EMPTY); + } + + private static String formatDate(final Long lastQueryDate, final String defaultString) { if (lastQueryDate != null) { final SimpleDateFormat format = new SimpleDateFormat(SPUIDefinitions.LAST_QUERY_DATE_FORMAT); format.setTimeZone(getBrowserTimeZone()); return format.format(new Date(lastQueryDate)); } - return null; + return defaultString; } /** diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss index 87ea5b0b9..beb405c30 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss @@ -143,9 +143,15 @@ .valo-menu-title { line-height: 1.2; } + .v-menubar-user-menu:after { display: none; } + + .v-menubar-menuitem-user-menuitem { + width: 100%; + } + .v-menubar-user-menu > .v-menubar-menuitem { white-space: normal !important; .v-icon { From 2462c7b6bfc706b499d28275f0600262edfa950b Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 15 Apr 2016 17:47:02 +0200 Subject: [PATCH 32/69] Add javadoc Signed-off-by: SirWayne --- .../hawkbit/ui/common/UserDetailsFormatter.java | 7 ++++++- .../ui/management/targettable/TargetTable.java | 2 +- .../eclipse/hawkbit/ui/utils/SPDateTimeUtil.java | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java index 92cfaab41..61261c1d1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java @@ -1,5 +1,10 @@ /** - * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + * 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.common; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index ea75b5d31..08503413f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -740,7 +740,7 @@ public class TargetTable extends AbstractTable implements .setValue(updatedTarget.getTargetInfo().getLastTargetQuery()); item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(UserDetailsFormatter.loadAndFormatCreatedBy(updatedTarget)); + .setValue(UserDetailsFormatter.loadAndFormatLastModifiedBy(updatedTarget)); item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) .setValue(SPDateTimeUtil.getFormattedDate(updatedTarget.getLastModifiedAt())); item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(updatedTarget.getDescription()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java index 4712f2f20..d28ac5f05 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java @@ -86,6 +86,13 @@ public final class SPDateTimeUtil { return formatDate(lastQueryDate, null); } + /** + * Get formatted date 'created at' by entity. + * + * @param baseEntity + * the entity + * @return String formatted date + */ public static String formatCreatedAt(final BaseEntity baseEntity) { if (baseEntity == null) { return StringUtils.EMPTY; @@ -93,6 +100,13 @@ public final class SPDateTimeUtil { return formatDate(baseEntity.getCreatedAt(), StringUtils.EMPTY); } + /** + * Get formatted date 'last modefied at' by entity. + * + * @param baseEntity + * the entity + * @return String formatted date + */ public static String formatLastModifiedAt(final BaseEntity baseEntity) { if (baseEntity == null) { return StringUtils.EMPTY; From 5fd220a5e3c44346d0d1e75f97121a2432de8b4f Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sat, 16 Apr 2016 10:42:26 +0200 Subject: [PATCH 33/69] change transaction handling of creating groups and check running Rollouts Signed-off-by: Michael Hirsch --- .../hawkbit/repository/RolloutManagement.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 1573048ec..6fb2ce0f9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -58,6 +58,8 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.TransactionTemplate; @@ -259,13 +261,7 @@ public class RolloutManagement { entityManager.flush(); executor.execute(() -> { try { - final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - def.setName("creatingRollout"); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - new TransactionTemplate(txManager, def).execute(status -> { - createRolloutGroups(amountGroup, conditions, savedRollout); - return null; - }); + createRolloutGroupsInNewTransaction(amountGroup, conditions, savedRollout); } finally { creatingRollouts.remove(savedRollout.getName()); } @@ -288,6 +284,15 @@ public class RolloutManagement { } } + private Rollout createRolloutGroupsInNewTransaction(final int amountGroup, final RolloutGroupConditions conditions, + final Rollout savedRollout) { + final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); + def.setName("creatingRollout"); + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + return new TransactionTemplate(txManager, def) + .execute(status -> createRolloutGroups(amountGroup, conditions, savedRollout)); + } + /** * Method for creating rollout groups and calculating group sizes. Group * sizes are calculated by dividing the total count of targets through the @@ -308,7 +313,8 @@ public class RolloutManagement { int groupIndex = 0; final Long totalCount = savedRollout.getTotalTargets(); final int groupSize = (int) Math.ceil((double) totalCount / (double) amountGroup); - // validate if the amount of groups that will be created are the amount + // validate if the amount of groups that will be created are the + // amount // of groups that the client what's to have created. int amountGroupValidated = amountGroup; final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); @@ -540,7 +546,7 @@ public class RolloutManagement { * this check. This check is only applied if the last check is * less than (lastcheck-delay). */ - @Transactional + @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) From fd7fb7bd0146847445980c7e5e4ea555570feb4c Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Mon, 18 Apr 2016 07:41:33 +0200 Subject: [PATCH 34/69] make use of the existencechecking annotation for targetrolloutgroup Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/repository/model/RolloutTargetGroup.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java index f1d4fe718..28a07f061 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java @@ -24,6 +24,9 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; +import org.eclipse.persistence.annotations.ExistenceChecking; +import org.eclipse.persistence.annotations.ExistenceType; + /** * @author Michael Hirsch * @@ -31,6 +34,7 @@ import javax.persistence.Table; @IdClass(RolloutTargetGroupId.class) @Entity @Table(name = "sp_rollouttargetgroup") +@ExistenceChecking(ExistenceType.ASSUME_NON_EXISTENCE) public class RolloutTargetGroup implements Serializable { private static final long serialVersionUID = 1L; From 8eac737219a84c9e22fbcbe866cf62aad5060d7f Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Mon, 18 Apr 2016 07:47:23 +0200 Subject: [PATCH 35/69] update javadoc and remove author from it Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/repository/model/RolloutTargetGroup.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java index 28a07f061..7a46b15b1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java @@ -28,8 +28,9 @@ import org.eclipse.persistence.annotations.ExistenceChecking; import org.eclipse.persistence.annotations.ExistenceType; /** - * @author Michael Hirsch - * + * Entity with JPA annotation to store the information which {@link Target} is + * in a specific {@link RolloutGroup}. + * */ @IdClass(RolloutTargetGroupId.class) @Entity From 878c5c869c0bccd7acccd92db7ec2d7e6f938bea Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Mon, 18 Apr 2016 07:54:38 +0200 Subject: [PATCH 36/69] adapt hawkBit user interface sentence Signed-off-by: Michael Hirsch --- hawkbit-ui/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/README.md b/hawkbit-ui/README.md index e1c7d8ffc..4bf9d67da 100644 --- a/hawkbit-ui/README.md +++ b/hawkbit-ui/README.md @@ -1,6 +1,6 @@ # hawkBit User Interface -The application with user interface to create and manage rollouts. +The hawkBit user interface is based on the Vaadin and Vaadin-Spring framework and allows to manage software updates and large scale roll-outs via a user interface. ## Debugging client-side code ### Debug using SuperDevMode From d49546e71f80842172cdf8fb1af188826f1bc36b Mon Sep 17 00:00:00 2001 From: SirWayne Date: Mon, 18 Apr 2016 16:17:28 +0200 Subject: [PATCH 37/69] Add tooltip for username Signed-off-by: SirWayne --- .../AbstractTableDetailsLayout.java | 11 ++--- .../ui/common/table/AbstractTable.java | 11 +++++ .../ui/components/SPUIComponentProvider.java | 47 +++++++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index b2df26179..360a9f925 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -17,7 +17,6 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -172,9 +171,7 @@ public abstract class AbstractTableDetailsLayout extends } private Label createHeaderCaption() { - final Label captionLabel = SPUIComponentProvider.getLabel(getDefaultCaption(), - SPUILabelDefinitions.SP_WIDGET_CAPTION); - return captionLabel; + return SPUIComponentProvider.getLabel(getDefaultCaption(), SPUILabelDefinitions.SP_WIDGET_CAPTION); } protected VerticalLayout getTabLayout() { @@ -220,8 +217,7 @@ public abstract class AbstractTableDetailsLayout extends logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.at"), SPDateTimeUtil.formatCreatedAt(selectedBaseEntity))); - logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.created.by"), - UserDetailsFormatter.loadAndFormatCreatedBy(selectedBaseEntity))); + logLayout.addComponent(SPUIComponentProvider.createCreatedByLabel(i18n, selectedBaseEntity)); if (selectedBaseEntity == null || selectedBaseEntity.getLastModifiedAt() == null) { return; @@ -230,8 +226,7 @@ public abstract class AbstractTableDetailsLayout extends logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.date"), SPDateTimeUtil.formatLastModifiedAt(selectedBaseEntity))); - logLayout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.modified.by"), - UserDetailsFormatter.loadAndFormatLastModifiedBy(selectedBaseEntity))); + logLayout.addComponent(SPUIComponentProvider.createLastModifiedByLabel(i18n, selectedBaseEntity)); } protected void updateDescriptionLayout(final String descriptionLabel, final String description) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 2d9067de8..1808cf070 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -329,6 +329,17 @@ public abstract class AbstractTable extends Table { columnList.add( new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); + setItemDescriptionGenerator((source, itemId, propertyId) -> { + + if (SPUILabelDefinitions.VAR_CREATED_BY.equals(propertyId)) { + return getItem(itemId).getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY).getValue().toString(); + } + if (SPUILabelDefinitions.VAR_LAST_MODIFIED_BY.equals(propertyId)) { + return getItem(itemId).getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).getValue().toString(); + } + return null; + }); + return columnList; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java index f5008eb31..d8e5e31d1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java @@ -12,7 +12,9 @@ import java.util.Arrays; import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.decorators.SPUIButtonDecorator; import org.eclipse.hawkbit.ui.decorators.SPUIComboBoxDecorator; import org.eclipse.hawkbit.ui.decorators.SPUIHeaderLayoutDecorator; @@ -20,6 +22,7 @@ import org.eclipse.hawkbit.ui.decorators.SPUILabelDecorator; import org.eclipse.hawkbit.ui.decorators.SPUITextAreaDecorator; import org.eclipse.hawkbit.ui.decorators.SPUITextFieldDecorator; import org.eclipse.hawkbit.ui.decorators.SPUIWindowDecorator; +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -328,6 +331,50 @@ public final class SPUIComponentProvider { return nameValueLabel; } + private static Label createUsernameLabel(final String label, final String username) { + String loadAndFormatUsername = StringUtils.EMPTY; + if (!StringUtils.isEmpty(username)) { + loadAndFormatUsername = UserDetailsFormatter.loadAndFormatUsername(username); + } + + final Label nameValueLabel = new Label(getBoldHTMLText(label) + loadAndFormatUsername, ContentMode.HTML); + nameValueLabel.setSizeFull(); + nameValueLabel.addStyleName(SPUIDefinitions.TEXT_STYLE); + nameValueLabel.addStyleName("label-style"); + nameValueLabel.setDescription(loadAndFormatUsername); + return nameValueLabel; + } + + /** + * Create label which represents the {@link BaseEntity#getCreatedBy()} by + * user name + * + * @param i18n + * the i18n + * @param baseEntity + * the entity + * @return the label + */ + public static Label createCreatedByLabel(final I18N i18n, final BaseEntity baseEntity) { + return createUsernameLabel(i18n.get("label.created.by"), + baseEntity == null ? StringUtils.EMPTY : baseEntity.getCreatedBy()); + } + + /** + * Create label which represents the + * {@link BaseEntity#getLastModifiedBy()()} by user name + * + * @param i18n + * the i18n + * @param baseEntity + * the entity + * @return the label + */ + public static Label createLastModifiedByLabel(final I18N i18n, final BaseEntity baseEntity) { + return createUsernameLabel(i18n.get("label.modified.by"), + baseEntity == null ? StringUtils.EMPTY : baseEntity.getLastModifiedBy()); + } + /** * Get Bold Text. * From f290eb78e556cb4fa47a6c988bd72e62dd608d7c Mon Sep 17 00:00:00 2001 From: venu1278 Date: Mon, 18 Apr 2016 20:12:30 +0530 Subject: [PATCH 38/69] Rollout management issues Signed-off-by: venu1278 --- .../client/CustomObjectRendererConnector.java | 9 +- .../renderers/CustomObjectRenederer.java | 4 +- .../{CustomObject.java => RendererData.java} | 27 +- .../renderers/CustomObjectRenderer.java | 12 +- .../ui/rollout/rollout/ProxyRollout.java | 14 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 287 +++++++++--------- .../ui/rollout/rollout/RolloutListGrid.java | 10 +- .../rolloutgroup/ProxyRolloutGroup.java | 14 +- .../rolloutgroup/RolloutGroupBeanQuery.java | 268 ++++++++-------- .../rolloutgroup/RolloutGroupListGrid.java | 6 +- 10 files changed, 336 insertions(+), 315 deletions(-) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/{CustomObject.java => RendererData.java} (68%) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java index c79e81924..321b8876e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.customrenderers.client; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.connectors.ClickableRendererConnector; @@ -17,9 +17,12 @@ import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; import com.vaadin.shared.ui.Connect; import elemental.json.JsonObject; - +/** + * A connector for {@link CustomObjectRenderer }. + * + */ @Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer.class) -public class CustomObjectRendererConnector extends ClickableRendererConnector { +public class CustomObjectRendererConnector extends ClickableRendererConnector { private static final long serialVersionUID = 7734682321931830566L; public org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer getRenderer() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java index 262648178..13d5887ca 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java @@ -18,7 +18,7 @@ import com.vaadin.client.widget.grid.RendererCellReference; * Used to display button with link. * */ -public class CustomObjectRenederer extends ClickableRenderer { +public class CustomObjectRenederer extends ClickableRenderer { @Override public VButton createWidget() { @@ -29,7 +29,7 @@ public class CustomObjectRenederer extends ClickableRenderer { +public class CustomObjectRenderer extends ClickableRenderer { private static final long serialVersionUID = -8754180585906263554L; @@ -29,7 +29,7 @@ public class CustomObjectRenderer extends ClickableRenderer { * Creates a new custom object renderer. */ public CustomObjectRenderer() { - super(CustomObject.class, null); + super(RendererData.class, null); } /** @@ -39,7 +39,7 @@ public class CustomObjectRenderer extends ClickableRenderer { * Class */ - public CustomObjectRenderer(Class presentationType) { + public CustomObjectRenderer(Class presentationType) { super(presentationType); } @@ -55,7 +55,7 @@ public class CustomObjectRenderer extends ClickableRenderer { } @Override - public JsonValue encode(CustomObject resource) { - return super.encode(resource, CustomObject.class); + public JsonValue encode(RendererData resource) { + return super.encode(resource, RendererData.class); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 6649d7dcb..c3e3d3896 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import com.vaadin.server.FontAwesome; @@ -33,14 +33,16 @@ public class ProxyRollout extends Rollout { private String totalTargetsCount; - private CustomObject customObject; + private RendererData rendererData; - public CustomObject getCustomObject() { - return customObject; + + + public RendererData getRendererData() { + return rendererData; } - public void setCustomObject(CustomObject customObject) { - this.customObject = customObject; + public void setRendererData(RendererData rendererData) { + this.rendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 114d2e432..9d915c80a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -40,164 +40,165 @@ import com.google.common.base.Strings; */ public class RolloutBeanQuery extends AbstractBeanQuery { - private static final long serialVersionUID = 4027879794344836185L; + private static final long serialVersionUID = 4027879794344836185L; - private final String searchText; + private final String searchText; - private Sort sort = new Sort(Direction.ASC, "createdAt"); + private Sort sort = new Sort(Direction.ASC, "createdAt"); - private transient RolloutManagement rolloutManagement; + private transient RolloutManagement rolloutManagement; - private transient TargetFilterQueryManagement filterQueryManagement; + private transient TargetFilterQueryManagement filterQueryManagement; - private transient RolloutUIState rolloutUIState; + private transient RolloutUIState rolloutUIState; - /** - * Parametric Constructor. - * - * @param definition - * as QueryDefinition - * @param queryConfig - * as Config - * @param sortIds - * as sort - * @param sortStates - * as Sort status - */ - public RolloutBeanQuery(final QueryDefinition definition, final Map queryConfig, - final Object[] sortIds, final boolean[] sortStates) { - super(definition, queryConfig, sortIds, sortStates); + /** + * Parametric Constructor. + * + * @param definition + * as QueryDefinition + * @param queryConfig + * as Config + * @param sortIds + * as sort + * @param sortStates + * as Sort status + */ + public RolloutBeanQuery(final QueryDefinition definition, final Map queryConfig, + final Object[] sortIds, final boolean[] sortStates) { + super(definition, queryConfig, sortIds, sortStates); - searchText = getSearchText(); + searchText = getSearchText(); - if (HawkbitCommonUtil.checkBolArray(sortStates)) { - // Initalize Sor - sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); - // Add sort. - for (int targetId = 1; targetId < sortIds.length; targetId++) { - sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); - } - } - } + if (HawkbitCommonUtil.checkBolArray(sortStates)) { + // Initalize Sor + sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); + // Add sort. + for (int targetId = 1; targetId < sortIds.length; targetId++) { + sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); + } + } + } - private String getSearchText() { - if (getRolloutUIState().getSearchText().isPresent()) { - return String.format("%%%s%%", getRolloutUIState().getSearchText().get()); - } - return null; - } + private String getSearchText() { + if (getRolloutUIState().getSearchText().isPresent()) { + return String.format("%%%s%%", getRolloutUIState().getSearchText().get()); + } + return null; + } - @Override - protected ProxyRollout constructBean() { - return new ProxyRollout(); - } + @Override + protected ProxyRollout constructBean() { + return new ProxyRollout(); + } - /* - * (non-Javadoc) - * - * @see - * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#loadBeans(int, - * int) - */ - @Override - protected List loadBeans(final int startIndex, final int count) { - final Slice rolloutBeans; - if (Strings.isNullOrEmpty(searchText)) { - rolloutBeans = getRolloutManagement().findAllRolloutsWithDetailedStatus( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); - } else { - rolloutBeans = getRolloutManagement().findRolloutByFilters( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), - searchText); - } - return getProxyRolloutList(rolloutBeans); - } + /* + * (non-Javadoc) + * + * @see + * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#loadBeans(int, + * int) + */ + @Override + protected List loadBeans(final int startIndex, final int count) { + final Slice rolloutBeans; + if (Strings.isNullOrEmpty(searchText)) { + rolloutBeans = getRolloutManagement().findAllRolloutsWithDetailedStatus( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + } else { + rolloutBeans = getRolloutManagement().findRolloutByFilters( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), + searchText); + } + return getProxyRolloutList(rolloutBeans); + } - private List getProxyRolloutList(final Slice rolloutBeans) { - final List proxyRolloutList = new ArrayList<>(); - for (final Rollout rollout : rolloutBeans) { - final ProxyRollout proxyRollout = new ProxyRollout(); - proxyRollout.setName(rollout.getName()); - proxyRollout.setDescription(rollout.getDescription()); - final DistributionSet distributionSet = rollout.getDistributionSet(); - proxyRollout.setDistributionSetNameVersion(HawkbitCommonUtil.getFormattedNameVersion( - distributionSet.getName(), distributionSet.getVersion())); - proxyRollout.setDistributionSet(distributionSet); - proxyRollout.setNumberOfGroups(Long.valueOf(rollout.getRolloutGroups().size())); - proxyRollout.setCreatedDate(SPDateTimeUtil.getFormattedDate(rollout.getCreatedAt())); - proxyRollout.setModifiedDate(SPDateTimeUtil.getFormattedDate(rollout.getLastModifiedAt())); - proxyRollout.setCreatedBy(HawkbitCommonUtil.getIMUser(rollout.getCreatedBy())); - proxyRollout.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rollout.getLastModifiedBy())); - proxyRollout.setForcedTime(rollout.getForcedTime()); - proxyRollout.setId(rollout.getId()); - proxyRollout.setStatus(rollout.getStatus()); - proxyRollout.setCustomObject(new CustomObject(rollout.getName(), rollout.getStatus().toString())); - - final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); - proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); - proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - - proxyRolloutList.add(proxyRollout); - } - return proxyRolloutList; - } + private List getProxyRolloutList(final Slice rolloutBeans) { + final List proxyRolloutList = new ArrayList<>(); + for (final Rollout rollout : rolloutBeans) { + final ProxyRollout proxyRollout = new ProxyRollout(); + proxyRollout.setName(rollout.getName()); + proxyRollout.setDescription(rollout.getDescription()); + final DistributionSet distributionSet = rollout.getDistributionSet(); + proxyRollout.setDistributionSetNameVersion( + HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())); + proxyRollout.setDistributionSet(distributionSet); + proxyRollout.setNumberOfGroups(Long.valueOf(rollout.getRolloutGroups().size())); + proxyRollout.setCreatedDate(SPDateTimeUtil.getFormattedDate(rollout.getCreatedAt())); + proxyRollout.setModifiedDate(SPDateTimeUtil.getFormattedDate(rollout.getLastModifiedAt())); + proxyRollout.setCreatedBy(HawkbitCommonUtil.getIMUser(rollout.getCreatedBy())); + proxyRollout.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rollout.getLastModifiedBy())); + proxyRollout.setForcedTime(rollout.getForcedTime()); + proxyRollout.setId(rollout.getId()); + proxyRollout.setStatus(rollout.getStatus()); + proxyRollout.setRendererData(new RendererData(rollout.getName(), rollout.getStatus().toString())); - /* - * (non-Javadoc) - * - * @see - * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#saveBeans(java - * .util.List, java.util.List, java.util.List) - */ - @Override - protected void saveBeans(final List arg0, final List arg1, final List arg2) { - /** - * CRUD operations on Target will be done through repository methods - */ - } + final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); + proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); + proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - /* - * (non-Javadoc) - * - * @see org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#size() - */ - @Override - public int size() { - int size = getRolloutManagement().countRolloutsAll().intValue(); - if (!Strings.isNullOrEmpty(searchText)) { - size = getRolloutManagement().countRolloutsAllByFilters(searchText).intValue(); - } - return size; - } + proxyRolloutList.add(proxyRollout); + } + return proxyRolloutList; + } - /** - * @return the rolloutManagement - */ - public RolloutManagement getRolloutManagement() { - if (null == rolloutManagement) { - rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); - } - return rolloutManagement; - } + /* + * (non-Javadoc) + * + * @see + * org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#saveBeans(java + * .util.List, java.util.List, java.util.List) + */ + @Override + protected void saveBeans(final List arg0, final List arg1, + final List arg2) { + /** + * CRUD operations on Target will be done through repository methods + */ + } - /** - * @return the filterQueryManagement - */ - public TargetFilterQueryManagement getFilterQueryManagement() { - if (null == filterQueryManagement) { - filterQueryManagement = SpringContextHelper.getBean(TargetFilterQueryManagement.class); - } - return filterQueryManagement; - } + /* + * (non-Javadoc) + * + * @see org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#size() + */ + @Override + public int size() { + int size = getRolloutManagement().countRolloutsAll().intValue(); + if (!Strings.isNullOrEmpty(searchText)) { + size = getRolloutManagement().countRolloutsAllByFilters(searchText).intValue(); + } + return size; + } - /** - * @return the rolloutUIState - */ - public RolloutUIState getRolloutUIState() { - if (null == rolloutUIState) { - rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); - } - return rolloutUIState; - } + /** + * @return the rolloutManagement + */ + public RolloutManagement getRolloutManagement() { + if (null == rolloutManagement) { + rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); + } + return rolloutManagement; + } + + /** + * @return the filterQueryManagement + */ + public TargetFilterQueryManagement getFilterQueryManagement() { + if (null == filterQueryManagement) { + filterQueryManagement = SpringContextHelper.getBean(TargetFilterQueryManagement.class); + } + return filterQueryManagement; + } + + /** + * @return the rolloutUIState + */ + public RolloutUIState getRolloutUIState() { + if (null == rolloutUIState) { + rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); + } + return rolloutUIState; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 65f94aee6..b6e828d6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -22,7 +22,7 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; @@ -145,7 +145,7 @@ public class RolloutListGrid extends AbstractGrid { .setValue(Long.valueOf(rollout.getRolloutGroups().size())); } item.getItemProperty(customObject) - .setValue(new CustomObject(rollout.getName(), rollout.getStatus().toString())); + .setValue(new RendererData(rollout.getName(), rollout.getStatus().toString())); } @@ -160,7 +160,7 @@ public class RolloutListGrid extends AbstractGrid { protected void addContainerProperties() { final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(customObject, CustomObject.class, null, false, false); + rolloutGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, false); @@ -287,7 +287,7 @@ public class RolloutListGrid extends AbstractGrid { getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - CustomObjectRenderer customObjectRenderer = new CustomObjectRenderer(CustomObject.class); + CustomObjectRenderer customObjectRenderer = new CustomObjectRenderer(RendererData.class); customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); getColumn(customObject).setRenderer(customObjectRenderer); @@ -452,7 +452,7 @@ public class RolloutListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((CustomObject) cell.getProperty().getValue()).getName(); + return ((RendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 71fe2aa8e..418ec5e40 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -9,10 +9,10 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; /** - * Proxy rollout group with custom properties. + * Proxy rollout group with renderer properties. * */ public class ProxyRolloutGroup extends RolloutGroup { @@ -41,14 +41,14 @@ public class ProxyRolloutGroup extends RolloutGroup { private String totalTargetsCount; - private CustomObject customObject; + private RendererData rendererData; - public CustomObject getCustomObject() { - return customObject; + public RendererData getRendererData() { + return rendererData; } - public void setCustomObject(CustomObject customObject) { - this.customObject = customObject; + public void setRendererData(RendererData rendererData) { + this.rendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 1902a7d9d..b025cb4bd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,7 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -35,160 +35,160 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition; */ public class RolloutGroupBeanQuery extends AbstractBeanQuery { - private static final long serialVersionUID = 5342450502894318589L; + private static final long serialVersionUID = 5342450502894318589L; - private Sort sort = new Sort(Direction.ASC, "createdAt"); + private Sort sort = new Sort(Direction.ASC, "createdAt"); - private transient Page firstPageRolloutGroupSets = null; + private transient Page firstPageRolloutGroupSets = null; - private transient RolloutManagement rolloutManagement; + private transient RolloutManagement rolloutManagement; - private transient RolloutGroupManagement rolloutGroupManagement; + private transient RolloutGroupManagement rolloutGroupManagement; - private transient RolloutUIState rolloutUIState; + private transient RolloutUIState rolloutUIState; - private final Long rolloutId; + private final Long rolloutId; - /** - * Parametric Constructor. - * - * @param definition - * as QueryDefinition - * @param queryConfig - * as Config - * @param sortPropertyIds - * as sort - * @param sortStates - * as Sort status - */ - public RolloutGroupBeanQuery(final QueryDefinition definition, final Map queryConfig, - final Object[] sortPropertyIds, final boolean[] sortStates) { - super(definition, queryConfig, sortPropertyIds, sortStates); + /** + * Parametric Constructor. + * + * @param definition + * as QueryDefinition + * @param queryConfig + * as Config + * @param sortPropertyIds + * as sort + * @param sortStates + * as Sort status + */ + public RolloutGroupBeanQuery(final QueryDefinition definition, final Map queryConfig, + final Object[] sortPropertyIds, final boolean[] sortStates) { + super(definition, queryConfig, sortPropertyIds, sortStates); - rolloutId = getRolloutId(); + rolloutId = getRolloutId(); - if (HawkbitCommonUtil.checkBolArray(sortStates)) { - // Initalize Sor - sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); - // Add sort. - for (int targetId = 1; targetId < sortPropertyIds.length; targetId++) { - sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, - (String) sortPropertyIds[targetId])); - } - } - } + if (HawkbitCommonUtil.checkBolArray(sortStates)) { + // Initalize Sor + sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); + // Add sort. + for (int targetId = 1; targetId < sortPropertyIds.length; targetId++) { + sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, + (String) sortPropertyIds[targetId])); + } + } + } - /** - * @return - */ - private Long getRolloutId() { - return getRolloutUIState().getRolloutId().isPresent() ? getRolloutUIState().getRolloutId().get() : null; - } + /** + * @return + */ + private Long getRolloutId() { + return getRolloutUIState().getRolloutId().isPresent() ? getRolloutUIState().getRolloutId().get() : null; + } - @Override - protected ProxyRolloutGroup constructBean() { - return new ProxyRolloutGroup(); - } + @Override + protected ProxyRolloutGroup constructBean() { + return new ProxyRolloutGroup(); + } - @Override - protected List loadBeans(final int startIndex, final int count) { - List proxyRolloutGroupsList = new ArrayList<>(); - if (startIndex == 0 && firstPageRolloutGroupSets != null) { - proxyRolloutGroupsList = firstPageRolloutGroupSets.getContent(); - } else if (null != rolloutId) { - proxyRolloutGroupsList = getRolloutGroupManagement() - .findAllRolloutGroupsWithDetailedStatus(rolloutId, new PageRequest(startIndex / count, count)) - .getContent(); - } - return getProxyRolloutGroupList(proxyRolloutGroupsList); - } + @Override + protected List loadBeans(final int startIndex, final int count) { + List proxyRolloutGroupsList = new ArrayList<>(); + if (startIndex == 0 && firstPageRolloutGroupSets != null) { + proxyRolloutGroupsList = firstPageRolloutGroupSets.getContent(); + } else if (null != rolloutId) { + proxyRolloutGroupsList = getRolloutGroupManagement() + .findAllRolloutGroupsWithDetailedStatus(rolloutId, new PageRequest(startIndex / count, count)) + .getContent(); + } + return getProxyRolloutGroupList(proxyRolloutGroupsList); + } - private List getProxyRolloutGroupList(final List rolloutGroupBeans) { - final List proxyRolloutGroupsList = new ArrayList<>(); - for (final RolloutGroup rolloutGroup : rolloutGroupBeans) { - final ProxyRolloutGroup proxyRolloutGroup = new ProxyRolloutGroup(); - proxyRolloutGroup.setName(rolloutGroup.getName()); - proxyRolloutGroup.setDescription(rolloutGroup.getDescription()); - proxyRolloutGroup.setCreatedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getCreatedAt())); - proxyRolloutGroup.setModifiedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getLastModifiedAt())); - proxyRolloutGroup.setCreatedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getCreatedBy())); - proxyRolloutGroup.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getLastModifiedBy())); - proxyRolloutGroup.setId(rolloutGroup.getId()); - proxyRolloutGroup.setStatus(rolloutGroup.getStatus()); - proxyRolloutGroup.setErrorAction(rolloutGroup.getErrorAction()); - proxyRolloutGroup.setErrorActionExp(rolloutGroup.getErrorActionExp()); - proxyRolloutGroup.setErrorCondition(rolloutGroup.getErrorCondition()); - proxyRolloutGroup.setErrorConditionExp(rolloutGroup.getErrorConditionExp()); - proxyRolloutGroup.setSuccessCondition(rolloutGroup.getSuccessCondition()); - proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); - proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - - proxyRolloutGroup.setCustomObject(new CustomObject(rolloutGroup.getName(), null)); + private List getProxyRolloutGroupList(final List rolloutGroupBeans) { + final List proxyRolloutGroupsList = new ArrayList<>(); + for (final RolloutGroup rolloutGroup : rolloutGroupBeans) { + final ProxyRolloutGroup proxyRolloutGroup = new ProxyRolloutGroup(); + proxyRolloutGroup.setName(rolloutGroup.getName()); + proxyRolloutGroup.setDescription(rolloutGroup.getDescription()); + proxyRolloutGroup.setCreatedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getCreatedAt())); + proxyRolloutGroup.setModifiedDate(SPDateTimeUtil.getFormattedDate(rolloutGroup.getLastModifiedAt())); + proxyRolloutGroup.setCreatedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getCreatedBy())); + proxyRolloutGroup.setLastModifiedBy(HawkbitCommonUtil.getIMUser(rolloutGroup.getLastModifiedBy())); + proxyRolloutGroup.setId(rolloutGroup.getId()); + proxyRolloutGroup.setStatus(rolloutGroup.getStatus()); + proxyRolloutGroup.setErrorAction(rolloutGroup.getErrorAction()); + proxyRolloutGroup.setErrorActionExp(rolloutGroup.getErrorActionExp()); + proxyRolloutGroup.setErrorCondition(rolloutGroup.getErrorCondition()); + proxyRolloutGroup.setErrorConditionExp(rolloutGroup.getErrorConditionExp()); + proxyRolloutGroup.setSuccessCondition(rolloutGroup.getSuccessCondition()); + proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); + proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); - proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); + proxyRolloutGroup.setRendererData(new RendererData(rolloutGroup.getName(), null)); - proxyRolloutGroupsList.add(proxyRolloutGroup); - } - return proxyRolloutGroupsList; - } + proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); + proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); - private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { - return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, getRolloutManagement() - .getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); - } + proxyRolloutGroupsList.add(proxyRolloutGroup); + } + return proxyRolloutGroupsList; + } - @Override - protected void saveBeans(final List arg0, final List arg1, - final List arg2) { - /** - * CRUD operations be done through repository methods. - */ - } + private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { + return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, getRolloutManagement() + .getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); + } - @Override - public int size() { - long size = 0; - if (null != rolloutId) { - firstPageRolloutGroupSets = getRolloutGroupManagement().findAllRolloutGroupsWithDetailedStatus(rolloutId, - new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); - size = firstPageRolloutGroupSets.getTotalElements(); - } - if (size > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } + @Override + protected void saveBeans(final List arg0, final List arg1, + final List arg2) { + /** + * CRUD operations be done through repository methods. + */ + } - return (int) size; - } + @Override + public int size() { + long size = 0; + if (null != rolloutId) { + firstPageRolloutGroupSets = getRolloutGroupManagement().findAllRolloutGroupsWithDetailedStatus(rolloutId, + new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); + size = firstPageRolloutGroupSets.getTotalElements(); + } + if (size > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } - /** - * @return the rolloutManagement - */ - public RolloutManagement getRolloutManagement() { - if (null == rolloutManagement) { - rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); - } - return rolloutManagement; - } + return (int) size; + } - /** - * @return the rolloutManagement - */ - public RolloutGroupManagement getRolloutGroupManagement() { - if (null == rolloutGroupManagement) { - rolloutGroupManagement = SpringContextHelper.getBean(RolloutGroupManagement.class); - } - return rolloutGroupManagement; - } + /** + * @return the rolloutManagement + */ + public RolloutManagement getRolloutManagement() { + if (null == rolloutManagement) { + rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class); + } + return rolloutManagement; + } - /** - * @return the rolloutUIState - */ - public RolloutUIState getRolloutUIState() { - if (null == rolloutUIState) { - rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); - } - return rolloutUIState; - } + /** + * @return the rolloutManagement + */ + public RolloutGroupManagement getRolloutGroupManagement() { + if (null == rolloutGroupManagement) { + rolloutGroupManagement = SpringContextHelper.getBean(RolloutGroupManagement.class); + } + return rolloutGroupManagement; + } + + /** + * @return the rolloutUIState + */ + public RolloutUIState getRolloutUIState() { + if (null == rolloutUIState) { + rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class); + } + return rolloutUIState; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index b8a799c41..3ccfb6d2d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObject; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; @@ -132,7 +132,7 @@ public class RolloutGroupListGrid extends AbstractGrid { final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(customObject, CustomObject.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, false, false); @@ -286,7 +286,7 @@ public class RolloutGroupListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((CustomObject) cell.getProperty().getValue()).getName(); + return ((RendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); From 702decee621284b3a0504e85bbcee7b5cb0c557c Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 19 Apr 2016 10:42:29 +0200 Subject: [PATCH 39/69] Rename deadletter queue and add ttl Signed-off-by: SirWayne --- .../src/main/resources/hawkbitdefaults.properties | 2 +- .../java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java | 6 ++++++ .../main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties b/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties index 198fce255..488777b8d 100644 --- a/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties +++ b/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties @@ -42,6 +42,6 @@ hawkbit.controller.minPollingTime=00:00:30 # Configuration for RabbitMQ integration -hawkbit.dmf.rabbitmq.deadLetterQueue=dmf_connector_deadletter +hawkbit.dmf.rabbitmq.deadLetterQueue=dmf_connector_deadletter_ttl hawkbit.dmf.rabbitmq.deadLetterExchange=dmf.connector.deadletter hawkbit.dmf.rabbitmq.receiverQueue=dmf_receiver \ No newline at end of file diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java index 448206924..20a11713f 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java @@ -41,6 +41,12 @@ public class AmqpConfiguration { @Autowired private ConnectionFactory connectionFactory; + /** + * Create a {@link RabbitAdmin} and ignore declaration exceptions. + * {@link RabbitAdmin#setIgnoreDeclarationExceptions(boolean)} + * + * @return the bean + */ @Bean public RabbitAdmin rabbitAdmin() { final RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java index 38c6d34b3..ce6068ce8 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.java @@ -21,7 +21,7 @@ public class AmqpProperties { /** * DMF API dead letter queue. */ - private String deadLetterQueue = "dmf_connector_deadletter"; + private String deadLetterQueue = "dmf_connector_deadletter_ttl"; /** * DMF API dead letter exchange. From 5437f36c7507048354df2021a2a72cc43e9bbca8 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 19 Apr 2016 10:42:56 +0200 Subject: [PATCH 40/69] Rename deadletter queue and add ttl Signed-off-by: SirWayne --- .../src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hawkbit-example-app/src/main/resources/application.properties b/examples/hawkbit-example-app/src/main/resources/application.properties index 7864087c8..64661d2ec 100644 --- a/examples/hawkbit-example-app/src/main/resources/application.properties +++ b/examples/hawkbit-example-app/src/main/resources/application.properties @@ -21,7 +21,7 @@ spring.rabbitmq.password=guest spring.rabbitmq.virtualHost=/ spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 -hawkbit.dmf.rabbitmq.deadLetterQueue=dmf_connector_deadletter +hawkbit.dmf.rabbitmq.deadLetterQueue=dmf_connector_deadletter_ttl hawkbit.dmf.rabbitmq.deadLetterExchange=dmf.connector.deadletter hawkbit.dmf.rabbitmq.receiverQueue=dmf_receiver From 86e313fc291f0d153c699f3e8195233469288c4c Mon Sep 17 00:00:00 2001 From: venu1278 Date: Tue, 19 Apr 2016 14:47:31 +0530 Subject: [PATCH 41/69] Rollout management issues Signed-off-by: venu1278 --- ...nector.java => RolloutRendererConnector.java} | 10 +++++----- ...ObjectRenederer.java => RolloutRenderer.java} | 4 ++-- ...endererData.java => RolloutRendererData.java} | 6 +++--- ...mObjectRenderer.java => RolloutRenderer.java} | 16 ++++++++-------- .../hawkbit/ui/rollout/rollout/ProxyRollout.java | 9 ++++----- .../ui/rollout/rollout/RolloutBeanQuery.java | 4 ++-- .../ui/rollout/rollout/RolloutListGrid.java | 12 ++++++------ .../rollout/rolloutgroup/ProxyRolloutGroup.java | 8 ++++---- .../rolloutgroup/RolloutGroupBeanQuery.java | 4 ++-- .../rolloutgroup/RolloutGroupListGrid.java | 10 +++++----- 10 files changed, 41 insertions(+), 42 deletions(-) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/{CustomObjectRendererConnector.java => RolloutRendererConnector.java} (80%) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/{CustomObjectRenederer.java => RolloutRenderer.java} (91%) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/{RendererData.java => RolloutRendererData.java} (87%) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/{CustomObjectRenderer.java => RolloutRenderer.java} (73%) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java similarity index 80% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java index 321b8876e..2175dea29 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/CustomObjectRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.customrenderers.client; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.connectors.ClickableRendererConnector; @@ -21,12 +21,12 @@ import elemental.json.JsonObject; * A connector for {@link CustomObjectRenderer }. * */ -@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer.class) -public class CustomObjectRendererConnector extends ClickableRendererConnector { +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer.class) +public class RolloutRendererConnector extends ClickableRendererConnector { private static final long serialVersionUID = 7734682321931830566L; - public org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer getRenderer() { - return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.CustomObjectRenederer) super.getRenderer(); + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer) super.getRenderer(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRenderer.java similarity index 91% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRenderer.java index 13d5887ca..da8fc2544 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/CustomObjectRenederer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRenderer.java @@ -18,7 +18,7 @@ import com.vaadin.client.widget.grid.RendererCellReference; * Used to display button with link. * */ -public class CustomObjectRenederer extends ClickableRenderer { +public class RolloutRenderer extends ClickableRenderer { @Override public VButton createWidget() { @@ -29,7 +29,7 @@ public class CustomObjectRenederer extends ClickableRenderer { +public class RolloutRenderer extends ClickableRenderer { private static final long serialVersionUID = -8754180585906263554L; /** * Creates a new custom object renderer. */ - public CustomObjectRenderer() { - super(RendererData.class, null); + public RolloutRenderer() { + super(RolloutRendererData.class, null); } /** @@ -39,7 +39,7 @@ public class CustomObjectRenderer extends ClickableRenderer { * Class */ - public CustomObjectRenderer(Class presentationType) { + public RolloutRenderer(Class presentationType) { super(presentationType); } @@ -49,13 +49,13 @@ public class CustomObjectRenderer extends ClickableRenderer { * @param listener * the click listener to register */ - public CustomObjectRenderer(RendererClickListener listener) { + public RolloutRenderer(RendererClickListener listener) { this(); addClickListener(listener); } @Override - public JsonValue encode(RendererData resource) { - return super.encode(resource, RendererData.class); + public JsonValue encode(RolloutRendererData resource) { + return super.encode(resource, RolloutRendererData.class); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index c3e3d3896..75c0f59cb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.vaadin.server.FontAwesome; @@ -33,15 +33,14 @@ public class ProxyRollout extends Rollout { private String totalTargetsCount; - private RendererData rendererData; + private RolloutRendererData rendererData; - - public RendererData getRendererData() { + public RolloutRendererData getRendererData() { return rendererData; } - public void setRendererData(RendererData rendererData) { + public void setRendererData(RolloutRendererData rendererData) { this.rendererData = rendererData; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 9d915c80a..aa98f6bf4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -131,7 +131,7 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); - proxyRollout.setRendererData(new RendererData(rollout.getName(), rollout.getStatus().toString())); + proxyRollout.setRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index b6e828d6c..4f9ba636f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -22,8 +22,8 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; @@ -145,7 +145,7 @@ public class RolloutListGrid extends AbstractGrid { .setValue(Long.valueOf(rollout.getRolloutGroups().size())); } item.getItemProperty(customObject) - .setValue(new RendererData(rollout.getName(), rollout.getStatus().toString())); + .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); } @@ -160,7 +160,7 @@ public class RolloutListGrid extends AbstractGrid { protected void addContainerProperties() { final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); + rolloutGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, false); @@ -287,7 +287,7 @@ public class RolloutListGrid extends AbstractGrid { getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - CustomObjectRenderer customObjectRenderer = new CustomObjectRenderer(RendererData.class); + RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); getColumn(customObject).setRenderer(customObjectRenderer); @@ -452,7 +452,7 @@ public class RolloutListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((RendererData) cell.getProperty().getValue()).getName(); + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 418ec5e40..be1e09794 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; /** * Proxy rollout group with renderer properties. @@ -41,13 +41,13 @@ public class ProxyRolloutGroup extends RolloutGroup { private String totalTargetsCount; - private RendererData rendererData; + private RolloutRendererData rendererData; - public RendererData getRendererData() { + public RolloutRendererData getRendererData() { return rendererData; } - public void setRendererData(RendererData rendererData) { + public void setRendererData(RolloutRendererData rendererData) { this.rendererData = rendererData; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index b025cb4bd..0850164c9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -15,7 +15,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -123,7 +123,7 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - proxyRolloutGroup.setRendererData(new RendererData(rolloutGroup.getName(), null)); + proxyRolloutGroup.setRendererData(new RolloutRendererData(rolloutGroup.getName(), null)); proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 3ccfb6d2d..da0a8271a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -23,8 +23,8 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; -import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.CustomObjectRenderer; +import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; @@ -132,7 +132,7 @@ public class RolloutGroupListGrid extends AbstractGrid { final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(customObject, RendererData.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, false, false); @@ -238,7 +238,7 @@ public class RolloutGroupListGrid extends AbstractGrid { getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), new TotalTargetCountStatusConverter()); if (permissionChecker.hasRolloutTargetsReadPermission()) { - getColumn(customObject).setRenderer(new CustomObjectRenderer(event -> onClickOfRolloutGroupName(event))); + getColumn(customObject).setRenderer(new RolloutRenderer(event -> onClickOfRolloutGroupName(event))); } } @@ -286,7 +286,7 @@ public class RolloutGroupListGrid extends AbstractGrid { } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { return SPUILabelDefinitions.ACTION.toLowerCase(); } else if (customObject.equals(cell.getPropertyId())) { - return ((RendererData) cell.getProperty().getValue()).getName(); + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); From 3c454bfb9be3eb9485d843c11a994db93cc64554 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 19 Apr 2016 11:27:33 +0200 Subject: [PATCH 42/69] Modfiy username formatting Signed-off-by: SirWayne --- .../ui/common/UserDetailsFormatter.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java index 61261c1d1..df741a6fd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java @@ -28,7 +28,7 @@ import com.vaadin.server.VaadinService; */ public final class UserDetailsFormatter { - private static final String TRIM_APPENDIX = ".."; + private static final String TRIM_APPENDIX = "..."; private static final String DETAIL_SEPERATOR = ", "; private UserDetailsFormatter() { @@ -45,7 +45,7 @@ public final class UserDetailsFormatter { * @return the formatted user name (max 100 characters) cannot be */ public static String loadAndFormatUsername(final String username) { - return loadAndFormatUsername(username, 50); + return loadAndFormatUsername(username, 100); } /** @@ -93,7 +93,7 @@ public final class UserDetailsFormatter { * @return the formatted user name (max 12 characters) cannot be */ public static String loadAndFormatCurrentUsername() { - return loadAndFormatUsername(getCurrentUser().getUsername(), 6); + return loadAndFormatUsername(getCurrentUser().getUsername(), 12); } /** @@ -109,7 +109,7 @@ public final class UserDetailsFormatter { * the user name * @param expectedNameLength * the name size of each name part - * @return the formatted user name (max 2 * expectedNameLength characters) + * @return the formatted user name (max expectedNameLength characters) * cannot be */ public static String loadAndFormatUsername(final String username, final int expectedNameLength) { @@ -120,13 +120,21 @@ public final class UserDetailsFormatter { final UserPrincipal userPrincipal = (UserPrincipal) userDetails; - final String trimmedFirstname = trimAndFormatDetail(userPrincipal.getFirstname(), expectedNameLength); - final String trimmedLastname = trimAndFormatDetail(userPrincipal.getLastname(), expectedNameLength); + String firstname = StringUtils.defaultIfEmpty(userPrincipal.getFirstname(), StringUtils.EMPTY); - if (StringUtils.isEmpty(trimmedFirstname) && StringUtils.isEmpty(trimmedLastname)) { - return StringUtils.substring(userPrincipal.getLoginname(), 0, 2 * expectedNameLength); + if (!StringUtils.isEmpty(firstname)) { + firstname += DETAIL_SEPERATOR; } - return trimmedFirstname + DETAIL_SEPERATOR + trimmedLastname; + + final String firstAndLastname = firstname + + StringUtils.defaultIfEmpty(userPrincipal.getLastname(), StringUtils.EMPTY); + + final String trimmedUsername = trimAndFormatDetail(firstAndLastname, expectedNameLength); + + if (StringUtils.isEmpty(trimmedUsername)) { + return trimAndFormatDetail(userPrincipal.getLoginname(), expectedNameLength); + } + return firstAndLastname; } /** @@ -168,8 +176,8 @@ public final class UserDetailsFormatter { throw new UsernameNotFoundException("User not found " + username); } return loadUserByUsername; - } catch (final UsernameNotFoundException e) { // NOSONAR + } catch (final UsernameNotFoundException e) { + return new User(username, "", Collections.emptyList()); } - return new User(username, "", Collections.emptyList()); } } From 681a23e51dec4ccc949dfa37fa4ceb10669269d8 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Wed, 20 Apr 2016 12:31:32 +0200 Subject: [PATCH 43/69] Update UserDetailsFormatter.java --- .../org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java index df741a6fd..04ad0c51a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java @@ -98,7 +98,7 @@ public final class UserDetailsFormatter { /** * Load user details by the user name and format the user name. If the - * loaded {@link UserDetails} is not a instance of a {@link UserPrincipal}, + * loaded {@link UserDetails} is not an instance of a {@link UserPrincipal}, * then just the {@link UserDetails#getUsername()} will return. * * If first and last name available, they will combined. Otherwise the From 5027b36c59dc01a85c431c232bb5661ae6227db2 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Wed, 20 Apr 2016 12:49:50 +0200 Subject: [PATCH 44/69] Update SPDateTimeUtil.java --- .../main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java index d28ac5f05..49bae86e1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPDateTimeUtil.java @@ -101,7 +101,7 @@ public final class SPDateTimeUtil { } /** - * Get formatted date 'last modefied at' by entity. + * Get formatted date 'last modified at' by entity. * * @param baseEntity * the entity From 1220b490f8bbd76fb7bcbbcfba7cc9dcb5b0645e Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Wed, 20 Apr 2016 16:15:03 +0200 Subject: [PATCH 45/69] Small fix since checkbox was using wrong item for enabling Signed-off-by: Jonathan Philip Knoblauch --- .../ui/tenantconfiguration/AuthenticationConfigurationView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index 616acaf3f..329318b0f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -113,7 +113,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); downloadAnonymousCheckBox.setId("downloadanonymouscheckbox"); - downloadAnonymousCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); + downloadAnonymousCheckBox.setValue(anonymousDownloadAuthenticationConfigurationItem.isConfigEnabled()); downloadAnonymousCheckBox.addValueChangeListener(this); anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this); gridLayout.addComponent(downloadAnonymousCheckBox, 0, 3); From d561ad99de28917a053b0ef2bd957a12d49407e0 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 21 Apr 2016 08:06:10 +0200 Subject: [PATCH 46/69] fix rollout renderer, using wrong itemd ID property naming Signed-off-by: Michael Hirsch --- .../ui/rollout/rollout/ProxyRollout.java | 10 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 2 +- .../ui/rollout/rollout/RolloutListGrid.java | 1116 ++++++++--------- .../rolloutgroup/ProxyRolloutGroup.java | 10 +- .../rolloutgroup/RolloutGroupBeanQuery.java | 2 +- .../rolloutgroup/RolloutGroupListGrid.java | 553 ++++---- 6 files changed, 847 insertions(+), 846 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 75c0f59cb..6514ba2df 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -33,15 +33,15 @@ public class ProxyRollout extends Rollout { private String totalTargetsCount; - private RolloutRendererData rendererData; + private RolloutRendererData rolloutRendererData; - public RolloutRendererData getRendererData() { - return rendererData; + public RolloutRendererData getRolloutRendererData() { + return rolloutRendererData; } - public void setRendererData(RolloutRendererData rendererData) { - this.rendererData = rendererData; + public void setRolloutRendererData(RolloutRendererData rendererData) { + this.rolloutRendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index aa98f6bf4..34ae323da 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -131,7 +131,7 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setForcedTime(rollout.getForcedTime()); proxyRollout.setId(rollout.getId()); proxyRollout.setStatus(rollout.getStatus()); - proxyRollout.setRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + proxyRollout.setRolloutRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 4f9ba636f..1bb0fd831 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -23,9 +23,9 @@ import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -68,562 +68,562 @@ import com.vaadin.ui.renderers.HtmlRenderer; @ViewScope public class RolloutListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; - - private static final String UPDATE_OPTION = "Update"; - - private static final String RESUME_OPTION = "Resume"; - - private static final String PAUSE_OPTION = "Pause"; - - private static final String START_OPTION = "Start"; - - private static final String customObject = "customObject"; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; - - @Autowired - private UINotification uiNotification; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - - /** - * Handles the RolloutEvent to refresh Grid. - * - */ - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - switch (event) { - case FILTER_BY_TEXT: - case CREATE_ROLLOUT: - case UPDATE_ROLLOUT: - case SHOW_ROLLOUTS: - refreshGrid(); - break; - default: - return; - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the grid. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - if (!rolloutUIState.isShowRollOuts()) { - return; - } - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - final int groupsCreated = rollout.getRolloutGroupsCreated(); - if (groupsCreated != 0) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); - } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Long.valueOf(rollout.getRolloutGroups().size())); - } - item.getItemProperty(customObject) - .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); - - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, - FontAwesome.CIRCLE_O.getHtml(), false, false); - - } - - @Override - protected void setColumnExpandRatio() { - - getColumn(customObject).setMinimumWidth(40); - getColumn(customObject).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - - setFrozenColumnCount(getColumns().size()); - } - - @Override - protected void setColumnHeaderNames() { - getColumn(customObject).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); - } - - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; - } - - @Override - protected void setColumnProperties() { - final List columnList = new ArrayList<>(); - columnList.add(customObject); - columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ACTION); - - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } - - @Override - protected void setHiddenColumns() { - final List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (final Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - - } - - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } - - @Override - protected void addColumnRenderes() { - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), - new TotalTargetGroupsConverter()); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - - createRolloutStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); - - getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - - RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); - customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); - getColumn(customObject).setRenderer(customObjectRenderer); - - } - - private void createRolloutStatusToFontMap() { - statusIconMap.put(RolloutStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutStatus.PAUSED, - new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); - statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); - statusIconMap.put(RolloutStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutStatus.STOPPED, - new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); - statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); - statusIconMap.put(RolloutStatus.ERROR_CREATING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.ERROR_STARTING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } - - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; - - @Override - public String getStyle(final CellReference cellReference) { - final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } - - private void onClickOfRolloutName(final RendererClickEvent event) { - rolloutUIState.setRolloutId((long) event.getItemId()); - final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - final String ds = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); - rolloutUIState.setRolloutDistributionSet(ds); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private void onClickOfActionBtn(final RendererClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); - contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - final Item row = getContainerDataSource().getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - - switch (rolloutStatus) { - case READY: - final ContextMenuItem startItem = context.addItem(START_OPTION); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - break; - case RUNNING: - final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - break; - case PAUSED: - final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - break; - case STARTING: - case CREATING: - case ERROR_CREATING: - case ERROR_STARTING: - // do not provide any action on these statuses - return context; - default: - break; - } - getUpdateMenuItem(context, rolloutId); - return context; - } - - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { - // Add 'Update' option only if user has update permission - if (!permissionChecker.hasRolloutUpdatePermission()) { - return; - } - final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - switch (contextMenuData.getAction()) { - case PAUSE: - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - break; - case RESUME: - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - break; - case START: - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - break; - case UPDATE: - onUpdate(contextMenuData); - break; - default: - break; - } - } - - private void onUpdate(final ContextMenuData contextMenuData) { - addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); - final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); - addTargetWindow.setCaption(i18n.get("caption.update.rollout")); - UI.getCurrent().addWindow(addTargetWindow); - addTargetWindow.setVisible(Boolean.TRUE); - } - - private void refreshGrid() { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - - /** - * Generator to generate fontIcon by String. - */ - public final class FontIconGenerator extends PropertyValueGenerator { - - private static final long serialVersionUID = 2544026030795375748L; - private final FontAwesome fontIcon; - - public FontIconGenerator(final FontAwesome icon) { - this.fontIcon = icon; - } - - @Override - public String getValue(final Item item, final Object itemId, final Object propertyId) { - return fontIcon.getHtml(); - } - - @Override - public Class getType() { - return String.class; - } - } - - private String getDescription(final CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (customObject.equals(cell.getPropertyId())) { - return ((RolloutRendererData) cell.getProperty().getValue()).getName(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } - - enum ACTION { - PAUSE, RESUME, START, UPDATE - } - - /** - * Represents data of context menu item. - * - */ - public static class ContextMenuData { - - private Long rolloutId; - - private ACTION action; - - /** - * Set rollout if and action. - * - * @param rolloutId - * id of rollout - * @param action - * user action {@link ACTION} - */ - public ContextMenuData(final Long rolloutId, final ACTION action) { - this.action = action; - this.rolloutId = rolloutId; - } - - /** - * @return the rolloutId - */ - public Long getRolloutId() { - return rolloutId; - } - - /** - * @param rolloutId - * the rolloutId to set - */ - public void setRolloutId(final Long rolloutId) { - this.rolloutId = rolloutId; - } - - /** - * @return the action - */ - public ACTION getAction() { - return action; - } - - /** - * @param action - * the action to set - */ - public void setAction(final ACTION action) { - this.action = action; - } - } - - /** - * - * Converter to convert {@link RolloutStatus} to string. - * - */ - class RolloutStatusConverter implements Converter { - - private static final long serialVersionUID = -1217685750825632678L; - - @Override - public RolloutStatus convertToModel(final String value, final Class targetType, - final Locale locale) { - return null; - } - - @Override - public String convertToPresentation(final RolloutStatus value, final Class targetType, - final Locale locale) { - return convertRolloutStatusToString(value); - } - - @Override - public Class getModelType() { - return RolloutStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - private String convertRolloutStatusToString(final RolloutStatus value) { - final StatusFontIcon statusFontIcon = statusIconMap.get(value); - final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - } - - /** - * Converter to convert {@link TotalTargetCountStatus} to formatted string - * with status and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { - - private static final long serialVersionUID = -5794528427855153924L; - - @Override - public TotalTargetCountStatus convertToModel(final String value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(final TotalTargetCountStatus value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } - - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - /** - * Converter to convert 0 to empty, if total target groups is zero. - * - */ - class TotalTargetGroupsConverter implements Converter { - - private static final long serialVersionUID = 6589305227035220369L; - - @Override - public Long convertToModel(String value, Class targetType, Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(Long value, Class targetType, Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - if (value == 0) { - return ""; - } - return value.toString(); - } - - @Override - public Class getModelType() { - return Long.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - } + private static final long serialVersionUID = 4060904914954370524L; + + private static final String UPDATE_OPTION = "Update"; + + private static final String RESUME_OPTION = "Resume"; + + private static final String PAUSE_OPTION = "Pause"; + + private static final String START_OPTION = "Start"; + + private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + + /** + * Handles the RolloutEvent to refresh Grid. + * + */ + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + switch (event) { + case FILTER_BY_TEXT: + case CREATE_ROLLOUT: + case UPDATE_ROLLOUT: + case SHOW_ROLLOUTS: + refreshGrid(); + break; + default: + return; + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the grid. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (!rolloutUIState.isShowRollOuts()) { + return; + } + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + final int groupsCreated = rollout.getRolloutGroupsCreated(); + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); + } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + item.getItemProperty(ROLLOUT_RENDERER_DATA) + .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + + getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); + getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + final List columnList = new ArrayList<>(); + columnList.add(ROLLOUT_RENDERER_DATA); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void setHiddenColumns() { + final List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (final Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), + new TotalTargetGroupsConverter()); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + + createRolloutStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); + + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + + final RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); + customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); + getColumn(ROLLOUT_RENDERER_DATA).setRenderer(customObjectRenderer); + + } + + private void createRolloutStatusToFontMap() { + statusIconMap.put(RolloutStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutStatus.PAUSED, + new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); + statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); + statusIconMap.put(RolloutStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutStatus.STOPPED, + new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); + statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); + statusIconMap.put(RolloutStatus.ERROR_CREATING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.ERROR_STARTING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + private void onClickOfRolloutName(final RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + rolloutUIState.setRolloutName(rolloutName); + final String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(final RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + + switch (rolloutStatus) { + case READY: + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + break; + case RUNNING: + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + break; + case PAUSED: + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + break; + case STARTING: + case CREATING: + case ERROR_CREATING: + case ERROR_STARTING: + // do not provide any action on these statuses + return context; + default: + break; + } + getUpdateMenuItem(context, rolloutId); + return context; + } + + private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { + // Add 'Update' option only if user has update permission + if (!permissionChecker.hasRolloutUpdatePermission()) { + return; + } + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + switch (contextMenuData.getAction()) { + case PAUSE: + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + break; + case RESUME: + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + break; + case START: + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + break; + case UPDATE: + onUpdate(contextMenuData); + break; + default: + break; + } + } + + private void onUpdate(final ContextMenuData contextMenuData) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + + private void refreshGrid() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + /** + * Generator to generate fontIcon by String. + */ + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(final FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(final Item item, final Object itemId, final Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + private String getDescription(final CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } + + enum ACTION { + PAUSE, RESUME, START, UPDATE + } + + /** + * Represents data of context menu item. + * + */ + public static class ContextMenuData { + + private Long rolloutId; + + private ACTION action; + + /** + * Set rollout if and action. + * + * @param rolloutId + * id of rollout + * @param action + * user action {@link ACTION} + */ + public ContextMenuData(final Long rolloutId, final ACTION action) { + this.action = action; + this.rolloutId = rolloutId; + } + + /** + * @return the rolloutId + */ + public Long getRolloutId() { + return rolloutId; + } + + /** + * @param rolloutId + * the rolloutId to set + */ + public void setRolloutId(final Long rolloutId) { + this.rolloutId = rolloutId; + } + + /** + * @return the action + */ + public ACTION getAction() { + return action; + } + + /** + * @param action + * the action to set + */ + public void setAction(final ACTION action) { + this.action = action; + } + } + + /** + * + * Converter to convert {@link RolloutStatus} to string. + * + */ + class RolloutStatusConverter implements Converter { + + private static final long serialVersionUID = -1217685750825632678L; + + @Override + public RolloutStatus convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, final Class targetType, + final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } + } + + /** + * Converter to convert {@link TotalTargetCountStatus} to formatted string + * with status and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { + + private static final long serialVersionUID = -5794528427855153924L; + + @Override + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * Converter to convert 0 to empty, if total target groups is zero. + * + */ + class TotalTargetGroupsConverter implements Converter { + + private static final long serialVersionUID = 6589305227035220369L; + + @Override + public Long convertToModel(final String value, final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final Long value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + if (value == 0) { + return ""; + } + return value.toString(); + } + + @Override + public Class getModelType() { + return Long.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index be1e09794..08f2c0a0b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -41,14 +41,14 @@ public class ProxyRolloutGroup extends RolloutGroup { private String totalTargetsCount; - private RolloutRendererData rendererData; + private RolloutRendererData rolloutRendererData; - public RolloutRendererData getRendererData() { - return rendererData; + public RolloutRendererData getRolloutRendererData() { + return rolloutRendererData; } - public void setRendererData(RolloutRendererData rendererData) { - this.rendererData = rendererData; + public void setRolloutRendererData(RolloutRendererData rendererData) { + this.rolloutRendererData = rendererData; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index 0850164c9..efc350dc4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -123,7 +123,7 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - proxyRolloutGroup.setRendererData(new RolloutRendererData(rolloutGroup.getName(), null)); + proxyRolloutGroup.setRolloutRendererData(new RolloutRendererData(rolloutGroup.getName(), null)); proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index da0a8271a..f09b02cfc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -24,9 +24,8 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; -import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; - +import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -60,329 +59,331 @@ import com.vaadin.ui.renderers.HtmlRenderer; @SpringComponent @ViewScope public class RolloutGroupListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; + private static final long serialVersionUID = 4060904914954370524L; - private static final String customObject = "customObject"; + private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; - @Autowired - private transient RolloutGroupManagement rolloutGroupManagement; + @Autowired + private transient RolloutGroupManagement rolloutGroupManagement; - @Autowired - private transient RolloutManagement rolloutManagement; + @Autowired + private transient RolloutManagement rolloutManagement; - @Autowired - private transient RolloutUIState rolloutUIState; + @Autowired + private transient RolloutUIState rolloutUIState; - @Autowired - private transient SpPermissionChecker permissionChecker; + @Autowired + private transient SpPermissionChecker permissionChecker; - private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); + private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { - return; - } - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { + return; + } + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } - /** - * - * Handles the RolloutGroupChangeEvent to refresh the item in the grid. - * - * - * @param rolloutGroupChangeEvent - * the event which contains the rollout group which has been - * change - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { - if (!rolloutUIState.isShowRolloutGroups()) { - return; - } - final RolloutGroup rolloutGroup = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutGroup.getId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setValue(rolloutGroup.getTotalTargetCountStatus()); - item.getItemProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) - .setValue(calculateFinishedPercentage(rolloutGroup)); - } + /** + * + * Handles the RolloutGroupChangeEvent to refresh the item in the grid. + * + * + * @param rolloutGroupChangeEvent + * the event which contains the rollout group which has been + * change + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { + if (!rolloutUIState.isShowRolloutGroups()) { + return; + } + final RolloutGroup rolloutGroup = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutGroup.getId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(rolloutGroup.getTotalTargetCountStatus()); + item.getItemProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setValue(calculateFinishedPercentage(rolloutGroup)); + } - private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { - return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, - rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); - } + private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { + return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, + rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); + } - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGroupGridContainer.addContainerProperty(customObject, RolloutRendererData.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, - String.class, null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, - null, false, false); + rolloutGroupGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, + null, false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, - false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, + false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, - false, false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); - } + } - @Override - protected void setColumnExpandRatio() { - getColumn(customObject).setMinimumWidth(40); - getColumn(customObject).setMaximumWidth(200); + @Override + protected void setColumnExpandRatio() { + getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); + getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(200); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - setFrozenColumnCount(7); - } + setFrozenColumnCount(7); + } - @Override - protected void setColumnHeaderNames() { - getColumn(customObject).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) - .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); - getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) - .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - } + @Override + protected void setColumnHeaderNames() { + getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + } - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; - } + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_GRID_ID; + } - @Override - protected void setColumnProperties() { - final List columnList = new ArrayList<>(); - columnList.add(customObject); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); - columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } + @Override + protected void setColumnProperties() { + final List columnList = new ArrayList<>(); + columnList.add(ROLLOUT_RENDERER_DATA); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } - @Override - protected void addColumnRenderes() { - createRolloutGroupStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), - new RolloutGroupStatusConverter()); + @Override + protected void addColumnRenderes() { + createRolloutGroupStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new RolloutGroupStatusConverter()); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - if (permissionChecker.hasRolloutTargetsReadPermission()) { - getColumn(customObject).setRenderer(new RolloutRenderer(event -> onClickOfRolloutGroupName(event))); - } - } + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + if (permissionChecker.hasRolloutTargetsReadPermission()) { + getColumn(ROLLOUT_RENDERER_DATA) + .setRenderer(new RolloutRenderer(event -> onClickOfRolloutGroupName(event))); + } + } - @Override - protected void setHiddenColumns() { - final List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (final Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - } + @Override + protected void setHiddenColumns() { + final List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (final Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + } - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } - private void onClickOfRolloutGroupName(final RendererClickEvent event) { - rolloutUIState - .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); - } + private void onClickOfRolloutGroupName(final RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } - private void createRolloutGroupStatusToFontMap() { - statusIconMap.put(RolloutGroupStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutGroupStatus.SCHEDULED, - new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); - statusIconMap.put(RolloutGroupStatus.RUNNING, - new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); - statusIconMap.put(RolloutGroupStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutGroupStatus.ERROR, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } + private void createRolloutGroupStatusToFontMap() { + statusIconMap.put(RolloutGroupStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutGroupStatus.SCHEDULED, + new StatusFontIcon(FontAwesome.HOURGLASS_1, SPUIStyleDefinitions.STATUS_ICON_PENDING)); + statusIconMap.put(RolloutGroupStatus.RUNNING, + new StatusFontIcon(FontAwesome.ADJUST, SPUIStyleDefinitions.STATUS_ICON_YELLOW)); + statusIconMap.put(RolloutGroupStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutGroupStatus.ERROR, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } - private String getDescription(final CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (customObject.equals(cell.getPropertyId())) { - return ((RolloutRendererData) cell.getProperty().getValue()).getName(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } + private String getDescription(final CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } + return null; + } - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; - @Override - public String getStyle(final CellReference cellReference) { - final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, - SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } + @Override + public String getStyle(final CellReference cellReference) { + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } - /** - * - * Converts {@link TotalTargetCountStatus} into formatted string with status - * and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { + /** + * + * Converts {@link TotalTargetCountStatus} into formatted string with status + * and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { - private static final long serialVersionUID = -9205943894818450807L; + private static final long serialVersionUID = -9205943894818450807L; - @Override - public TotalTargetCountStatus convertToModel(final String value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } + @Override + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } - @Override - public String convertToPresentation(final TotalTargetCountStatus value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } + @Override + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } - @Override - public Class getPresentationType() { - return String.class; - } - } + @Override + public Class getPresentationType() { + return String.class; + } + } - /** - * - * Converts {@link RolloutGroupStatus} to string. - * - */ - class RolloutGroupStatusConverter implements Converter { + /** + * + * Converts {@link RolloutGroupStatus} to string. + * + */ + class RolloutGroupStatusConverter implements Converter { - private static final long serialVersionUID = 5448062736373292820L; + private static final long serialVersionUID = 5448062736373292820L; - @Override - public RolloutGroupStatus convertToModel(final String value, - final Class targetType, final Locale locale) { - return null; - } + @Override + public RolloutGroupStatus convertToModel(final String value, + final Class targetType, final Locale locale) { + return null; + } - @Override - public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, - final Locale locale) { - return convertRolloutGroupStatusToString(value); - } + @Override + public String convertToPresentation(final RolloutGroupStatus value, final Class targetType, + final Locale locale) { + return convertRolloutGroupStatusToString(value); + } - @Override - public Class getModelType() { - return RolloutGroupStatus.class; - } + @Override + public Class getModelType() { + return RolloutGroupStatus.class; + } - @Override - public Class getPresentationType() { - return String.class; - } + @Override + public Class getPresentationType() { + return String.class; + } - private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - final StatusFontIcon statusFontIcon = statusIconMap.get(value); - final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); - } + } - } + } } From ffd3373b3480ed694b65700b9f53d283ecf0916d Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 21 Apr 2016 11:53:54 +0200 Subject: [PATCH 47/69] Signed-off-by: SirWayne --- 3rd-dependencies/listDeps.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 3rd-dependencies/listDeps.sh diff --git a/3rd-dependencies/listDeps.sh b/3rd-dependencies/listDeps.sh old mode 100755 new mode 100644 From f7b30a59ba1d3353f87fe47258d6000a0dce721b Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 21 Apr 2016 16:58:08 +0200 Subject: [PATCH 48/69] Signed-off-by: SirWayne --- 3rd-dependencies/listDeps.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 3rd-dependencies/listDeps.sh diff --git a/3rd-dependencies/listDeps.sh b/3rd-dependencies/listDeps.sh old mode 100755 new mode 100644 From 6e85c724bf79b7a7d54148f228419b192b2191d6 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Mon, 25 Apr 2016 14:09:38 +0200 Subject: [PATCH 49/69] Removed the method exception from transaction manager as they where not needed anymore. The bean in systemmanagement should also not open a transaction. Signed-off-by: Kai Zimmermann --- .../MultiTenantJpaTransactionManager.java | 16 ---------------- .../hawkbit/repository/SystemManagement.java | 3 +-- .../hawkbit/tenancy/MultiTenancyEntityTest.java | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java index ac6bc8806..a45c846a9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit; import javax.persistence.EntityManager; import javax.transaction.Transaction; -import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.persistence.config.PersistenceUnitProperties; @@ -37,11 +36,6 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { protected void doBegin(final Object transaction, final TransactionDefinition definition) { super.doBegin(transaction, definition); - // ignore transactions on tenant independent calls - if (isTenantManagement(definition) || isCurrentTenantKeyGenerator(definition)) { - return; - } - final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager .getResource(getEntityManagerFactory()); final EntityManager em = emHolder.getEntityManager(); @@ -54,14 +48,4 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); } - - private boolean isCurrentTenantKeyGenerator(final TransactionDefinition definition) { - return definition.getName() - .startsWith(SystemManagement.class.getCanonicalName() + ".currentTenantKeyGenerator"); - } - - private boolean isTenantManagement(final TransactionDefinition definition) { - return definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant") - && !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants"); - } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 5577e1d61..c1cee7223 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -164,6 +164,7 @@ public class SystemManagement { * @return the {@link CurrentTenantKeyGenerator} */ @Bean + @Transactional(propagation = Propagation.NOT_SUPPORTED) public CurrentTenantKeyGenerator currentTenantKeyGenerator() { return new CurrentTenantKeyGenerator(); } @@ -206,7 +207,6 @@ public class SystemManagement { @NotNull @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - // tenant independent public List findTenants() { return tenantMetaDataRepository.findAll().stream().map(md -> md.getTenant()).collect(Collectors.toList()); } @@ -221,7 +221,6 @@ public class SystemManagement { @Transactional @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) - // tenant independent public void deleteTenant(@NotNull final String tenant) { cacheManager.evictCaches(tenant); cacheManager.getCache("currentTenant").evict(currentTenantKeyGenerator().generate(null, null)); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java index 1dd4c9823..67b9b5a26 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java @@ -78,6 +78,22 @@ public class MultiTenancyEntityTest extends AbstractIntegrationTest { assertThat(findTargetsForTenant).hasSize(1); } + @Test + @Description(value = "Ensures that tenant with proper permissions can read and delete other tenants.") + @WithUser(tenantId = "mytenant", allSpPermissions = true) + public void deleteAnotherTenantPossible() throws Exception { + // create target for another tenant + final String anotherTenant = "anotherTenant"; + final String controllerAnotherTenant = "anotherController"; + createTargetForTenant(controllerAnotherTenant, anotherTenant); + + assertThat(systemManagement.findTenants()).as("Expected number if tenants before deletion is").hasSize(3); + + systemManagement.deleteTenant(anotherTenant); + + assertThat(systemManagement.findTenants()).as("Expected number if tenants after deletion is").hasSize(2); + } + @Test @Description(value = "Ensures that tenant metadata is retrieved for the current tenant.") @WithUser(tenantId = "mytenant", autoCreateTenant = false, allSpPermissions = true) From 23d15bf646242e44b4f752bd49c95b4cc7e18fbb Mon Sep 17 00:00:00 2001 From: venu1278 Date: Tue, 26 Apr 2016 16:13:06 +0530 Subject: [PATCH 50/69] Displaying DistributionSet Details in Tooltip Signed-off-by: venu1278 --- .../ui/common/table/AbstractTable.java | 4 + .../hawkbit/ui/components/ProxyTarget.java | 478 +++---- .../CreateOrUpdateFilterTable.java | 402 +++--- .../targettable/TargetBeanQuery.java | 329 ++--- .../management/targettable/TargetTable.java | 65 + .../ui/rollout/rollout/ProxyRollout.java | 77 ++ .../ui/rollout/rollout/RolloutBeanQuery.java | 5 + .../ui/rollout/rollout/RolloutListGrid.java | 1173 +++++++++-------- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 8 + 9 files changed, 1426 insertions(+), 1115 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 0737f42c8..8e68be0d5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -323,6 +323,10 @@ public abstract class AbstractTable extends Table { return columnList; } columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); + columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, + i18n.get("header.assigned.ds"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, + i18n.get("header.installed.ds"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java index d85b2bc71..084890f87 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java @@ -10,9 +10,11 @@ package org.eclipse.hawkbit.ui.components; import java.net.URI; import java.security.SecureRandom; +import java.util.Set; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -26,275 +28,293 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; * */ public class ProxyTarget extends Target { - private static final long serialVersionUID = -8891449133620645310L; - private String controllerId; - private URI address = null; - private Long lastTargetQuery = null; - private Long installationDate; + private static final long serialVersionUID = -8891449133620645310L; + private String controllerId; + private URI address = null; + private Long lastTargetQuery = null; + private Long installationDate; - private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; + private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; - private DistributionSet installedDistributionSet; + private DistributionSet installedDistributionSet; - private TargetIdName targetIdName; + private DistributionSet assignedDistributionSet; - private String assignedDistNameVersion; + private TargetIdName targetIdName; - private String installedDistNameVersion; + private String assignedDistNameVersion; - private String pollStatusToolTip; + private String installedDistNameVersion; - private String createdByUser; + private String pollStatusToolTip; - private String createdDate; + private String createdByUser; - private String lastModifiedDate; + private String createdDate; - private String modifiedByUser; + private String lastModifiedDate; - private Status status; + private String modifiedByUser; - /** - * @param controllerId - */ - public ProxyTarget() { - super(null); - final Integer generatedId = new SecureRandom().nextInt(Integer.MAX_VALUE) - Integer.MAX_VALUE; - targetIdName = new TargetIdName(generatedId, generatedId.toString(), generatedId.toString()); - } + private Status status; - /** - * @return the createdByUser - */ - public String getCreatedByUser() { - return createdByUser; - } + /** + * @param controllerId + */ + public ProxyTarget() { + super(null); + final Integer generatedId = new SecureRandom().nextInt(Integer.MAX_VALUE) - Integer.MAX_VALUE; + targetIdName = new TargetIdName(generatedId, generatedId.toString(), generatedId.toString()); + } - /** - * @param createdByUser - * the createdByUser to set - */ - public void setCreatedByUser(final String createdByUser) { - this.createdByUser = createdByUser; - } + /** + * @return the createdByUser + */ + public String getCreatedByUser() { + return createdByUser; + } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @param createdByUser + * the createdByUser to set + */ + public void setCreatedByUser(final String createdByUser) { + this.createdByUser = createdByUser; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @return the modifiedByUser - */ - public String getModifiedByUser() { - return modifiedByUser; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @param modifiedByUser - * the modifiedByUser to set - */ - public void setModifiedByUser(final String modifiedByUser) { - this.modifiedByUser = modifiedByUser; - } + /** + * @return the modifiedByUser + */ + public String getModifiedByUser() { + return modifiedByUser; + } - /** - * @return the lastModifiedDate - */ - public String getLastModifiedDate() { - return lastModifiedDate; - } + /** + * @param modifiedByUser + * the modifiedByUser to set + */ + public void setModifiedByUser(final String modifiedByUser) { + this.modifiedByUser = modifiedByUser; + } - /** - * @param lastModifiedDate - * the lastModifiedDate to set - */ - public void setLastModifiedDate(final String lastModifiedDate) { - this.lastModifiedDate = lastModifiedDate; - } + /** + * @return the lastModifiedDate + */ + public String getLastModifiedDate() { + return lastModifiedDate; + } - /** - * @return the assignedDistNameVersion - */ - public String getAssignedDistNameVersion() { - return assignedDistNameVersion; - } + /** + * @param lastModifiedDate + * the lastModifiedDate to set + */ + public void setLastModifiedDate(final String lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } - /** - * @param assignedDistNameVersion - * the assignedDistNameVersion to set - */ - public void setAssignedDistNameVersion(final String assignedDistNameVersion) { - this.assignedDistNameVersion = assignedDistNameVersion; - } + /** + * @return the assignedDistNameVersion + */ + public String getAssignedDistNameVersion() { + return assignedDistNameVersion; + } - /** - * @return the installedDistNameVersion - */ - public String getInstalledDistNameVersion() { - return installedDistNameVersion; - } + /** + * @param assignedDistNameVersion + * the assignedDistNameVersion to set + */ + public void setAssignedDistNameVersion(final String assignedDistNameVersion) { + this.assignedDistNameVersion = assignedDistNameVersion; + } - /** - * @param installedDistNameVersion - * the installedDistNameVersion to set - */ - public void setInstalledDistNameVersion(final String installedDistNameVersion) { - this.installedDistNameVersion = installedDistNameVersion; - } + /** + * @return the installedDistNameVersion + */ + public String getInstalledDistNameVersion() { + return installedDistNameVersion; + } - /** - * GET - ID. - * - * @return String as ID. - */ - @Override - public String getControllerId() { - return controllerId; - } + /** + * @param installedDistNameVersion + * the installedDistNameVersion to set + */ + public void setInstalledDistNameVersion(final String installedDistNameVersion) { + this.installedDistNameVersion = installedDistNameVersion; + } - /** - * SET - ID. - * - * @param controllerId - * as ID - */ - @Override - public void setControllerId(final String controllerId) { - this.controllerId = controllerId; - } + /** + * GET - ID. + * + * @return String as ID. + */ + @Override + public String getControllerId() { + return controllerId; + } - /** - * @return the ipAddress - */ - public URI getAddress() { - return address; - } + /** + * SET - ID. + * + * @param controllerId + * as ID + */ + @Override + public void setControllerId(final String controllerId) { + this.controllerId = controllerId; + } - /** - * @param ipAddress - * the ipAddress to set - */ - public void setAddress(final URI address) { - this.address = address; - } + /** + * @return the ipAddress + */ + public URI getAddress() { + return address; + } - /** - * @return the lastTargetQuery - */ - public Long getLastTargetQuery() { - return lastTargetQuery; - } + /** + * @param ipAddress + * the ipAddress to set + */ + public void setAddress(final URI address) { + this.address = address; + } - /** - * @param lastTargetQuery - * the lastTargetQuery to set - */ - public void setLastTargetQuery(final Long lastTargetQuery) { - this.lastTargetQuery = lastTargetQuery; - } + /** + * @return the lastTargetQuery + */ + public Long getLastTargetQuery() { + return lastTargetQuery; + } - /** - * @return the installationDate - */ - public Long getInstallationDate() { - return installationDate; - } + /** + * @param lastTargetQuery + * the lastTargetQuery to set + */ + public void setLastTargetQuery(final Long lastTargetQuery) { + this.lastTargetQuery = lastTargetQuery; + } - /** - * @param installationDate - * the installationDate to set - */ - public void setInstallationDate(final Long installationDate) { - this.installationDate = installationDate; - } + /** + * @return the installationDate + */ + public Long getInstallationDate() { + return installationDate; + } - /** - * @return the updateStatus - */ - public TargetUpdateStatus getUpdateStatus() { - return updateStatus; - } + /** + * @param installationDate + * the installationDate to set + */ + public void setInstallationDate(final Long installationDate) { + this.installationDate = installationDate; + } - /** - * @param updateStatus - * the updateStatus to set - */ - public void setUpdateStatus(final TargetUpdateStatus updateStatus) { - this.updateStatus = updateStatus; - } + /** + * @return the updateStatus + */ + public TargetUpdateStatus getUpdateStatus() { + return updateStatus; + } - /** - * @return the installedDistributionSet - */ - public DistributionSet getInstalledDistributionSet() { - return installedDistributionSet; - } + /** + * @param updateStatus + * the updateStatus to set + */ + public void setUpdateStatus(final TargetUpdateStatus updateStatus) { + this.updateStatus = updateStatus; + } - /** - * @param installedDistributionSet - * the installedDistributionSet to set - */ - public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) { - this.installedDistributionSet = installedDistributionSet; - } + /** + * @return the installedDistributionSet + */ + public DistributionSet getInstalledDistributionSet() { + return installedDistributionSet; + } - /** - * @return the targetIdName - */ - @Override - public TargetIdName getTargetIdName() { - if (this.targetIdName == null) { - return super.getTargetIdName(); - } - return this.targetIdName; - } + /** + * @param installedDistributionSet + * the installedDistributionSet to set + */ + public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) { + this.installedDistributionSet = installedDistributionSet; + } - /** - * @param targetIdName - * the targetIdName to set - */ - public void setTargetIdName(final TargetIdName targetIdName) { - this.targetIdName = targetIdName; - } + /** + * @return the assignedDistributionSet + */ + public DistributionSet getAssignedDistributionSet() { + return assignedDistributionSet; + } - /** - * @return the pollStatusToolTip - */ - public String getPollStatusToolTip() { - return pollStatusToolTip; - } + /** + * @param assignedDistributionSet + * the assignedDistributionSet to set + */ + public void setAssignedDistributionSet(DistributionSet assignedDistributionSet) { + this.assignedDistributionSet = assignedDistributionSet; + } - /** - * @param pollStatusToolTip - * the pollStatusToolTip to set - */ - public void setPollStatusToolTip(final String pollStatusToolTip) { - this.pollStatusToolTip = pollStatusToolTip; - } + /** + * @return the targetIdName + */ + @Override + public TargetIdName getTargetIdName() { + if (this.targetIdName == null) { + return super.getTargetIdName(); + } + return this.targetIdName; + } - /** - * @return the status - */ - public Status getStatus() { - return status; - } + /** + * @param targetIdName + * the targetIdName to set + */ + public void setTargetIdName(final TargetIdName targetIdName) { + this.targetIdName = targetIdName; + } + + /** + * @return the pollStatusToolTip + */ + public String getPollStatusToolTip() { + return pollStatusToolTip; + } + + /** + * @param pollStatusToolTip + * the pollStatusToolTip to set + */ + public void setPollStatusToolTip(final String pollStatusToolTip) { + this.pollStatusToolTip = pollStatusToolTip; + } + + /** + * @return the status + */ + public Status getStatus() { + return status; + } + + /** + * @param status + * the status to set + */ + public void setStatus(final Status status) { + this.status = status; + } - /** - * @param status - * the status to set - */ - public void setStatus(final Status status) { - this.status = status; - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java index ebeb95957..d067b388b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java @@ -13,10 +13,13 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; @@ -54,194 +57,259 @@ import com.vaadin.ui.themes.ValoTheme; @ViewScope public class CreateOrUpdateFilterTable extends Table { - private static final long serialVersionUID = 6887304217281629713L; + private static final long serialVersionUID = 6887304217281629713L; - @Autowired - private I18N i18n; + @Autowired + private I18N i18n; - @Autowired - private transient EventBus.SessionEventBus eventBus; + @Autowired + private transient EventBus.SessionEventBus eventBus; - @Autowired - private FilterManagementUIState filterManagementUIState; + @Autowired + private FilterManagementUIState filterManagementUIState; - private LazyQueryContainer container; + private LazyQueryContainer container; - private static final int PROPERTY_DEPT = 3; + private static final int PROPERTY_DEPT = 3; - /** - * Initialize the Action History Table. - */ - @PostConstruct - public void init() { - setStyleName("sp-table"); - setSizeFull(); - setImmediate(true); - setHeight(100.0f, Unit.PERCENTAGE); - addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); - addStyleName(ValoTheme.TABLE_SMALL); - setColumnCollapsingAllowed(true); - addCustomGeneratedColumns(); - restoreOnLoad(); - populateTableData(); - setId(SPUIComponetIdProvider.CUSTOM_FILTER_TARGET_TABLE_ID); - setSelectable(false); - eventBus.subscribe(this); - } + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } + private static final String INSTALL_DIST_SET = "installedDistributionSet"; - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final CustomFilterUIEvent custFUIEvent) { - if (custFUIEvent == CustomFilterUIEvent.TARGET_DETAILS_VIEW - || custFUIEvent == CustomFilterUIEvent.CREATE_NEW_FILTER_CLICK) { - UI.getCurrent().access(() -> populateTableData()); - } else if (custFUIEvent == CustomFilterUIEvent.FILTER_TARGET_BY_QUERY) { - UI.getCurrent().access(() -> onQuery()); - } - } + /** + * Initialize the Action History Table. + */ + @PostConstruct + public void init() { + setStyleName("sp-table"); + setSizeFull(); + setImmediate(true); + setHeight(100.0f, Unit.PERCENTAGE); + addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); + addStyleName(ValoTheme.TABLE_SMALL); + setColumnCollapsingAllowed(true); + addCustomGeneratedColumns(); + restoreOnLoad(); + populateTableData(); + setId(SPUIComponetIdProvider.CUSTOM_FILTER_TARGET_TABLE_ID); + setSelectable(false); + eventBus.subscribe(this); + setItemDescriptionGenerator(new TooltipGenerator()); + } - private void restoreOnLoad() { - if (filterManagementUIState.isCreateFilterViewDisplayed()) { - filterManagementUIState.setFilterQueryValue(null); - } else { - filterManagementUIState.getTfQuery() - .ifPresent(value -> filterManagementUIState.setFilterQueryValue(value.getQuery())); - } - } + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } - /** - * Create a empty HierarchicalContainer. - */ - private LazyQueryContainer createContainer() { - // ADD all the filters to the query config - final Map queryConfig = prepareQueryConfigFilters(); + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final CustomFilterUIEvent custFUIEvent) { + if (custFUIEvent == CustomFilterUIEvent.TARGET_DETAILS_VIEW + || custFUIEvent == CustomFilterUIEvent.CREATE_NEW_FILTER_CLICK) { + UI.getCurrent().access(() -> populateTableData()); + } else if (custFUIEvent == CustomFilterUIEvent.FILTER_TARGET_BY_QUERY) { + UI.getCurrent().access(() -> onQuery()); + } + } - // Create TargetBeanQuery factory with the query config. - final BeanQueryFactory targetQF = new BeanQueryFactory<>(CustomTargetBeanQuery.class); - targetQF.setQueryConfiguration(queryConfig); + private void restoreOnLoad() { + if (filterManagementUIState.isCreateFilterViewDisplayed()) { + filterManagementUIState.setFilterQueryValue(null); + } else { + filterManagementUIState.getTfQuery() + .ifPresent(value -> filterManagementUIState.setFilterQueryValue(value.getQuery())); + } + } - // create lazy query container with lazy defination and query - final LazyQueryContainer targetTableContainer = new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME), - targetQF); - targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT); + /** + * Create a empty HierarchicalContainer. + */ + private LazyQueryContainer createContainer() { + // ADD all the filters to the query config + final Map queryConfig = prepareQueryConfigFilters(); - return targetTableContainer; + // Create TargetBeanQuery factory with the query config. + final BeanQueryFactory targetQF = new BeanQueryFactory<>(CustomTargetBeanQuery.class); + targetQF.setQueryConfiguration(queryConfig); - } + // create lazy query container with lazy defination and query + final LazyQueryContainer targetTableContainer = new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME), + targetQF); + targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT); - private Map prepareQueryConfigFilters() { - final Map queryConfig = new HashMap<>(); - if (!Strings.isNullOrEmpty(filterManagementUIState.getFilterQueryValue())) { - queryConfig.put(SPUIDefinitions.FILTER_BY_QUERY, filterManagementUIState.getFilterQueryValue()); - } - queryConfig.put(SPUIDefinitions.FILTER_BY_INVALID_QUERY, - filterManagementUIState.getIsFilterByInvalidFilterQuery()); - return queryConfig; - } + return targetTableContainer; - /** - * populate campaign data. - * - */ - public void populateTableData() { - container = createContainer(); - setContainerDataSource(container); - addContainerproperties(); - setColumnProperties(); - setPageLength(30); - setCollapsibleColumns(); - } + } - private void setCollapsibleColumns() { - setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, true); - } + private Map prepareQueryConfigFilters() { + final Map queryConfig = new HashMap<>(); + if (!Strings.isNullOrEmpty(filterManagementUIState.getFilterQueryValue())) { + queryConfig.put(SPUIDefinitions.FILTER_BY_QUERY, filterManagementUIState.getFilterQueryValue()); + } + queryConfig.put(SPUIDefinitions.FILTER_BY_INVALID_QUERY, + filterManagementUIState.getIsFilterByInvalidFilterQuery()); + return queryConfig; + } - /** - * Create a empty HierarchicalContainer. - */ - private void addContainerproperties() { - /* Create HierarchicalContainer container */ - container.addContainerProperty(SPUILabelDefinitions.NAME, String.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, Date.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, null, false, true); - container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); - container.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, String.class, ""); - container.addContainerProperty(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, String.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_TARGET_STATUS, TargetUpdateStatus.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); - } + /** + * populate campaign data. + * + */ + public void populateTableData() { + container = createContainer(); + setContainerDataSource(container); + addContainerproperties(); + setColumnProperties(); + setPageLength(30); + setCollapsibleColumns(); + } - private List getVisbleColumns() { - final List columnList = new ArrayList<>(); - columnList.add(new TableColumn(SPUILabelDefinitions.NAME, i18n.get("header.name"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, - i18n.get("header.assigned.ds"), 0.125F)); - columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, - i18n.get("header.installed.ds"), 0.125F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.STATUS_ICON, i18n.get("header.status"), 0.1F)); - return columnList; - } + private void setCollapsibleColumns() { + setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, true); + setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, true); - private Component getStatusIcon(final Object itemId) { - final Item row1 = getItem(itemId); - final TargetUpdateStatus targetStatus = (TargetUpdateStatus) row1 - .getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).getValue(); - final Label label = SPUIComponentProvider.getLabel("", SPUILabelDefinitions.SP_LABEL_SIMPLE); - label.setContentMode(ContentMode.HTML); - if (targetStatus == TargetUpdateStatus.PENDING) { - label.setDescription("Pending"); - label.setStyleName("statusIconYellow"); - label.setValue(FontAwesome.ADJUST.getHtml()); - } else if (targetStatus == TargetUpdateStatus.REGISTERED) { - label.setDescription("Registered"); - label.setStyleName("statusIconLightBlue"); - label.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); - } else if (targetStatus == TargetUpdateStatus.ERROR) { - label.setDescription(i18n.get("label.error")); - label.setStyleName("statusIconRed"); - label.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); - } else if (targetStatus == TargetUpdateStatus.IN_SYNC) { - label.setStyleName("statusIconGreen"); - label.setDescription("In-Synch"); - label.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); - } else if (targetStatus == TargetUpdateStatus.UNKNOWN) { - label.setStyleName("statusIconBlue"); - label.setDescription(i18n.get("label.unknown")); - label.setValue(FontAwesome.QUESTION_CIRCLE.getHtml()); - } - return label; - } + setColumnCollapsed(ASSIGN_DIST_SET, true); + setColumnCollapsed(INSTALL_DIST_SET, true); + } - private void setColumnProperties() { - final List columnList = getVisbleColumns(); - final List swColumnIds = new ArrayList<>(); - for (final TableColumn column : columnList) { - setColumnHeader(column.getColumnPropertyId(), column.getColumnHeader()); - setColumnExpandRatio(column.getColumnPropertyId(), column.getExpandRatio()); - swColumnIds.add(column.getColumnPropertyId()); - } - setVisibleColumns(swColumnIds.toArray()); - } + /** + * Create a empty HierarchicalContainer. + */ + private void addContainerproperties() { + /* Create HierarchicalContainer container */ + container.addContainerProperty(SPUILabelDefinitions.NAME, String.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, Date.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, null, false, true); + container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); + container.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, String.class, ""); + container.addContainerProperty(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, String.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_TARGET_STATUS, TargetUpdateStatus.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); - protected void addCustomGeneratedColumns() { - addGeneratedColumn(SPUILabelDefinitions.STATUS_ICON, (source, itemId, columnId) -> getStatusIcon(itemId)); - } + container.addContainerProperty(ASSIGN_DIST_SET, DistributionSet.class, null, false, true); + container.addContainerProperty(INSTALL_DIST_SET, DistributionSet.class, null, false, true); + } - private void onQuery() { - populateTableData(); - eventBus.publish(this, CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON); - } + private List getVisbleColumns() { + final List columnList = new ArrayList<>(); + columnList.add(new TableColumn(SPUILabelDefinitions.NAME, i18n.get("header.name"), 0.15f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); + columnList.add( + new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, + i18n.get("header.assigned.ds"), 0.125F)); + columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, + i18n.get("header.installed.ds"), 0.125F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.STATUS_ICON, i18n.get("header.status"), 0.1F)); + return columnList; + } + + private Component getStatusIcon(final Object itemId) { + final Item row1 = getItem(itemId); + final TargetUpdateStatus targetStatus = (TargetUpdateStatus) row1 + .getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).getValue(); + final Label label = SPUIComponentProvider.getLabel("", SPUILabelDefinitions.SP_LABEL_SIMPLE); + label.setContentMode(ContentMode.HTML); + if (targetStatus == TargetUpdateStatus.PENDING) { + label.setDescription("Pending"); + label.setStyleName("statusIconYellow"); + label.setValue(FontAwesome.ADJUST.getHtml()); + } else if (targetStatus == TargetUpdateStatus.REGISTERED) { + label.setDescription("Registered"); + label.setStyleName("statusIconLightBlue"); + label.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); + } else if (targetStatus == TargetUpdateStatus.ERROR) { + label.setDescription(i18n.get("label.error")); + label.setStyleName("statusIconRed"); + label.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); + } else if (targetStatus == TargetUpdateStatus.IN_SYNC) { + label.setStyleName("statusIconGreen"); + label.setDescription("In-Synch"); + label.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); + } else if (targetStatus == TargetUpdateStatus.UNKNOWN) { + label.setStyleName("statusIconBlue"); + label.setDescription(i18n.get("label.unknown")); + label.setValue(FontAwesome.QUESTION_CIRCLE.getHtml()); + } + return label; + } + + private void setColumnProperties() { + final List columnList = getVisbleColumns(); + final List swColumnIds = new ArrayList<>(); + for (final TableColumn column : columnList) { + setColumnHeader(column.getColumnPropertyId(), column.getColumnHeader()); + setColumnExpandRatio(column.getColumnPropertyId(), column.getExpandRatio()); + swColumnIds.add(column.getColumnPropertyId()); + } + setVisibleColumns(swColumnIds.toArray()); + } + + protected void addCustomGeneratedColumns() { + addGeneratedColumn(SPUILabelDefinitions.STATUS_ICON, (source, itemId, columnId) -> getStatusIcon(itemId)); + } + + private void onQuery() { + populateTableData(); + eventBus.publish(this, CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON); + } + + public class TooltipGenerator implements ItemDescriptionGenerator { + private static final long serialVersionUID = 688730421728162456L; + + @Override + public String generateDescription(Component source, Object itemId, Object propertyId) { + final DistributionSet distributionSet; + final Item item = getItem(itemId); + if (propertyId != null) { + if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } + } + return null; + } + + private String getDSDetails(final DistributionSet distributionSet) { + StringBuilder swModuleNames = new StringBuilder(); + StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = (Set)distributionSet.getModules(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("
    "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" Required Migration step : ") + .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append("
  • "); + + stringBuilder.append("
"); + return stringBuilder.toString(); + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index dac50ab0d..fae76caf9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -41,183 +41,188 @@ import com.google.common.base.Strings; * */ public class TargetBeanQuery extends AbstractBeanQuery { - private static final long serialVersionUID = -5645680058303167558L; - private Sort sort = new Sort(SPUIDefinitions.TARGET_TABLE_CREATE_AT_SORT_ORDER, "createdAt"); - private Collection status = null; - private String[] targetTags = null; - private Long distributionId = null; - private String searchText = null; - private Boolean noTagClicked = Boolean.FALSE; - private transient TargetManagement targetManagement; - private transient I18N i18N; - private Long pinnedDistId = null; - private TargetFilterQuery targetFilterQuery; - private ManagementUIState managementUIState; + private static final long serialVersionUID = -5645680058303167558L; + private Sort sort = new Sort(SPUIDefinitions.TARGET_TABLE_CREATE_AT_SORT_ORDER, "createdAt"); + private Collection status = null; + private String[] targetTags = null; + private Long distributionId = null; + private String searchText = null; + private Boolean noTagClicked = Boolean.FALSE; + private transient TargetManagement targetManagement; + private transient I18N i18N; + private Long pinnedDistId = null; + private TargetFilterQuery targetFilterQuery; + private ManagementUIState managementUIState; - /** - * Parametric Constructor. - * - * @param definition - * as Def - * @param queryConfig - * as Config - * @param sortIds - * as sort - * @param sortStates - * as Sort status - */ - public TargetBeanQuery(final QueryDefinition definition, final Map queryConfig, - final Object[] sortIds, final boolean[] sortStates) { - super(definition, queryConfig, sortIds, sortStates); + /** + * Parametric Constructor. + * + * @param definition + * as Def + * @param queryConfig + * as Config + * @param sortIds + * as sort + * @param sortStates + * as Sort status + */ + public TargetBeanQuery(final QueryDefinition definition, final Map queryConfig, + final Object[] sortIds, final boolean[] sortStates) { + super(definition, queryConfig, sortIds, sortStates); - if (HawkbitCommonUtil.mapCheckStrKey(queryConfig)) { - status = (Collection) queryConfig.get(SPUIDefinitions.FILTER_BY_STATUS); - targetTags = (String[]) queryConfig.get(SPUIDefinitions.FILTER_BY_TAG); - noTagClicked = (Boolean) queryConfig.get(SPUIDefinitions.FILTER_BY_NO_TAG); - distributionId = (Long) queryConfig.get(SPUIDefinitions.FILTER_BY_DISTRIBUTION); - searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); - targetFilterQuery = (TargetFilterQuery) queryConfig.get(SPUIDefinitions.FILTER_BY_TARGET_FILTER_QUERY); - if (!Strings.isNullOrEmpty(searchText)) { - searchText = String.format("%%%s%%", searchText); - } - pinnedDistId = (Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION); - } + if (HawkbitCommonUtil.mapCheckStrKey(queryConfig)) { + status = (Collection) queryConfig.get(SPUIDefinitions.FILTER_BY_STATUS); + targetTags = (String[]) queryConfig.get(SPUIDefinitions.FILTER_BY_TAG); + noTagClicked = (Boolean) queryConfig.get(SPUIDefinitions.FILTER_BY_NO_TAG); + distributionId = (Long) queryConfig.get(SPUIDefinitions.FILTER_BY_DISTRIBUTION); + searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); + targetFilterQuery = (TargetFilterQuery) queryConfig.get(SPUIDefinitions.FILTER_BY_TARGET_FILTER_QUERY); + if (!Strings.isNullOrEmpty(searchText)) { + searchText = String.format("%%%s%%", searchText); + } + pinnedDistId = (Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION); + } - if (HawkbitCommonUtil.checkBolArray(sortStates)) { - // Initalize Sor - sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); - // Add sort. - for (int targetId = 1; targetId < sortIds.length; targetId++) { - sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); - } - } - } + if (HawkbitCommonUtil.checkBolArray(sortStates)) { + // Initalize Sor + sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); + // Add sort. + for (int targetId = 1; targetId < sortIds.length; targetId++) { + sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); + } + } + } - @Override - protected ProxyTarget constructBean() { - return new ProxyTarget(); - } + @Override + protected ProxyTarget constructBean() { + return new ProxyTarget(); + } - @Override - protected List loadBeans(final int startIndex, final int count) { - Slice targetBeans; - final List proxyTargetBeans = new ArrayList<>(); - if (pinnedDistId != null) { - targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet( - new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId, - distributionId, status, searchText, noTagClicked, targetTags); - } else if (null != targetFilterQuery) { - targetBeans = getTargetManagement().findTargetsAll(targetFilterQuery, - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); - } else if (!anyFilterSelected()) { - targetBeans = getTargetManagement().findTargetsAll( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); - } else { - targetBeans = getTargetManagement().findTargetByFilters( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), status, - searchText, distributionId, noTagClicked, targetTags); - } - for (final Target targ : targetBeans) { - final ProxyTarget prxyTarget = new ProxyTarget(); - prxyTarget.setTargetIdName(targ.getTargetIdName()); - prxyTarget.setName(targ.getName()); - prxyTarget.setDescription(targ.getDescription()); - prxyTarget.setControllerId(targ.getControllerId()); - prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate()); - prxyTarget.setAddress(targ.getTargetInfo().getAddress()); - prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); - prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); - prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); - prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); - prxyTarget.setCreatedAt(targ.getCreatedAt()); - prxyTarget.setCreatedByUser(HawkbitCommonUtil.getIMUser(targ.getCreatedBy())); - prxyTarget.setModifiedByUser(HawkbitCommonUtil.getIMUser(targ.getLastModifiedBy())); + @Override + protected List loadBeans(final int startIndex, final int count) { + Slice targetBeans; + final List proxyTargetBeans = new ArrayList<>(); + if (pinnedDistId != null) { + targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet( + new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId, + distributionId, status, searchText, noTagClicked, targetTags); + } else if (null != targetFilterQuery) { + targetBeans = getTargetManagement().findTargetsAll(targetFilterQuery, + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + } else if (!anyFilterSelected()) { + targetBeans = getTargetManagement().findTargetsAll( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + } else { + targetBeans = getTargetManagement().findTargetByFilters( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), status, + searchText, distributionId, noTagClicked, targetTags); + } + for (final Target targ : targetBeans) { + final ProxyTarget prxyTarget = new ProxyTarget(); + prxyTarget.setTargetIdName(targ.getTargetIdName()); + prxyTarget.setName(targ.getName()); + prxyTarget.setDescription(targ.getDescription()); + prxyTarget.setControllerId(targ.getControllerId()); + prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate()); + prxyTarget.setAddress(targ.getTargetInfo().getAddress()); + prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); + prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); + prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); + prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); + prxyTarget.setCreatedAt(targ.getCreatedAt()); + prxyTarget.setCreatedByUser(HawkbitCommonUtil.getIMUser(targ.getCreatedBy())); + prxyTarget.setModifiedByUser(HawkbitCommonUtil.getIMUser(targ.getLastModifiedBy())); - if (pinnedDistId == null) { - prxyTarget.setInstalledDistributionSet(null); - prxyTarget.setAssignedDistributionSet(null); - } else { - final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); - final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); - prxyTarget.setInstalledDistributionSet(installedDistributionSet); - final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet(); - prxyTarget.setAssignedDistributionSet(assignedDistributionSet); - } + if (pinnedDistId == null) { + prxyTarget.setInstalledDistributionSet(null); + prxyTarget.setAssignedDistributionSet(null); - prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); - prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); - prxyTarget.setTargetInfo(targ.getTargetInfo()); - prxyTarget.setPollStatusToolTip( - HawkbitCommonUtil.getPollStatusToolTip(prxyTarget.getTargetInfo().getPollStatus(), getI18N())); - proxyTargetBeans.add(prxyTarget); - } - return proxyTargetBeans; - } + } else { + final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); + final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); + prxyTarget.setInstalledDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( + installedDistributionSet.getName(), installedDistributionSet.getVersion())); + prxyTarget.setInstalledDistributionSet(installedDistributionSet); + final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet(); + prxyTarget.setAssignedDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( + assignedDistributionSet.getName(), assignedDistributionSet.getVersion())); + prxyTarget.setAssignedDistributionSet(assignedDistributionSet); + } - private Boolean isTagSelected() { - if (targetTags == null && !noTagClicked) { - return false; - } - return true; - } + prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); + prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); + prxyTarget.setTargetInfo(targ.getTargetInfo()); + prxyTarget.setPollStatusToolTip( + HawkbitCommonUtil.getPollStatusToolTip(prxyTarget.getTargetInfo().getPollStatus(), getI18N())); + proxyTargetBeans.add(prxyTarget); + } + return proxyTargetBeans; + } - @Override - protected void saveBeans(final List addedTargets, final List modifiedTargets, - final List removedTargets) { - // CRUD operations on Target will be done through repository methods - } + private Boolean isTagSelected() { + if (targetTags == null && !noTagClicked) { + return false; + } + return true; + } - private Boolean anyFilterSelected() { - if (status == null && distributionId == null && Strings.isNullOrEmpty(searchText) && !isTagSelected()) { - return false; - } - return true; - } + @Override + protected void saveBeans(final List addedTargets, final List modifiedTargets, + final List removedTargets) { + // CRUD operations on Target will be done through repository methods + } - @Override - public int size() { - final long totSize = getTargetManagement().countTargetsAll(); - long size; - if (null != targetFilterQuery) { - size = getTargetManagement().countTargetByTargetFilterQuery(targetFilterQuery); - } else if (!anyFilterSelected()) { - size = totSize; - } else { - size = getTargetManagement().countTargetByFilters(status, searchText, distributionId, noTagClicked, - targetTags); - } + private Boolean anyFilterSelected() { + if (status == null && distributionId == null && Strings.isNullOrEmpty(searchText) && !isTagSelected()) { + return false; + } + return true; + } - final ManagementUIState tmpManagementUIState = getManagementUIState(); - tmpManagementUIState.setTargetsCountAll(totSize); - if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) { - tmpManagementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES); - size = SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES; - } else { - tmpManagementUIState.setTargetsTruncated(null); - } + @Override + public int size() { + final long totSize = getTargetManagement().countTargetsAll(); + long size; + if (null != targetFilterQuery) { + size = getTargetManagement().countTargetByTargetFilterQuery(targetFilterQuery); + } else if (!anyFilterSelected()) { + size = totSize; + } else { + size = getTargetManagement().countTargetByFilters(status, searchText, distributionId, noTagClicked, + targetTags); + } - return (int) size; - } + final ManagementUIState tmpManagementUIState = getManagementUIState(); + tmpManagementUIState.setTargetsCountAll(totSize); + if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) { + tmpManagementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES); + size = SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES; + } else { + tmpManagementUIState.setTargetsTruncated(null); + } - private TargetManagement getTargetManagement() { - if (targetManagement == null) { - targetManagement = SpringContextHelper.getBean(TargetManagement.class); - } - return targetManagement; - } + return (int) size; + } - private ManagementUIState getManagementUIState() { - if (managementUIState == null) { - managementUIState = SpringContextHelper.getBean(ManagementUIState.class); - } - return managementUIState; - } + private TargetManagement getTargetManagement() { + if (targetManagement == null) { + targetManagement = SpringContextHelper.getBean(TargetManagement.class); + } + return targetManagement; + } - private I18N getI18N() { - if (i18N == null) { - i18N = SpringContextHelper.getBean(I18N.class); - } - return i18N; - } + private ManagementUIState getManagementUIState() { + if (managementUIState == null) { + managementUIState = SpringContextHelper.getBean(ManagementUIState.class); + } + return managementUIState; + } + + private I18N getI18N() { + if (i18N == null) { + i18N = SpringContextHelper.getBean(I18N.class); + } + return i18N; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 3b9c18952..2bfb717f3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -24,7 +24,9 @@ import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetIdName; @@ -40,6 +42,7 @@ 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.filtermanagement.CreateOrUpdateFilterTable.TooltipGenerator; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementViewAcceptCriteria; @@ -92,6 +95,7 @@ import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; +import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator; /** * Concrete implementation of Target table. @@ -108,6 +112,9 @@ public class TargetTable extends AbstractTable implements private static final int PROPERTY_DEPT = 3; private static final String ACTION_NOT_ALLOWED_MSG = "message.action.not.allowed"; + + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; + private static final String INSTALL_DIST_SET = "installedDistributionSet"; @Autowired private transient TargetManagement targetManagement; @@ -136,6 +143,7 @@ public class TargetTable extends AbstractTable implements addActionHandler(this); actionSelectAll = new ShortcutAction(i18n.get("action.target.table.selectall")); actionUnSelectAll = new ShortcutAction(i18n.get("action.target.table.clear")); + setItemDescriptionGenerator(new TooltipGenerator()); } /** @@ -1073,4 +1081,61 @@ public class TargetTable extends AbstractTable implements private boolean isFilteredByTags() { return !managementUIState.getTargetTableFilters().getClickedTargetTags().isEmpty(); } + + + /** + * tooltip for assignedDS and installedDS + */ + + protected class TooltipGenerator implements ItemDescriptionGenerator { + private static final long serialVersionUID = 688730421728162456L; + + @Override + public String generateDescription(Component source, Object itemId, Object propertyId) { + final DistributionSet distributionSet; + final Item item = getItem(itemId); + if (propertyId != null) { + if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } + } + return null; + } + + private String getDSDetails(final DistributionSet distributionSet) { + StringBuilder swModuleNames = new StringBuilder(); + StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = (Set)distributionSet.getModules(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("
    "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" Required Migration step : ") + .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append("
  • "); + stringBuilder.append("
"); + return stringBuilder.toString(); + } + } } \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 6514ba2df..a010a3ba4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -8,7 +8,10 @@ */ package org.eclipse.hawkbit.ui.rollout.rollout; +import java.util.Set; + import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.vaadin.server.FontAwesome; @@ -30,11 +33,85 @@ public class ProxyRollout extends Rollout { private Long numberOfGroups; private Boolean isActionRecieved = Boolean.FALSE; + + private Boolean isRequiredMigrationStep = Boolean.FALSE; private String totalTargetsCount; private RolloutRendererData rolloutRendererData; + + private String discription; + private String type; + + private Set swModules; + + + + /** + * @return the isRequiredMigrationStep + */ + + public Boolean getIsRequiredMigrationStep() { + return isRequiredMigrationStep; + } + + /** + * @param isRequiredMigrationStep + * the isRequiredMigrationStep to set + */ + + public void setIsRequiredMigrationStep(Boolean isRequiredMigrationStep) { + this.isRequiredMigrationStep = isRequiredMigrationStep; + } + + + /** + * @return the discription + */ + + public String getDiscription() { + return discription; + } + + /** + * @param discription + * the discription to set + */ + + public void setDiscription(String discription) { + this.discription = discription; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type + * the type to set + */ + + public void setType(String type) { + this.type = type; + } + /** + * + * @return the Set of Software modules + */ + public Set getSwModules() { + return swModules; + } + /** + * @param swModules + * Set to set + */ + public void setSwModules(Set swModules) { + this.swModules = swModules; + } public RolloutRendererData getRolloutRendererData() { return rolloutRendererData; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 34ae323da..dbd01ac8a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -136,6 +136,11 @@ public class RolloutBeanQuery extends AbstractBeanQuery { final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); + + proxyRollout.setDescription(distributionSet.getDescription()); + proxyRollout.setType(distributionSet.getType().getName()); + proxyRollout.setIsRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); + proxyRollout.setSwModules(distributionSet.getModules()); proxyRolloutList.add(proxyRollout); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 1bb0fd831..c68bbf700 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -14,12 +14,14 @@ import java.util.EnumMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; @@ -68,562 +70,619 @@ import com.vaadin.ui.renderers.HtmlRenderer; @ViewScope public class RolloutListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; - - private static final String UPDATE_OPTION = "Update"; - - private static final String RESUME_OPTION = "Resume"; - - private static final String PAUSE_OPTION = "Pause"; - - private static final String START_OPTION = "Start"; - - private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; - - @Autowired - private UINotification uiNotification; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - - /** - * Handles the RolloutEvent to refresh Grid. - * - */ - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - switch (event) { - case FILTER_BY_TEXT: - case CREATE_ROLLOUT: - case UPDATE_ROLLOUT: - case SHOW_ROLLOUTS: - refreshGrid(); - break; - default: - return; - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the grid. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - if (!rolloutUIState.isShowRollOuts()) { - return; - } - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - final int groupsCreated = rollout.getRolloutGroupsCreated(); - if (groupsCreated != 0) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); - } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Long.valueOf(rollout.getRolloutGroups().size())); - } - item.getItemProperty(ROLLOUT_RENDERER_DATA) - .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); - - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, - FontAwesome.CIRCLE_O.getHtml(), false, false); - - } - - @Override - protected void setColumnExpandRatio() { - - getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); - getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - - setFrozenColumnCount(getColumns().size()); - } - - @Override - protected void setColumnHeaderNames() { - getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); - } - - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; - } - - @Override - protected void setColumnProperties() { - final List columnList = new ArrayList<>(); - columnList.add(ROLLOUT_RENDERER_DATA); - columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ACTION); - - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } - - @Override - protected void setHiddenColumns() { - final List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (final Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - - } - - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } - - @Override - protected void addColumnRenderes() { - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), - new TotalTargetGroupsConverter()); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - - createRolloutStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); - - getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - - final RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); - customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); - getColumn(ROLLOUT_RENDERER_DATA).setRenderer(customObjectRenderer); - - } - - private void createRolloutStatusToFontMap() { - statusIconMap.put(RolloutStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutStatus.PAUSED, - new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); - statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); - statusIconMap.put(RolloutStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutStatus.STOPPED, - new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); - statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); - statusIconMap.put(RolloutStatus.ERROR_CREATING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.ERROR_STARTING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } - - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; - - @Override - public String getStyle(final CellReference cellReference) { - final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } - - private void onClickOfRolloutName(final RendererClickEvent event) { - rolloutUIState.setRolloutId((long) event.getItemId()); - final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - final String ds = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); - rolloutUIState.setRolloutDistributionSet(ds); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private void onClickOfActionBtn(final RendererClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); - contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - final Item row = getContainerDataSource().getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - - switch (rolloutStatus) { - case READY: - final ContextMenuItem startItem = context.addItem(START_OPTION); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - break; - case RUNNING: - final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - break; - case PAUSED: - final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - break; - case STARTING: - case CREATING: - case ERROR_CREATING: - case ERROR_STARTING: - // do not provide any action on these statuses - return context; - default: - break; - } - getUpdateMenuItem(context, rolloutId); - return context; - } - - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { - // Add 'Update' option only if user has update permission - if (!permissionChecker.hasRolloutUpdatePermission()) { - return; - } - final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - switch (contextMenuData.getAction()) { - case PAUSE: - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - break; - case RESUME: - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - break; - case START: - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - break; - case UPDATE: - onUpdate(contextMenuData); - break; - default: - break; - } - } - - private void onUpdate(final ContextMenuData contextMenuData) { - addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); - final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); - addTargetWindow.setCaption(i18n.get("caption.update.rollout")); - UI.getCurrent().addWindow(addTargetWindow); - addTargetWindow.setVisible(Boolean.TRUE); - } - - private void refreshGrid() { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - - /** - * Generator to generate fontIcon by String. - */ - public final class FontIconGenerator extends PropertyValueGenerator { - - private static final long serialVersionUID = 2544026030795375748L; - private final FontAwesome fontIcon; - - public FontIconGenerator(final FontAwesome icon) { - this.fontIcon = icon; - } - - @Override - public String getValue(final Item item, final Object itemId, final Object propertyId) { - return fontIcon.getHtml(); - } - - @Override - public Class getType() { - return String.class; - } - } - - private String getDescription(final CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { - return ((RolloutRendererData) cell.getProperty().getValue()).getName(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } - return null; - } - - enum ACTION { - PAUSE, RESUME, START, UPDATE - } - - /** - * Represents data of context menu item. - * - */ - public static class ContextMenuData { - - private Long rolloutId; - - private ACTION action; - - /** - * Set rollout if and action. - * - * @param rolloutId - * id of rollout - * @param action - * user action {@link ACTION} - */ - public ContextMenuData(final Long rolloutId, final ACTION action) { - this.action = action; - this.rolloutId = rolloutId; - } - - /** - * @return the rolloutId - */ - public Long getRolloutId() { - return rolloutId; - } - - /** - * @param rolloutId - * the rolloutId to set - */ - public void setRolloutId(final Long rolloutId) { - this.rolloutId = rolloutId; - } - - /** - * @return the action - */ - public ACTION getAction() { - return action; - } - - /** - * @param action - * the action to set - */ - public void setAction(final ACTION action) { - this.action = action; - } - } - - /** - * - * Converter to convert {@link RolloutStatus} to string. - * - */ - class RolloutStatusConverter implements Converter { - - private static final long serialVersionUID = -1217685750825632678L; - - @Override - public RolloutStatus convertToModel(final String value, final Class targetType, - final Locale locale) { - return null; - } - - @Override - public String convertToPresentation(final RolloutStatus value, final Class targetType, - final Locale locale) { - return convertRolloutStatusToString(value); - } - - @Override - public Class getModelType() { - return RolloutStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - private String convertRolloutStatusToString(final RolloutStatus value) { - final StatusFontIcon statusFontIcon = statusIconMap.get(value); - final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - } - - /** - * Converter to convert {@link TotalTargetCountStatus} to formatted string - * with status and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { - - private static final long serialVersionUID = -5794528427855153924L; - - @Override - public TotalTargetCountStatus convertToModel(final String value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(final TotalTargetCountStatus value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } - - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - /** - * Converter to convert 0 to empty, if total target groups is zero. - * - */ - class TotalTargetGroupsConverter implements Converter { - - private static final long serialVersionUID = 6589305227035220369L; - - @Override - public Long convertToModel(final String value, final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(final Long value, final Class targetType, - final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - if (value == 0) { - return ""; - } - return value.toString(); - } - - @Override - public Class getModelType() { - return Long.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - } + private static final long serialVersionUID = 4060904914954370524L; + + private static final String UPDATE_OPTION = "Update"; + + private static final String RESUME_OPTION = "Resume"; + + private static final String PAUSE_OPTION = "Pause"; + + private static final String START_OPTION = "Start"; + + private static final String DS_TYPE = "type"; + + private static final String SW_MODULES = "swModules"; + + private static final String IS_REQUIRED_MIGRATION_STEP = "isRequiredMigrationStep"; + + private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + + /** + * Handles the RolloutEvent to refresh Grid. + * + */ + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + switch (event) { + case FILTER_BY_TEXT: + case CREATE_ROLLOUT: + case UPDATE_ROLLOUT: + case SHOW_ROLLOUTS: + refreshGrid(); + break; + default: + return; + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the grid. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (!rolloutUIState.isShowRollOuts()) { + return; + } + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + final int groupsCreated = rollout.getRolloutGroupsCreated(); + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); + } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + item.getItemProperty(ROLLOUT_RENDERER_DATA) + .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGridContainer.addContainerProperty(DS_TYPE, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SW_MODULES, Set.class, null, false, false); + rolloutGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(IS_REQUIRED_MIGRATION_STEP, boolean.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + + getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); + getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); + getColumn(DS_TYPE).setHeaderCaption("Type"); + getColumn(SW_MODULES).setHeaderCaption("swModules"); + getColumn(IS_REQUIRED_MIGRATION_STEP).setHeaderCaption("IsRequiredMigrationStep"); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + final List columnList = new ArrayList<>(); + columnList.add(ROLLOUT_RENDERER_DATA); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(DS_TYPE); + columnList.add(SW_MODULES); + columnList.add(IS_REQUIRED_MIGRATION_STEP); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void setHiddenColumns() { + final List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + columnsToBeHidden.add(IS_REQUIRED_MIGRATION_STEP); + columnsToBeHidden.add(DS_TYPE); + columnsToBeHidden.add(SW_MODULES); + for (final Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), + new TotalTargetGroupsConverter()); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + + createRolloutStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); + + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + + final RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); + customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); + getColumn(ROLLOUT_RENDERER_DATA).setRenderer(customObjectRenderer); + + } + + private void createRolloutStatusToFontMap() { + statusIconMap.put(RolloutStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutStatus.PAUSED, + new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); + statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); + statusIconMap.put(RolloutStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutStatus.STOPPED, + new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); + statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); + statusIconMap.put(RolloutStatus.ERROR_CREATING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.ERROR_STARTING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + private void onClickOfRolloutName(final RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + rolloutUIState.setRolloutName(rolloutName); + final String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(final RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + + switch (rolloutStatus) { + case READY: + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + break; + case RUNNING: + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + break; + case PAUSED: + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + break; + case STARTING: + case CREATING: + case ERROR_CREATING: + case ERROR_STARTING: + // do not provide any action on these statuses + return context; + default: + break; + } + getUpdateMenuItem(context, rolloutId); + return context; + } + + private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { + // Add 'Update' option only if user has update permission + if (!permissionChecker.hasRolloutUpdatePermission()) { + return; + } + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + switch (contextMenuData.getAction()) { + case PAUSE: + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + break; + case RESUME: + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + break; + case START: + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + break; + case UPDATE: + onUpdate(contextMenuData); + break; + default: + break; + } + } + + private void onUpdate(final ContextMenuData contextMenuData) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + + private void refreshGrid() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + /** + * Generator to generate fontIcon by String. + */ + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(final FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(final Item item, final Object itemId, final Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + private String getDescription(final CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } else if (SPUILabelDefinitions.VAR_DIST_NAME_VERSION.equals(cell.getPropertyId())) { + return getDSDetails((Item) cell.getItem()); + } + return null; + } + + private String getDSDetails(final Item rolloutItem) { + StringBuilder swModuleNames = new StringBuilder(); + StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = (Set) rolloutItem.getItemProperty(SW_MODULES).getValue(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("
    "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Description : ") + .append((String) rolloutItem.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Type : ") + .append((String) rolloutItem.getItemProperty(DS_TYPE).getValue()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("Required Migration step : ") + .append((boolean) rolloutItem.getItemProperty(IS_REQUIRED_MIGRATION_STEP).getValue() ? "Yes" : "No"); + stringBuilder.append("
  • "); + + stringBuilder.append("
  • "); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append("
  • "); + + stringBuilder.append("
  • "); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append("
  • "); + + stringBuilder.append("
"); + return stringBuilder.toString(); + } + + enum ACTION { + PAUSE, RESUME, START, UPDATE + } + + /** + * Represents data of context menu item. + * + */ + public static class ContextMenuData { + + private Long rolloutId; + + private ACTION action; + + /** + * Set rollout if and action. + * + * @param rolloutId + * id of rollout + * @param action + * user action {@link ACTION} + */ + public ContextMenuData(final Long rolloutId, final ACTION action) { + this.action = action; + this.rolloutId = rolloutId; + } + + /** + * @return the rolloutId + */ + public Long getRolloutId() { + return rolloutId; + } + + /** + * @param rolloutId + * the rolloutId to set + */ + public void setRolloutId(final Long rolloutId) { + this.rolloutId = rolloutId; + } + + /** + * @return the action + */ + public ACTION getAction() { + return action; + } + + /** + * @param action + * the action to set + */ + public void setAction(final ACTION action) { + this.action = action; + } + } + + /** + * + * Converter to convert {@link RolloutStatus} to string. + * + */ + class RolloutStatusConverter implements Converter { + + private static final long serialVersionUID = -1217685750825632678L; + + @Override + public RolloutStatus convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, final Class targetType, + final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } + } + + /** + * Converter to convert {@link TotalTargetCountStatus} to formatted string + * with status and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { + + private static final long serialVersionUID = -5794528427855153924L; + + @Override + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * Converter to convert 0 to empty, if total target groups is zero. + * + */ + class TotalTargetGroupsConverter implements Converter { + + private static final long serialVersionUID = 6589305227035220369L; + + @Override + public Long convertToModel(final String value, final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final Long value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + if (value == 0) { + return ""; + } + return value.toString(); + } + + @Override + public Class getModelType() { + return Long.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 117b5bcb8..7fdf3a46b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -106,6 +107,9 @@ public final class HawkbitCommonUtil { private static final String TARGET_TAG_DROP_REMOVE_SCRIPT = "var m = document.getElementById('show-filter-drop-hint'); if(m) { document.head.removeChild(m); } "; private static final String DELETE_DROP_CREATE_SCRIPT = "var q = document.getElementById('show-delete-drop-hint'); if(q) { } else { showDeleteDrop = document.createElement('style'); showDeleteDrop.id=\"show-delete-drop-hint\"; document.head.appendChild(showDeleteDrop); }"; private static final String DELETE_TAG_DROP_REMOVE_SCRIPT = "var o = document.getElementById('show-delete-drop-hint'); if(o) { document.head.removeChild(o); } "; + + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; + private static final String INSTALL_DIST_SET = "installedDistributionSet"; /** * Define empty string. @@ -1090,6 +1094,10 @@ public final class HawkbitCommonUtil { targetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP, String.class, null, false, true); targetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); + + targetTableContainer.addContainerProperty(ASSIGN_DIST_SET, DistributionSet.class, null, false, true); + targetTableContainer.addContainerProperty(INSTALL_DIST_SET, DistributionSet.class, null, false, true); + } /** From 0b275655c01f07bd5c0bd0b3bcf4df2dd2b73659 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Tue, 26 Apr 2016 18:47:47 +0530 Subject: [PATCH 51/69] Focus-TextArea-On-AddNewWindow Signed-off-by: venu1278 --- .../artifacts/smtable/SoftwareModuleAddUpdateWindow.java | 3 ++- .../artifacts/smtype/CreateUpdateSoftwareTypeLayout.java | 1 + .../disttype/CreateUpdateDistSetTypeLayout.java | 3 ++- .../dstable/DistributionAddUpdateWindowLayout.java | 7 ++++--- .../hawkbit/ui/management/tag/CreateUpdateTagLayout.java | 7 ++++--- .../targettable/TargetAddUpdateWindowLayout.java | 2 +- .../ui/rollout/rollout/AddUpdateRolloutWindowLayout.java | 1 + 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index cc08929bb..1e4029087 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -234,12 +234,13 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { mainLayout.addComponent(hLayout); mainLayout.setComponentAlignment(hLayout, Alignment.MIDDLE_LEFT); mainLayout.addComponents(nameTextField, versionTextField, vendorTextField, descTextArea, buttonsLayout); - + /* add main layout to the window */ window = SPUIComponentProvider.getWindow(i18n.get("upload.caption.add.new.swmodule"), null, SPUIDefinitions.CREATE_UPDATE_WINDOW); window.setContent(mainLayout); window.setModal(true); + nameTextField.focus(); } private void addDescriptionTextChangeListener() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index dc6d1081e..fe1fa9024 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -257,6 +257,7 @@ public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements C mainLayout = new HorizontalLayout(); mainLayout.addComponent(fieldButtonLayout); setCompositionRoot(mainLayout); + typeName.focus(); } private void addListeners() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java index 8d609f628..64a06bd38 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java @@ -284,7 +284,7 @@ public class CreateUpdateDistSetTypeLayout extends CustomComponent implements Co mainLayout.addComponent(fieldLayout); mainLayout.addComponent(twinTableLayout); - + colorLayout = new HorizontalLayout(); sliderLayout = new VerticalLayout(); final HorizontalLayout chooseColorLayout = new HorizontalLayout(); @@ -299,6 +299,7 @@ public class CreateUpdateDistSetTypeLayout extends CustomComponent implements Co mainWindowLayout.addComponent(colorLayout); mainWindowLayout.addComponent(buttonLayout); setCompositionRoot(mainWindowLayout); + typeName.focus(); } private HorizontalLayout createTwinColumnLayout() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 80c1b5700..5d9304191 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -145,11 +145,12 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { setSizeUndefined(); addComponents(madatoryLabel, distsetTypeNameComboBox, distNameTextField, distVersionTextField, descTextArea, reqMigStepCheckbox); - + addComponent(buttonsLayout); setComponentAlignment(madatoryLabel, Alignment.MIDDLE_LEFT); - - } + distNameTextField.focus(); + + } /** * Create required UI components. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java index b78db6b4f..6bed7dd4f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java @@ -171,7 +171,7 @@ public abstract class CreateUpdateTagLayout extends CustomComponent implements C tagName = SPUIComponentProvider.getTextField("", ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_NAME, true, "", i18n.get("textfield.name"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH); tagName.setId(SPUIDefinitions.NEW_TARGET_TAG_NAME); - + tagDesc = SPUIComponentProvider.getTextArea("", ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_DESC, false, "", i18n.get("textfield.description"), SPUILabelDefinitions.TEXT_AREA_MAX_LENGTH); @@ -237,7 +237,8 @@ public abstract class CreateUpdateTagLayout extends CustomComponent implements C fieldLayout.addComponent(madatoryLabel); fieldLayout.addComponent(tagName); fieldLayout.addComponent(tagDesc); - + + final HorizontalLayout colorLabelLayout = new HorizontalLayout(); colorLabelLayout.addComponents(colorLabel, tagColorPreviewBtn); fieldLayout.addComponent(colorLabelLayout); @@ -257,8 +258,8 @@ public abstract class CreateUpdateTagLayout extends CustomComponent implements C mainLayout = new HorizontalLayout(); mainLayout.addComponent(fieldButtonLayout); - setCompositionRoot(mainLayout); + tagName.focus(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index 973d61857..e54911d86 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -152,7 +152,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { madatoryLabel.setVisible(Boolean.FALSE); } mainLayout.addComponents(madatoryLabel, controllerIDTextField, nameTextField, descTextArea, buttonsLayout); - + nameTextField.focus(); } private void addListeners() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index e5e86c520..7e8d45e1b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -209,6 +209,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { actionTypeOptionGroupLayout, linkToHelp, getSaveDiscardButtonLayout()); mainLayout.setComponentAlignment(linkToHelp, Alignment.BOTTOM_RIGHT); setCompositionRoot(mainLayout); + rolloutName.focus(); } private HorizontalLayout getGroupDetailsLayout() { From 5c86d2ad682c6c07fd5162087aedb0e54c3de190 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 26 Apr 2016 17:36:19 +0200 Subject: [PATCH 52/69] Upgrade Vaadin and MariaDB to newest stable version. Signed-off-by: Kai Zimmermann --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0c3207c13..b6d09758e 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 1.0.0 0.0.6.RELEASE - 7.6.4 + 7.6.5 ${vaadin.version} 7.4.0.1 2.2.0 @@ -94,7 +94,7 @@ 0.9.1 1.8.5 19.0 - 1.3.5 + 1.4.3 1.50.2 1.18.1 2.2.4 From 9dd51e710544a58134ceb7d40981e3b0f0191c7e Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 27 Apr 2016 15:37:54 +0200 Subject: [PATCH 53/69] Use java 8 duration to calculate ttl Signed-off-by: SirWayne --- .../org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java index e9ad60a1c..7ed5e90c1 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpDeadletterProperties.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.amqp; +import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -25,7 +26,7 @@ public class AmqpDeadletterProperties { * Message time to live (ttl) for the deadletter queue. Default ttl is 3 * weeks. */ - private int ttl = 1_814_400_000; + private long ttl = Duration.ofDays(21).toMillis(); /** * Return the deadletter arguments. @@ -57,11 +58,11 @@ public class AmqpDeadletterProperties { return args; } - public int getTtl() { + public long getTtl() { return ttl; } - public void setTtl(final int ttl) { + public void setTtl(final long ttl) { this.ttl = ttl; } From b53a635c1fc12146697767d6fcedcb851f60d0a9 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Wed, 27 Apr 2016 16:50:33 +0200 Subject: [PATCH 54/69] introduce a conditional property which allows to disable the startup generation of default simulator devices. Signed-off-by: Michael Hirsch --- .../java/org/eclipse/hawkbit/simulator/SimulatorStartup.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java index b772bae1f..9e6c0573a 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; @@ -25,6 +26,7 @@ import org.springframework.stereotype.Component; * */ @Component +@ConditionalOnProperty(prefix = "com.bosch.hawkbit.simulator", name = "generateOnStartup", matchIfMissing = true) public class SimulatorStartup implements ApplicationListener { private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorStartup.class); From e5880561a1191fb2a96dbe7fa121638d74e3a8c7 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Wed, 27 Apr 2016 16:59:39 +0200 Subject: [PATCH 55/69] re-name property aligning the autostart property Signed-off-by: Michael Hirsch --- .../java/org/eclipse/hawkbit/simulator/SimulatorStartup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java index 9e6c0573a..19367a9d4 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -26,7 +26,7 @@ import org.springframework.stereotype.Component; * */ @Component -@ConditionalOnProperty(prefix = "com.bosch.hawkbit.simulator", name = "generateOnStartup", matchIfMissing = true) +@ConditionalOnProperty(prefix = "hawkbit.device.simulator", name = "autostart", matchIfMissing = true) public class SimulatorStartup implements ApplicationListener { private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorStartup.class); From 63d6448432d5474373de49cde1d7f5194d8981cc Mon Sep 17 00:00:00 2001 From: venu1278 Date: Thu, 28 Apr 2016 11:55:48 +0530 Subject: [PATCH 56/69] Displaying DistributionSet Details in Tooltip Signed-off-by: venu1278 --- .../hawkbit/ui/management/targettable/TargetBeanQuery.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index d6b7f47c9..943efc262 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -131,8 +131,8 @@ public class TargetBeanQuery extends AbstractBeanQuery { prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); prxyTarget.setCreatedAt(targ.getCreatedAt()); - prxyTarget.setCreatedByUser(HawkbitCommonUtil.getIMUser(targ.getCreatedBy())); - prxyTarget.setModifiedByUser(HawkbitCommonUtil.getIMUser(targ.getLastModifiedBy())); + prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); + prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ)); if (pinnedDistId == null) { prxyTarget.setInstalledDistributionSet(null); From f62b740ae8dfd1518910484b9e99d6ffb40a5a32 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 11:43:46 +0200 Subject: [PATCH 57/69] change propagation level to SUPPORTS instead of NOT_SUPPORTED Signed-off-by: Michael Hirsch --- .../java/org/eclipse/hawkbit/repository/SystemManagement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index c1cee7223..be370cf2d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -164,7 +164,7 @@ public class SystemManagement { * @return the {@link CurrentTenantKeyGenerator} */ @Bean - @Transactional(propagation = Propagation.NOT_SUPPORTED) + @Transactional(propagation = Propagation.SUPPORTS) public CurrentTenantKeyGenerator currentTenantKeyGenerator() { return new CurrentTenantKeyGenerator(); } From 30788904be49bb3ab6064f5d6126871e945c2581 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 11:45:06 +0200 Subject: [PATCH 58/69] code cleanup pull-request feedback Signed-off-by: Michael Hirsch --- .../hawkbit/repository/RolloutManagement.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 6fb2ce0f9..d02b64f35 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -299,7 +299,7 @@ public class RolloutManagement { * amount of given groups. In same cases this will lead to less rollout * groups than given by client. * - * @param amountGroup + * @param amountOfGroups * the amount of groups * @param conditions * the rollout group conditions @@ -307,18 +307,17 @@ public class RolloutManagement { * the rollout * @return the rollout with created groups */ - private Rollout createRolloutGroups(final int amountGroup, final RolloutGroupConditions conditions, + private Rollout createRolloutGroups(final int amountOfGroups, final RolloutGroupConditions conditions, final Rollout savedRollout) { int pageIndex = 0; int groupIndex = 0; final Long totalCount = savedRollout.getTotalTargets(); - final int groupSize = (int) Math.ceil((double) totalCount / (double) amountGroup); - // validate if the amount of groups that will be created are the - // amount + final int groupSize = (int) Math.ceil((double) totalCount / (double) amountOfGroups); + // validate if the amount of groups that will be created are the amount // of groups that the client what's to have created. - int amountGroupValidated = amountGroup; + int amountGroupValidated = amountOfGroups; final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); - if (amountGroupCreation == (amountGroup - 1)) { + if (amountGroupCreation == (amountOfGroups - 1)) { amountGroupValidated--; } RolloutGroup lastSavedGroup = null; From 4e48c7c9d7e7d8323e337762560ae47ffb90ad60 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 11:46:01 +0200 Subject: [PATCH 59/69] code cleanup pull-request feedback Signed-off-by: Michael Hirsch --- .../org/eclipse/hawkbit/repository/RolloutManagement.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index d02b64f35..9508a6aeb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -284,13 +284,13 @@ public class RolloutManagement { } } - private Rollout createRolloutGroupsInNewTransaction(final int amountGroup, final RolloutGroupConditions conditions, + private Rollout createRolloutGroupsInNewTransaction(final int amountOfGroups, final RolloutGroupConditions conditions, final Rollout savedRollout) { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("creatingRollout"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); return new TransactionTemplate(txManager, def) - .execute(status -> createRolloutGroups(amountGroup, conditions, savedRollout)); + .execute(status -> createRolloutGroups(amountOfGroups, conditions, savedRollout)); } /** From d8d026e9a1167749b6d9f4a0f22d6c2ba814a4e7 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Thu, 28 Apr 2016 15:17:01 +0530 Subject: [PATCH 60/69] Displaying DistributionSet Details in Tooltip Signed-off-by: venu1278 --- .../ui/common/table/AbstractTable.java | 6 +- .../hawkbit/ui/components/ProxyTarget.java | 488 ++++--- .../CreateOrUpdateFilterTable.java | 448 +++--- .../targettable/TargetBeanQuery.java | 330 ++--- .../management/targettable/TargetTable.java | 109 +- .../ui/rollout/rollout/ProxyRollout.java | 317 +++-- .../ui/rollout/rollout/RolloutBeanQuery.java | 10 +- .../ui/rollout/rollout/RolloutListGrid.java | 1228 ++++++++--------- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 6 +- 9 files changed, 1468 insertions(+), 1474 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 7e62eef1f..843d86ca3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -324,9 +324,9 @@ public abstract class AbstractTable extends Table { } columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, - i18n.get("header.assigned.ds"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, - i18n.get("header.installed.ds"), 0.1F)); + i18n.get("header.assigned.ds"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, + i18n.get("header.installed.ds"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java index 084890f87..9ac39616d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java @@ -10,11 +10,9 @@ package org.eclipse.hawkbit.ui.components; import java.net.URI; import java.security.SecureRandom; -import java.util.Set; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -28,293 +26,293 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; * */ public class ProxyTarget extends Target { - private static final long serialVersionUID = -8891449133620645310L; - private String controllerId; - private URI address = null; - private Long lastTargetQuery = null; - private Long installationDate; + private static final long serialVersionUID = -8891449133620645310L; + private String controllerId; + private URI address = null; + private Long lastTargetQuery = null; + private Long installationDate; - private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; + private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; - private DistributionSet installedDistributionSet; + private DistributionSet installedDistributionSet; - private DistributionSet assignedDistributionSet; + private DistributionSet assignedDistributionSet; - private TargetIdName targetIdName; + private TargetIdName targetIdName; - private String assignedDistNameVersion; + private String assignedDistNameVersion; - private String installedDistNameVersion; + private String installedDistNameVersion; - private String pollStatusToolTip; + private String pollStatusToolTip; - private String createdByUser; + private String createdByUser; - private String createdDate; + private String createdDate; - private String lastModifiedDate; + private String lastModifiedDate; - private String modifiedByUser; + private String modifiedByUser; - private Status status; + private Status status; - /** - * @param controllerId - */ - public ProxyTarget() { - super(null); - final Integer generatedId = new SecureRandom().nextInt(Integer.MAX_VALUE) - Integer.MAX_VALUE; - targetIdName = new TargetIdName(generatedId, generatedId.toString(), generatedId.toString()); - } + /** + * @param controllerId + */ + public ProxyTarget() { + super(null); + final Integer generatedId = new SecureRandom().nextInt(Integer.MAX_VALUE) - Integer.MAX_VALUE; + targetIdName = new TargetIdName(generatedId, generatedId.toString(), generatedId.toString()); + } - /** - * @return the createdByUser - */ - public String getCreatedByUser() { - return createdByUser; - } + /** + * @return the createdByUser + */ + public String getCreatedByUser() { + return createdByUser; + } - /** - * @param createdByUser - * the createdByUser to set - */ - public void setCreatedByUser(final String createdByUser) { - this.createdByUser = createdByUser; - } + /** + * @param createdByUser + * the createdByUser to set + */ + public void setCreatedByUser(final String createdByUser) { + this.createdByUser = createdByUser; + } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @return the modifiedByUser - */ - public String getModifiedByUser() { - return modifiedByUser; - } + /** + * @return the modifiedByUser + */ + public String getModifiedByUser() { + return modifiedByUser; + } - /** - * @param modifiedByUser - * the modifiedByUser to set - */ - public void setModifiedByUser(final String modifiedByUser) { - this.modifiedByUser = modifiedByUser; - } + /** + * @param modifiedByUser + * the modifiedByUser to set + */ + public void setModifiedByUser(final String modifiedByUser) { + this.modifiedByUser = modifiedByUser; + } - /** - * @return the lastModifiedDate - */ - public String getLastModifiedDate() { - return lastModifiedDate; - } + /** + * @return the lastModifiedDate + */ + public String getLastModifiedDate() { + return lastModifiedDate; + } - /** - * @param lastModifiedDate - * the lastModifiedDate to set - */ - public void setLastModifiedDate(final String lastModifiedDate) { - this.lastModifiedDate = lastModifiedDate; - } + /** + * @param lastModifiedDate + * the lastModifiedDate to set + */ + public void setLastModifiedDate(final String lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } - /** - * @return the assignedDistNameVersion - */ - public String getAssignedDistNameVersion() { - return assignedDistNameVersion; - } + /** + * @return the assignedDistNameVersion + */ + public String getAssignedDistNameVersion() { + return assignedDistNameVersion; + } - /** - * @param assignedDistNameVersion - * the assignedDistNameVersion to set - */ - public void setAssignedDistNameVersion(final String assignedDistNameVersion) { - this.assignedDistNameVersion = assignedDistNameVersion; - } + /** + * @param assignedDistNameVersion + * the assignedDistNameVersion to set + */ + public void setAssignedDistNameVersion(final String assignedDistNameVersion) { + this.assignedDistNameVersion = assignedDistNameVersion; + } - /** - * @return the installedDistNameVersion - */ - public String getInstalledDistNameVersion() { - return installedDistNameVersion; - } + /** + * @return the installedDistNameVersion + */ + public String getInstalledDistNameVersion() { + return installedDistNameVersion; + } - /** - * @param installedDistNameVersion - * the installedDistNameVersion to set - */ - public void setInstalledDistNameVersion(final String installedDistNameVersion) { - this.installedDistNameVersion = installedDistNameVersion; - } + /** + * @param installedDistNameVersion + * the installedDistNameVersion to set + */ + public void setInstalledDistNameVersion(final String installedDistNameVersion) { + this.installedDistNameVersion = installedDistNameVersion; + } - /** - * GET - ID. - * - * @return String as ID. - */ - @Override - public String getControllerId() { - return controllerId; - } + /** + * GET - ID. + * + * @return String as ID. + */ + @Override + public String getControllerId() { + return controllerId; + } - /** - * SET - ID. - * - * @param controllerId - * as ID - */ - @Override - public void setControllerId(final String controllerId) { - this.controllerId = controllerId; - } + /** + * SET - ID. + * + * @param controllerId + * as ID + */ + @Override + public void setControllerId(final String controllerId) { + this.controllerId = controllerId; + } - /** - * @return the ipAddress - */ - public URI getAddress() { - return address; - } + /** + * @return the ipAddress + */ + public URI getAddress() { + return address; + } - /** - * @param ipAddress - * the ipAddress to set - */ - public void setAddress(final URI address) { - this.address = address; - } + /** + * @param ipAddress + * the ipAddress to set + */ + public void setAddress(final URI address) { + this.address = address; + } - /** - * @return the lastTargetQuery - */ - public Long getLastTargetQuery() { - return lastTargetQuery; - } + /** + * @return the lastTargetQuery + */ + public Long getLastTargetQuery() { + return lastTargetQuery; + } - /** - * @param lastTargetQuery - * the lastTargetQuery to set - */ - public void setLastTargetQuery(final Long lastTargetQuery) { - this.lastTargetQuery = lastTargetQuery; - } + /** + * @param lastTargetQuery + * the lastTargetQuery to set + */ + public void setLastTargetQuery(final Long lastTargetQuery) { + this.lastTargetQuery = lastTargetQuery; + } - /** - * @return the installationDate - */ - public Long getInstallationDate() { - return installationDate; - } + /** + * @return the installationDate + */ + public Long getInstallationDate() { + return installationDate; + } - /** - * @param installationDate - * the installationDate to set - */ - public void setInstallationDate(final Long installationDate) { - this.installationDate = installationDate; - } + /** + * @param installationDate + * the installationDate to set + */ + public void setInstallationDate(final Long installationDate) { + this.installationDate = installationDate; + } - /** - * @return the updateStatus - */ - public TargetUpdateStatus getUpdateStatus() { - return updateStatus; - } + /** + * @return the updateStatus + */ + public TargetUpdateStatus getUpdateStatus() { + return updateStatus; + } - /** - * @param updateStatus - * the updateStatus to set - */ - public void setUpdateStatus(final TargetUpdateStatus updateStatus) { - this.updateStatus = updateStatus; - } + /** + * @param updateStatus + * the updateStatus to set + */ + public void setUpdateStatus(final TargetUpdateStatus updateStatus) { + this.updateStatus = updateStatus; + } - /** - * @return the installedDistributionSet - */ - public DistributionSet getInstalledDistributionSet() { - return installedDistributionSet; - } + /** + * @return the installedDistributionSet + */ + public DistributionSet getInstalledDistributionSet() { + return installedDistributionSet; + } - /** - * @param installedDistributionSet - * the installedDistributionSet to set - */ - public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) { - this.installedDistributionSet = installedDistributionSet; - } + /** + * @param installedDistributionSet + * the installedDistributionSet to set + */ + public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) { + this.installedDistributionSet = installedDistributionSet; + } - /** - * @return the assignedDistributionSet - */ - public DistributionSet getAssignedDistributionSet() { - return assignedDistributionSet; - } + /** + * @return the assignedDistributionSet + */ + public DistributionSet getAssignedDistributionSet() { + return assignedDistributionSet; + } - /** - * @param assignedDistributionSet - * the assignedDistributionSet to set - */ - public void setAssignedDistributionSet(DistributionSet assignedDistributionSet) { - this.assignedDistributionSet = assignedDistributionSet; - } + /** + * @param assignedDistributionSet + * the assignedDistributionSet to set + */ + public void setAssignedDistributionSet(DistributionSet assignedDistributionSet) { + this.assignedDistributionSet = assignedDistributionSet; + } - /** - * @return the targetIdName - */ - @Override - public TargetIdName getTargetIdName() { - if (this.targetIdName == null) { - return super.getTargetIdName(); - } - return this.targetIdName; - } + /** + * @return the targetIdName + */ + @Override + public TargetIdName getTargetIdName() { + if (this.targetIdName == null) { + return super.getTargetIdName(); + } + return this.targetIdName; + } - /** - * @param targetIdName - * the targetIdName to set - */ - public void setTargetIdName(final TargetIdName targetIdName) { - this.targetIdName = targetIdName; - } + /** + * @param targetIdName + * the targetIdName to set + */ + public void setTargetIdName(final TargetIdName targetIdName) { + this.targetIdName = targetIdName; + } - /** - * @return the pollStatusToolTip - */ - public String getPollStatusToolTip() { - return pollStatusToolTip; - } + /** + * @return the pollStatusToolTip + */ + public String getPollStatusToolTip() { + return pollStatusToolTip; + } - /** - * @param pollStatusToolTip - * the pollStatusToolTip to set - */ - public void setPollStatusToolTip(final String pollStatusToolTip) { - this.pollStatusToolTip = pollStatusToolTip; - } + /** + * @param pollStatusToolTip + * the pollStatusToolTip to set + */ + public void setPollStatusToolTip(final String pollStatusToolTip) { + this.pollStatusToolTip = pollStatusToolTip; + } - /** - * @return the status - */ - public Status getStatus() { - return status; - } + /** + * @return the status + */ + public Status getStatus() { + return status; + } - /** - * @param status - * the status to set - */ - public void setStatus(final Status status) { - this.status = status; - } + /** + * @param status + * the status to set + */ + public void setStatus(final Status status) { + this.status = status; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java index d067b388b..cf8a514d4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java @@ -57,259 +57,259 @@ import com.vaadin.ui.themes.ValoTheme; @ViewScope public class CreateOrUpdateFilterTable extends Table { - private static final long serialVersionUID = 6887304217281629713L; + private static final long serialVersionUID = 6887304217281629713L; - @Autowired - private I18N i18n; + @Autowired + private I18N i18n; - @Autowired - private transient EventBus.SessionEventBus eventBus; + @Autowired + private transient EventBus.SessionEventBus eventBus; - @Autowired - private FilterManagementUIState filterManagementUIState; + @Autowired + private FilterManagementUIState filterManagementUIState; - private LazyQueryContainer container; + private LazyQueryContainer container; - private static final int PROPERTY_DEPT = 3; + private static final int PROPERTY_DEPT = 3; - private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; - private static final String INSTALL_DIST_SET = "installedDistributionSet"; + private static final String INSTALL_DIST_SET = "installedDistributionSet"; - /** - * Initialize the Action History Table. - */ - @PostConstruct - public void init() { - setStyleName("sp-table"); - setSizeFull(); - setImmediate(true); - setHeight(100.0f, Unit.PERCENTAGE); - addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); - addStyleName(ValoTheme.TABLE_SMALL); - setColumnCollapsingAllowed(true); - addCustomGeneratedColumns(); - restoreOnLoad(); - populateTableData(); - setId(SPUIComponetIdProvider.CUSTOM_FILTER_TARGET_TABLE_ID); - setSelectable(false); - eventBus.subscribe(this); - setItemDescriptionGenerator(new TooltipGenerator()); - } + /** + * Initialize the Action History Table. + */ + @PostConstruct + public void init() { + setStyleName("sp-table"); + setSizeFull(); + setImmediate(true); + setHeight(100.0f, Unit.PERCENTAGE); + addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); + addStyleName(ValoTheme.TABLE_SMALL); + setColumnCollapsingAllowed(true); + addCustomGeneratedColumns(); + restoreOnLoad(); + populateTableData(); + setId(SPUIComponetIdProvider.CUSTOM_FILTER_TARGET_TABLE_ID); + setSelectable(false); + eventBus.subscribe(this); + setItemDescriptionGenerator(new TooltipGenerator()); + } - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final CustomFilterUIEvent custFUIEvent) { - if (custFUIEvent == CustomFilterUIEvent.TARGET_DETAILS_VIEW - || custFUIEvent == CustomFilterUIEvent.CREATE_NEW_FILTER_CLICK) { - UI.getCurrent().access(() -> populateTableData()); - } else if (custFUIEvent == CustomFilterUIEvent.FILTER_TARGET_BY_QUERY) { - UI.getCurrent().access(() -> onQuery()); - } - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final CustomFilterUIEvent custFUIEvent) { + if (custFUIEvent == CustomFilterUIEvent.TARGET_DETAILS_VIEW + || custFUIEvent == CustomFilterUIEvent.CREATE_NEW_FILTER_CLICK) { + UI.getCurrent().access(() -> populateTableData()); + } else if (custFUIEvent == CustomFilterUIEvent.FILTER_TARGET_BY_QUERY) { + UI.getCurrent().access(() -> onQuery()); + } + } - private void restoreOnLoad() { - if (filterManagementUIState.isCreateFilterViewDisplayed()) { - filterManagementUIState.setFilterQueryValue(null); - } else { - filterManagementUIState.getTfQuery() - .ifPresent(value -> filterManagementUIState.setFilterQueryValue(value.getQuery())); - } - } + private void restoreOnLoad() { + if (filterManagementUIState.isCreateFilterViewDisplayed()) { + filterManagementUIState.setFilterQueryValue(null); + } else { + filterManagementUIState.getTfQuery() + .ifPresent(value -> filterManagementUIState.setFilterQueryValue(value.getQuery())); + } + } - /** - * Create a empty HierarchicalContainer. - */ - private LazyQueryContainer createContainer() { - // ADD all the filters to the query config - final Map queryConfig = prepareQueryConfigFilters(); + /** + * Create a empty HierarchicalContainer. + */ + private LazyQueryContainer createContainer() { + // ADD all the filters to the query config + final Map queryConfig = prepareQueryConfigFilters(); - // Create TargetBeanQuery factory with the query config. - final BeanQueryFactory targetQF = new BeanQueryFactory<>(CustomTargetBeanQuery.class); - targetQF.setQueryConfiguration(queryConfig); + // Create TargetBeanQuery factory with the query config. + final BeanQueryFactory targetQF = new BeanQueryFactory<>(CustomTargetBeanQuery.class); + targetQF.setQueryConfiguration(queryConfig); - // create lazy query container with lazy defination and query - final LazyQueryContainer targetTableContainer = new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME), - targetQF); - targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT); + // create lazy query container with lazy defination and query + final LazyQueryContainer targetTableContainer = new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME), + targetQF); + targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT); - return targetTableContainer; + return targetTableContainer; - } + } - private Map prepareQueryConfigFilters() { - final Map queryConfig = new HashMap<>(); - if (!Strings.isNullOrEmpty(filterManagementUIState.getFilterQueryValue())) { - queryConfig.put(SPUIDefinitions.FILTER_BY_QUERY, filterManagementUIState.getFilterQueryValue()); - } - queryConfig.put(SPUIDefinitions.FILTER_BY_INVALID_QUERY, - filterManagementUIState.getIsFilterByInvalidFilterQuery()); - return queryConfig; - } + private Map prepareQueryConfigFilters() { + final Map queryConfig = new HashMap<>(); + if (!Strings.isNullOrEmpty(filterManagementUIState.getFilterQueryValue())) { + queryConfig.put(SPUIDefinitions.FILTER_BY_QUERY, filterManagementUIState.getFilterQueryValue()); + } + queryConfig.put(SPUIDefinitions.FILTER_BY_INVALID_QUERY, + filterManagementUIState.getIsFilterByInvalidFilterQuery()); + return queryConfig; + } - /** - * populate campaign data. - * - */ - public void populateTableData() { - container = createContainer(); - setContainerDataSource(container); - addContainerproperties(); - setColumnProperties(); - setPageLength(30); - setCollapsibleColumns(); - } + /** + * populate campaign data. + * + */ + public void populateTableData() { + container = createContainer(); + setContainerDataSource(container); + addContainerproperties(); + setColumnProperties(); + setPageLength(30); + setCollapsibleColumns(); + } - private void setCollapsibleColumns() { - setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, true); - setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, true); + private void setCollapsibleColumns() { + setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, true); + setColumnCollapsed(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, true); - setColumnCollapsed(ASSIGN_DIST_SET, true); - setColumnCollapsed(INSTALL_DIST_SET, true); - } + setColumnCollapsed(ASSIGN_DIST_SET, true); + setColumnCollapsed(INSTALL_DIST_SET, true); + } - /** - * Create a empty HierarchicalContainer. - */ - private void addContainerproperties() { - /* Create HierarchicalContainer container */ - container.addContainerProperty(SPUILabelDefinitions.NAME, String.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, Date.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, null, false, true); - container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); - container.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, String.class, ""); - container.addContainerProperty(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, String.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_TARGET_STATUS, TargetUpdateStatus.class, null); - container.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); + /** + * Create a empty HierarchicalContainer. + */ + private void addContainerproperties() { + /* Create HierarchicalContainer container */ + container.addContainerProperty(SPUILabelDefinitions.NAME, String.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, Date.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, null, false, true); + container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); + container.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, String.class, ""); + container.addContainerProperty(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, String.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_TARGET_STATUS, TargetUpdateStatus.class, null); + container.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); - container.addContainerProperty(ASSIGN_DIST_SET, DistributionSet.class, null, false, true); - container.addContainerProperty(INSTALL_DIST_SET, DistributionSet.class, null, false, true); - } + container.addContainerProperty(ASSIGN_DIST_SET, DistributionSet.class, null, false, true); + container.addContainerProperty(INSTALL_DIST_SET, DistributionSet.class, null, false, true); + } - private List getVisbleColumns() { - final List columnList = new ArrayList<>(); - columnList.add(new TableColumn(SPUILabelDefinitions.NAME, i18n.get("header.name"), 0.15f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, - i18n.get("header.assigned.ds"), 0.125F)); - columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, - i18n.get("header.installed.ds"), 0.125F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.STATUS_ICON, i18n.get("header.status"), 0.1F)); - return columnList; - } + private List getVisbleColumns() { + final List columnList = new ArrayList<>(); + columnList.add(new TableColumn(SPUILabelDefinitions.NAME, i18n.get("header.name"), 0.15f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); + columnList.add( + new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, + i18n.get("header.assigned.ds"), 0.125F)); + columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, + i18n.get("header.installed.ds"), 0.125F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.STATUS_ICON, i18n.get("header.status"), 0.1F)); + return columnList; + } - private Component getStatusIcon(final Object itemId) { - final Item row1 = getItem(itemId); - final TargetUpdateStatus targetStatus = (TargetUpdateStatus) row1 - .getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).getValue(); - final Label label = SPUIComponentProvider.getLabel("", SPUILabelDefinitions.SP_LABEL_SIMPLE); - label.setContentMode(ContentMode.HTML); - if (targetStatus == TargetUpdateStatus.PENDING) { - label.setDescription("Pending"); - label.setStyleName("statusIconYellow"); - label.setValue(FontAwesome.ADJUST.getHtml()); - } else if (targetStatus == TargetUpdateStatus.REGISTERED) { - label.setDescription("Registered"); - label.setStyleName("statusIconLightBlue"); - label.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); - } else if (targetStatus == TargetUpdateStatus.ERROR) { - label.setDescription(i18n.get("label.error")); - label.setStyleName("statusIconRed"); - label.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); - } else if (targetStatus == TargetUpdateStatus.IN_SYNC) { - label.setStyleName("statusIconGreen"); - label.setDescription("In-Synch"); - label.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); - } else if (targetStatus == TargetUpdateStatus.UNKNOWN) { - label.setStyleName("statusIconBlue"); - label.setDescription(i18n.get("label.unknown")); - label.setValue(FontAwesome.QUESTION_CIRCLE.getHtml()); - } - return label; - } + private Component getStatusIcon(final Object itemId) { + final Item row1 = getItem(itemId); + final TargetUpdateStatus targetStatus = (TargetUpdateStatus) row1 + .getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).getValue(); + final Label label = SPUIComponentProvider.getLabel("", SPUILabelDefinitions.SP_LABEL_SIMPLE); + label.setContentMode(ContentMode.HTML); + if (targetStatus == TargetUpdateStatus.PENDING) { + label.setDescription("Pending"); + label.setStyleName("statusIconYellow"); + label.setValue(FontAwesome.ADJUST.getHtml()); + } else if (targetStatus == TargetUpdateStatus.REGISTERED) { + label.setDescription("Registered"); + label.setStyleName("statusIconLightBlue"); + label.setValue(FontAwesome.DOT_CIRCLE_O.getHtml()); + } else if (targetStatus == TargetUpdateStatus.ERROR) { + label.setDescription(i18n.get("label.error")); + label.setStyleName("statusIconRed"); + label.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); + } else if (targetStatus == TargetUpdateStatus.IN_SYNC) { + label.setStyleName("statusIconGreen"); + label.setDescription("In-Synch"); + label.setValue(FontAwesome.CHECK_CIRCLE.getHtml()); + } else if (targetStatus == TargetUpdateStatus.UNKNOWN) { + label.setStyleName("statusIconBlue"); + label.setDescription(i18n.get("label.unknown")); + label.setValue(FontAwesome.QUESTION_CIRCLE.getHtml()); + } + return label; + } - private void setColumnProperties() { - final List columnList = getVisbleColumns(); - final List swColumnIds = new ArrayList<>(); - for (final TableColumn column : columnList) { - setColumnHeader(column.getColumnPropertyId(), column.getColumnHeader()); - setColumnExpandRatio(column.getColumnPropertyId(), column.getExpandRatio()); - swColumnIds.add(column.getColumnPropertyId()); - } - setVisibleColumns(swColumnIds.toArray()); - } + private void setColumnProperties() { + final List columnList = getVisbleColumns(); + final List swColumnIds = new ArrayList<>(); + for (final TableColumn column : columnList) { + setColumnHeader(column.getColumnPropertyId(), column.getColumnHeader()); + setColumnExpandRatio(column.getColumnPropertyId(), column.getExpandRatio()); + swColumnIds.add(column.getColumnPropertyId()); + } + setVisibleColumns(swColumnIds.toArray()); + } - protected void addCustomGeneratedColumns() { - addGeneratedColumn(SPUILabelDefinitions.STATUS_ICON, (source, itemId, columnId) -> getStatusIcon(itemId)); - } + protected void addCustomGeneratedColumns() { + addGeneratedColumn(SPUILabelDefinitions.STATUS_ICON, (source, itemId, columnId) -> getStatusIcon(itemId)); + } - private void onQuery() { - populateTableData(); - eventBus.publish(this, CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON); - } + private void onQuery() { + populateTableData(); + eventBus.publish(this, CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON); + } - public class TooltipGenerator implements ItemDescriptionGenerator { - private static final long serialVersionUID = 688730421728162456L; + public class TooltipGenerator implements ItemDescriptionGenerator { + private static final long serialVersionUID = 688730421728162456L; - @Override - public String generateDescription(Component source, Object itemId, Object propertyId) { - final DistributionSet distributionSet; - final Item item = getItem(itemId); - if (propertyId != null) { - if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } - } - return null; - } + @Override + public String generateDescription(Component source, Object itemId, Object propertyId) { + final DistributionSet distributionSet; + final Item item = getItem(itemId); + if (propertyId != null) { + if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } + } + return null; + } - private String getDSDetails(final DistributionSet distributionSet) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set)distributionSet.getModules(); - swModules.forEach(swModule -> { - swModuleNames.append(swModule.getName()); - swModuleNames.append(" , "); - swModuleVendors.append(swModule.getVendor()); - swModuleVendors.append(" , "); - }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append(" Required Migration step : ") - .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); - - stringBuilder.append("
"); - return stringBuilder.toString(); - } + private String getDSDetails(final DistributionSet distributionSet) { + StringBuilder swModuleNames = new StringBuilder(); + StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = (Set) distributionSet.getModules(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("
    "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" Required Migration step : ") + .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append("
  • "); - } + stringBuilder.append("
"); + return stringBuilder.toString(); + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index 943efc262..d127b4198 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -42,188 +42,188 @@ import com.google.common.base.Strings; * */ public class TargetBeanQuery extends AbstractBeanQuery { - private static final long serialVersionUID = -5645680058303167558L; - private Sort sort = new Sort(SPUIDefinitions.TARGET_TABLE_CREATE_AT_SORT_ORDER, "createdAt"); - private Collection status = null; - private String[] targetTags = null; - private Long distributionId = null; - private String searchText = null; - private Boolean noTagClicked = Boolean.FALSE; - private transient TargetManagement targetManagement; - private transient I18N i18N; - private Long pinnedDistId = null; - private TargetFilterQuery targetFilterQuery; - private ManagementUIState managementUIState; + private static final long serialVersionUID = -5645680058303167558L; + private Sort sort = new Sort(SPUIDefinitions.TARGET_TABLE_CREATE_AT_SORT_ORDER, "createdAt"); + private Collection status = null; + private String[] targetTags = null; + private Long distributionId = null; + private String searchText = null; + private Boolean noTagClicked = Boolean.FALSE; + private transient TargetManagement targetManagement; + private transient I18N i18N; + private Long pinnedDistId = null; + private TargetFilterQuery targetFilterQuery; + private ManagementUIState managementUIState; - /** - * Parametric Constructor. - * - * @param definition - * as Def - * @param queryConfig - * as Config - * @param sortIds - * as sort - * @param sortStates - * as Sort status - */ - public TargetBeanQuery(final QueryDefinition definition, final Map queryConfig, - final Object[] sortIds, final boolean[] sortStates) { - super(definition, queryConfig, sortIds, sortStates); + /** + * Parametric Constructor. + * + * @param definition + * as Def + * @param queryConfig + * as Config + * @param sortIds + * as sort + * @param sortStates + * as Sort status + */ + public TargetBeanQuery(final QueryDefinition definition, final Map queryConfig, + final Object[] sortIds, final boolean[] sortStates) { + super(definition, queryConfig, sortIds, sortStates); - if (HawkbitCommonUtil.mapCheckStrKey(queryConfig)) { - status = (Collection) queryConfig.get(SPUIDefinitions.FILTER_BY_STATUS); - targetTags = (String[]) queryConfig.get(SPUIDefinitions.FILTER_BY_TAG); - noTagClicked = (Boolean) queryConfig.get(SPUIDefinitions.FILTER_BY_NO_TAG); - distributionId = (Long) queryConfig.get(SPUIDefinitions.FILTER_BY_DISTRIBUTION); - searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); - targetFilterQuery = (TargetFilterQuery) queryConfig.get(SPUIDefinitions.FILTER_BY_TARGET_FILTER_QUERY); - if (!Strings.isNullOrEmpty(searchText)) { - searchText = String.format("%%%s%%", searchText); - } - pinnedDistId = (Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION); - } + if (HawkbitCommonUtil.mapCheckStrKey(queryConfig)) { + status = (Collection) queryConfig.get(SPUIDefinitions.FILTER_BY_STATUS); + targetTags = (String[]) queryConfig.get(SPUIDefinitions.FILTER_BY_TAG); + noTagClicked = (Boolean) queryConfig.get(SPUIDefinitions.FILTER_BY_NO_TAG); + distributionId = (Long) queryConfig.get(SPUIDefinitions.FILTER_BY_DISTRIBUTION); + searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); + targetFilterQuery = (TargetFilterQuery) queryConfig.get(SPUIDefinitions.FILTER_BY_TARGET_FILTER_QUERY); + if (!Strings.isNullOrEmpty(searchText)) { + searchText = String.format("%%%s%%", searchText); + } + pinnedDistId = (Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION); + } - if (HawkbitCommonUtil.checkBolArray(sortStates)) { - // Initalize Sor - sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); - // Add sort. - for (int targetId = 1; targetId < sortIds.length; targetId++) { - sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); - } - } - } + if (HawkbitCommonUtil.checkBolArray(sortStates)) { + // Initalize Sor + sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]); + // Add sort. + for (int targetId = 1; targetId < sortIds.length; targetId++) { + sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId])); + } + } + } - @Override - protected ProxyTarget constructBean() { - return new ProxyTarget(); - } + @Override + protected ProxyTarget constructBean() { + return new ProxyTarget(); + } - @Override - protected List loadBeans(final int startIndex, final int count) { - Slice targetBeans; - final List proxyTargetBeans = new ArrayList<>(); - if (pinnedDistId != null) { - targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet( - new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId, - distributionId, status, searchText, noTagClicked, targetTags); - } else if (null != targetFilterQuery) { - targetBeans = getTargetManagement().findTargetsAll(targetFilterQuery, - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); - } else if (!anyFilterSelected()) { - targetBeans = getTargetManagement().findTargetsAll( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); - } else { - targetBeans = getTargetManagement().findTargetByFilters( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), status, - searchText, distributionId, noTagClicked, targetTags); - } - for (final Target targ : targetBeans) { - final ProxyTarget prxyTarget = new ProxyTarget(); - prxyTarget.setTargetIdName(targ.getTargetIdName()); - prxyTarget.setName(targ.getName()); - prxyTarget.setDescription(targ.getDescription()); - prxyTarget.setControllerId(targ.getControllerId()); - prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate()); - prxyTarget.setAddress(targ.getTargetInfo().getAddress()); - prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); - prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); - prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); - prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); - prxyTarget.setCreatedAt(targ.getCreatedAt()); - prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); + @Override + protected List loadBeans(final int startIndex, final int count) { + Slice targetBeans; + final List proxyTargetBeans = new ArrayList<>(); + if (pinnedDistId != null) { + targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet( + new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId, + distributionId, status, searchText, noTagClicked, targetTags); + } else if (null != targetFilterQuery) { + targetBeans = getTargetManagement().findTargetsAll(targetFilterQuery, + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + } else if (!anyFilterSelected()) { + targetBeans = getTargetManagement().findTargetsAll( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + } else { + targetBeans = getTargetManagement().findTargetByFilters( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), status, + searchText, distributionId, noTagClicked, targetTags); + } + for (final Target targ : targetBeans) { + final ProxyTarget prxyTarget = new ProxyTarget(); + prxyTarget.setTargetIdName(targ.getTargetIdName()); + prxyTarget.setName(targ.getName()); + prxyTarget.setDescription(targ.getDescription()); + prxyTarget.setControllerId(targ.getControllerId()); + prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate()); + prxyTarget.setAddress(targ.getTargetInfo().getAddress()); + prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); + prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); + prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt())); + prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt())); + prxyTarget.setCreatedAt(targ.getCreatedAt()); + prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ)); - if (pinnedDistId == null) { - prxyTarget.setInstalledDistributionSet(null); - prxyTarget.setAssignedDistributionSet(null); + if (pinnedDistId == null) { + prxyTarget.setInstalledDistributionSet(null); + prxyTarget.setAssignedDistributionSet(null); - } else { - final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); - final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); - prxyTarget.setInstalledDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( - installedDistributionSet.getName(), installedDistributionSet.getVersion())); - prxyTarget.setInstalledDistributionSet(installedDistributionSet); - final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet(); - prxyTarget.setAssignedDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( - assignedDistributionSet.getName(), assignedDistributionSet.getVersion())); - prxyTarget.setAssignedDistributionSet(assignedDistributionSet); - } + } else { + final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); + final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); + prxyTarget.setInstalledDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( + installedDistributionSet.getName(), installedDistributionSet.getVersion())); + prxyTarget.setInstalledDistributionSet(installedDistributionSet); + final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet(); + prxyTarget.setAssignedDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( + assignedDistributionSet.getName(), assignedDistributionSet.getVersion())); + prxyTarget.setAssignedDistributionSet(assignedDistributionSet); + } - prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); - prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); - prxyTarget.setTargetInfo(targ.getTargetInfo()); - prxyTarget.setPollStatusToolTip( - HawkbitCommonUtil.getPollStatusToolTip(prxyTarget.getTargetInfo().getPollStatus(), getI18N())); - proxyTargetBeans.add(prxyTarget); - } - return proxyTargetBeans; - } + prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); + prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); + prxyTarget.setTargetInfo(targ.getTargetInfo()); + prxyTarget.setPollStatusToolTip( + HawkbitCommonUtil.getPollStatusToolTip(prxyTarget.getTargetInfo().getPollStatus(), getI18N())); + proxyTargetBeans.add(prxyTarget); + } + return proxyTargetBeans; + } - private Boolean isTagSelected() { - if (targetTags == null && !noTagClicked) { - return false; - } - return true; - } + private Boolean isTagSelected() { + if (targetTags == null && !noTagClicked) { + return false; + } + return true; + } - @Override - protected void saveBeans(final List addedTargets, final List modifiedTargets, - final List removedTargets) { - // CRUD operations on Target will be done through repository methods - } + @Override + protected void saveBeans(final List addedTargets, final List modifiedTargets, + final List removedTargets) { + // CRUD operations on Target will be done through repository methods + } - private Boolean anyFilterSelected() { - if (status == null && distributionId == null && Strings.isNullOrEmpty(searchText) && !isTagSelected()) { - return false; - } - return true; - } + private Boolean anyFilterSelected() { + if (status == null && distributionId == null && Strings.isNullOrEmpty(searchText) && !isTagSelected()) { + return false; + } + return true; + } - @Override - public int size() { - final long totSize = getTargetManagement().countTargetsAll(); - long size; - if (null != targetFilterQuery) { - size = getTargetManagement().countTargetByTargetFilterQuery(targetFilterQuery); - } else if (!anyFilterSelected()) { - size = totSize; - } else { - size = getTargetManagement().countTargetByFilters(status, searchText, distributionId, noTagClicked, - targetTags); - } + @Override + public int size() { + final long totSize = getTargetManagement().countTargetsAll(); + long size; + if (null != targetFilterQuery) { + size = getTargetManagement().countTargetByTargetFilterQuery(targetFilterQuery); + } else if (!anyFilterSelected()) { + size = totSize; + } else { + size = getTargetManagement().countTargetByFilters(status, searchText, distributionId, noTagClicked, + targetTags); + } - final ManagementUIState tmpManagementUIState = getManagementUIState(); - tmpManagementUIState.setTargetsCountAll(totSize); - if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) { - tmpManagementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES); - size = SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES; - } else { - tmpManagementUIState.setTargetsTruncated(null); - } + final ManagementUIState tmpManagementUIState = getManagementUIState(); + tmpManagementUIState.setTargetsCountAll(totSize); + if (size > SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES) { + tmpManagementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES); + size = SPUIDefinitions.MAX_TARGET_TABLE_ENTRIES; + } else { + tmpManagementUIState.setTargetsTruncated(null); + } - return (int) size; - } + return (int) size; + } - private TargetManagement getTargetManagement() { - if (targetManagement == null) { - targetManagement = SpringContextHelper.getBean(TargetManagement.class); - } - return targetManagement; - } + private TargetManagement getTargetManagement() { + if (targetManagement == null) { + targetManagement = SpringContextHelper.getBean(TargetManagement.class); + } + return targetManagement; + } - private ManagementUIState getManagementUIState() { - if (managementUIState == null) { - managementUIState = SpringContextHelper.getBean(ManagementUIState.class); - } - return managementUIState; - } + private ManagementUIState getManagementUIState() { + if (managementUIState == null) { + managementUIState = SpringContextHelper.getBean(ManagementUIState.class); + } + return managementUIState; + } - private I18N getI18N() { - if (i18N == null) { - i18N = SpringContextHelper.getBean(I18N.class); - } - return i18N; - } + private I18N getI18N() { + if (i18N == null) { + i18N = SpringContextHelper.getBean(I18N.class); + } + return i18N; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index f119229b0..a1e759950 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -43,7 +43,6 @@ 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.filtermanagement.CreateOrUpdateFilterTable.TooltipGenerator; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementViewAcceptCriteria; @@ -96,7 +95,6 @@ import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; -import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator; /** * Concrete implementation of Target table. @@ -113,9 +111,9 @@ public class TargetTable extends AbstractTable implements private static final int PROPERTY_DEPT = 3; private static final String ACTION_NOT_ALLOWED_MSG = "message.action.not.allowed"; - - private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; - private static final String INSTALL_DIST_SET = "installedDistributionSet"; + + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; + private static final String INSTALL_DIST_SET = "installedDistributionSet"; @Autowired private transient TargetManagement targetManagement; @@ -1082,61 +1080,60 @@ public class TargetTable extends AbstractTable implements private boolean isFilteredByTags() { return !managementUIState.getTargetTableFilters().getClickedTargetTags().isEmpty(); } - - + /** * tooltip for assignedDS and installedDS */ - + protected class TooltipGenerator implements ItemDescriptionGenerator { - private static final long serialVersionUID = 688730421728162456L; + private static final long serialVersionUID = 688730421728162456L; - @Override - public String generateDescription(Component source, Object itemId, Object propertyId) { - final DistributionSet distributionSet; - final Item item = getItem(itemId); - if (propertyId != null) { - if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } - } - return null; - } + @Override + public String generateDescription(Component source, Object itemId, Object propertyId) { + final DistributionSet distributionSet; + final Item item = getItem(itemId); + if (propertyId != null) { + if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } + } + return null; + } - private String getDSDetails(final DistributionSet distributionSet) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set)distributionSet.getModules(); - swModules.forEach(swModule -> { - swModuleNames.append(swModule.getName()); - swModuleNames.append(" , "); - swModuleVendors.append(swModule.getVendor()); - swModuleVendors.append(" , "); - }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append(" Required Migration step : ") - .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
"); - return stringBuilder.toString(); - } - } + private String getDSDetails(final DistributionSet distributionSet) { + StringBuilder swModuleNames = new StringBuilder(); + StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = (Set) distributionSet.getModules(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("
    "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" Required Migration step : ") + .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append("
  • "); + stringBuilder.append("
"); + return stringBuilder.toString(); + } + } } \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index a010a3ba4..04c6659a5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -22,197 +22,196 @@ import com.vaadin.server.FontAwesome; */ public class ProxyRollout extends Rollout { - private static final long serialVersionUID = 4539849939617681918L; + private static final long serialVersionUID = 4539849939617681918L; - private String distributionSetNameVersion; + private String distributionSetNameVersion; - private String createdDate; + private String createdDate; - private String modifiedDate; + private String modifiedDate; - private Long numberOfGroups; + private Long numberOfGroups; - private Boolean isActionRecieved = Boolean.FALSE; - - private Boolean isRequiredMigrationStep = Boolean.FALSE; + private Boolean isActionRecieved = Boolean.FALSE; - private String totalTargetsCount; + private Boolean isRequiredMigrationStep = Boolean.FALSE; - private RolloutRendererData rolloutRendererData; - - private String discription; + private String totalTargetsCount; - private String type; - - private Set swModules; - - - - /** - * @return the isRequiredMigrationStep - */ + private RolloutRendererData rolloutRendererData; - public Boolean getIsRequiredMigrationStep() { - return isRequiredMigrationStep; - } + private String discription; - /** - * @param isRequiredMigrationStep - * the isRequiredMigrationStep to set - */ + private String type; - public void setIsRequiredMigrationStep(Boolean isRequiredMigrationStep) { - this.isRequiredMigrationStep = isRequiredMigrationStep; - } + private Set swModules; - - /** - * @return the discription - */ + /** + * @return the isRequiredMigrationStep + */ - public String getDiscription() { - return discription; - } + public Boolean getIsRequiredMigrationStep() { + return isRequiredMigrationStep; + } - /** - * @param discription - * the discription to set - */ + /** + * @param isRequiredMigrationStep + * the isRequiredMigrationStep to set + */ - public void setDiscription(String discription) { - this.discription = discription; - } + public void setIsRequiredMigrationStep(Boolean isRequiredMigrationStep) { + this.isRequiredMigrationStep = isRequiredMigrationStep; + } - /** - * @return the type - */ - public String getType() { - return type; - } + /** + * @return the discription + */ - /** - * @param type - * the type to set - */ + public String getDiscription() { + return discription; + } - public void setType(String type) { - this.type = type; - } - /** - * - * @return the Set of Software modules - */ - public Set getSwModules() { - return swModules; - } - /** - * @param swModules - * Set to set - */ - public void setSwModules(Set swModules) { - this.swModules = swModules; - } + /** + * @param discription + * the discription to set + */ - public RolloutRendererData getRolloutRendererData() { - return rolloutRendererData; - } + public void setDiscription(String discription) { + this.discription = discription; + } - public void setRolloutRendererData(RolloutRendererData rendererData) { - this.rolloutRendererData = rendererData; - } + /** + * @return the type + */ + public String getType() { + return type; + } - /** - * @return the distributionSetNameVersion - */ - public String getDistributionSetNameVersion() { - return distributionSetNameVersion; - } + /** + * @param type + * the type to set + */ - /** - * @param distributionSetNameVersion - * the distributionSetNameVersion to set - */ - public void setDistributionSetNameVersion(final String distributionSetNameVersion) { - this.distributionSetNameVersion = distributionSetNameVersion; - } + public void setType(String type) { + this.type = type; + } - /** - * @return the numberOfGroups - */ - public Long getNumberOfGroups() { - return numberOfGroups; - } + /** + * + * @return the Set of Software modules + */ + public Set getSwModules() { + return swModules; + } - /** - * @param numberOfGroups - * the numberOfGroups to set - */ - public void setNumberOfGroups(final Long numberOfGroups) { - this.numberOfGroups = numberOfGroups; - } + /** + * @param swModules + * Set to set + */ + public void setSwModules(Set swModules) { + this.swModules = swModules; + } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + public RolloutRendererData getRolloutRendererData() { + return rolloutRendererData; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + public void setRolloutRendererData(RolloutRendererData rendererData) { + this.rolloutRendererData = rendererData; + } - /** - * @return the modifiedDate - */ - public String getModifiedDate() { - return modifiedDate; - } + /** + * @return the distributionSetNameVersion + */ + public String getDistributionSetNameVersion() { + return distributionSetNameVersion; + } - /** - * @param modifiedDate - * the modifiedDate to set - */ - public void setModifiedDate(final String modifiedDate) { - this.modifiedDate = modifiedDate; - } + /** + * @param distributionSetNameVersion + * the distributionSetNameVersion to set + */ + public void setDistributionSetNameVersion(final String distributionSetNameVersion) { + this.distributionSetNameVersion = distributionSetNameVersion; + } - /** - * @return the isActionRecieved - */ - public Boolean getIsActionRecieved() { - return isActionRecieved; - } + /** + * @return the numberOfGroups + */ + public Long getNumberOfGroups() { + return numberOfGroups; + } - /** - * @param isActionRecieved - * the isActionRecieved to set - */ - public void setIsActionRecieved(final Boolean isActionRecieved) { - this.isActionRecieved = isActionRecieved; - } + /** + * @param numberOfGroups + * the numberOfGroups to set + */ + public void setNumberOfGroups(final Long numberOfGroups) { + this.numberOfGroups = numberOfGroups; + } - /** - * @return the totalTargetsCount - */ - public String getTotalTargetsCount() { - return totalTargetsCount; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param totalTargetsCount - * the totalTargetsCount to set - */ - public void setTotalTargetsCount(final String totalTargetsCount) { - this.totalTargetsCount = totalTargetsCount; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - public String getAction() { - return FontAwesome.CIRCLE_O.getHtml(); - } + /** + * @return the modifiedDate + */ + public String getModifiedDate() { + return modifiedDate; + } + + /** + * @param modifiedDate + * the modifiedDate to set + */ + public void setModifiedDate(final String modifiedDate) { + this.modifiedDate = modifiedDate; + } + + /** + * @return the isActionRecieved + */ + public Boolean getIsActionRecieved() { + return isActionRecieved; + } + + /** + * @param isActionRecieved + * the isActionRecieved to set + */ + public void setIsActionRecieved(final Boolean isActionRecieved) { + this.isActionRecieved = isActionRecieved; + } + + /** + * @return the totalTargetsCount + */ + public String getTotalTargetsCount() { + return totalTargetsCount; + } + + /** + * @param totalTargetsCount + * the totalTargetsCount to set + */ + public void setTotalTargetsCount(final String totalTargetsCount) { + this.totalTargetsCount = totalTargetsCount; + } + + public String getAction() { + return FontAwesome.CIRCLE_O.getHtml(); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 41f69acb1..8a9675564 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -138,11 +138,11 @@ public class RolloutBeanQuery extends AbstractBeanQuery { final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - - proxyRollout.setDescription(distributionSet.getDescription()); - proxyRollout.setType(distributionSet.getType().getName()); - proxyRollout.setIsRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); - proxyRollout.setSwModules(distributionSet.getModules()); + + proxyRollout.setDescription(distributionSet.getDescription()); + proxyRollout.setType(distributionSet.getType().getName()); + proxyRollout.setIsRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); + proxyRollout.setSwModules(distributionSet.getModules()); proxyRolloutList.add(proxyRollout); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index c68bbf700..1ad0bfc35 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -70,619 +70,619 @@ import com.vaadin.ui.renderers.HtmlRenderer; @ViewScope public class RolloutListGrid extends AbstractGrid { - private static final long serialVersionUID = 4060904914954370524L; - - private static final String UPDATE_OPTION = "Update"; - - private static final String RESUME_OPTION = "Resume"; - - private static final String PAUSE_OPTION = "Pause"; - - private static final String START_OPTION = "Start"; - - private static final String DS_TYPE = "type"; - - private static final String SW_MODULES = "swModules"; - - private static final String IS_REQUIRED_MIGRATION_STEP = "isRequiredMigrationStep"; - - private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; - - @Autowired - private transient RolloutManagement rolloutManagement; - - @Autowired - private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; - - @Autowired - private UINotification uiNotification; - - @Autowired - private transient RolloutUIState rolloutUIState; - - @Autowired - private transient SpPermissionChecker permissionChecker; - - private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - - /** - * Handles the RolloutEvent to refresh Grid. - * - */ - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final RolloutEvent event) { - switch (event) { - case FILTER_BY_TEXT: - case CREATE_ROLLOUT: - case UPDATE_ROLLOUT: - case SHOW_ROLLOUTS: - refreshGrid(); - break; - default: - return; - } - } - - /** - * Handles the RolloutChangeEvent to refresh the item in the grid. - * - * @param rolloutChangeEvent - * the event which contains the rollout which has been changed - */ - @SuppressWarnings("unchecked") - @EventBusListenerMethod(scope = EventScope.SESSION) - public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { - if (!rolloutUIState.isShowRollOuts()) { - return; - } - final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); - final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); - final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); - final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); - if (item == null) { - return; - } - item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); - item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); - final int groupsCreated = rollout.getRolloutGroupsCreated(); - if (groupsCreated != 0) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); - } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Long.valueOf(rollout.getRolloutGroups().size())); - } - item.getItemProperty(ROLLOUT_RENDERER_DATA) - .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); - - } - - @Override - protected Container createContainer() { - final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); - return new LazyQueryContainer( - new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); - } - - @Override - protected void addContainerProperties() { - final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutGridContainer.addContainerProperty(DS_TYPE, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(SW_MODULES, Set.class, null, false, false); - rolloutGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutGridContainer.addContainerProperty(IS_REQUIRED_MIGRATION_STEP, boolean.class, null, false, false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, - false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, - false); - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, - TotalTargetCountStatus.class, null, false, false); - - rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, - FontAwesome.CIRCLE_O.getHtml(), false, false); - - } - - @Override - protected void setColumnExpandRatio() { - - getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); - getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); - - getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); - - getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); - getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); - - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); - - setFrozenColumnCount(getColumns().size()); - } - - @Override - protected void setColumnHeaderNames() { - getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); - getColumn(DS_TYPE).setHeaderCaption("Type"); - getColumn(SW_MODULES).setHeaderCaption("swModules"); - getColumn(IS_REQUIRED_MIGRATION_STEP).setHeaderCaption("IsRequiredMigrationStep"); - getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); - getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); - getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); - getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); - getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) - .setHeaderCaption(i18n.get("header.detail.status")); - getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); - getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); - } - - @Override - protected String getGridId() { - return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; - } - - @Override - protected void setColumnProperties() { - final List columnList = new ArrayList<>(); - columnList.add(ROLLOUT_RENDERER_DATA); - columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); - columnList.add(DS_TYPE); - columnList.add(SW_MODULES); - columnList.add(IS_REQUIRED_MIGRATION_STEP); - columnList.add(SPUILabelDefinitions.VAR_STATUS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); - columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); - columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); - columnList.add(SPUILabelDefinitions.ACTION); - - columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnList.add(SPUILabelDefinitions.VAR_DESC); - setColumnOrder(columnList.toArray()); - alignColumns(); - } - - @Override - protected void setHiddenColumns() { - final List columnsToBeHidden = new ArrayList<>(); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); - columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - columnsToBeHidden.add(IS_REQUIRED_MIGRATION_STEP); - columnsToBeHidden.add(DS_TYPE); - columnsToBeHidden.add(SW_MODULES); - for (final Object propertyId : columnsToBeHidden) { - getColumn(propertyId).setHidden(true); - } - - } - - @Override - protected CellDescriptionGenerator getDescriptionGenerator() { - return cell -> getDescription(cell); - } - - @Override - protected void addColumnRenderes() { - getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), - new TotalTargetGroupsConverter()); - getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), - new TotalTargetCountStatusConverter()); - - createRolloutStatusToFontMap(); - getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); - - getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); - - final RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); - customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); - getColumn(ROLLOUT_RENDERER_DATA).setRenderer(customObjectRenderer); - - } - - private void createRolloutStatusToFontMap() { - statusIconMap.put(RolloutStatus.FINISHED, - new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); - statusIconMap.put(RolloutStatus.PAUSED, - new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); - statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); - statusIconMap.put(RolloutStatus.READY, - new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); - statusIconMap.put(RolloutStatus.STOPPED, - new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); - statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); - statusIconMap.put(RolloutStatus.ERROR_CREATING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - statusIconMap.put(RolloutStatus.ERROR_STARTING, - new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); - } - - private void alignColumns() { - setCellStyleGenerator(new CellStyleGenerator() { - private static final long serialVersionUID = 5573570647129792429L; - - @Override - public String getStyle(final CellReference cellReference) { - final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; - if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { - return "centeralign"; - } - return null; - } - }); - } - - private void onClickOfRolloutName(final RendererClickEvent event) { - rolloutUIState.setRolloutId((long) event.getItemId()); - final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutUIState.setRolloutName(rolloutName); - final String ds = (String) getContainerDataSource().getItem(event.getItemId()) - .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); - rolloutUIState.setRolloutDistributionSet(ds); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); - } - - private void onClickOfActionBtn(final RendererClickEvent event) { - final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); - contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); - contextMenu.open(event.getClientX(), event.getClientY()); - } - - private ContextMenu createContextMenu(final Long rolloutId) { - final ContextMenu context = new ContextMenu(); - context.addItemClickListener(event -> menuItemClicked(event)); - final Item row = getContainerDataSource().getItem(rolloutId); - final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) - .getValue(); - - switch (rolloutStatus) { - case READY: - final ContextMenuItem startItem = context.addItem(START_OPTION); - startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); - break; - case RUNNING: - final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); - pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); - break; - case PAUSED: - final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); - resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); - break; - case STARTING: - case CREATING: - case ERROR_CREATING: - case ERROR_STARTING: - // do not provide any action on these statuses - return context; - default: - break; - } - getUpdateMenuItem(context, rolloutId); - return context; - } - - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { - // Add 'Update' option only if user has update permission - if (!permissionChecker.hasRolloutUpdatePermission()) { - return; - } - final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); - cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); - } - - private void menuItemClicked(final ContextMenuItemClickEvent event) { - final ContextMenuItem item = (ContextMenuItem) event.getSource(); - final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); - final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); - final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - switch (contextMenuData.getAction()) { - case PAUSE: - rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); - break; - case RESUME: - rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); - uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); - break; - case START: - rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); - uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); - break; - case UPDATE: - onUpdate(contextMenuData); - break; - default: - break; - } - } - - private void onUpdate(final ContextMenuData contextMenuData) { - addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); - final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); - addTargetWindow.setCaption(i18n.get("caption.update.rollout")); - UI.getCurrent().addWindow(addTargetWindow); - addTargetWindow.setVisible(Boolean.TRUE); - } - - private void refreshGrid() { - ((LazyQueryContainer) getContainerDataSource()).refresh(); - } - - /** - * Generator to generate fontIcon by String. - */ - public final class FontIconGenerator extends PropertyValueGenerator { - - private static final long serialVersionUID = 2544026030795375748L; - private final FontAwesome fontIcon; - - public FontIconGenerator(final FontAwesome icon) { - this.fontIcon = icon; - } - - @Override - public String getValue(final Item item, final Object itemId, final Object propertyId) { - return fontIcon.getHtml(); - } - - @Override - public Class getType() { - return String.class; - } - } - - private String getDescription(final CellReference cell) { - if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { - return cell.getProperty().getValue().toString().toLowerCase(); - } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { - return SPUILabelDefinitions.ACTION.toLowerCase(); - } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { - return ((RolloutRendererData) cell.getProperty().getValue()).getName(); - } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { - return DistributionBarHelper - .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); - } else if (SPUILabelDefinitions.VAR_DIST_NAME_VERSION.equals(cell.getPropertyId())) { - return getDSDetails((Item) cell.getItem()); - } - return null; - } - - private String getDSDetails(final Item rolloutItem) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set) rolloutItem.getItemProperty(SW_MODULES).getValue(); - swModules.forEach(swModule -> { - swModuleNames.append(swModule.getName()); - swModuleNames.append(" , "); - swModuleVendors.append(swModule.getVendor()); - swModuleVendors.append(" , "); - }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ") - .append((String) rolloutItem.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Type : ") - .append((String) rolloutItem.getItemProperty(DS_TYPE).getValue()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); - stringBuilder.append("Required Migration step : ") - .append((boolean) rolloutItem.getItemProperty(IS_REQUIRED_MIGRATION_STEP).getValue() ? "Yes" : "No"); - stringBuilder.append("
  • "); - - stringBuilder.append("
  • "); - stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - - stringBuilder.append("
  • "); - stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); - - stringBuilder.append("
"); - return stringBuilder.toString(); - } - - enum ACTION { - PAUSE, RESUME, START, UPDATE - } - - /** - * Represents data of context menu item. - * - */ - public static class ContextMenuData { - - private Long rolloutId; - - private ACTION action; - - /** - * Set rollout if and action. - * - * @param rolloutId - * id of rollout - * @param action - * user action {@link ACTION} - */ - public ContextMenuData(final Long rolloutId, final ACTION action) { - this.action = action; - this.rolloutId = rolloutId; - } - - /** - * @return the rolloutId - */ - public Long getRolloutId() { - return rolloutId; - } - - /** - * @param rolloutId - * the rolloutId to set - */ - public void setRolloutId(final Long rolloutId) { - this.rolloutId = rolloutId; - } - - /** - * @return the action - */ - public ACTION getAction() { - return action; - } - - /** - * @param action - * the action to set - */ - public void setAction(final ACTION action) { - this.action = action; - } - } - - /** - * - * Converter to convert {@link RolloutStatus} to string. - * - */ - class RolloutStatusConverter implements Converter { - - private static final long serialVersionUID = -1217685750825632678L; - - @Override - public RolloutStatus convertToModel(final String value, final Class targetType, - final Locale locale) { - return null; - } - - @Override - public String convertToPresentation(final RolloutStatus value, final Class targetType, - final Locale locale) { - return convertRolloutStatusToString(value); - } - - @Override - public Class getModelType() { - return RolloutStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - private String convertRolloutStatusToString(final RolloutStatus value) { - final StatusFontIcon statusFontIcon = statusIconMap.get(value); - final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - } - - /** - * Converter to convert {@link TotalTargetCountStatus} to formatted string - * with status and count details. - * - */ - class TotalTargetCountStatusConverter implements Converter { - - private static final long serialVersionUID = -5794528427855153924L; - - @Override - public TotalTargetCountStatus convertToModel(final String value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(final TotalTargetCountStatus value, - final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); - } - - @Override - public Class getModelType() { - return TotalTargetCountStatus.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - } - - /** - * Converter to convert 0 to empty, if total target groups is zero. - * - */ - class TotalTargetGroupsConverter implements Converter { - - private static final long serialVersionUID = 6589305227035220369L; - - @Override - public Long convertToModel(final String value, final Class targetType, final Locale locale) - throws com.vaadin.data.util.converter.Converter.ConversionException { - return null; - } - - @Override - public String convertToPresentation(final Long value, final Class targetType, - final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - if (value == 0) { - return ""; - } - return value.toString(); - } - - @Override - public Class getModelType() { - return Long.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - - } + private static final long serialVersionUID = 4060904914954370524L; + + private static final String UPDATE_OPTION = "Update"; + + private static final String RESUME_OPTION = "Resume"; + + private static final String PAUSE_OPTION = "Pause"; + + private static final String START_OPTION = "Start"; + + private static final String DS_TYPE = "type"; + + private static final String SW_MODULES = "swModules"; + + private static final String IS_REQUIRED_MIGRATION_STEP = "isRequiredMigrationStep"; + + private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); + + /** + * Handles the RolloutEvent to refresh Grid. + * + */ + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + switch (event) { + case FILTER_BY_TEXT: + case CREATE_ROLLOUT: + case UPDATE_ROLLOUT: + case SHOW_ROLLOUTS: + refreshGrid(); + break; + default: + return; + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the grid. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (!rolloutUIState.isShowRollOuts()) { + return; + } + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (item == null) { + return; + } + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + final int groupsCreated = rollout.getRolloutGroupsCreated(); + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Long.valueOf(groupsCreated)); + } else if (rollout.getRolloutGroups() != null && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + item.getItemProperty(ROLLOUT_RENDERER_DATA) + .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGridContainer.addContainerProperty(DS_TYPE, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SW_MODULES, Set.class, null, false, false); + rolloutGridContainer.addContainerProperty(ROLLOUT_RENDERER_DATA, RolloutRendererData.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(IS_REQUIRED_MIGRATION_STEP, boolean.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Long.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + + getColumn(ROLLOUT_RENDERER_DATA).setMinimumWidth(40); + getColumn(ROLLOUT_RENDERER_DATA).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setMinimumWidth(280); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + getColumn(ROLLOUT_RENDERER_DATA).setHeaderCaption(i18n.get("header.name")); + getColumn(DS_TYPE).setHeaderCaption("Type"); + getColumn(SW_MODULES).setHeaderCaption("swModules"); + getColumn(IS_REQUIRED_MIGRATION_STEP).setHeaderCaption("IsRequiredMigrationStep"); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getGridId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_GRID_ID; + } + + @Override + protected void setColumnProperties() { + final List columnList = new ArrayList<>(); + columnList.add(ROLLOUT_RENDERER_DATA); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(DS_TYPE); + columnList.add(SW_MODULES); + columnList.add(IS_REQUIRED_MIGRATION_STEP); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + @Override + protected void setHiddenColumns() { + final List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_NAME); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + columnsToBeHidden.add(IS_REQUIRED_MIGRATION_STEP); + columnsToBeHidden.add(DS_TYPE); + columnsToBeHidden.add(SW_MODULES); + for (final Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + } + + @Override + protected void addColumnRenderes() { + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setRenderer(new HtmlRenderer(), + new TotalTargetGroupsConverter()); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), + new TotalTargetCountStatusConverter()); + + createRolloutStatusToFontMap(); + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutStatusConverter()); + + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + + final RolloutRenderer customObjectRenderer = new RolloutRenderer(RolloutRendererData.class); + customObjectRenderer.addClickListener(event -> onClickOfRolloutName(event)); + getColumn(ROLLOUT_RENDERER_DATA).setRenderer(customObjectRenderer); + + } + + private void createRolloutStatusToFontMap() { + statusIconMap.put(RolloutStatus.FINISHED, + new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); + statusIconMap.put(RolloutStatus.PAUSED, + new StatusFontIcon(FontAwesome.PAUSE, SPUIStyleDefinitions.STATUS_ICON_BLUE)); + statusIconMap.put(RolloutStatus.RUNNING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_YELLOW)); + statusIconMap.put(RolloutStatus.READY, + new StatusFontIcon(FontAwesome.DOT_CIRCLE_O, SPUIStyleDefinitions.STATUS_ICON_LIGHT_BLUE)); + statusIconMap.put(RolloutStatus.STOPPED, + new StatusFontIcon(FontAwesome.STOP, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.CREATING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_GREY)); + statusIconMap.put(RolloutStatus.STARTING, new StatusFontIcon(null, SPUIStyleDefinitions.STATUS_SPINNER_BLUE)); + statusIconMap.put(RolloutStatus.ERROR_CREATING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + statusIconMap.put(RolloutStatus.ERROR_STARTING, + new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + private void onClickOfRolloutName(final RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + rolloutUIState.setRolloutName(rolloutName); + final String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(final RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + + switch (rolloutStatus) { + case READY: + final ContextMenuItem startItem = context.addItem(START_OPTION); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + break; + case RUNNING: + final ContextMenuItem pauseItem = context.addItem(PAUSE_OPTION); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + break; + case PAUSED: + final ContextMenuItem resumeItem = context.addItem(RESUME_OPTION); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + break; + case STARTING: + case CREATING: + case ERROR_CREATING: + case ERROR_STARTING: + // do not provide any action on these statuses + return context; + default: + break; + } + getUpdateMenuItem(context, rolloutId); + return context; + } + + private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { + // Add 'Update' option only if user has update permission + if (!permissionChecker.hasRolloutUpdatePermission()) { + return; + } + final ContextMenuItem cancelItem = context.addItem(UPDATE_OPTION); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + switch (contextMenuData.getAction()) { + case PAUSE: + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + break; + case RESUME: + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + break; + case START: + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + break; + case UPDATE: + onUpdate(contextMenuData); + break; + default: + break; + } + } + + private void onUpdate(final ContextMenuData contextMenuData) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + + private void refreshGrid() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + /** + * Generator to generate fontIcon by String. + */ + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(final FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(final Item item, final Object itemId, final Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + private String getDescription(final CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (ROLLOUT_RENDERER_DATA.equals(cell.getPropertyId())) { + return ((RolloutRendererData) cell.getProperty().getValue()).getName(); + } else if (SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS.equals(cell.getPropertyId())) { + return DistributionBarHelper + .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); + } else if (SPUILabelDefinitions.VAR_DIST_NAME_VERSION.equals(cell.getPropertyId())) { + return getDSDetails((Item) cell.getItem()); + } + return null; + } + + private String getDSDetails(final Item rolloutItem) { + StringBuilder swModuleNames = new StringBuilder(); + StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = (Set) rolloutItem.getItemProperty(SW_MODULES).getValue(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("
    "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Description : ") + .append((String) rolloutItem.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append(" DistributionSet Type : ") + .append((String) rolloutItem.getItemProperty(DS_TYPE).getValue()); + stringBuilder.append("
  • "); + stringBuilder.append("
  • "); + stringBuilder.append("Required Migration step : ") + .append((boolean) rolloutItem.getItemProperty(IS_REQUIRED_MIGRATION_STEP).getValue() ? "Yes" : "No"); + stringBuilder.append("
  • "); + + stringBuilder.append("
  • "); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append("
  • "); + + stringBuilder.append("
  • "); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append("
  • "); + + stringBuilder.append("
"); + return stringBuilder.toString(); + } + + enum ACTION { + PAUSE, RESUME, START, UPDATE + } + + /** + * Represents data of context menu item. + * + */ + public static class ContextMenuData { + + private Long rolloutId; + + private ACTION action; + + /** + * Set rollout if and action. + * + * @param rolloutId + * id of rollout + * @param action + * user action {@link ACTION} + */ + public ContextMenuData(final Long rolloutId, final ACTION action) { + this.action = action; + this.rolloutId = rolloutId; + } + + /** + * @return the rolloutId + */ + public Long getRolloutId() { + return rolloutId; + } + + /** + * @param rolloutId + * the rolloutId to set + */ + public void setRolloutId(final Long rolloutId) { + this.rolloutId = rolloutId; + } + + /** + * @return the action + */ + public ACTION getAction() { + return action; + } + + /** + * @param action + * the action to set + */ + public void setAction(final ACTION action) { + this.action = action; + } + } + + /** + * + * Converter to convert {@link RolloutStatus} to string. + * + */ + class RolloutStatusConverter implements Converter { + + private static final long serialVersionUID = -1217685750825632678L; + + @Override + public RolloutStatus convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, final Class targetType, + final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } + } + + /** + * Converter to convert {@link TotalTargetCountStatus} to formatted string + * with status and count details. + * + */ + class TotalTargetCountStatusConverter implements Converter { + + private static final long serialVersionUID = -5794528427855153924L; + + @Override + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + } + + /** + * Converter to convert 0 to empty, if total target groups is zero. + * + */ + class TotalTargetGroupsConverter implements Converter { + + private static final long serialVersionUID = 6589305227035220369L; + + @Override + public Long convertToModel(final String value, final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(final Long value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + if (value == 0) { + return ""; + } + return value.toString(); + } + + @Override + public Class getModelType() { + return Long.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 46a76fb17..df4a1309e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -103,9 +103,9 @@ public final class HawkbitCommonUtil { private static final String TARGET_TAG_DROP_REMOVE_SCRIPT = "var m = document.getElementById('show-filter-drop-hint'); if(m) { document.head.removeChild(m); } "; private static final String DELETE_DROP_CREATE_SCRIPT = "var q = document.getElementById('show-delete-drop-hint'); if(q) { } else { showDeleteDrop = document.createElement('style'); showDeleteDrop.id=\"show-delete-drop-hint\"; document.head.appendChild(showDeleteDrop); }"; private static final String DELETE_TAG_DROP_REMOVE_SCRIPT = "var o = document.getElementById('show-delete-drop-hint'); if(o) { document.head.removeChild(o); } "; - + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; - private static final String INSTALL_DIST_SET = "installedDistributionSet"; + private static final String INSTALL_DIST_SET = "installedDistributionSet"; /** * Define empty string. @@ -1041,7 +1041,7 @@ public final class HawkbitCommonUtil { targetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP, String.class, null, false, true); targetTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); - + targetTableContainer.addContainerProperty(ASSIGN_DIST_SET, DistributionSet.class, null, false, true); targetTableContainer.addContainerProperty(INSTALL_DIST_SET, DistributionSet.class, null, false, true); From 8dcfc8412d7f2ae72fbf59ce87a9be777bc9f069 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 28 Apr 2016 16:05:37 +0200 Subject: [PATCH 61/69] Fix: Return trimmed username Signed-off-by: SirWayne --- .../hawkbit/ui/common/UserDetailsFormatter.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java index 04ad0c51a..d4a733de3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/UserDetailsFormatter.java @@ -88,12 +88,10 @@ public final class UserDetailsFormatter { * name to max 12 characters. @see * {@link UserDetailsFormatter#loadAndFormatUsername(String, int)} * - * @param baseEntity - * the entity * @return the formatted user name (max 12 characters) cannot be */ - public static String loadAndFormatCurrentUsername() { - return loadAndFormatUsername(getCurrentUser().getUsername(), 12); + public static String formatCurrentUsername() { + return loadAndFormatUsername(getCurrentUser().getUsername(), 5); } /** @@ -114,6 +112,10 @@ public final class UserDetailsFormatter { */ public static String loadAndFormatUsername(final String username, final int expectedNameLength) { final UserDetails userDetails = loadUserByUsername(username); + return formatUserName(expectedNameLength, userDetails); + } + + private static String formatUserName(final int expectedNameLength, final UserDetails userDetails) { if (!(userDetails instanceof UserPrincipal)) { return userDetails.getUsername(); } @@ -134,7 +136,7 @@ public final class UserDetailsFormatter { if (StringUtils.isEmpty(trimmedUsername)) { return trimAndFormatDetail(userPrincipal.getLoginname(), expectedNameLength); } - return firstAndLastname; + return trimmedUsername; } /** From f203e31d00258195d55ddd7950a884fa21e800fb Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 16:20:13 +0200 Subject: [PATCH 62/69] use constants for html tags used often Signed-off-by: Michael Hirsch --- .../CreateOrUpdateFilterTable.java | 41 +++++++++++-------- .../management/targettable/TargetTable.java | 41 +++++++++++-------- .../ui/rollout/rollout/RolloutListGrid.java | 37 +++++++++-------- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 5 +++ 4 files changed, 72 insertions(+), 52 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java index cf8a514d4..debd35056 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.filtermanagement; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -263,7 +268,7 @@ public class CreateOrUpdateFilterTable extends Table { private static final long serialVersionUID = 688730421728162456L; @Override - public String generateDescription(Component source, Object itemId, Object propertyId) { + public String generateDescription(final Component source, final Object itemId, final Object propertyId) { final DistributionSet distributionSet; final Item item = getItem(itemId); if (propertyId != null) { @@ -279,35 +284,35 @@ public class CreateOrUpdateFilterTable extends Table { } private String getDSDetails(final DistributionSet distributionSet) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set) distributionSet.getModules(); + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = distributionSet.getModules(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); swModuleNames.append(" , "); swModuleVendors.append(swModule.getVendor()); swModuleVendors.append(" , "); }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" Required Migration step : ") .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
"); + stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index a1e759950..0055e06e4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.management.targettable; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -1089,7 +1094,7 @@ public class TargetTable extends AbstractTable implements private static final long serialVersionUID = 688730421728162456L; @Override - public String generateDescription(Component source, Object itemId, Object propertyId) { + public String generateDescription(final Component source, final Object itemId, final Object propertyId) { final DistributionSet distributionSet; final Item item = getItem(itemId); if (propertyId != null) { @@ -1105,34 +1110,34 @@ public class TargetTable extends AbstractTable implements } private String getDSDetails(final DistributionSet distributionSet) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set) distributionSet.getModules(); + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = distributionSet.getModules(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); swModuleNames.append(" , "); swModuleVendors.append(swModule.getVendor()); swModuleVendors.append(" , "); }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" Required Migration step : ") .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
"); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 1ad0bfc35..7f3877a9a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.rollout.rollout; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + import java.util.ArrayList; import java.util.Arrays; import java.util.EnumMap; @@ -477,14 +482,14 @@ public class RolloutListGrid extends AbstractGrid { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); } else if (SPUILabelDefinitions.VAR_DIST_NAME_VERSION.equals(cell.getPropertyId())) { - return getDSDetails((Item) cell.getItem()); + return getDSDetails(cell.getItem()); } return null; } private String getDSDetails(final Item rolloutItem) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); final Set swModules = (Set) rolloutItem.getItemProperty(SW_MODULES).getValue(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); @@ -492,30 +497,30 @@ public class RolloutListGrid extends AbstractGrid { swModuleVendors.append(swModule.getVendor()); swModuleVendors.append(" , "); }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Description : ") .append((String) rolloutItem.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ") .append((String) rolloutItem.getItemProperty(DS_TYPE).getValue()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Required Migration step : ") .append((boolean) rolloutItem.getItemProperty(IS_REQUIRED_MIGRATION_STEP).getValue() ? "Yes" : "No"); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
"); + stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index df4a1309e..0e71567af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -73,6 +73,11 @@ public final class HawkbitCommonUtil { */ public static final String SPAN_CLOSE = ""; + public static final String HTML_LI_CLOSE_TAG = ""; + public static final String HTML_LI_OPEN_TAG = "
  • "; + public static final String HTML_UL_CLOSE_TAG = ""; + public static final String HTML_UL_OPEN_TAG = "
      "; + private static final Logger LOG = LoggerFactory.getLogger(HawkbitCommonUtil.class); private static final String JS_DRAG_COUNT_REM_CHILD = " if(x) { document.head.removeChild(x); } "; From 345e9a7cf3bf4cf25f7fbaf0ffe1409550cb0076 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 28 Apr 2016 16:24:13 +0200 Subject: [PATCH 63/69] Rename method Signed-off-by: SirWayne --- .../main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java index 690cb51a2..5a822ff86 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardMenu.java @@ -193,7 +193,7 @@ public final class DashboardMenu extends CustomComponent { final MenuItem settingsItem = settings.addItem("", new ThemeResource("images/profile-pic-57px.jpg"), null); final String formattedTenant = UserDetailsFormatter.formatCurrentTenant(); - final String formattedUsername = UserDetailsFormatter.loadAndFormatCurrentUsername(); + final String formattedUsername = UserDetailsFormatter.formatCurrentUsername(); String tenantAndUsernameHtml = ""; if (!StringUtils.isEmpty(formattedTenant)) { tenantAndUsernameHtml += formattedTenant + "
      "; From 607c98b819be9c64c8ef4dff1c8ff455044429af Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 29 Apr 2016 07:21:43 +0200 Subject: [PATCH 64/69] remove current tenant null check cause not all queries have current tenant and must set it for tenant indenpendent queries like SystemManagement Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/MultiTenantJpaTransactionManager.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java index a45c846a9..597aee5e8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit; import javax.persistence.EntityManager; import javax.transaction.Transaction; -import org.eclipse.hawkbit.repository.exception.TenantNotExistException; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.springframework.beans.factory.annotation.Autowired; @@ -41,11 +40,8 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { final EntityManager em = emHolder.getEntityManager(); final String currentTenant = tenantAware.getCurrentTenant(); - if (currentTenant == null) { - throw new TenantNotExistException("Tenant Unknown. Canceling transaction."); + if (currentTenant != null) { + em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); } - - em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); - } } From c1b9fb48e89a49c02910709e8d9f9b460c2987d7 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 29 Apr 2016 08:44:29 +0200 Subject: [PATCH 65/69] No need to get EM if no tenant has to be set. Signed-off-by: Kai Zimmermann --- .../eclipse/hawkbit/MultiTenantJpaTransactionManager.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java index 597aee5e8..b3821e5f3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java @@ -35,12 +35,11 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { protected void doBegin(final Object transaction, final TransactionDefinition definition) { super.doBegin(transaction, definition); - final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager - .getResource(getEntityManagerFactory()); - final EntityManager em = emHolder.getEntityManager(); - final String currentTenant = tenantAware.getCurrentTenant(); if (currentTenant != null) { + final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager + .getResource(getEntityManagerFactory()); + final EntityManager em = emHolder.getEntityManager(); em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); } } From 3c548c9121f70a742d82a5ef38b796d613d09f7e Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 29 Apr 2016 10:18:45 +0200 Subject: [PATCH 66/69] use vaadin-version placeholder in case of hard-coded vaadin version Signed-off-by: Michael Hirsch --- examples/hawkbit-device-simulator/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml index a23051124..c74eace3e 100644 --- a/examples/hawkbit-device-simulator/pom.xml +++ b/examples/hawkbit-device-simulator/pom.xml @@ -139,7 +139,7 @@ com.vaadin vaadin-bom - 7.6.3 + ${vaadin.version} pom import From 8e2ea76c8ca4709c68dd0908d6abbc7291128ee2 Mon Sep 17 00:00:00 2001 From: venu1278 Date: Fri, 29 Apr 2016 16:10:10 +0530 Subject: [PATCH 67/69] fix_assigned_installed_ds_tooltip_gliches Signed-off-by: venu1278 --- .../ui/common/table/AbstractTable.java | 4 - .../CreateOrUpdateFilterTable.java | 72 ++-------------- .../management/targettable/TargetTable.java | 73 ++--------------- .../AssignInstalledDSTooltipGenerator.java | 82 +++++++++++++++++++ 4 files changed, 97 insertions(+), 134 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 843d86ca3..1808cf070 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -323,10 +323,6 @@ public abstract class AbstractTable extends Table { return columnList; } columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); - columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, - i18n.get("header.assigned.ds"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, - i18n.get("header.installed.ds"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java index debd35056..6e4933d69 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java @@ -8,27 +8,22 @@ */ package org.eclipse.hawkbit.ui.filtermanagement; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; +import org.eclipse.hawkbit.ui.utils.AssignInstalledDSTooltipGenerator; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -99,7 +94,7 @@ public class CreateOrUpdateFilterTable extends Table { setId(SPUIComponetIdProvider.CUSTOM_FILTER_TARGET_TABLE_ID); setSelectable(false); eventBus.subscribe(this); - setItemDescriptionGenerator(new TooltipGenerator()); + setItemDescriptionGenerator(new AssignInstalledDSTooltipGenerator()); } @PreDestroy @@ -188,13 +183,13 @@ public class CreateOrUpdateFilterTable extends Table { container.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, Date.class, null); container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, null, false, true); container.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); - container.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, String.class, ""); - container.addContainerProperty(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, String.class, null); container.addContainerProperty(SPUILabelDefinitions.VAR_TARGET_STATUS, TargetUpdateStatus.class, null); container.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, true); container.addContainerProperty(ASSIGN_DIST_SET, DistributionSet.class, null, false, true); container.addContainerProperty(INSTALL_DIST_SET, DistributionSet.class, null, false, true); + container.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, String.class, ""); + container.addContainerProperty(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, String.class, null); } private List getVisbleColumns() { @@ -205,12 +200,12 @@ public class CreateOrUpdateFilterTable extends Table { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); columnList.add( new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.STATUS_ICON, i18n.get("header.status"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, i18n.get("header.assigned.ds"), 0.125F)); columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, i18n.get("header.installed.ds"), 0.125F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.STATUS_ICON, i18n.get("header.status"), 0.1F)); return columnList; } @@ -263,58 +258,5 @@ public class CreateOrUpdateFilterTable extends Table { populateTableData(); eventBus.publish(this, CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON); } - - public class TooltipGenerator implements ItemDescriptionGenerator { - private static final long serialVersionUID = 688730421728162456L; - - @Override - public String generateDescription(final Component source, final Object itemId, final Object propertyId) { - final DistributionSet distributionSet; - final Item item = getItem(itemId); - if (propertyId != null) { - if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } - } - return null; - } - - private String getDSDetails(final DistributionSet distributionSet) { - final StringBuilder swModuleNames = new StringBuilder(); - final StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = distributionSet.getModules(); - swModules.forEach(swModule -> { - swModuleNames.append(swModule.getName()); - swModuleNames.append(" , "); - swModuleVendors.append(swModule.getVendor()); - swModuleVendors.append(" , "); - }); - final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(HTML_UL_OPEN_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append(" Required Migration step : ") - .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - - stringBuilder.append(HTML_UL_CLOSE_TAG); - return stringBuilder.toString(); - } - - } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 0055e06e4..6232ebcf8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -8,11 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.targettable; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; -import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -59,6 +54,7 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.TargetTableFilters; +import org.eclipse.hawkbit.ui.utils.AssignInstalledDSTooltipGenerator; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -117,9 +113,7 @@ public class TargetTable extends AbstractTable implements private static final int PROPERTY_DEPT = 3; private static final String ACTION_NOT_ALLOWED_MSG = "message.action.not.allowed"; - private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; - private static final String INSTALL_DIST_SET = "installedDistributionSet"; - + @Autowired private transient TargetManagement targetManagement; @@ -147,7 +141,7 @@ public class TargetTable extends AbstractTable implements addActionHandler(this); actionSelectAll = new ShortcutAction(i18n.get("action.target.table.selectall")); actionUnSelectAll = new ShortcutAction(i18n.get("action.target.table.clear")); - setItemDescriptionGenerator(new TooltipGenerator()); + setItemDescriptionGenerator(new AssignInstalledDSTooltipGenerator()); } /** @@ -341,6 +335,11 @@ public class TargetTable extends AbstractTable implements if (!isMaximized()) { columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0F)); columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0F)); + }else{ + columnList.add(new TableColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, + i18n.get("header.assigned.ds"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER, + i18n.get("header.installed.ds"), 0.1F)); } return columnList; @@ -1085,60 +1084,4 @@ public class TargetTable extends AbstractTable implements private boolean isFilteredByTags() { return !managementUIState.getTargetTableFilters().getClickedTargetTags().isEmpty(); } - - /** - * tooltip for assignedDS and installedDS - */ - - protected class TooltipGenerator implements ItemDescriptionGenerator { - private static final long serialVersionUID = 688730421728162456L; - - @Override - public String generateDescription(final Component source, final Object itemId, final Object propertyId) { - final DistributionSet distributionSet; - final Item item = getItem(itemId); - if (propertyId != null) { - if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { - distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); - return getDSDetails(distributionSet); - } - } - return null; - } - - private String getDSDetails(final DistributionSet distributionSet) { - final StringBuilder swModuleNames = new StringBuilder(); - final StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = distributionSet.getModules(); - swModules.forEach(swModule -> { - swModuleNames.append(swModule.getName()); - swModuleNames.append(" , "); - swModuleVendors.append(swModule.getVendor()); - swModuleVendors.append(" , "); - }); - final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(HTML_UL_OPEN_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append(" Required Migration step : ") - .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_LI_OPEN_TAG); - stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append(HTML_UL_CLOSE_TAG); - return stringBuilder.toString(); - } - } } \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java new file mode 100644 index 000000000..5a3b91a7a --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java @@ -0,0 +1,82 @@ +/** + * 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.utils; + +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + +import java.util.Set; + +import com.vaadin.data.Item; +import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +public class AssignInstalledDSTooltipGenerator implements ItemDescriptionGenerator { + private static final long serialVersionUID = 688730421728162456L; + + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; + private static final String INSTALL_DIST_SET = "installedDistributionSet"; + + @Override + public String generateDescription(final Component source, final Object itemId, final Object propertyId) { + final DistributionSet distributionSet; + final Item item = ((Table)source).getItem(itemId); + if (propertyId != null) { + if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } else if (propertyId.equals(SPUILabelDefinitions.INSTALLED_DISTRIBUTION_NAME_VER)) { + distributionSet = (DistributionSet) item.getItemProperty(INSTALL_DIST_SET).getValue(); + return getDSDetails(distributionSet); + } + } + return null; + } + + private String getDSDetails(final DistributionSet distributionSet) { + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = distributionSet.getModules(); + swModules.forEach(swModule -> { + swModuleNames.append(swModule.getName()); + swModuleNames.append(" , "); + swModuleVendors.append(swModule.getVendor()); + swModuleVendors.append(" , "); + }); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" Required Migration step : ") + .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_UL_CLOSE_TAG); + return stringBuilder.toString(); + } + } + + From 59bec04c58c7649f2b1be5c10e842b92453200ae Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 29 Apr 2016 12:52:27 +0200 Subject: [PATCH 68/69] add null check for distribution set Signed-off-by: Michael Hirsch --- .../AssignInstalledDSTooltipGenerator.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java index 5a3b91a7a..c4e78b3e5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/AssignInstalledDSTooltipGenerator.java @@ -9,9 +9,6 @@ package org.eclipse.hawkbit.ui.utils; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.SoftwareModule; - import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; @@ -19,21 +16,24 @@ import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; import java.util.Set; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + import com.vaadin.data.Item; import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator; import com.vaadin.ui.Component; import com.vaadin.ui.Table; -public class AssignInstalledDSTooltipGenerator implements ItemDescriptionGenerator { +public class AssignInstalledDSTooltipGenerator implements ItemDescriptionGenerator { private static final long serialVersionUID = 688730421728162456L; - + private static final String ASSIGN_DIST_SET = "assignedDistributionSet"; private static final String INSTALL_DIST_SET = "installedDistributionSet"; @Override public String generateDescription(final Component source, final Object itemId, final Object propertyId) { final DistributionSet distributionSet; - final Item item = ((Table)source).getItem(itemId); + final Item item = ((Table) source).getItem(itemId); if (propertyId != null) { if (propertyId.equals(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER)) { distributionSet = (DistributionSet) item.getItemProperty(ASSIGN_DIST_SET).getValue(); @@ -47,6 +47,9 @@ public class AssignInstalledDSTooltipGenerator implements ItemDescriptionGenera } private String getDSDetails(final DistributionSet distributionSet) { + if (distributionSet == null) { + return null; + } final StringBuilder swModuleNames = new StringBuilder(); final StringBuilder swModuleVendors = new StringBuilder(); final Set swModules = distributionSet.getModules(); @@ -77,6 +80,4 @@ public class AssignInstalledDSTooltipGenerator implements ItemDescriptionGenera stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } - } - - +} From a946f51da4149bcf050e2cdb4e268345758a618d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 29 Apr 2016 12:57:25 +0200 Subject: [PATCH 69/69] fix installed and assigned distribution set setting on the proxy target Signed-off-by: Michael Hirsch --- .../targettable/TargetBeanQuery.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index d127b4198..e48004d7a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -134,22 +134,21 @@ public class TargetBeanQuery extends AbstractBeanQuery { prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ)); prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ)); - if (pinnedDistId == null) { - prxyTarget.setInstalledDistributionSet(null); - prxyTarget.setAssignedDistributionSet(null); + final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); + final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); + final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet(); - } else { - final Target target = getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()); - final DistributionSet installedDistributionSet = target.getTargetInfo().getInstalledDistributionSet(); + prxyTarget.setInstalledDistributionSet(installedDistributionSet); + prxyTarget.setAssignedDistributionSet(assignedDistributionSet); + + if (installedDistributionSet != null) { prxyTarget.setInstalledDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( installedDistributionSet.getName(), installedDistributionSet.getVersion())); - prxyTarget.setInstalledDistributionSet(installedDistributionSet); - final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet(); + } + if (assignedDistributionSet != null) { prxyTarget.setAssignedDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion( assignedDistributionSet.getName(), assignedDistributionSet.getVersion())); - prxyTarget.setAssignedDistributionSet(assignedDistributionSet); } - prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus()); prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery()); prxyTarget.setTargetInfo(targ.getTargetInfo());