code improvements
Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -183,8 +183,8 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
||||
|
||||
@Override
|
||||
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
||||
EventBusHolder.getInstance().getEventBus().post(new ActionPropertyChangeEvent(this,
|
||||
EntityPropertyChangeHelper.getChangeSet(Action.class, descriptorEvent)));
|
||||
EventBusHolder.getInstance().getEventBus()
|
||||
.post(new ActionPropertyChangeEvent(this, EntityPropertyChangeHelper.getChangeSet(descriptorEvent)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,8 +72,6 @@ import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implements DistributionSet, EventAwareEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String COMPLETE_PROPERTY = "complete";
|
||||
|
||||
private static final String DELETED_PROPERTY = "deleted";
|
||||
|
||||
@Column(name = "required_migration_step")
|
||||
@@ -299,8 +297,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
@Override
|
||||
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
||||
|
||||
final Map<String, PropertyChange> changeSet = EntityPropertyChangeHelper.getChangeSet(JpaDistributionSet.class,
|
||||
descriptorEvent);
|
||||
final Map<String, PropertyChange> changeSet = EntityPropertyChangeHelper.getChangeSet(descriptorEvent);
|
||||
EventBusHolder.getInstance().getEventBus().post(new DistributionSetUpdateEvent(this));
|
||||
|
||||
if (changeSet.containsKey(DELETED_PROPERTY)) {
|
||||
|
||||
@@ -208,8 +208,8 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
|
||||
|
||||
@Override
|
||||
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
||||
EventBusHolder.getInstance().getEventBus().post(new RolloutPropertyChangeEvent(this,
|
||||
EntityPropertyChangeHelper.getChangeSet(Rollout.class, descriptorEvent)));
|
||||
EventBusHolder.getInstance().getEventBus()
|
||||
.post(new RolloutPropertyChangeEvent(this, EntityPropertyChangeHelper.getChangeSet(descriptorEvent)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -247,8 +247,8 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
|
||||
|
||||
@Override
|
||||
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
||||
EventBusHolder.getInstance().getEventBus().post(new RolloutGroupPropertyChangeEvent(this,
|
||||
EntityPropertyChangeHelper.getChangeSet(RolloutGroup.class, descriptorEvent)));
|
||||
EventBusHolder.getInstance().getEventBus().post(
|
||||
new RolloutGroupPropertyChangeEvent(this, EntityPropertyChangeHelper.getChangeSet(descriptorEvent)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent.PropertyChange;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.eclipse.persistence.internal.sessions.ObjectChangeSet;
|
||||
import org.eclipse.persistence.queries.UpdateObjectQuery;
|
||||
@@ -21,9 +20,12 @@ import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord;
|
||||
/**
|
||||
* Helper class to get the change set for the property changes in the Entity.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class EntityPropertyChangeHelper<T extends TenantAwareBaseEntity> {
|
||||
public final class EntityPropertyChangeHelper {
|
||||
|
||||
private EntityPropertyChangeHelper() {
|
||||
// noop
|
||||
}
|
||||
|
||||
/**
|
||||
* To get the map of entity property change set
|
||||
@@ -32,14 +34,11 @@ public class EntityPropertyChangeHelper<T extends TenantAwareBaseEntity> {
|
||||
* @param event
|
||||
* @return the map of the changeSet
|
||||
*/
|
||||
public static <T extends TenantAwareBaseEntity> Map<String, PropertyChange> getChangeSet(final Class<T> clazz,
|
||||
final DescriptorEvent event) {
|
||||
final T rolloutGroup = clazz.cast(event.getObject());
|
||||
public static Map<String, PropertyChange> 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 PropertyChange(record.getOldValue(), record.getNewValue())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
|
||||
@@ -84,7 +83,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
private SpPermissionChecker permissionChecker;
|
||||
|
||||
@Autowired
|
||||
private UINotification notification;
|
||||
private UINotification uiNotification;
|
||||
|
||||
@Autowired
|
||||
private ManagementUIState managementUIState;
|
||||
@@ -101,9 +100,6 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
@Autowired
|
||||
private transient DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
private transient EntityFactory entityFactory;
|
||||
|
||||
private String notAllowedMsg;
|
||||
|
||||
private Boolean isDistPinned = false;
|
||||
@@ -394,7 +390,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distList,
|
||||
distTagName);
|
||||
|
||||
notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n));
|
||||
uiNotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n));
|
||||
if (result.getAssigned() >= 1 && managementUIState.getDistributionTableFilters().isNoTagSelected()) {
|
||||
refreshFilter();
|
||||
}
|
||||
@@ -414,7 +410,8 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
.add(new TargetIdName(target.getId(), target.getControllerId(), target.getName())));
|
||||
assignTargetToDs(getItem(distItemId), targetDetailsList);
|
||||
} else {
|
||||
notification.displaySuccess(i18n.get("message.no.targets.assiged.fortag", new Object[] { targetTagName }));
|
||||
uiNotification
|
||||
.displaySuccess(i18n.get("message.no.targets.assiged.fortag", new Object[] { targetTagName }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,13 +458,13 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
} else if (wrapperSource.getId().startsWith(SPUIDefinitions.TARGET_TAG_ID_PREFIXS)) {
|
||||
return !isNoTagButton(tagData, SPUIDefinitions.TARGET_TAG_BUTTON);
|
||||
}
|
||||
notification.displayValidationError(notAllowedMsg);
|
||||
uiNotification.displayValidationError(notAllowedMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
private Boolean isNoTagButton(final String tagData, final String targetNoTagData) {
|
||||
if (tagData.equals(targetNoTagData)) {
|
||||
notification.displayValidationError(
|
||||
uiNotification.displayValidationError(
|
||||
i18n.get("message.tag.cannot.be.assigned", new Object[] { i18n.get("label.no.tag.assigned") }));
|
||||
return true;
|
||||
}
|
||||
@@ -505,7 +502,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
eventBus.publish(this, ManagementUIEvent.UPDATE_COUNT);
|
||||
}
|
||||
if (null != message) {
|
||||
notification.displayValidationError(message);
|
||||
uiNotification.displayValidationError(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -37,10 +35,8 @@ import org.vaadin.alump.distributionbar.DistributionBar;
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.server.Sizeable.Unit;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.UI;
|
||||
@@ -174,58 +170,6 @@ public final class HawkbitCommonUtil {
|
||||
return boldStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target label Id.
|
||||
*
|
||||
* @param controllerId
|
||||
* as String
|
||||
* @return String as label name
|
||||
*/
|
||||
public static String getTargetLabelId(final String controllerId) {
|
||||
return new StringBuilder("target").append('.').append(controllerId).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get distribution table cell id.
|
||||
*
|
||||
* @param name
|
||||
* distribution name
|
||||
* @param version
|
||||
* distribution version
|
||||
* @return String distribution label id
|
||||
*/
|
||||
public static String getDistributionLabelId(final String name, final String version) {
|
||||
return new StringBuilder("dist").append('.').append(name).append('.').append(version).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get software module label id.
|
||||
*
|
||||
* @param name
|
||||
* software module name
|
||||
* @param version
|
||||
* software module version
|
||||
* @return String software module label id
|
||||
*/
|
||||
public static String getSwModuleLabelId(final String name, final String version) {
|
||||
return new StringBuilder("swModule").append('.').append(name).append('.').append(version).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get label with software module name and description.
|
||||
*
|
||||
* @param name
|
||||
* software module name
|
||||
* @param desc
|
||||
* software module description
|
||||
* @return String
|
||||
*/
|
||||
public static String getSwModuleNameDescLabel(final String name, final String desc) {
|
||||
return new StringBuilder().append(
|
||||
DIV_DESCRIPTION_START + getBoldHTMLText(getFormattedName(name)) + "<br>" + getFormattedName(desc))
|
||||
.append(DIV_DESCRIPTION_END).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label for Artifact Details.
|
||||
*
|
||||
@@ -294,31 +238,6 @@ public final class HawkbitCommonUtil {
|
||||
return trimAndNullIfEmpty(orgText) == null ? SPUIDefinitions.SPACE : orgText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find extra height required to increase by all the components to utilize
|
||||
* the full height of browser for the responsive UI.
|
||||
*
|
||||
* @param newBrowserHeight
|
||||
* as current browser height.
|
||||
* @return extra height required to increase.
|
||||
*/
|
||||
public static float findRequiredExtraHeight(final float newBrowserHeight) {
|
||||
return newBrowserHeight > SPUIDefinitions.REQ_MIN_BROWSER_HEIGHT
|
||||
? (newBrowserHeight - SPUIDefinitions.REQ_MIN_BROWSER_HEIGHT) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find required extra height of software module.
|
||||
*
|
||||
* @param newBrowserHeight
|
||||
* new browser height
|
||||
* @return float heigth of software module table
|
||||
*/
|
||||
public static float findRequiredSwModuleExtraHeight(final float newBrowserHeight) {
|
||||
return newBrowserHeight > SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_HEIGHT
|
||||
? (newBrowserHeight - SPUIDefinitions.REQ_MIN_UPLOAD_BROWSER_HEIGHT) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find required extra width of software module.
|
||||
*
|
||||
@@ -363,94 +282,6 @@ public final class HawkbitCommonUtil {
|
||||
return extraWidth + minPopupHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find extra width required to increase by all the components to utilize
|
||||
* the full width of browser for the responsive UI.
|
||||
*
|
||||
* @param newBrowserWidth
|
||||
* as current browser width.
|
||||
* @return extra width required to be increased.
|
||||
*/
|
||||
public static float findRequiredExtraWidth(final float newBrowserWidth) {
|
||||
float width = 0;
|
||||
if (newBrowserWidth < SPUIDefinitions.REQ_MIN_BROWSER_WIDTH) {
|
||||
width = SPUIDefinitions.REQ_MIN_BROWSER_WIDTH - newBrowserWidth;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find extra width required to increase by all the components to utilize
|
||||
* the full width of browser for the responsive UI.
|
||||
*
|
||||
* @param newBrowserWidth
|
||||
* as current browser width.
|
||||
* @return extra width required to be increased.
|
||||
*/
|
||||
public static float findExtraWidth(final float newBrowserWidth) {
|
||||
return newBrowserWidth > SPUIDefinitions.REQ_MIN_BROWSER_WIDTH
|
||||
? (newBrowserWidth - SPUIDefinitions.REQ_MIN_BROWSER_WIDTH) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target table width based on screen width.
|
||||
*
|
||||
* @param newBrowserWidth
|
||||
* new browser width.
|
||||
* @param minTargetTableLength
|
||||
* minimum target table width.
|
||||
* @param minDistTableLength
|
||||
* minimum distribution table width.
|
||||
* @return float as table width
|
||||
*/
|
||||
public static float getTargetTableWidth(final float newBrowserWidth, final float minTargetTableLength,
|
||||
final float minDistTableLength) {
|
||||
float width = 0;
|
||||
final float requiredExtraWidth = findRequiredExtraWidth(newBrowserWidth);
|
||||
// adjusting the target table width if distribution table width has
|
||||
// reached the maximum width
|
||||
if (requiredExtraWidth + minDistTableLength > SPUIDefinitions.MAX_DIST_TABLE_WIDTH) {
|
||||
width = requiredExtraWidth + minDistTableLength - SPUIDefinitions.MAX_DIST_TABLE_WIDTH;
|
||||
}
|
||||
if (width + minTargetTableLength + requiredExtraWidth > SPUIDefinitions.MAX_TARGET_TABLE_WIDTH) {
|
||||
return SPUIDefinitions.MAX_TARGET_TABLE_WIDTH;
|
||||
}
|
||||
return width + minTargetTableLength + requiredExtraWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get distribution table width based on screen width.
|
||||
*
|
||||
* @param newBrowserWidth
|
||||
* new browser width.
|
||||
* @param minTableWidth
|
||||
* min distribution table width.
|
||||
* @return float as distribution table width.
|
||||
*/
|
||||
public static float getDistTableWidth(final float newBrowserWidth, final float minTableWidth) {
|
||||
final float requiredExtraWidth = findExtraWidth(newBrowserWidth);
|
||||
float expectedDistWidth = minTableWidth;
|
||||
if (requiredExtraWidth > 0) {
|
||||
expectedDistWidth = expectedDistWidth + Math.round(requiredExtraWidth * 0.5F);
|
||||
}
|
||||
return expectedDistWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get software module table width.
|
||||
*
|
||||
* @param newBrowserWidth
|
||||
* @param minTableWidth
|
||||
* @return
|
||||
*/
|
||||
public static float getSoftwareModuleTableWidth(final float newBrowserWidth, final float minTableWidth) {
|
||||
final float requiredExtraWidth = findRequiredExtraWidth(newBrowserWidth);
|
||||
if (requiredExtraWidth + minTableWidth > SPUIDefinitions.MAX_UPLOAD_SW_MODULE_TABLE_WIDTH) {
|
||||
return SPUIDefinitions.MAX_UPLOAD_SW_MODULE_TABLE_WIDTH;
|
||||
}
|
||||
return requiredExtraWidth + minTableWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the prefix from text.
|
||||
*
|
||||
@@ -514,55 +345,6 @@ public final class HawkbitCommonUtil {
|
||||
return name + ":" + version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set height of artifact details table and drop area layout.
|
||||
*
|
||||
* @param dropLayout
|
||||
* drop area layout
|
||||
* @param artifactDetailsLayout
|
||||
* artifact details table
|
||||
* @param newHeight
|
||||
* new browser height
|
||||
*/
|
||||
public static void setArtifactDetailsLayoutHeight(final Component artifactDetailsLayout, final float newHeight) {
|
||||
final float extraBrowserHeight = HawkbitCommonUtil.findRequiredSwModuleExtraHeight(newHeight);
|
||||
final float tableHeight = SPUIDefinitions.MIN_UPLOAD_ARTIFACT_TABLE_HEIGHT + extraBrowserHeight;
|
||||
artifactDetailsLayout.setHeight(tableHeight, Unit.PIXELS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set height of artifact details table and drop area layout.
|
||||
*
|
||||
* @param artifactDetailsLayout
|
||||
* artifact details table
|
||||
* @param newHeight
|
||||
* new browser height
|
||||
*/
|
||||
public static void setManageDistArtifactDetailsLayoutHeight(final Component artifactDetailsLayout,
|
||||
final float newHeight) {
|
||||
final float tableHeight = SPUIDefinitions.MIN_TARGET_DIST_TABLE_HEIGHT
|
||||
+ HawkbitCommonUtil.findRequiredExtraHeight(newHeight) + 62;
|
||||
artifactDetailsLayout.setHeight(tableHeight, Unit.PIXELS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate check - Unique Key.
|
||||
*
|
||||
* @param name
|
||||
* as string
|
||||
* @param version
|
||||
* as string
|
||||
* @param type
|
||||
* key as string
|
||||
* @return boolean as flag
|
||||
*/
|
||||
public static boolean isDuplicate(final String name, final String version, final String type) {
|
||||
final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class);
|
||||
final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version,
|
||||
swMgmtService.findSoftwareModuleTypeByName(type));
|
||||
return swModule != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new base software module.
|
||||
*
|
||||
@@ -593,15 +375,6 @@ public final class HawkbitCommonUtil {
|
||||
return newSWModule;
|
||||
}
|
||||
|
||||
public static void setTargetVisibleColumns(final Table targTable) {
|
||||
final List<Object> targColumnIds = new ArrayList<>();
|
||||
final List<String> targColumnLabels = new ArrayList<>();
|
||||
targColumnIds.add(SPUIDefinitions.TARGET_TABLE_VISIBILE_COLUMN_NAME);
|
||||
targColumnLabels.add(SPUIDefinitions.TARGET_TABLE_VISIBILE_COLUMN_NAME);
|
||||
targTable.setVisibleColumns(targColumnIds.toArray());
|
||||
targTable.setColumnHeaders(targColumnLabels.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param distName
|
||||
* @param distVersion
|
||||
|
||||
Reference in New Issue
Block a user