Merge branch 'master' into MECS-794-Display-DS-Details-Tooltip

Conflicts:
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java
	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java
This commit is contained in:
venu1278
2016-04-27 18:51:26 +05:30
25 changed files with 640 additions and 462 deletions

0
3rd-dependencies/listDeps.sh Executable file → Normal file
View File

View File

@@ -11,8 +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;
import org.eclipse.persistence.config.PersistenceUnitProperties;
@@ -42,34 +40,12 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager {
.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.");
}
}
private boolean notGetOrCreateTenantMetadata(final TransactionDefinition definition) {
return !definition.getName()
.startsWith(SystemManagement.class.getCanonicalName() + ".getOrCreateTenantMetadata");
}
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
private boolean notRolloutScheduler(final TransactionDefinition definition) {
return !definition.getName().startsWith(RolloutManagement.class.getCanonicalName() + ".rolloutScheduler");
}
private boolean notCurrentTenantKeyGenerator(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")
&& !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants");
}
}

View File

@@ -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<String> 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));

View File

@@ -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)

View File

@@ -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<ProxyBaseSoftwareMo
proxy.setVersion(bean.getVersion());
proxy.setVendor(bean.getVendor());
proxy.setDescription(bean.getDescription());
proxy.setCreatedByUser(HawkbitCommonUtil.getIMUser(bean.getCreatedBy()));
proxy.setModifiedByUser(HawkbitCommonUtil.getIMUser(bean.getLastModifiedBy()));
proxy.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(bean));
proxy.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(bean));
return proxy;
}

View File

@@ -0,0 +1,183 @@
/**
* 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;
import java.util.Collections;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.im.authentication.UserPrincipal;
import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import com.vaadin.server.VaadinService;
/**
* A Utility class to user details e.g. username
*/
public final class UserDetailsFormatter {
private static final String TRIM_APPENDIX = "...";
private static final String DETAIL_SEPERATOR = ", ";
private UserDetailsFormatter() {
}
/**
* Load user details by the user name and format the user name to max 100
* characters.
*
* @see {@link UserDetailsFormatter#loadAndFormatUsername(String, int)}
*
* @param username
* the user name
* @return the formatted user name (max 100 characters) cannot be <null>
*/
public static String loadAndFormatUsername(final String username) {
return loadAndFormatUsername(username, 100);
}
/**
* 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 <null>
*/
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 <null>
*/
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 <null>
*/
public static String loadAndFormatCurrentUsername() {
return loadAndFormatUsername(getCurrentUser().getUsername(), 12);
}
/**
* Load user details by the user name and format the user name. If the
* 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
* {@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 expectedNameLength characters)
* cannot be <null>
*/
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;
String firstname = StringUtils.defaultIfEmpty(userPrincipal.getFirstname(), StringUtils.EMPTY);
if (!StringUtils.isEmpty(firstname)) {
firstname += DETAIL_SEPERATOR;
}
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;
}
/**
* Format the current tenant. The information is loaded by the current
* session information.
*
* @return the formatted user name (max 8 characters) can be <null>
*/
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) {
return new User(username, "", Collections.emptyList());
}
}
}

View File

@@ -171,9 +171,7 @@ public abstract class AbstractTableDetailsLayout<T extends NamedEntity> 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() {
@@ -213,22 +211,22 @@ public abstract class AbstractTableDetailsLayout<T extends NamedEntity> 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.createCreatedByLabel(i18n, 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.createLastModifiedByLabel(i18n, selectedBaseEntity));
}
protected void updateDescriptionLayout(final String descriptionLabel, final String description) {
@@ -320,19 +318,6 @@ public abstract class AbstractTableDetailsLayout<T extends NamedEntity> 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());

View File

@@ -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<E extends NamedEntity, I> 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)
@@ -333,6 +333,17 @@ public abstract class AbstractTable<E extends NamedEntity, I> 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;
}

View File

@@ -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.
*

View File

@@ -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> {
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);
}

View File

@@ -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<ProxyBaseSwModuleItem>
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());

View File

@@ -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<ProxyTarget> {
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);

View File

@@ -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<ProxyTargetFilter>
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);
}

View File

@@ -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>
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);

View File

@@ -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;

View File

@@ -34,6 +34,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;
@@ -747,7 +748,7 @@ public class TargetTable extends AbstractTable<Target, TargetIdName> implements
.setValue(updatedTarget.getTargetInfo().getLastTargetQuery());
item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY)
.setValue(HawkbitCommonUtil.getIMUser(updatedTarget.getLastModifiedBy()));
.setValue(UserDetailsFormatter.loadAndFormatLastModifiedBy(updatedTarget));
item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE)
.setValue(SPDateTimeUtil.getFormattedDate(updatedTarget.getLastModifiedAt()));
item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(updatedTarget.getDescription());

View File

@@ -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 + "<br>";
}
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)) {

View File

@@ -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<ProxyDistribution>
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<ProxyDistribution>
final List<ProxyDistribution> 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>
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);
}

View File

