From 536098c4c786752256e29aaacece0f7d11aa5acb Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 15 Apr 2016 17:40:03 +0200 Subject: [PATCH] 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 {