diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 31c0174a3..26e79ae9f 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -109,16 +109,14 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { LOG.debug("targetAssignDistributionSet retrieved for controller {}. I will forward it to DMF broker.", assignedEvent.getControllerId()); - sendUpdateMessageToTarget(assignedEvent.getTenant(), - targetManagement.findTargetByControllerID(assignedEvent.getControllerId()).get(), - assignedEvent.getActionId(), assignedEvent.getModules()); + targetManagement.findTargetByControllerID(assignedEvent.getControllerId()).ifPresent(target -> sendUpdateMessageToTarget(assignedEvent.getTenant(), + target, + assignedEvent.getActionId(), assignedEvent.getModules())); + } void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId, final Collection modules) { - if (target == null) { - return; - } final URI targetAdress = target.getTargetInfo().getAddress(); if (!IpUtil.isAmqpUri(targetAdress)) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index a8c43840b..90ba98b3d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; @@ -126,9 +127,10 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; + final SoftwareModuleType softwareModuleTypeByName = softwareManagement.findSoftwareModuleTypeByName(type) + .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type)); final SoftwareModuleCreate softwareModule = entityFactory.softwareModule().create() - .type(softwareManagement.findSoftwareModuleTypeByName(type).get()).name(name).version(version) - .description(description).vendor(vendor); + .type(softwareModuleTypeByName).name(name).version(version).description(description).vendor(vendor); final SoftwareModule newSoftwareModule = softwareManagement.createSoftwareModule(softwareModule); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index cf0279bd2..0d2b9a644 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -15,6 +15,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; @@ -160,10 +161,12 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final boolean isMigStepReq = reqMigStepCheckbox.getValue(); - final DistributionSet newDist = distributionSetManagement.createDistributionSet( - entityFactory.distributionSet().create().name(name).version(version).description(desc) - .type(distributionSetManagement.findDistributionSetTypeById(distSetTypeId).get()) - .requiredMigrationStep(isMigStepReq)); + final DistributionSetType distributionSetType = distributionSetManagement + .findDistributionSetTypeById(distSetTypeId) + .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distSetTypeId)); + final DistributionSet newDist = distributionSetManagement + .createDistributionSet(entityFactory.distributionSet().create().name(name).version(version) + .description(desc).type(distributionSetType).requiredMigrationStep(isMigStepReq)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.ADD_ENTITY, newDist)); @@ -252,7 +255,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { * * @return */ - private LazyQueryContainer getDistSetTypeLazyQueryContainer() { + private static LazyQueryContainer getDistSetTypeLazyQueryContainer() { final BeanQueryFactory dtQF = new BeanQueryFactory<>( DistributionSetTypeBeanQuery.class); dtQF.setQueryConfiguration(Collections.emptyMap()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java index 58b20788a..bef95d4c8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java @@ -26,8 +26,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; -import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; import org.slf4j.Logger; @@ -277,7 +275,7 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy, Applicati } private void collectRolloutEvent(final TenantAwareEvent event) { - Long rolloutId = null; + Long rolloutId; Long rolloutGroupId = null; if (event instanceof ActionCreatedEvent) { rolloutId = ((ActionCreatedEvent) event).getRolloutId(); @@ -303,19 +301,4 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy, Applicati offerEventIfNotContains(new RolloutGroupChangeEvent(event.getTenant(), rolloutId, rolloutGroupId)); } } - - private static Long getRolloutGroupId(final RolloutGroup rolloutGroup) { - if (rolloutGroup != null) { - return rolloutGroup.getId(); - } - return null; - } - - private static Long getRolloutId(final Rollout rollout) { - if (rollout != null) { - return rollout.getId(); - } - return null; - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java index fcf41d8ca..b8c87d4fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java @@ -164,11 +164,12 @@ public class RolloutView extends VerticalLayout implements View { } private boolean isRolloutDeleted() { - if (!rolloutUIState.getRolloutId().isPresent()) { + final Optional rolloutIdInState = rolloutUIState.getRolloutId(); + if (!rolloutIdInState.isPresent()) { return true; } - final Optional rollout = rolloutManagement.findRolloutById(rolloutUIState.getRolloutId().get()); + final Optional rollout = rolloutManagement.findRolloutById(rolloutIdInState.get()); return !rollout.isPresent() || rollout.get().isDeleted(); }