@@ -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.customrenderers.client.renderers.RolloutRendererData;
import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
@@ -40,170 +41,171 @@ import com.google.common.base.Strings;
*/
public class RolloutBeanQuery extends AbstractBeanQuery<ProxyRollout> {
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<String, Object> 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<String, Object> 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<ProxyRollout> loadBeans(final int startIndex, final int count) {
final Slice<Rollout> 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<ProxyRollout> loadBeans(final int startIndex, final int count) {
final Slice<Rollout> 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<ProxyRollout> getProxyRolloutList(final Slice<Rollout> rolloutBeans) {
final List<ProxyRollout> 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.setRolloutRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString()));
private List<ProxyRollout> getProxyRolloutList(final Slice<Rollout> rolloutBeans) {
final List<ProxyRollout> 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(UserDetailsFormatter.loadAndFormatCreatedBy(rollout));
proxyRollout.setLastModifiedBy(UserDetailsFormatter.loadAndFormatLastModifiedBy(rollout));
proxyRollout.setForcedTime(rollout.getForcedTime());
proxyRollout.setId(rollout.getId());
proxyRollout.setStatus(rollout.getStatus());
proxyRollout
.setRolloutRendererData(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString()));
final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus();
proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus);
proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets()));
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);
}
return proxyRolloutList;
}
proxyRolloutList.add(proxyRollout);
}
return proxyRolloutList;
}
/*
* (non-Javadoc)
*
* @see
* org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#saveBeans(java
* .util.List, java.util.List, java.util.List)
*/
@Override
protected void saveBeans(final List<ProxyRollout> arg0, final List<ProxyRollout> arg1,
final List<ProxyRollout> arg2) {
/**
* CRUD operations on Target will be done through repository methods
*/
}
/*
* (non-Javadoc)
*
* @see
* org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery#saveBeans(java
* .util.List, java.util.List, java.util.List)
*/
@Override
protected void saveBeans(final List<ProxyRollout> arg0, final List<ProxyRollout> arg1,
final List<ProxyRollout> arg2) {
/**
* CRUD operations on Target will be done through repository methods
*/
}
/*
* (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;
}
/*
* (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 rolloutManagement
*/
public RolloutManagement getRolloutManagement() {
if (null == rolloutManagement) {
rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class);
}
return rolloutManagement;
}
/**
* @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 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;
}
/**
* @return the rolloutUIState
*/
public RolloutUIState getRolloutUIState() {
if (null == rolloutUIState) {
rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class);
}
return rolloutUIState;
}
}

View File

@@ -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.customrenderers.client.renderers.RolloutRendererData;
import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
@@ -35,160 +36,160 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
*/
public class RolloutGroupBeanQuery extends AbstractBeanQuery<ProxyRolloutGroup> {
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<RolloutGroup> firstPageRolloutGroupSets = null;
private transient Page<RolloutGroup> 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<String, Object> 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<String, Object> 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<ProxyRolloutGroup> loadBeans(final int startIndex, final int count) {
List<RolloutGroup> 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<ProxyRolloutGroup> loadBeans(final int startIndex, final int count) {
List<RolloutGroup> 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<ProxyRolloutGroup> getProxyRolloutGroupList(final List<RolloutGroup> rolloutGroupBeans) {
final List<ProxyRolloutGroup> 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));
private List<ProxyRolloutGroup> getProxyRolloutGroupList(final List<RolloutGroup> rolloutGroupBeans) {
final List<ProxyRolloutGroup> 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(UserDetailsFormatter.loadAndFormatCreatedBy(rolloutGroup));
proxyRolloutGroup.setLastModifiedBy(UserDetailsFormatter.loadAndFormatLastModifiedBy(rolloutGroup));
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.setRolloutRendererData(new RolloutRendererData(rolloutGroup.getName(), null));
proxyRolloutGroup.setRolloutRendererData(new RolloutRendererData(rolloutGroup.getName(), null));
proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets()));
proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus());
proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets()));
proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus());
proxyRolloutGroupsList.add(proxyRolloutGroup);
}
return proxyRolloutGroupsList;
}
proxyRolloutGroupsList.add(proxyRolloutGroup);
}
return proxyRolloutGroupsList;
}
private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) {
return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, getRolloutManagement()
.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup));
}
private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) {
return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, getRolloutManagement()
.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup));
}
@Override
protected void saveBeans(final List<ProxyRolloutGroup> arg0, final List<ProxyRolloutGroup> arg1,
final List<ProxyRolloutGroup> arg2) {
/**
* CRUD operations be done through repository methods.
*/
}
@Override
protected void saveBeans(final List<ProxyRolloutGroup> arg0, final List<ProxyRolloutGroup> arg1,
final List<ProxyRolloutGroup> arg2) {
/**
* CRUD operations be done through repository methods.
*/
}
@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
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 (int) size;
}
return (int) size;
}
/**
* @return the rolloutManagement
*/
public RolloutManagement getRolloutManagement() {
if (null == rolloutManagement) {
rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class);
}
return rolloutManagement;
}
/**
* @return the rolloutManagement
*/
public RolloutManagement getRolloutManagement() {
if (null == rolloutManagement) {
rolloutManagement = SpringContextHelper.getBean(RolloutManagement.class);
}
return rolloutManagement;
}
/**
* @return the rolloutManagement
*/
public RolloutGroupManagement getRolloutGroupManagement() {
if (null == rolloutGroupManagement) {
rolloutGroupManagement = SpringContextHelper.getBean(RolloutGroupManagement.class);
}
return rolloutGroupManagement;
}
/**
* @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;
}
/**
* @return the rolloutUIState
*/
public RolloutUIState getRolloutUIState() {
if (null == rolloutUIState) {
rolloutUIState = SpringContextHelper.getBean(RolloutUIState.class);
}
return rolloutUIState;
}
}

View File

@@ -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<ProxyTarget>
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());
}

View File

@@ -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);

View File

@@ -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.DistributionSet;
@@ -35,9 +34,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;
@@ -609,31 +605,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.
*
@@ -690,30 +661,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.
*

View File

@@ -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,45 @@ public final class SPDateTimeUtil {
* @param lastQueryDate
* @return String formatted date
*/
public static String getFormattedDate(final Long lastQueryDate) {
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;
}
return formatDate(baseEntity.getCreatedAt(), StringUtils.EMPTY);
}
/**
* Get formatted date 'last modified at' by entity.
*
* @param baseEntity
* the entity
* @return String formatted date
*/
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;
}
/**

View File

@@ -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 {