Fix code smells (#447)
* fix sonar condition always true Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * remove useless assignment and useless private methods Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * fix unsafe usage of Optional.get Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -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<org.eclipse.hawkbit.repository.model.SoftwareModule> modules) {
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final URI targetAdress = target.getTargetInfo().getAddress();
|
||||
if (!IpUtil.isAmqpUri(targetAdress)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<DistributionSetTypeBeanQuery> dtQF = new BeanQueryFactory<>(
|
||||
DistributionSetTypeBeanQuery.class);
|
||||
dtQF.setQueryConfiguration(Collections.emptyMap());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -164,11 +164,12 @@ public class RolloutView extends VerticalLayout implements View {
|
||||
}
|
||||
|
||||
private boolean isRolloutDeleted() {
|
||||
if (!rolloutUIState.getRolloutId().isPresent()) {
|
||||
final Optional<Long> rolloutIdInState = rolloutUIState.getRolloutId();
|
||||
if (!rolloutIdInState.isPresent()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Optional<Rollout> rollout = rolloutManagement.findRolloutById(rolloutUIState.getRolloutId().get());
|
||||
final Optional<Rollout> rollout = rolloutManagement.findRolloutById(rolloutIdInState.get());
|
||||
return !rollout.isPresent() || rollout.get().isDeleted();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user