From 3accac9aded02c55ebc75bbec9caf7bebe5ec342 Mon Sep 17 00:00:00 2001 From: Dominic Schabel Date: Mon, 15 Aug 2016 11:30:21 +0200 Subject: [PATCH] Minor code improvements Signed-off-by: Dominic Schabel dominic.schabel@bosch-si.com --- .../simulator/DeviceSimulatorUpdater.java | 24 ++-- .../hawkbit/repository/FieldNameProvider.java | 89 ++++++-------- .../model/target/MgmtTargetAttributes.java | 3 +- .../event/AbstractPropertyChangeEvent.java | 17 ++- .../event/ActionPropertyChangeEvent.java | 3 +- .../RolloutGroupPropertyChangeEvent.java | 4 +- .../event/RolloutPropertyChangeEvent.java | 5 +- .../report/model/AbstractReportSeries.java | 7 -- .../report/model/ListReportSeries.java | 10 +- .../jpa/JpaDeploymentManagement.java | 19 +-- .../repository/jpa/JpaRolloutManagement.java | 2 +- .../jpa/JpaTargetFilterQueryManagement.java | 1 - .../ExceptionMappingAspectHandler.java | 11 +- .../model/EntityPropertyChangeListener.java | 23 ++-- .../repository/jpa/model/JpaActionStatus.java | 4 +- .../repository/jpa/model/JpaTarget.java | 4 +- .../repository/jpa/model/JpaTargetInfo.java | 4 +- .../repository/jpa/rsql/RSQLUtility.java | 24 ++-- .../util/RestResourceConversionHelper.java | 88 +++++++------- .../eclipse/hawkbit/security/DosFilter.java | 4 +- .../java/org/eclipse/hawkbit/util/IpUtil.java | 26 +++-- .../org/eclipse/hawkbit/util/IpUtilTest.java | 56 +++++---- .../smtable/SoftwareModuleTable.java | 25 ++-- ...dow.java => UploadConfirmationWindow.java} | 59 ++++------ .../ui/artifacts/upload/UploadLayout.java | 6 +- .../upload/UploadStatusInfoWindow.java | 79 ++++++------- .../hawkbit/ui/common/CoordinatesToColor.java | 29 ++--- .../DistributionSetMetadatadetailslayout.java | 110 +++++++++--------- .../filterlayout/AbstractFilterButtons.java | 36 +++--- .../ui/components/SPUIComponentProvider.java | 41 +++---- .../client/RolloutRendererConnector.java | 17 +-- .../client/renderers/RolloutRendererData.java | 66 +++++------ .../renderers/RolloutRenderer.java | 68 ++++++----- .../ui/decorators/SPUIWindowDecorator.java | 59 +++++----- .../disttype/DSTypeFilterButtons.java | 1 - .../smtable/SwMetadataPopupLayout.java | 44 +++---- .../smtype/DistSMTypeFilterButtons.java | 28 +++-- .../state/ManageDistUIState.java | 26 +++-- .../AbstractCreateUpdateTagLayout.java | 6 +- ...eateUpdateDistributionTagLayoutWindow.java | 8 +- .../dstag/DistributionTagButtons.java | 2 +- .../targettable/BulkUploadHandler.java | 26 ++--- .../targettag/TargetTagFilterButtons.java | 2 +- .../hawkbit/ui/menu/DashboardMenu.java | 54 +++++---- .../ui/rollout/DistributionBarHelper.java | 47 ++++---- .../rollout/AddUpdateRolloutWindowLayout.java | 14 +-- .../rolloutgroup/RolloutGroupListGrid.java | 24 ++-- .../AuthenticationConfigurationView.java | 8 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 12 +- .../hawkbit/ui/utils/SPUIDefinitions.java | 10 +- 50 files changed, 639 insertions(+), 696 deletions(-) rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/{UploadConfirmationwindow.java => UploadConfirmationWindow.java} (95%) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java index 9c4c43ad2..01a9231e3 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java @@ -8,9 +8,12 @@ */ package org.eclipse.hawkbit.simulator; +import static java.util.concurrent.Executors.newScheduledThreadPool; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.security.DigestOutputStream; import java.security.KeyManagementException; import java.security.KeyStoreException; @@ -20,7 +23,6 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; import java.util.Random; -import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -56,9 +58,10 @@ import com.google.common.io.ByteStreams; */ @Service public class DeviceSimulatorUpdater { + private static final Logger LOGGER = LoggerFactory.getLogger(DeviceSimulatorUpdater.class); - private static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(8); + private static final ScheduledExecutorService threadPool = newScheduledThreadPool(8); @Autowired private SpSenderService spSenderService; @@ -118,14 +121,9 @@ public class DeviceSimulatorUpdater { } private static final class DeviceSimulatorUpdateThread implements Runnable { - /** - * - */ + private static final String BUT_GOT_LOG_MESSAGE = " but got: "; - /** - * - */ private static final String DOWNLOAD_LOG_MESSAGE = "Download "; private static final int MINIMUM_TOKENLENGTH_FOR_HINT = 6; @@ -279,13 +277,17 @@ public class DeviceSimulatorUpdater { private static long getOverallRead(final CloseableHttpResponse response, final MessageDigest md) throws IOException { + long overallread; - try (final BufferedOutputStream bdos = new BufferedOutputStream( - new DigestOutputStream(ByteStreams.nullOutputStream(), md))) { + + try (final OutputStream os = ByteStreams.nullOutputStream(); + final BufferedOutputStream bos = new BufferedOutputStream(new DigestOutputStream(os, md))) { + try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) { - overallread = ByteStreams.copy(bis, bdos); + overallread = ByteStreams.copy(bis, bos); } } + return overallread; } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java index 574ce61e2..841f6d7e6 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java @@ -16,7 +16,6 @@ import java.util.Map; * An interface for declaring the name of the field described in the database * which is used as string representation of the field, e.g. for sorting the * fields over REST. - * */ public interface FieldNameProvider { /** @@ -32,64 +31,18 @@ public interface FieldNameProvider { /** * Contains the sub entity the given field. - * + * * @param propertyField * the given field * @return contains contains not */ default boolean containsSubEntityAttribute(final String propertyField) { - return FieldNameProvider.containsSubEntityAttribute(propertyField, getSubEntityAttributes()); - } - /** - * - * @return all sub entities attributes. - */ - default List getSubEntityAttributes() { - return Collections.emptyList(); - } - - /** - * the database column for the key - * - * @return key fieldname - */ - default String getKeyFieldName() { - return null; - } - - /** - * the database column for the value - * - * @return key fieldname - */ - default String getValueFieldName() { - return null; - } - - /** - * Is the entity field a {@link Map}. - * - * @return is a map is not a map - */ - default boolean isMap() { - return getKeyFieldName() != null; - } - - /** - * Check if a sub attribute exists. - * - * @param propertyField - * the sub property field. - * @param subEntityAttribues - * the list of available properties - * @return property exists not exists - */ - static boolean containsSubEntityAttribute(final String propertyField, final List subEntityAttribues) { - if (subEntityAttribues.contains(propertyField)) { + final List subEntityAttributes = getSubEntityAttributes(); + if (subEntityAttributes.contains(propertyField)) { return true; } - for (final String attribute : subEntityAttribues) { + for (final String attribute : subEntityAttributes) { final String[] graph = attribute.split("\\" + SUB_ATTRIBUTE_SEPERATOR); for (final String subAttribute : graph) { @@ -102,4 +55,38 @@ public interface FieldNameProvider { return false; } + /** + * + * @return all sub entities attributes. + */ + default List getSubEntityAttributes() { + return Collections.emptyList(); + } + + /** + * the database column for the key + * + * @return key fieldname + */ + default String getKeyFieldName() { + return null; + } + + /** + * the database column for the value + * + * @return key fieldname + */ + default String getValueFieldName() { + return null; + } + + /** + * Is the entity field a {@link Map}. + * + * @return is a map is not a map + */ + default boolean isMap() { + return getKeyFieldName() != null; + } } diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/target/MgmtTargetAttributes.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/target/MgmtTargetAttributes.java index dad8e868f..ea01b87ca 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/target/MgmtTargetAttributes.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/target/MgmtTargetAttributes.java @@ -8,8 +8,9 @@ import java.util.Map; /** * {@link Map} with attributes of SP Target. - * */ public class MgmtTargetAttributes extends HashMap { + private static final long serialVersionUID = 1L; + } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java index 97cf13b66..2520ebc9c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java @@ -20,18 +20,18 @@ import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; public class AbstractPropertyChangeEvent extends AbstractBaseEntityEvent { private static final long serialVersionUID = -3671601415138242311L; - private final transient Map changeSet; + private final transient Map changeSet; /** * Initialize base entity and property changed with old and new value. - * + * * @param baseEntity * entity changed * @param changeSetValues * details of properties changed and old value and new value of * the changed properties */ - public AbstractPropertyChangeEvent(final E baseEntity, final Map changeSetValues) { + public AbstractPropertyChangeEvent(final E baseEntity, final Map changeSetValues) { super(baseEntity); this.changeSet = changeSetValues; } @@ -39,27 +39,27 @@ public class AbstractPropertyChangeEvent extend /** * @return the changeSet */ - public Map getChangeSet() { + public Map getChangeSet() { return changeSet; } /** * Carries old value and new value of a property . - * */ - public class Values { + public static class PropertyChange { + private final Object oldValue; private final Object newValue; /** * Initialize old value and new changes value of property. - * + * * @param oldValue * old value before change * @param newValue * new value after change */ - public Values(final Object oldValue, final Object newValue) { + public PropertyChange(final Object oldValue, final Object newValue) { super(); this.oldValue = oldValue; this.newValue = newValue; @@ -78,6 +78,5 @@ public class AbstractPropertyChangeEvent extend public Object getNewValue() { return newValue; } - } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java index 84487547e..5197bd9a0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java @@ -22,8 +22,7 @@ public class ActionPropertyChangeEvent extends AbstractPropertyChangeEvent.Values> changeSetValues) { + public ActionPropertyChangeEvent(final Action action, final Map changeSetValues) { super(action, changeSetValues); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java index 887a1c2ff..b0b31b79a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java @@ -20,12 +20,12 @@ public class RolloutGroupPropertyChangeEvent extends AbstractPropertyChangeEvent private static final long serialVersionUID = 4026477044419472686L; /** - * + * * @param rolloutGroup * @param changeSetValues */ public RolloutGroupPropertyChangeEvent(final RolloutGroup rolloutGroup, - final Map.Values> changeSetValues) { + final Map changeSetValues) { super(rolloutGroup, changeSetValues); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java index 9287a0fb3..9bb975c3a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java @@ -19,12 +19,11 @@ public class RolloutPropertyChangeEvent extends AbstractPropertyChangeEvent.Values> changeSetValues) { + public RolloutPropertyChangeEvent(final Rollout rollout, final Map changeSetValues) { super(rollout, changeSetValues); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java index 747cd8279..9ba5ba2da 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java @@ -12,16 +12,9 @@ import java.io.Serializable; /** * An abstract report series. - * - * - * - * */ public class AbstractReportSeries implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private final String name; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java index 18b011420..27f5fb3ec 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java @@ -14,13 +14,11 @@ import java.util.List; /** * A simple list report series which just contains a list of values of a report. - * - * - * - * */ public class ListReportSeries extends AbstractReportSeries { + private static final long serialVersionUID = 1L; + private final List data = new ArrayList<>(); /** @@ -50,8 +48,8 @@ public class ListReportSeries extends AbstractReportSeries { * @param values */ private void setData(final Number... values) { - this.data.clear(); - Collections.addAll(this.data, values); + data.clear(); + Collections.addAll(data, values); } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 6236e8d6f..5a2c6fdda 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -82,7 +82,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -599,11 +598,16 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Override public Page findActionsByTarget(final String rsqlParam, final Target target, final Pageable pageable) { - final Specification specification = RSQLUtility.parse(rsqlParam, ActionFields.class); - return convertAcPage(actionRepository.findAll((Specification) (root, query, cb) -> cb - .and(specification.toPredicate(root, query, cb), cb.equal(root.get(JpaAction_.target), target)), - pageable), pageable); + final Specification byTargetSpec = createSpecificationFor(target, rsqlParam); + final Page actions = actionRepository.findAll(byTargetSpec, pageable); + return convertAcPage(actions, pageable); + } + + private Specification createSpecificationFor(final Target target, final String rsqlParam) { + final Specification spec = RSQLUtility.parse(rsqlParam, ActionFields.class); + return (root, query, cb) -> cb.and(spec.toPredicate(root, query, cb), + cb.equal(root.get(JpaAction_.target), target)); } private static Page convertAcPage(final Page findAll, final Pageable pageable) { @@ -642,10 +646,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Override public Long countActionsByTarget(final String rsqlParam, final Target target) { - final Specification spec = RSQLUtility.parse(rsqlParam, ActionFields.class); - - return actionRepository.count((root, query, cb) -> cb.and(spec.toPredicate(root, query, cb), - cb.equal(root.get(JpaAction_.target), target))); + return actionRepository.count(createSpecificationFor(target, rsqlParam)); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 239302a70..3a903ea89 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -599,7 +599,7 @@ public class JpaRolloutManagement implements RolloutManagement { /** * Get count of targets in different status in rollout. * - * @param page + * @param pageable * the page request to sort and limit the result * @return a list of rollouts with details of targets count for different * statuses diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 65ed6faa4..6438e19f6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -26,7 +26,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specifications; import org.springframework.data.jpa.repository.Modifying; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index be21cdfe7..c18f614fd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -46,6 +46,7 @@ import org.springframework.transaction.TransactionSystemException; */ @Aspect public class ExceptionMappingAspectHandler implements Ordered { + private static final Logger LOG = LoggerFactory.getLogger(ExceptionMappingAspectHandler.class); private static final Map EXCEPTION_MAPPING = new HashMap<>(); @@ -63,6 +64,7 @@ public class ExceptionMappingAspectHandler implements Ordered { private final SQLStateSQLExceptionTranslator sqlStateExceptionTranslator = new SQLStateSQLExceptionTranslator(); static { + MAPPED_EXCEPTION_ORDER.add(DuplicateKeyException.class); MAPPED_EXCEPTION_ORDER.add(DataIntegrityViolationException.class); MAPPED_EXCEPTION_ORDER.add(ConcurrencyFailureException.class); @@ -90,9 +92,11 @@ public class ExceptionMappingAspectHandler implements Ordered { + " || execution( * org.eclipse.hawkbit.controller.*.*(..)) " + " || execution( * org.eclipse.hawkbit.rest.resource.*.*(..)) " + " || execution( * org.eclipse.hawkbit.service.*.*(..)) )", throwing = "ex") - // Exception squid:S00112 - Is aspectJ proxy - @SuppressWarnings({ "squid:S00112" }) + // Exception for squid:S00112, squid:S1162 + // It is a AspectJ proxy which deals with exceptions. + @SuppressWarnings({ "squid:S00112", "squid:S1162" }) public void catchAndWrapJpaExceptionsService(final Exception ex) throws Throwable { + LOG.trace("exception occured", ex); Exception translatedAccessException = translateEclipseLinkExceptionIfPossible(ex); @@ -122,6 +126,7 @@ public class ExceptionMappingAspectHandler implements Ordered { break; } } + LOG.trace("mapped exception {} to {}", translatedAccessException.getClass(), mappingException.getClass()); throw mappingException; } @@ -138,7 +143,7 @@ public class ExceptionMappingAspectHandler implements Ordered { * translate the exception by the sql error code. Luckily, there we can use * {@link SQLStateSQLExceptionTranslator} if we can get a * {@link SQLException}. - * + * * @param accessException * the base access exception from jpa * @return the translated accessException diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java index 2dd0fdb40..6b1385440 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.model; import java.util.Map; import java.util.stream.Collectors; -import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent.PropertyChange; import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; @@ -33,7 +33,6 @@ import com.google.common.eventbus.EventBus; /** * Listens to change in property values of an entity. - * */ public class EntityPropertyChangeListener extends DescriptorEventAdapter { @@ -53,27 +52,23 @@ public class EntityPropertyChangeListener extends DescriptorEventAdapter { @Override public void postUpdate(final DescriptorEvent event) { if (event.getObject().getClass().equals(JpaAction.class)) { - getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post( - new ActionPropertyChangeEvent((Action) event.getObject(), getChangeSet(Action.class, event)))); + getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus() + .post(new ActionPropertyChangeEvent((Action) event.getObject(), getChangeSet(event)))); } else if (event.getObject().getClass().equals(JpaRollout.class)) { - getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post( - new RolloutPropertyChangeEvent((Rollout) event.getObject(), getChangeSet(Rollout.class, event)))); + getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus() + .post(new RolloutPropertyChangeEvent((Rollout) event.getObject(), getChangeSet(event)))); } else if (event.getObject().getClass().equals(JpaRolloutGroup.class)) { - getAfterTransactionCommmitExecutor().afterCommit( - () -> getEventBus().post(new RolloutGroupPropertyChangeEvent((RolloutGroup) event.getObject(), - getChangeSet(RolloutGroup.class, event)))); + getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus() + .post(new RolloutGroupPropertyChangeEvent((RolloutGroup) event.getObject(), getChangeSet(event)))); } } - private Map.Values> getChangeSet( - final Class clazz, final DescriptorEvent event) { - final T rolloutGroup = clazz.cast(event.getObject()); + private Map getChangeSet(final DescriptorEvent event) { final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery()).getObjectChangeSet(); return changeSet.getChanges().stream().filter(record -> record instanceof DirectToFieldChangeRecord) .map(record -> (DirectToFieldChangeRecord) record) .collect(Collectors.toMap(record -> record.getAttribute(), - record -> new AbstractPropertyChangeEvent(rolloutGroup, null).new Values( - record.getOldValue(), record.getNewValue()))); + record -> new PropertyChange(record.getOldValue(), record.getNewValue()))); } private AfterTransactionCommitExecutor getAfterTransactionCommmitExecutor() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java index 3a8cb8683..e1843eb33 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -98,8 +98,8 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements * the status for this action status * @param occurredAt * the occurred timestamp - * @param messages - * the messages which should be added to this action status + * @param message + * the message which should be added to this action status */ public JpaActionStatus(final JpaAction action, final Status status, final Long occurredAt, final String message) { this.action = action; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index 183405470..233e89664 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -65,6 +65,7 @@ import org.springframework.data.domain.Persistable; // sub entities @SuppressWarnings("squid:S2160") public class JpaTarget extends AbstractJpaNamedEntity implements Persistable, Target { + private static final long serialVersionUID = 1L; @Column(name = "controller_id", length = 64) @@ -180,7 +181,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable, TargetInfo { private boolean requestControllerAttributes = true; /** - * Constructor for {@link TargetStatus}. + * Constructor for {@link JpaTargetInfo}. * * @param target * related to this status. @@ -144,7 +144,7 @@ public class JpaTargetInfo implements Persistable, TargetInfo { } /** - * @param isNew + * @param entityNew * the isNew to set */ public void setNew(final boolean entityNew) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java index 91e03342e..90dd039f5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.repository.jpa.rsql; +import static org.eclipse.hawkbit.repository.FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -15,7 +17,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Expression; @@ -49,7 +50,7 @@ import cz.jirutka.rsql.parser.ast.RSQLVisitor; * A utility class which is able to parse RSQL strings into an spring data * {@link Specification} which then can be enhanced sql queries to filter * entities. RSQL parser library: https://github.com/jirutka/rsql-parser - * + * *
    *
  • Equal to : ==
  • *
  • Not equal to : !=
  • @@ -83,14 +84,12 @@ public final class RSQLUtility { /** * parses an RSQL valid string into an JPA {@link Specification} which then * can be used to filter for JPA entities with the given RSQL query. - * + * * @param rsql * the rsql query * @param fieldNameProvider * the enum class type which implements the * {@link FieldNameProvider} - * @param entityManager - * {@link EntityManager} * @return an specification which can be used with JPA * @throws RSQLParameterUnsupportedFieldException * if a field in the RSQL string is used but not provided by the @@ -105,10 +104,10 @@ public final class RSQLUtility { /** * Validate the given rsql string regarding existence and correct syntax. - * + * * @param rsql * the rsql string to get validated - * + * */ public static void isValid(final String rsql) { parseRsql(rsql); @@ -156,7 +155,7 @@ public final class RSQLUtility { /** * An implementation of the {@link RSQLVisitor} to visit the parsed tokens * and build jpa where clauses. - * + * * * * @param @@ -205,7 +204,7 @@ public final class RSQLUtility { } private String getAndValidatePropertyFieldName(final A propertyEnum, final ComparisonNode node) { - String finalProperty = propertyEnum.getFieldName(); + final String[] graph = node.getSelector().split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR); validateMapParamter(propertyEnum, node, graph); @@ -215,9 +214,12 @@ public final class RSQLUtility { throw createRSQLParameterUnsupportedException(node); } + final StringBuilder fieldNameBuilder = new StringBuilder(propertyEnum.getFieldName()); + for (int i = 1; i < graph.length; i++) { + final String propertyField = graph[i]; - finalProperty += FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR + propertyField; + fieldNameBuilder.append(SUB_ATTRIBUTE_SEPERATOR).append(propertyField); // the key of map is not in the graph if (propertyEnum.isMap() && graph.length == (i + 1)) { @@ -229,7 +231,7 @@ public final class RSQLUtility { } } - return finalProperty; + return fieldNameBuilder.toString(); } private void validateMapParamter(final A propertyEnum, final ComparisonNode node, final String[] graph) { diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java index 0c9dd39c5..7e2fbed7c 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java @@ -9,11 +9,24 @@ package org.eclipse.hawkbit.rest.util; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.net.HttpHeaders.ACCEPT_RANGES; +import static com.google.common.net.HttpHeaders.CONTENT_DISPOSITION; +import static com.google.common.net.HttpHeaders.CONTENT_LENGTH; +import static com.google.common.net.HttpHeaders.CONTENT_RANGE; +import static com.google.common.net.HttpHeaders.ETAG; +import static com.google.common.net.HttpHeaders.IF_RANGE; +import static com.google.common.net.HttpHeaders.LAST_MODIFIED; +import static java.math.RoundingMode.DOWN; +import static javax.servlet.http.HttpServletResponse.SC_PARTIAL_CONTENT; +import static org.eclipse.hawkbit.rest.util.ByteRange.MULTIPART_BOUNDARY; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.PARTIAL_CONTENT; +import static org.springframework.http.HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE; +import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.math.RoundingMode; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,23 +40,19 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import com.google.common.math.DoubleMath; -import com.google.common.net.HttpHeaders; /** * Utility class for the Rest Source API. - * */ public final class RestResourceConversionHelper { + private static final Logger LOG = LoggerFactory.getLogger(RestResourceConversionHelper.class); private static final int BUFFER_SIZE = 4096; - // utility class, private constructor. private RestResourceConversionHelper() { } @@ -92,7 +101,8 @@ public final class RestResourceConversionHelper { * * @return http code * - * @see https://tools.ietf.org/html/rfc7233 + * @see https://tools.ietf.org + * /html/rfc7233 */ public static ResponseEntity writeFileResponse(final LocalArtifact artifact, final HttpServletResponse response, final HttpServletRequest request, final DbArtifact file, @@ -107,11 +117,11 @@ public final class RestResourceConversionHelper { response.reset(); response.setBufferSize(BUFFER_SIZE); - response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFilename()); - response.setHeader(HttpHeaders.ETAG, etag); - response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); - response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified); - response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + response.setHeader(CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFilename()); + response.setHeader(ETAG, etag); + response.setHeader(ACCEPT_RANGES, "bytes"); + response.setDateHeader(LAST_MODIFIED, lastModified); + response.setContentType(APPLICATION_OCTET_STREAM_VALUE); final ByteRange full = new ByteRange(0, length - 1, length); final List ranges = new ArrayList<>(); @@ -123,9 +133,9 @@ public final class RestResourceConversionHelper { // Range header matches"bytes=n-n,n-n,n-n..." if (!range.matches("^bytes=\\d*-\\d*(,\\d*-\\d*)*$")) { - response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes */" + length); + response.setHeader(CONTENT_RANGE, "bytes */" + length); LOG.debug("range header for filename ({}) is not satisfiable: ", artifact.getFilename()); - return new ResponseEntity<>(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE); + return new ResponseEntity<>(REQUESTED_RANGE_NOT_SATISFIABLE); } // RFC: if the representation is unchanged, send me the part(s) that @@ -144,32 +154,31 @@ public final class RestResourceConversionHelper { // full request - no range if (ranges.isEmpty() || ranges.get(0).equals(full)) { LOG.debug("filename ({}) results into a full request: ", artifact.getFilename()); - fullfileRequest(artifact, response, file, controllerManagement, statusId, full); - result = new ResponseEntity<>(HttpStatus.OK); + handleFullFileRequest(artifact, response, file, controllerManagement, statusId, full); + result = new ResponseEntity<>(OK); } // standard range request else if (ranges.size() == 1) { LOG.debug("filename ({}) results into a standard range request: ", artifact.getFilename()); - standardRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); - result = new ResponseEntity<>(HttpStatus.PARTIAL_CONTENT); + handleStandardRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); + result = new ResponseEntity<>(PARTIAL_CONTENT); } // multipart range request else { LOG.debug("filename ({}) results into a multipart range request: ", artifact.getFilename()); - multipartRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); - result = new ResponseEntity<>(HttpStatus.PARTIAL_CONTENT); + handleMultipartRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); + result = new ResponseEntity<>(PARTIAL_CONTENT); } return result; - } - private static void fullfileRequest(final LocalArtifact artifact, final HttpServletResponse response, + private static void handleFullFileRequest(final LocalArtifact artifact, final HttpServletResponse response, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final ByteRange full) { final ByteRange r = full; - response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); - response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(r.getLength())); + response.setHeader(CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); + response.setHeader(CONTENT_LENGTH, String.valueOf(r.getLength())); try { copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, @@ -182,7 +191,7 @@ public final class RestResourceConversionHelper { private static ResponseEntity extractRange(final HttpServletResponse response, final long length, final List ranges, final String range) { - ResponseEntity result = null; + if (ranges.isEmpty()) { for (final String part : range.substring(6).split(",")) { long start = sublong(part, 0, part.indexOf('-')); @@ -198,9 +207,8 @@ public final class RestResourceConversionHelper { // Check if Range is syntactically valid. If not, then return // 416. if (start > end) { - response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes */" + length); - result = new ResponseEntity<>(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE); - return result; + response.setHeader(CONTENT_RANGE, "bytes */" + length); + return new ResponseEntity<>(REQUESTED_RANGE_NOT_SATISFIABLE); } // Add range. @@ -218,10 +226,10 @@ public final class RestResourceConversionHelper { private static void checkForShortcut(final HttpServletRequest request, final String etag, final long lastModified, final ByteRange full, final List ranges) { - final String ifRange = request.getHeader(HttpHeaders.IF_RANGE); + final String ifRange = request.getHeader(IF_RANGE); if (ifRange != null && !ifRange.equals(etag)) { try { - final long ifRangeTime = request.getDateHeader(HttpHeaders.IF_RANGE); + final long ifRangeTime = request.getDateHeader(IF_RANGE); if (ifRangeTime != -1 && ifRangeTime + 1000 < lastModified) { ranges.add(full); } @@ -232,17 +240,17 @@ public final class RestResourceConversionHelper { } } - private static void multipartRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, + private static void handleMultipartRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { - response.setContentType("multipart/byteranges; boundary=" + ByteRange.MULTIPART_BOUNDARY); - response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); + response.setContentType("multipart/byteranges; boundary=" + MULTIPART_BOUNDARY); + response.setStatus(SC_PARTIAL_CONTENT); try { for (final ByteRange r : ranges) { // Add multipart boundary and header fields for every range. response.getOutputStream().println(); - response.getOutputStream().println("--" + ByteRange.MULTIPART_BOUNDARY); + response.getOutputStream().println("--" + MULTIPART_BOUNDARY); response.getOutputStream() .println("Content-Range: bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); @@ -253,20 +261,20 @@ public final class RestResourceConversionHelper { // End with final multipart boundary. response.getOutputStream().println(); - response.getOutputStream().print("--" + ByteRange.MULTIPART_BOUNDARY + "--"); + response.getOutputStream().print("--" + MULTIPART_BOUNDARY + "--"); } catch (final IOException e) { LOG.error("multipartRangeRequest of file ({}) failed!", artifact.getFilename(), e); throw new FileSteamingFailedException(artifact.getFilename()); } } - private static void standardRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, + private static void handleStandardRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { final ByteRange r = ranges.get(0); - response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); - response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(r.getLength())); - response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); + response.setHeader(CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); + response.setHeader(CONTENT_LENGTH, String.valueOf(r.getLength())); + response.setStatus(SC_PARTIAL_CONTENT); try { copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, @@ -315,7 +323,7 @@ public final class RestResourceConversionHelper { } if (controllerManagement != null) { - final int newPercent = DoubleMath.roundToInt(total * 100.0 / length, RoundingMode.DOWN); + final int newPercent = DoubleMath.roundToInt(total * 100.0 / length, DOWN); // every 10 percent an event if (newPercent == 100 || newPercent > progressPercent + 10) { diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/DosFilter.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/DosFilter.java index 008aa3e95..89d0f4387 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/DosFilter.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/DosFilter.java @@ -100,7 +100,8 @@ public class DosFilter extends OncePerRequestFilter { boolean processChain; - final String ip = IpUtil.getClientIpFromRequest(request, forwardHeader, true).getHost(); + final String ip = IpUtil.getClientIpFromRequest(request, forwardHeader).getHost(); + if (checkIpFails(ip)) { processChain = handleMissingIpAddress(response); } else { @@ -121,7 +122,6 @@ public class DosFilter extends OncePerRequestFilter { if (processChain) { filterChain.doFilter(request, response); } - } /** diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/util/IpUtil.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/util/IpUtil.java index c7778f776..30306526a 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/util/IpUtil.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/util/IpUtil.java @@ -44,7 +44,7 @@ public final class IpUtil { * {@link HttpServletRequest} by either the * {@link HttpHeaders#X_FORWARDED_FOR} or by the * {@link HttpServletRequest#getRemoteAddr()} methods. - * + * * @param request * the {@link HttpServletRequest} to determine the IP address * where this request has been sent from @@ -65,21 +65,23 @@ public final class IpUtil { * {@link HttpServletRequest} by either the * {@link HttpHeaders#X_FORWARDED_FOR} or by the * {@link HttpServletRequest#getRemoteAddr()} methods. - * + * * @param request * the {@link HttpServletRequest} to determine the IP address * where this request has been sent from * @param forwardHeader * the header name containing the IP address e.g. forwarded by a * proxy {@code x-forwarded-for} - * - * @param trackRemoteIp - * to true if remote IP should be tracked. * @return the {@link URI} based IP address from the client which sent the * request */ - public static URI getClientIpFromRequest(final HttpServletRequest request, final String forwardHeader, + public static URI getClientIpFromRequest(final HttpServletRequest request, final String forwardHeader) { + return getClientIpFromRequest(request, forwardHeader, true); + } + + private static URI getClientIpFromRequest(final HttpServletRequest request, final String forwardHeader, final boolean trackRemoteIp) { + String ip; if (trackRemoteIp) { @@ -113,7 +115,7 @@ public final class IpUtil { /** * Create a {@link URI} with scheme and host. - * + * * @param scheme * the scheme * @param host @@ -132,7 +134,7 @@ public final class IpUtil { /** * Create a {@link URI} with amqp scheme and host. - * + * * @param host * the host * @param exchange @@ -147,7 +149,7 @@ public final class IpUtil { /** * Create a {@link URI} with http scheme and host. - * + * * @param host * the host * @return the {@link URI} @@ -160,7 +162,7 @@ public final class IpUtil { /** * Check if scheme contains http and uri ist not null. - * + * * @param uri * the uri * @return true = is http host false = not @@ -171,7 +173,7 @@ public final class IpUtil { /** * Check if host scheme amqp and uri ist not null. - * + * * @param uri * the uri * @return true = is http host false = not @@ -183,7 +185,7 @@ public final class IpUtil { /** * Check if the IP address of that {@link URI} is known, i.e. not an AQMP * exchange in DMF case and not HIDDEN_IP in DDI case. - * + * * @param uri * the uri * @return true if IP address is actually known by the server diff --git a/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java b/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java index 0f4a01d26..836a9f13e 100644 --- a/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java +++ b/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.util; +import static com.google.common.net.HttpHeaders.X_FORWARDED_FOR; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -21,13 +22,13 @@ import java.net.URI; import javax.servlet.http.HttpServletRequest; +import org.eclipse.hawkbit.security.HawkbitSecurityProperties; +import org.eclipse.hawkbit.security.HawkbitSecurityProperties.Clients; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import com.google.common.net.HttpHeaders; - import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; @@ -37,69 +38,73 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("IP Util Test") public class IpUtilTest { + private static final String KNOWN_REQUEST_HEADER = "bumlux"; + @Mock private HttpServletRequest requestMock; + @Mock + private Clients clientMock; + + @Mock + private HawkbitSecurityProperties securityPropertyMock; + @Test @Description("Tests create uri from request") public void getRemoteAddrFromRequestIfForwaredHeaderNotPresent() { - // known values + final URI knownRemoteClientIP = IpUtil.createHttpUri("127.0.0.1"); - // mock - when(requestMock.getHeader(HttpHeaders.X_FORWARDED_FOR)).thenReturn(null); + when(requestMock.getHeader(X_FORWARDED_FOR)).thenReturn(null); when(requestMock.getRemoteAddr()).thenReturn(knownRemoteClientIP.getHost()); - // test - final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "bumlux", true); + final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, KNOWN_REQUEST_HEADER); // verify assertThat(remoteAddr).as("The remote address should be as the known client IP address") .isEqualTo(knownRemoteClientIP); - verify(requestMock, times(1)).getHeader("bumlux"); + verify(requestMock, times(1)).getHeader(KNOWN_REQUEST_HEADER); verify(requestMock, times(1)).getRemoteAddr(); } @Test @Description("Tests create uri from request with masked IP when IP tracking is disabled") public void maskRemoteAddrIfDisabled() { - // known values + final URI knownRemoteClientIP = IpUtil.createHttpUri("***"); - // mock - when(requestMock.getHeader(HttpHeaders.X_FORWARDED_FOR)).thenReturn(null); + when(requestMock.getHeader(X_FORWARDED_FOR)).thenReturn(null); when(requestMock.getRemoteAddr()).thenReturn(knownRemoteClientIP.getHost()); + when(securityPropertyMock.getClients()).thenReturn(clientMock); + when(clientMock.getRemoteIpHeader()).thenReturn(KNOWN_REQUEST_HEADER); + when(clientMock.isTrackRemoteIp()).thenReturn(false); - // test - final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "bumlux", false); + final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, securityPropertyMock); - // verify assertThat(remoteAddr).as("The remote address should be as the known client IP address") .isEqualTo(knownRemoteClientIP); - verify(requestMock, times(0)).getHeader("bumlux"); + verify(requestMock, times(0)).getHeader(KNOWN_REQUEST_HEADER); verify(requestMock, times(0)).getRemoteAddr(); } @Test @Description("Tests create uri from x forward header") public void getRemoteAddrFromXForwardedForHeader() { - // known values + final URI knownRemoteClientIP = IpUtil.createHttpUri("10.99.99.1"); - // mock - when(requestMock.getHeader(HttpHeaders.X_FORWARDED_FOR)).thenReturn(knownRemoteClientIP.getHost()); + when(requestMock.getHeader(X_FORWARDED_FOR)).thenReturn(knownRemoteClientIP.getHost()); when(requestMock.getRemoteAddr()).thenReturn(null); - // test - final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "X-Forwarded-For", true); + final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "X-Forwarded-For"); - // verify assertThat(remoteAddr).as("The remote address should be as the known client IP address") .isEqualTo(knownRemoteClientIP); - verify(requestMock, times(1)).getHeader(HttpHeaders.X_FORWARDED_FOR); + verify(requestMock, times(1)).getHeader(X_FORWARDED_FOR); verify(requestMock, times(0)).getRemoteAddr(); } @Test @Description("Tests create http uri ipv4 and ipv6") public void testCreateHttpUri() { + final String ipv4 = "10.99.99.1"; URI httpUri = IpUtil.createHttpUri(ipv4); assertHttpUri(ipv4, httpUri); @@ -111,7 +116,6 @@ public class IpUtilTest { final String ipv6 = "0:0:0:0:0:0:0:1"; httpUri = IpUtil.createHttpUri(ipv6); assertHttpUri("[" + ipv6 + "]", httpUri); - } private void assertHttpUri(final String host, final URI httpUri) { @@ -124,6 +128,7 @@ public class IpUtilTest { @Test @Description("Tests create amqp uri ipv4 and ipv6") public void testCreateAmqpUri() { + final String ipv4 = "10.99.99.1"; URI amqpUri = IpUtil.createAmqpUri(ipv4, "path"); assertAmqpUri(ipv4, amqpUri); @@ -138,6 +143,7 @@ public class IpUtilTest { } private void assertAmqpUri(final String host, final URI amqpUri) { + assertTrue("The given URI is an AMQP scheme", IpUtil.isAmqpUri(amqpUri)); assertFalse("The given URI is not an HTTP scheme", IpUtil.isHttpUri(amqpUri)); assertEquals("The given host matches the URI host", host, amqpUri.getHost()); @@ -148,17 +154,19 @@ public class IpUtilTest { @Test @Description("Tests create invalid uri") public void testCreateInvalidUri() { + final String host = "10.99.99.1"; final URI testUri = IpUtil.createUri("test", host); + assertFalse("The given URI is not an AMQP address", IpUtil.isAmqpUri(testUri)); assertFalse("The given URI is not an HTTP address", IpUtil.isHttpUri(testUri)); assertEquals("The given host matches the URI host", host, testUri.getHost()); + try { IpUtil.createUri(":/", host); fail("Missing expected IllegalArgumentException due invalid URI"); } catch (final IllegalArgumentException e) { // expected } - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 1cfd28718..8ce3b8519 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -52,8 +52,8 @@ import com.vaadin.ui.UI; /** * Header of Software module table. */ -@SpringComponent @ViewScope +@SpringComponent public class SoftwareModuleTable extends AbstractNamedVersionTable { private static final long serialVersionUID = 6469417305487144809L; @@ -66,7 +66,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable refreshFilter()); + UI.getCurrent().access(this::refreshFilter); } } @@ -197,12 +197,12 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable showMetadataDetails((Long) itemId, nameVersionStr)); + manageMetaDataBtn.addClickListener(event -> showMetadataDetails((Long) itemId)); return manageMetaDataBtn; } }); } - + @Override protected List getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); @@ -237,8 +237,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable updateProgress(event.getUploadStatus().getFileName(), event.getUploadStatus().getBytesRead(), - event.getUploadStatus().getContentLength(), event.getUploadStatus().getSoftwareModule())); + UI.getCurrent() + .access(() -> updateProgress(event.getUploadStatus().getFileName(), + event.getUploadStatus().getBytesRead(), event.getUploadStatus().getContentLength(), + event.getUploadStatus().getSoftwareModule())); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { UI.getCurrent().access(() -> onStartOfUpload(event)); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { - ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getFailureReason(), event.getUploadStatus().getSoftwareModule())); + ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), + event.getUploadStatus().getFailureReason(), event.getUploadStatus().getSoftwareModule())); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) { - UI.getCurrent().access( - () -> uploadSucceeded(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getSoftwareModule())); + UI.getCurrent().access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), + event.getUploadStatus().getSoftwareModule())); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { - ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getSoftwareModule())); + ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), + event.getUploadStatus().getSoftwareModule())); } } - private void onStartOfUpload(UploadStatusEvent event) { + private void onStartOfUpload(final UploadStatusEvent event) { uploadSessionStarted(); uploadStarted(event.getUploadStatus().getFileName(), event.getUploadStatus().getSoftwareModule()); } @@ -169,19 +169,19 @@ public class UploadStatusInfoWindow extends Window { } private void restoreState() { - Indexed container = grid.getContainerDataSource(); + final Indexed container = grid.getContainerDataSource(); if (container.getItemIds().isEmpty()) { container.removeAllItems(); - for (UploadStatusObject statusObject : artifactUploadState.getUploadedFileStatusList()) { - Item item = container.addItem(getItemid(statusObject.getFilename(), - statusObject.getSelectedSoftwareModule())); + for (final UploadStatusObject statusObject : artifactUploadState.getUploadedFileStatusList()) { + final Item item = container + .addItem(getItemid(statusObject.getFilename(), statusObject.getSelectedSoftwareModule())); item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : ""); item.getItemProperty(STATUS).setValue(statusObject.getStatus()); item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); - SoftwareModule sw = statusObject.getSelectedSoftwareModule(); - item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue( - HawkbitCommonUtil.getFormattedNameVersion(sw.getName(), sw.getVersion())); + final SoftwareModule sw = statusObject.getSelectedSoftwareModule(); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION) + .setValue(HawkbitCommonUtil.getFormattedNameVersion(sw.getName(), sw.getVersion())); } if (artifactUploadState.isUploadCompleted()) { minimizeButton.setEnabled(false); @@ -209,7 +209,7 @@ public class UploadStatusInfoWindow extends Window { } private Grid createGrid() { - Grid statusGrid = new Grid(uploads); + final Grid statusGrid = new Grid(uploads); statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID); statusGrid.setSelectionMode(SelectionMode.NONE); statusGrid.setHeaderVisible(true); @@ -219,7 +219,7 @@ public class UploadStatusInfoWindow extends Window { } private IndexedContainer getGridContainer() { - IndexedContainer uploadContainer = new IndexedContainer(); + final IndexedContainer uploadContainer = new IndexedContainer(); uploadContainer.addContainerProperty(STATUS, String.class, "Active"); uploadContainer.addContainerProperty(FILE_NAME, String.class, null); uploadContainer.addContainerProperty(PROGRESS, Double.class, 0D); @@ -329,7 +329,7 @@ public class UploadStatusInfoWindow extends Window { HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion())); } grid.scrollToEnd(); - UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule); + final UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule); uploadStatus.setStatus("Active"); artifactUploadState.getUploadedFileStatusList().add(uploadStatus); } @@ -337,56 +337,53 @@ public class UploadStatusInfoWindow extends Window { void updateProgress(final String filename, final long readBytes, final long contentLength, final SoftwareModule softwareModule) { final Item item = uploads.getItem(getItemid(filename, softwareModule)); - double progress = (double) readBytes / (double) contentLength; + final double progress = (double) readBytes / (double) contentLength; if (item != null) { item.getItemProperty(PROGRESS).setValue(progress); } - List uploadStatusObjectList = (List) artifactUploadState - .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) - .collect(Collectors.toList()); + final List uploadStatusObjectList = artifactUploadState.getUploadedFileStatusList().stream() + .filter(e -> e.getFilename().equals(filename)).collect(Collectors.toList()); if (!uploadStatusObjectList.isEmpty()) { - UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + final UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); uploadStatusObject.setProgress(progress); } } /** * Called when each file upload is success. - * + * * @param filename * of the uploaded file. * @param softwareModule * selected software module */ - public void uploadSucceeded(final String filename, SoftwareModule softwareModule) { + public void uploadSucceeded(final String filename, final SoftwareModule softwareModule) { final Item item = uploads.getItem(getItemid(filename, softwareModule)); - String status = "Finished"; + final String status = "Finished"; if (item != null) { item.getItemProperty(STATUS).setValue(status); } - List uploadStatusObjectList = (List) artifactUploadState - .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) - .collect(Collectors.toList()); + final List uploadStatusObjectList = artifactUploadState.getUploadedFileStatusList().stream() + .filter(e -> e.getFilename().equals(filename)).collect(Collectors.toList()); if (!uploadStatusObjectList.isEmpty()) { - UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + final UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); uploadStatusObject.setStatus(status); uploadStatusObject.setProgress(1d); } } - void uploadFailed(final String filename, final String errorReason, SoftwareModule softwareModule) { + void uploadFailed(final String filename, final String errorReason, final SoftwareModule softwareModule) { errorOccured = true; - String status = "Failed"; + final String status = "Failed"; final Item item = uploads.getItem(getItemid(filename, softwareModule)); if (item != null) { item.getItemProperty(REASON).setValue(errorReason); item.getItemProperty(STATUS).setValue(status); } - List uploadStatusObjectList = (List) artifactUploadState - .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) - .collect(Collectors.toList()); + final List uploadStatusObjectList = artifactUploadState.getUploadedFileStatusList().stream() + .filter(e -> e.getFilename().equals(filename)).collect(Collectors.toList()); if (!uploadStatusObjectList.isEmpty()) { - UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + final UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); uploadStatusObject.setStatus(status); uploadStatusObject.setReason(errorReason); } @@ -428,8 +425,8 @@ public class UploadStatusInfoWindow extends Window { return resizeBtn; } - private void resizeWindow(ClickEvent event) { - if (event.getButton().getIcon() == FontAwesome.EXPAND) { + private void resizeWindow(final ClickEvent event) { + if (FontAwesome.EXPAND.equals(event.getButton().getIcon())) { event.getButton().setIcon(FontAwesome.COMPRESS); setWindowMode(WindowMode.MAXIMIZED); resetColumnWidth(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CoordinatesToColor.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CoordinatesToColor.java index d3b13adb3..09f88d655 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CoordinatesToColor.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CoordinatesToColor.java @@ -13,10 +13,6 @@ import com.vaadin.ui.AbstractColorPicker.Coordinates2Color; /** * Converts 2d-coordinates to a Color. - * - * - * - * */ public class CoordinatesToColor implements Coordinates2Color { @@ -30,32 +26,31 @@ public class CoordinatesToColor implements Coordinates2Color { @Override public int[] calculate(final Color color) { final float[] hsv = color.getHSV(); - final int x = Math.round(hsv[0] * 220f); - int y = 0; - y = calculateYCoordinateOfColor(hsv); + final int x = Math.round(hsv[0] * 220F); + final int y = calculateYCoordinateOfColor(hsv); return new int[] { x, y }; } - private Color calculateHSVColor(final int x, final int y) { - final float h = x / 220f; - float s = 1f; - float v = 1f; + private static Color calculateHSVColor(final int x, final int y) { + final float h = x / 220F; + float s = 1F; + float v = 1F; if (y < 110) { - s = y / 110f; + s = y / 110F; } else if (y > 110) { - v = 1f - (y - 110f) / 110f; + v = 1F - (y - 110F) / 110F; } return new Color(Color.HSVtoRGB(h, s, v)); } - private int calculateYCoordinateOfColor(final float[] hsv) { + private static int calculateYCoordinateOfColor(final float[] hsv) { int y; // lower half /* Assuming hsv[] array value will have in the range of 0 to 1 */ - if (hsv[1] < 1f) { - y = Math.round(hsv[1] * 110f); + if (hsv[1] < 1F) { + y = Math.round(hsv[1] * 110F); } else { - y = Math.round(110f - (hsv[1] + hsv[2]) * 110f); + y = Math.round(110F - (hsv[1] + hsv[2]) * 110F); } return y; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailslayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailslayout.java index d3892a9dc..04fd2c316 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailslayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailslayout.java @@ -33,45 +33,43 @@ import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; /** - * + * * DistributionSet Metadata details layout. * */ @SpringComponent @VaadinSessionScope -public class DistributionSetMetadatadetailslayout extends Table{ - +public class DistributionSetMetadatadetailslayout extends Table { + private static final long serialVersionUID = 2913758299611837718L; - - - private DistributionSetManagement distributionSetManagement; - - private DsMetadataPopupLayout dsMetadataPopupLayout; private static final String METADATA_KEY = "Key"; - - private static final String VIEW ="view"; + + private static final String VIEW = "view"; + + private transient DistributionSetManagement distributionSetManagement; + + private DsMetadataPopupLayout dsMetadataPopupLayout; private SpPermissionChecker permissionChecker; - + private transient EntityFactory entityFactory; private I18N i18n; - - private Long selectedDistSetId; - - /** - * - * @param i18n - * @param permissionChecker - * @param distributionSetManagement - * @param dsMetadataPopupLayout - */ + + private Long selectedDistSetId; + + /** + * + * @param i18n + * @param permissionChecker + * @param distributionSetManagement + * @param dsMetadataPopupLayout + */ public void init(final I18N i18n, final SpPermissionChecker permissionChecker, - final DistributionSetManagement distributionSetManagement, - final DsMetadataPopupLayout dsMetadataPopupLayout, - final EntityFactory entityFactory) { + final DistributionSetManagement distributionSetManagement, + final DsMetadataPopupLayout dsMetadataPopupLayout, final EntityFactory entityFactory) { this.i18n = i18n; this.permissionChecker = permissionChecker; this.distributionSetManagement = distributionSetManagement; @@ -80,45 +78,44 @@ public class DistributionSetMetadatadetailslayout extends Table{ createDSMetadataTable(); addCustomGeneratedColumns(); } - /** * Populate software module metadata. - * + * * @param distributionSet */ public void populateDSMetadata(final DistributionSet distributionSet) { removeAllItems(); if (null == distributionSet) { - return; + return; } selectedDistSetId = distributionSet.getId(); final List dsMetadataList = distributionSet.getMetadata(); if (null != dsMetadataList && !dsMetadataList.isEmpty()) { dsMetadataList.forEach(dsMetadata -> setDSMetadataProperties(dsMetadata)); } - + } - + /** - * Create metadata . - * + * Create metadata. + * * @param metadataKeyName */ - public void createMetadata(final String metadataKeyName){ + public void createMetadata(final String metadataKeyName) { final IndexedContainer metadataContainer = (IndexedContainer) getContainerDataSource(); final Item item = metadataContainer.addItem(metadataKeyName); item.getItemProperty(METADATA_KEY).setValue(metadataKeyName); } - + /** * Delete metadata. - * + * * @param metadataKeyName */ - public void deleteMetadata(final String metadataKeyName){ + public void deleteMetadata(final String metadataKeyName) { final IndexedContainer metadataContainer = (IndexedContainer) getContainerDataSource(); - metadataContainer.removeItem(metadataKeyName); + metadataContainer.removeItem(metadataKeyName); } private void createDSMetadataTable() { @@ -131,9 +128,9 @@ public class DistributionSetMetadatadetailslayout extends Table{ setContainerDataSource(getDistSetContainer()); setColumnHeaderMode(ColumnHeaderMode.EXPLICIT); addDSMetadataTableHeader(); - setSizeFull(); - //same as height of other tabs in details tabsheet - setHeight(116,Unit.PIXELS); + setSizeFull(); + // same as height of other tabs in details tabsheet + setHeight(116, Unit.PIXELS); } private IndexedContainer getDistSetContainer() { @@ -141,7 +138,7 @@ public class DistributionSetMetadatadetailslayout extends Table{ container.addContainerProperty(METADATA_KEY, String.class, ""); setColumnExpandRatio(METADATA_KEY, 0.7f); setColumnAlignment(METADATA_KEY, Align.LEFT); - + if (permissionChecker.hasUpdateDistributionPermission()) { container.addContainerProperty(VIEW, Label.class, ""); setColumnExpandRatio(VIEW, 0.2F); @@ -154,39 +151,36 @@ public class DistributionSetMetadatadetailslayout extends Table{ setColumnHeader(METADATA_KEY, i18n.get("header.key")); } - - private void setDSMetadataProperties(final DistributionSetMetadata dsMetadata){ + private void setDSMetadataProperties(final DistributionSetMetadata dsMetadata) { final Item item = getContainerDataSource().addItem(dsMetadata.getKey()); item.getItemProperty(METADATA_KEY).setValue(dsMetadata.getKey()); - + } - - private void addCustomGeneratedColumns() { - addGeneratedColumn(METADATA_KEY, - (source, itemId, columnId) -> customMetadataDetailButton((String) itemId)); + + private void addCustomGeneratedColumns() { + addGeneratedColumn(METADATA_KEY, (source, itemId, columnId) -> customMetadataDetailButton((String) itemId)); } private Button customMetadataDetailButton(final String metadataKey) { - final Button viewIcon = SPUIComponentProvider.getButton(getDetailLinkId(metadataKey), metadataKey, "View " - + metadataKey + " Metadata details", null, false, null, SPUIButtonStyleSmallNoBorder.class); + final Button viewIcon = SPUIComponentProvider.getButton(getDetailLinkId(metadataKey), metadataKey, + "View " + metadataKey + " Metadata details", null, false, null, SPUIButtonStyleSmallNoBorder.class); viewIcon.setData(metadataKey); viewIcon.addStyleName(ValoTheme.BUTTON_TINY + " " + ValoTheme.BUTTON_LINK + " " + "on-focus-no-border link" + " " + "text-style"); viewIcon.addClickListener(event -> showMetadataDetails(selectedDistSetId, metadataKey)); return viewIcon; } - + private static String getDetailLinkId(final String name) { - return new StringBuilder(SPUIComponentIdProvider.DS_METADATA_DETAIL_LINK).append('.').append(name) - .toString(); + return new StringBuilder(SPUIComponentIdProvider.DS_METADATA_DETAIL_LINK).append('.').append(name).toString(); } - - private void showMetadataDetails(final Long selectedDistSetId , final String metadataKey) { - DistributionSet distSet = distributionSetManagement.findDistributionSetById(selectedDistSetId); - + + private void showMetadataDetails(final Long selectedDistSetId, final String metadataKey) { + final DistributionSet distSet = distributionSetManagement.findDistributionSetById(selectedDistSetId); + /* display the window */ UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(distSet, - entityFactory.generateDistributionSetMetadata(distSet, metadataKey, "") )); + entityFactory.generateDistributionSetMetadata(distSet, metadataKey, ""))); } - + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java index aec0029d0..621bf3b8f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.ui.common.filterlayout; +import static org.eclipse.hawkbit.ui.utils.SPUIDefinitions.NO_TAG_BUTTON_ID; + import java.util.ArrayList; import java.util.List; @@ -50,7 +52,7 @@ public abstract class AbstractFilterButtons extends Table { /** * Initialize layout of filter buttons. - * + * * @param filterButtonClickBehaviour * click behaviour of filter buttons. */ @@ -95,16 +97,12 @@ public abstract class AbstractFilterButtons extends Table { container.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, null, true, true); } - @SuppressWarnings("serial") protected void addColumn() { addGeneratedColumn(FILTER_BUTTON_COLUMN, (source, itemId, columnId) -> addGeneratedCell(itemId)); } - /** - * @param itemId - * @return - */ private DragAndDropWrapper addGeneratedCell(final Object itemId) { + final Item item = getItem(itemId); final Long id = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_ID).getValue(); final String name = (String) item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); @@ -116,16 +114,18 @@ public abstract class AbstractFilterButtons extends Table { ? item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue().toString() : DEFAULT_GREEN; final Button typeButton = createFilterButton(id, name, desc, color, itemId); typeButton.addClickListener(event -> filterButtonClickBehaviour.processFilterButtonClick(event)); - if (typeButton.getData().equals(SPUIDefinitions.NO_TAG_BUTTON_ID) && isNoTagSateSelected()) { - filterButtonClickBehaviour.setDefaultClickedButton(typeButton); - } else if (id != null && isClickedByDefault(name)) { + + if ((NO_TAG_BUTTON_ID.equals(typeButton.getData()) && isNoTagStateSelected()) + || (id != null && isClickedByDefault(name))) { + filterButtonClickBehaviour.setDefaultClickedButton(typeButton); } + return createDragAndDropWrapper(typeButton, name, id); } - protected boolean isNoTagSateSelected() { - return Boolean.FALSE; + protected boolean isNoTagStateSelected() { + return false; } private DragAndDropWrapper createDragAndDropWrapper(final Button tagButton, final String name, final Long id) { @@ -195,21 +195,21 @@ public abstract class AbstractFilterButtons extends Table { /** * Id of the buttons table to be used in test cases. - * + * * @return Id of the Button table. */ protected abstract String getButtonsTableId(); /** * create new lazyquery container to display the buttons. - * + * * @return reference of {@link LazyQueryContainer} */ protected abstract LazyQueryContainer createButtonsLazyQueryContainer(); /** * Check if button should be displayed as clicked by default. - * + * * @param buttonCaption * button caption * @return true if button is clicked @@ -218,7 +218,7 @@ public abstract class AbstractFilterButtons extends Table { /** * Get filter button Id. - * + * * @param name * @return */ @@ -226,7 +226,7 @@ public abstract class AbstractFilterButtons extends Table { /** * Get Drop Handler for Filter Buttons. - * + * * @return */ protected abstract DropHandler getFilterButtonDropHandler(); @@ -234,14 +234,14 @@ public abstract class AbstractFilterButtons extends Table { /** * Get prefix Id of Button Wrapper to be used for drag and drop, delete and * test cases. - * + * * @return prefix Id of Button Wrapper */ protected abstract String getButttonWrapperIdPrefix(); /** * Get info to be set for the button wrapper. - * + * * @return button wrapper info. */ protected abstract String getButtonWrapperData(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java index 8161c2895..9bfb81a27 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIComponentProvider.java @@ -15,9 +15,9 @@ 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.HeaderLayoutDecorator; import org.eclipse.hawkbit.ui.decorators.SPUIButtonDecorator; import org.eclipse.hawkbit.ui.decorators.SPUIComboBoxDecorator; -import org.eclipse.hawkbit.ui.decorators.HeaderLayoutDecorator; import org.eclipse.hawkbit.ui.decorators.SPUILabelDecorator; import org.eclipse.hawkbit.ui.decorators.SPUITextAreaDecorator; import org.eclipse.hawkbit.ui.decorators.SPUITextFieldDecorator; @@ -82,8 +82,6 @@ public final class SPUIComponentProvider { /** * Get HorizontalLayout UI component. * - * @param className - * as Layout * @return HorizontalLayout as UI */ public static HorizontalLayout getHorizontalLayout() { @@ -117,8 +115,7 @@ public final class SPUIComponentProvider { hLayout = layoutDecorator.decorate(hLayout); } catch (final InstantiationException | IllegalAccessException exception) { - LOG.error("Error occured while creating horizontal decorator " + HeaderLayoutDecorator.class, - exception); + LOG.error("Error occured while creating horizontal decorator " + HeaderLayoutDecorator.class, exception); } return hLayout; @@ -139,7 +136,7 @@ public final class SPUIComponentProvider { /** * Get window component. - * + * * @param caption * window caption * @param id @@ -154,7 +151,7 @@ public final class SPUIComponentProvider { /** * Get Label UI component. - * + * * @param caption * set the caption of the textfield * @param style @@ -182,7 +179,7 @@ public final class SPUIComponentProvider { /** * Get Label UI component. * - * + * * @param caption * set the caption of the textArea * @param style @@ -206,7 +203,7 @@ public final class SPUIComponentProvider { /** * Get Label UI component. - * + * * @param caption * caption of the combo box * @param height @@ -252,7 +249,7 @@ public final class SPUIComponentProvider { /** * Get Button - Factory Approach for decoration. - * + * * @param id * as string * @param buttonName @@ -289,7 +286,7 @@ public final class SPUIComponentProvider { /** * Get the style required. - * + * * @return String */ public static String getPinButtonStyle() { @@ -305,7 +302,7 @@ public final class SPUIComponentProvider { /** * Get DistributionSet Info Panel. - * + * * @param distributionSet * as DistributionSet * @param caption @@ -323,7 +320,7 @@ public final class SPUIComponentProvider { /** * Method to CreateName value labels. - * + * * @param label * as string * @param values @@ -356,7 +353,7 @@ public final class SPUIComponentProvider { /** * Create label which represents the {@link BaseEntity#getCreatedBy()} by * user name - * + * * @param i18n * the i18n * @param baseEntity @@ -371,7 +368,7 @@ public final class SPUIComponentProvider { /** * Create label which represents the * {@link BaseEntity#getLastModifiedBy()()} by user name - * + * * @param i18n * the i18n * @param baseEntity @@ -385,7 +382,7 @@ public final class SPUIComponentProvider { /** * Get Bold Text. - * + * * @param text * as String * @return String as bold @@ -396,7 +393,7 @@ public final class SPUIComponentProvider { /** * Get the layout for Target:Controller Attributes. - * + * * @param controllerAttibs * as Map * @return VerticalLayout @@ -407,7 +404,7 @@ public final class SPUIComponentProvider { /** * Get Tabsheet. - * + * * @return SPUITabSheet */ public static TabSheet getDetailsTabSheet() { @@ -416,7 +413,7 @@ public final class SPUIComponentProvider { /** * Layout of tabs in detail tabsheet. - * + * * @return VerticalLayout */ public static VerticalLayout getDetailTabLayout() { @@ -429,7 +426,7 @@ public final class SPUIComponentProvider { /** * Method to create a link. - * + * * @param id * of the link * @param name @@ -465,10 +462,10 @@ public final class SPUIComponentProvider { /** * Generates help/documentation links from within management UI. - * + * * @param uri * to documentation site - * + * * @return generated link */ public static Link getHelpLink(final String uri) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java index 2175dea29..ca58648ac 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/RolloutRendererConnector.java @@ -17,21 +17,22 @@ import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; import com.vaadin.shared.ui.Connect; import elemental.json.JsonObject; + /** * A connector for {@link CustomObjectRenderer }. * */ @Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer.class) public class RolloutRendererConnector extends ClickableRendererConnector { - private static final long serialVersionUID = 7734682321931830566L; + private static final long serialVersionUID = 7734682321931830566L; - public org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer getRenderer() { - return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer) super.getRenderer(); - } + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRenderer) super.getRenderer(); + } - @Override - protected HandlerRegistration addClickHandler( - RendererClickHandler handler) { + @Override + protected HandlerRegistration addClickHandler(final RendererClickHandler handler) { return getRenderer().addClickHandler(handler); - } + } } \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRendererData.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRendererData.java index 6c751e6a2..7e212ea67 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRendererData.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/RolloutRendererData.java @@ -11,52 +11,42 @@ package org.eclipse.hawkbit.ui.customrenderers.client.renderers; import java.io.Serializable; /** - * RendererData class with Name and Status. - * + * RendererData class with name and status. */ - public class RolloutRendererData implements Serializable { - private static final long serialVersionUID = -5018181529953620263L; - private String name; + private static final long serialVersionUID = -5018181529953620263L; - private String status; + private String name; - /** - * Initialize the RendererData. - */ - public RolloutRendererData() { + private String status; - } + /** + * Initialize the RendererData. + * + * @param name + * Name of the Rollout. + * @param status + * Status of Rollout. + */ + public RolloutRendererData(final String name, final String status) { + this.name = name; + this.status = status; + } - /** - * Initialize the RendererData. - * - * @param name - * Name of the Rollout. - * @param status - * Status of Rollout. - */ - public RolloutRendererData(String name, String status) { - super(); - this.name = name; - this.status = status; - } + public String getName() { + return name; + } - public String getName() { - return name; - } + public void setName(final String name) { + this.name = name; + } - public void setName(String name) { - this.name = name; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } + public String getStatus() { + return status; + } + public void setStatus(final String status) { + this.status = status; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/RolloutRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/RolloutRenderer.java index 29663dd9d..8af3ccfc9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/RolloutRenderer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/RolloutRenderer.java @@ -16,46 +16,44 @@ import com.vaadin.ui.renderers.ClickableRenderer; import elemental.json.JsonValue; /** - * Renders button with provided CustomObject. - * Used to display button with link. - * + * Renders button with provided CustomObject. Used to display button with link. */ - public class RolloutRenderer extends ClickableRenderer { - private static final long serialVersionUID = -8754180585906263554L; + private static final long serialVersionUID = -8754180585906263554L; - /** - * Creates a new custom object renderer. - */ - public RolloutRenderer() { - super(RolloutRendererData.class, null); - } - - /** - * Initialize custom object renderer with {@link Class} - * - * @param presentationType - * Class - */ + /** + * Creates a new custom object renderer. + */ + public RolloutRenderer() { + super(RolloutRendererData.class, null); + } - public RolloutRenderer(Class presentationType) { - super(presentationType); - } + /** + * Initialize custom object renderer with the given type. + * + * @param presentationType + * Class + */ - /** - * Creates a new custom object renderer and adds the given click listener to it. - * - * @param listener - * the click listener to register - */ - public RolloutRenderer(RendererClickListener listener) { - this(); - addClickListener(listener); - } + public RolloutRenderer(final Class presentationType) { + super(presentationType); + } - @Override - public JsonValue encode(RolloutRendererData resource) { - return super.encode(resource, RolloutRendererData.class); - } + /** + * Creates a new custom object renderer and adds the given click listener to + * it. + * + * @param listener + * the click listener to register + */ + public RolloutRenderer(final RendererClickListener listener) { + this(); + addClickListener(listener); + } + + @Override + public JsonValue encode(final RolloutRendererData resource) { + return super.encode(resource, RolloutRendererData.class); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/decorators/SPUIWindowDecorator.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/decorators/SPUIWindowDecorator.java index 714f1f3a3..da60b83d1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/decorators/SPUIWindowDecorator.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/decorators/SPUIWindowDecorator.java @@ -21,9 +21,6 @@ import com.vaadin.ui.Window; /** * Decorator for Window. - * - * - * */ public final class SPUIWindowDecorator { @@ -36,7 +33,7 @@ public final class SPUIWindowDecorator { /** * Decorates window based on type. - * + * * @param caption * window caption * @param id @@ -48,36 +45,38 @@ public final class SPUIWindowDecorator { public static CommonDialogWindow getWindow(final String caption, final String id, final String type, final Component content, final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener, final String helpLink, final AbstractLayout layout, - final I18N i18n) { - CommonDialogWindow window = null; - if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) { - window = new CustomCommonDialogWindow(caption, content, helpLink, saveButtonClickListener, - cancelButtonClickListener, layout, i18n); - window.setDraggable(true); - window.setClosable(true); - } else { - window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener, - cancelButtonClickListener, layout, i18n); - if (null != id) { - window.setId(id); - } - if (SPUIDefinitions.CONFIRMATION_WINDOW.equals(type)) { - window.setDraggable(false); - window.setClosable(true); - window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION); + final I18N i18n) { - } else if (SPUIDefinitions.CREATE_UPDATE_WINDOW.equals(type)) { - window.setDraggable(true); - window.setClosable(true); - } - } - return window; - } + CommonDialogWindow window; + + if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) { + window = new CustomCommonDialogWindow(caption, content, helpLink, saveButtonClickListener, + cancelButtonClickListener, layout, i18n); + window.setDraggable(true); + window.setClosable(true); + } else { + window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener, + cancelButtonClickListener, layout, i18n); + if (null != id) { + window.setId(id); + } + if (SPUIDefinitions.CONFIRMATION_WINDOW.equals(type)) { + window.setDraggable(false); + window.setClosable(true); + window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION); + + } else if (SPUIDefinitions.CREATE_UPDATE_WINDOW.equals(type)) { + window.setDraggable(true); + window.setClosable(true); + } + } + + return window; + } - /** * Decorates window based on type. - * + * * @param caption * window caption * @param id diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java index 9b819e1b4..fb7285764 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java @@ -117,5 +117,4 @@ public class DSTypeFilterButtons extends AbstractFilterButtons { private void refreshTypeTable() { setContainerDataSource(createButtonsLazyQueryContainer()); } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java index a6542cbd4..3ff0dd476 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java @@ -15,11 +15,9 @@ import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.AbstractMetadataPopupLayout; import org.eclipse.hawkbit.ui.distributions.event.MetadataEvent; import org.eclipse.hawkbit.ui.distributions.event.MetadataEvent.MetadataUIEvent; -import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -27,7 +25,6 @@ import com.vaadin.spring.annotation.ViewScope; /** * Pop up layout to display software module metadata. - * */ @SpringComponent @ViewScope @@ -39,39 +36,35 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout getMetadataList() { return getSelectedEntity().getMetadata(); } - + /** * delete metadata for SWModule. */ @Override - protected void deleteMetadata(SoftwareModule entity, String key, String value) { - SoftwareModuleMetadata swMetadata = entityFactory.generateSoftwareModuleMetadata(entity, key, value); + protected void deleteMetadata(final SoftwareModule entity, final String key, final String value) { + final SoftwareModuleMetadata swMetadata = entityFactory.generateSoftwareModuleMetadata(entity, key, value); softwareManagement.deleteSoftwareModuleMetadata(entity, key); eventBus.publish(this, new MetadataEvent(MetadataUIEvent.DELETE_SOFTWARE_MODULE_METADATA, swMetadata)); } - + @Override protected boolean hasCreatePermission() { return permChecker.hasCreateDistributionPermission(); } - + @Override protected boolean hasUpdatePermission() { return permChecker.hasUpdateDistributionPermission(); } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java index 4fd478bda..9fe3ec3f1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.distributions.smtype; +import static org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE; +import static org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE; +import static org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider.SW_MODULE_TYPE_TABLE_ID; +import static org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions.VAR_NAME; + import java.util.HashMap; import java.util.Map; @@ -19,7 +24,6 @@ import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -35,10 +39,9 @@ import com.vaadin.spring.annotation.ViewScope; /** * Software Module Type filter buttons. - * */ -@SpringComponent @ViewScope +@SpringComponent public class DistSMTypeFilterButtons extends AbstractFilterButtons { private static final long serialVersionUID = 6804534533362387433L; @@ -51,7 +54,7 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { @Override protected String getButtonsTableId() { - return SPUIComponentIdProvider.SW_MODULE_TYPE_TABLE_ID; + return SW_MODULE_TYPE_TABLE_ID; } @Override @@ -60,7 +63,7 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { final BeanQueryFactory typeQF = new BeanQueryFactory<>( SoftwareModuleTypeBeanQuery.class); typeQF.setQueryConfiguration(queryConfig); - return new LazyQueryContainer(new LazyQueryDefinition(true, 20, SPUILabelDefinitions.VAR_NAME), typeQF); + return new LazyQueryContainer(new LazyQueryDefinition(true, 20, VAR_NAME), typeQF); } @Override @@ -70,8 +73,8 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { @Override protected boolean isClickedByDefault(final String typeName) { - return manageDistUIState.getSoftwareModuleFilters().getSoftwareModuleType().isPresent() - && manageDistUIState.getSoftwareModuleFilters().getSoftwareModuleType().get().getName().equals(typeName); + return manageDistUIState.getSoftwareModuleFilters().getSoftwareModuleType().isPresent() && manageDistUIState + .getSoftwareModuleFilters().getSoftwareModuleType().get().getName().equals(typeName); } @Override @@ -104,13 +107,16 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleTypeEvent event) { - if (event.getSoftwareModuleTypeEnum() == SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE - || event.getSoftwareModuleTypeEnum() == SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE - && event.getSoftwareModuleType() != null) { + if (isCreateOrUpdate(event) && event.getSoftwareModuleType() != null) { refreshTypeTable(); } } + private boolean isCreateOrUpdate(final SoftwareModuleTypeEvent event) { + return event.getSoftwareModuleTypeEnum() == ADD_SOFTWARE_MODULE_TYPE + || event.getSoftwareModuleTypeEnum() == UPDATE_SOFTWARE_MODULE_TYPE; + } + @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SaveActionWindowEvent event) { if (event == SaveActionWindowEvent.SAVED_DELETE_SW_MODULE_TYPES) { @@ -121,6 +127,4 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { private void refreshTypeTable() { setContainerDataSource(createButtonsLazyQueryContainer()); } - - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java index 45ad7ac89..caac53147 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java @@ -8,8 +8,9 @@ */ package org.eclipse.hawkbit.ui.distributions.state; +import static java.util.Collections.emptySet; + import java.io.Serializable; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -49,7 +50,7 @@ public class ManageDistUIState implements ManagmentEntityState selectedSoftwareModules = Collections.emptySet(); + private Set selectedSoftwareModules = emptySet(); private Set selectedDeleteDistSetTypes = new HashSet<>(); @@ -57,23 +58,23 @@ public class ManageDistUIState implements ManagmentEntityState deleteSofwareModulesList = new HashMap<>(); - private boolean swModuleTableMaximized = Boolean.FALSE; + private boolean swModuleTableMaximized; - private boolean dsTableMaximized = Boolean.FALSE; + private boolean dsTableMaximized; private final Map assignedSoftwareModuleDetails = new HashMap<>(); private final Map>> consolidatedDistSoftwarewList = new HashMap<>(); - private boolean noDataAvilableSwModule = Boolean.FALSE; + private boolean noDataAvilableSwModule; - private boolean noDataAvailableDist = Boolean.FALSE; + private boolean noDataAvailableDist; /** * @return the manageDistFilters @@ -117,6 +118,7 @@ public class ManageDistUIState implements ManagmentEntityState values) { selectedDistributions = values; } @@ -223,7 +225,7 @@ public class ManageDistUIState implements ManagmentEntityState discard(), null, mainLayout, i18n); return window; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java index 9544776a6..f56cd0ae7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java @@ -118,12 +118,10 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat /** * RESET. - * - * @param event */ @Override - public void discard(final ClickEvent event) { - super.discard(event); + public void discard() { + super.discard(); resetDistTagValues(); } @@ -144,7 +142,7 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat /** * Select tag & set tag name & tag desc values corresponding to selected * tag. - * + * * @param distTagSelected * as the selected tag from combo */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java index deaace968..8b5ee85cf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java @@ -121,7 +121,7 @@ public class DistributionTagButtons extends AbstractFilterButtons { } @Override - protected boolean isNoTagSateSelected() { + protected boolean isNoTagStateSelected() { return managementUIState.getDistributionTableFilters().isNoTagSelected(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 83082be01..14b096fcf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -391,22 +391,22 @@ public class BulkUploadHandler extends CustomComponent eventBus.publish(this, new BulkUploadValidationMessageEvent(errorMessage.toString())); } } - } - private void addNewTarget(final String controllerId, final String name) { - final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerId); - if (mandatoryCheck(newControllerId) && duplicateCheck(newControllerId)) { - final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(name); - final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + private void addNewTarget(final String controllerId, final String name) { + final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerId); + if (mandatoryCheck(newControllerId) && duplicateCheck(newControllerId)) { + final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(name); + final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + + /* create new target entity */ + final Target newTarget = entityFactory.generateTarget(newControllerId); + setTargetValues(newTarget, newName, newDesc); + targetManagement.createTarget(newTarget); + managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId); + successfullTargetCount++; + } - /* create new target entity */ - final Target newTarget = entityFactory.generateTarget(newControllerId); - setTargetValues(newTarget, newName, newDesc); - targetManagement.createTarget(newTarget); - managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId); - successfullTargetCount++; } - } private static void setTargetValues(final Target target, final String name, final String description) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index e9d3f6e1e..c1287e978 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -131,7 +131,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { } @Override - protected boolean isNoTagSateSelected() { + protected boolean isNoTagStateSelected() { return managementUIState.getTargetTableFilters().isNoTagSelected(); } 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 defcc82c0..4016d5fd7 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 @@ -37,6 +37,7 @@ import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.UIScope; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Component; import com.vaadin.ui.CustomComponent; @@ -52,14 +53,11 @@ import com.vaadin.ui.themes.ValoTheme; * A responsive menu component providing user information and the controls for * primary navigation between the views. */ -@SpringComponent @UIScope +@SpringComponent public final class DashboardMenu extends CustomComponent { - private static final String STYLE_VISIBLE = "valo-menu-visible"; - public static final String ID = "dashboard-menu"; - public static final String REPORTS_BADGE_ID = "dashboard-menu-reports-badge"; - public static final String NOTIFICATIONS_BADGE_ID = "dashboard-menu-notifications-badge"; + private static final String ID = "dashboard-menu"; @Autowired private I18N i18n; @@ -208,13 +206,7 @@ public final class DashboardMenu extends CustomComponent { } private Component buildToggleButton() { - final Button valoMenuToggleButton = new Button("Menu", (ClickListener) event -> { - if (getCompositionRoot().getStyleName().contains(STYLE_VISIBLE)) { - getCompositionRoot().removeStyleName(STYLE_VISIBLE); - } else { - getCompositionRoot().addStyleName(STYLE_VISIBLE); - } - }); + final Button valoMenuToggleButton = new Button("Menu", new MenuToggleClickListenerMyClickListener()); valoMenuToggleButton.setIcon(FontAwesome.LIST); valoMenuToggleButton.addStyleName("valo-menu-toggle"); valoMenuToggleButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); @@ -244,7 +236,7 @@ public final class DashboardMenu extends CustomComponent { /** * Returns all views which are currently accessible by the current logged in * user. - * + * * @return a list of all views which are currently visible and accessible * for the current logged in user */ @@ -264,7 +256,7 @@ public final class DashboardMenu extends CustomComponent { /** * Returns the view name for the start page after login. - * + * * @return the initialViewName of the start page */ public String getInitialViewName() { @@ -273,7 +265,7 @@ public final class DashboardMenu extends CustomComponent { /** * Is a View available. - * + * * @return the accessibleViewsEmpty no rights for any view a * view is available */ @@ -284,7 +276,7 @@ public final class DashboardMenu extends CustomComponent { /** * notifies the dashboard that the view has been changed and the button * needs to be re-styled. - * + * * @param event * the post view change event */ @@ -294,7 +286,7 @@ public final class DashboardMenu extends CustomComponent { /** * Returns the dashboard view type by a given view name. - * + * * @param viewName * the name of the view to retrieve * @return the dashboard view for a given viewname or {@code null} if view @@ -313,7 +305,7 @@ public final class DashboardMenu extends CustomComponent { /** * Is the given view accessible. - * + * * @param viewName * the view name * @return = denied, = accessible @@ -329,15 +321,28 @@ public final class DashboardMenu extends CustomComponent { return accessDeined; } + private class MenuToggleClickListenerMyClickListener implements ClickListener { + + private static final long serialVersionUID = 1L; + private static final String STYLE_VISIBLE = "valo-menu-visible"; + + @Override + public void buttonClick(final ClickEvent event) { + if (getCompositionRoot().getStyleName().contains(STYLE_VISIBLE)) { + getCompositionRoot().removeStyleName(STYLE_VISIBLE); + } else { + getCompositionRoot().addStyleName(STYLE_VISIBLE); + } + } + } + /** * An menu item button wrapper for the dashboard menu item. - * - * - * - * */ public static final class ValoMenuItemButton extends Button { + private static final long serialVersionUID = 1L; + private static final String STYLE_SELECTED = "selected"; private final DashboardMenuItem view; @@ -345,7 +350,7 @@ public final class DashboardMenu extends CustomComponent { /** * creates a new button in case of pressed switches to the given * {@code view}. - * + * * @param view * the view to switch to in case the button is pressed */ @@ -358,12 +363,11 @@ public final class DashboardMenu extends CustomComponent { /* Avoid double click */ setDisableOnClick(true); addClickListener(event -> event.getComponent().getUI().getNavigator().navigateTo(view.getViewName())); - } /** * notifies the button to change his style. - * + * * @param event * the post view change event */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java index 4d46945ca..3d167d4cb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarHelper.java @@ -20,6 +20,7 @@ import org.vaadin.alump.distributionbar.gwt.client.GwtDistributionBar; * */ public final class DistributionBarHelper { + private static final String HTML_DIV_END = ""; private static final int PARENT_SIZE_IN_PCT = 100; private static final double MINIMUM_PART_SIZE = 10; private static final String DISTRIBUTION_BAR_PART_MAIN_STYLE = GwtDistributionBar.CLASSNAME + "-part"; @@ -38,23 +39,23 @@ public final class DistributionBarHelper { * * @return string of format "status1:count,status2:count" */ - public static String getDistributionBarAsHTMLString(Map statusTotalCountMap) { - StringBuilder htmlString = new StringBuilder(); - Map statusMapWithNonZeroValues = getStatusMapWithNonZeroValues(statusTotalCountMap); - Long totalValue = getTotalSizes(statusTotalCountMap); + public static String getDistributionBarAsHTMLString(final Map statusTotalCountMap) { + final StringBuilder htmlString = new StringBuilder(); + final Map statusMapWithNonZeroValues = getStatusMapWithNonZeroValues(statusTotalCountMap); + final Long totalValue = getTotalSizes(statusTotalCountMap); if (statusMapWithNonZeroValues.size() <= 0) { return getUnintialisedBar(); } int partIndex = 1; htmlString.append(getParentDivStart()); - for (Map.Entry entry : statusMapWithNonZeroValues.entrySet()) { + for (final Map.Entry entry : statusMapWithNonZeroValues.entrySet()) { if (entry.getValue() > 0) { htmlString.append(getPart(partIndex, entry.getKey(), entry.getValue(), totalValue, statusMapWithNonZeroValues.size())); partIndex++; } } - htmlString.append(getParentDivEnd()); + htmlString.append(HTML_DIV_END); return htmlString.toString(); } @@ -65,7 +66,7 @@ public final class DistributionBarHelper { * map with status and count * @return map with non zero values */ - public static Map getStatusMapWithNonZeroValues(Map statusTotalCountMap) { + public static Map getStatusMapWithNonZeroValues(final Map statusTotalCountMap) { return statusTotalCountMap.entrySet().stream().filter(p -> p.getValue() > 0) .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue())); } @@ -77,19 +78,20 @@ public final class DistributionBarHelper { * map with status and count details * @return tool tip */ - public static String getTooltip(Map statusCountMap) { - Map nonZeroStatusCountMap = DistributionBarHelper.getStatusMapWithNonZeroValues(statusCountMap); - StringBuilder tooltip = new StringBuilder(); - for (Entry entry : nonZeroStatusCountMap.entrySet()) { + public static String getTooltip(final Map statusCountMap) { + final Map nonZeroStatusCountMap = DistributionBarHelper + .getStatusMapWithNonZeroValues(statusCountMap); + final StringBuilder tooltip = new StringBuilder(); + for (final Entry entry : nonZeroStatusCountMap.entrySet()) { tooltip.append(entry.getKey().toString().toLowerCase()).append(" : ").append(entry.getValue()) .append("
    "); } return tooltip.toString(); } - private static String getPartStyle(int partIndex, int noOfParts, String customStyle) { - StringBuilder mainStyle = new StringBuilder(); - StringBuilder styleName = new StringBuilder(GwtDistributionBar.CLASSNAME); + private static String getPartStyle(final int partIndex, final int noOfParts, final String customStyle) { + final StringBuilder mainStyle = new StringBuilder(); + final StringBuilder styleName = new StringBuilder(GwtDistributionBar.CLASSNAME); if (noOfParts == 1) { styleName.append("-only"); } else if (partIndex == 1) { @@ -108,15 +110,16 @@ public final class DistributionBarHelper { return mainStyle.toString(); } - private static String getPartWidth(Long value, Long totalValue, int noOfParts) { + private static String getPartWidth(final Long value, final Long totalValue, final int noOfParts) { final double minTotalSize = MINIMUM_PART_SIZE * noOfParts; final double availableSize = PARENT_SIZE_IN_PCT - minTotalSize; - double val = MINIMUM_PART_SIZE + (double) value / totalValue * availableSize; + final double val = MINIMUM_PART_SIZE + (double) value / totalValue * availableSize; return String.format("%.3f", val) + "%"; } - private static String getPart(int partIndex, Status status, Long value, Long totalValue, int noOfParts) { - String partValue = status.toString().toLowerCase(); + private static String getPart(final int partIndex, final Status status, final Long value, final Long totalValue, + final int noOfParts) { + final String partValue = status.toString().toLowerCase(); return "
    " + value + "
    "; @@ -127,9 +130,9 @@ public final class DistributionBarHelper { + DISTRIBUTION_BAR_PART_VALUE_CLASSNAME + "\">uninitialized"; } - private static Long getTotalSizes(Map statusTotalCountMap) { + private static Long getTotalSizes(final Map statusTotalCountMap) { Long total = 0L; - for (Long value : statusTotalCountMap.values()) { + for (final Long value : statusTotalCountMap.values()) { total = total + value; } return total; @@ -139,8 +142,4 @@ public final class DistributionBarHelper { return "
    "; } - - private static String getParentDivEnd() { - return "
    "; - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index 8a7d11df1..6a20bf9f0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -152,7 +152,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { /** * Get the window. - * + * * @param rolloutId * the rollout id * @return the window @@ -499,14 +499,6 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { return errorThresoldPercent; } - private boolean validateFields() { - if (!noOfGroups.isValid() || !errorThreshold.isValid() || !triggerThreshold.isValid()) { - uiNotification.displayValidationError(i18n.get("message.correct.invalid.value")); - return false; - } - return true; - } - private boolean duplicateCheck() { if (rolloutManagement.findRolloutByName(getRolloutName()) != null) { uiNotification.displayValidationError( @@ -694,9 +686,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } /** - * + * * Populate rollout details. - * + * * @param rolloutId * rollout id */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 0d78763be..19df8b139 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -52,7 +52,7 @@ import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; import com.vaadin.ui.renderers.HtmlRenderer; /** - * + * * Rollout group list grid component. * */ @@ -86,10 +86,10 @@ public class RolloutGroupListGrid extends AbstractGrid { } /** - * + * * Handles the RolloutGroupChangeEvent to refresh the item in the grid. - * - * + * + * * @param rolloutGroupChangeEvent * the event which contains the rollout group which has been * change @@ -242,6 +242,12 @@ public class RolloutGroupListGrid extends AbstractGrid { } } + private void onClickOfRolloutGroupName(final RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } + @Override protected void setHiddenColumns() { final List columnsToBeHidden = new ArrayList<>(); @@ -261,12 +267,6 @@ public class RolloutGroupListGrid extends AbstractGrid { return this::getDescription; } - private void onClickOfRolloutGroupName(final RendererClickEvent event) { - rolloutUIState - .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); - eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); - } - private void createRolloutGroupStatusToFontMap() { statusIconMap.put(RolloutGroupStatus.FINISHED, new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); @@ -311,7 +311,7 @@ public class RolloutGroupListGrid extends AbstractGrid { } /** - * + * * Converts {@link TotalTargetCountStatus} into formatted string with status * and count details. * @@ -346,7 +346,7 @@ public class RolloutGroupListGrid extends AbstractGrid { } /** - * + * * Converts {@link RolloutGroupStatus} to string. * */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index 329318b0f..584f28931 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -161,13 +161,13 @@ public class AuthenticationConfigurationView extends BaseConfigurationView final CheckBox checkBox = (CheckBox) event.getProperty(); AuthenticationConfigurationItem configurationItem; - if (checkBox == gatewaySecTokenCheckBox) { + if (gatewaySecTokenCheckBox.equals(checkBox)) { configurationItem = gatewaySecurityTokenAuthenticationConfigurationItem; - } else if (checkBox == targetSecTokenCheckBox) { + } else if (targetSecTokenCheckBox.equals(checkBox)) { configurationItem = targetSecurityTokenAuthenticationConfigurationItem; - } else if (checkBox == certificateAuthCheckbox) { + } else if (certificateAuthCheckbox.equals(checkBox)) { configurationItem = certificateAuthenticationConfigurationItem; - } else if (checkBox == downloadAnonymousCheckBox) { + } else if (downloadAnonymousCheckBox.equals(checkBox)) { configurationItem = anonymousDownloadAuthenticationConfigurationItem; } else { return; 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 b5ac26d11..18ffda663 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 @@ -441,7 +441,7 @@ public final class HawkbitCommonUtil { */ public static float findRequiredExtraHeight(final float newBrowserHeight) { return newBrowserHeight > SPUIDefinitions.REQ_MIN_BROWSER_HEIGHT - ? newBrowserHeight - SPUIDefinitions.REQ_MIN_BROWSER_HEIGHT : 0; + ? (newBrowserHeight - SPUIDefinitions.REQ_MIN_BROWSER_HEIGHT) : 0; } /** @@ -453,7 +453,7 @@ public final class HawkbitCommonUtil { */ public static float findRequiredSwModuleExtraHeight(final float newBrowserHeight) { return newBrowserHeight > SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_HEIGHT - ? newBrowserHeight - SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_HEIGHT : 0; + ? (newBrowserHeight - SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_HEIGHT) : 0; } /** @@ -465,7 +465,7 @@ public final class HawkbitCommonUtil { */ public static float findRequiredSwModuleExtraWidth(final float newBrowserWidth) { return newBrowserWidth > SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_WIDTH - ? newBrowserWidth - SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_WIDTH : 0; + ? (newBrowserWidth - SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_WIDTH) : 0; } /** @@ -528,7 +528,7 @@ public final class HawkbitCommonUtil { */ public static float findExtraWidth(final float newBrowserWidth) { return newBrowserWidth > SPUIDefinitions.REQ_MIN_BROWSER_WIDTH - ? newBrowserWidth - SPUIDefinitions.REQ_MIN_BROWSER_WIDTH : 0; + ? (newBrowserWidth - SPUIDefinitions.REQ_MIN_BROWSER_WIDTH) : 0; } /** @@ -570,7 +570,7 @@ public final class HawkbitCommonUtil { final float requiredExtraWidth = findExtraWidth(newBrowserWidth); float expectedDistWidth = minTableWidth; if (requiredExtraWidth > 0) { - expectedDistWidth = expectedDistWidth + Math.round(requiredExtraWidth * 0.5f); + expectedDistWidth = expectedDistWidth + Math.round(requiredExtraWidth * 0.5F); } return expectedDistWidth; } @@ -741,6 +741,8 @@ public final class HawkbitCommonUtil { * base software module type * @param description * base software module description + * @param entityFactory + * the entity factory to create new entity instances * @return BaseSoftwareModule new base software module */ public static SoftwareModule addNewBaseSoftware(final EntityFactory entityFactory, final String bsname, diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java index f035c4995..c4091bde2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java @@ -273,10 +273,6 @@ public final class SPUIDefinitions { * New Target save icon id. */ public static final String NEW_TARGET_SAVE = "target.add.save"; - /** - * New Target discard icon id. - */ - // public static final String NEW_TARGET_DISCARD = "target.add.discard"; /** * New Target add icon id. */ @@ -1017,12 +1013,12 @@ public final class SPUIDefinitions { * Rollout action column property. */ public static final String ROLLOUT_ACTION = "rollout-action"; - + /** * DistributionSet Metadata tab Id */ public static final String DISTRIBUTIONSET_METADATA_TAB_ID = "distSet.metadata.tab.id"; - + /** * SoftwareModule Metadata tab Id */ @@ -1031,7 +1027,7 @@ public final class SPUIDefinitions { /*** * Custom window for metadata. */ - public static final String CUSTOM_METADATA_WINDOW = "custom.metadata.window"; + public static final String CUSTOM_METADATA_WINDOW = "custom.metadata.window"; /** * /** Constructor.