Fix sonar findings (#1951)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-05 16:19:29 +02:00
committed by GitHub
parent abcf2748e0
commit 8d3cc6d59f
5 changed files with 157 additions and 139 deletions

View File

@@ -21,6 +21,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper; import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
import org.springframework.amqp.support.converter.MessageConversionException; import org.springframework.amqp.support.converter.MessageConversionException;
import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.util.ObjectUtils;
/** /**
* A base class which provide basis amqp staff. * A base class which provide basis amqp staff.
@@ -63,7 +64,7 @@ public class BaseAmqpService {
} }
protected static boolean isMessageBodyEmpty(final Message message) { protected static boolean isMessageBodyEmpty(final Message message) {
return message.getBody() == null || message.getBody().length == 0; return ObjectUtils.isEmpty(message.getBody());
} }
protected static final void logAndThrowMessageError(final Message message, final String error) { protected static final void logAndThrowMessageError(final Message message, final String error) {

View File

@@ -11,10 +11,10 @@ package org.eclipse.hawkbit.ui.simple.view;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Key; import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.checkbox.Checkbox; import com.vaadin.flow.component.checkbox.Checkbox;
@@ -42,50 +42,47 @@ public class ConfigView extends VerticalLayout {
public ConfigView(final HawkbitMgmtClient hawkbitClient) { public ConfigView(final HawkbitMgmtClient hawkbitClient) {
setSpacing(false); setSpacing(false);
final Button saveButton = new Button("Save"); final Button saveButton = new Button("Save");
hawkbitClient.getTenantManagementRestApi().getTenantConfiguration().getBody().forEach((k, v) -> { Optional.ofNullable(
Component value = null; hawkbitClient.getTenantManagementRestApi().getTenantConfiguration().getBody()).ifPresent(config ->
if (v.getValue() instanceof String strValue) { config.forEach((k, v) -> {
TextField tf = new TextField(k, strValue, event -> { if (v.getValue() instanceof String strValue) {
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest(); final TextField tf = new TextField(k, strValue, event -> {
vre.setValue(event.getValue()); final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
configValue.put(k, vre); vre.setValue(event.getValue());
}); configValue.put(k, vre);
tf.getElement().getStyle().set(WIDTH, PX_300); });
value = tf; tf.getElement().getStyle().set(WIDTH, PX_300);
} else if (v.getValue() instanceof Boolean boolValue) { add(tf);
value = new Checkbox(k, boolValue, event -> { } else if (v.getValue() instanceof Boolean boolValue) {
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest(); add(new Checkbox(k, boolValue, event -> {
vre.setValue(event.getValue()); final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
configValue.put(k, vre); vre.setValue(event.getValue());
}); configValue.put(k, vre);
} else if (v.getValue() instanceof Long longValue) { }));
final NumberField nf = new NumberField(k, (double) longValue, event -> { } else if (v.getValue() instanceof Long longValue) {
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest(); final NumberField nf = new NumberField(k, (double) longValue, event -> {
vre.setValue(event.getValue()); final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
configValue.put(k, vre); vre.setValue(event.getValue());
}); configValue.put(k, vre);
nf.getElement().getStyle().set(WIDTH, PX_300); });
value = nf; nf.getElement().getStyle().set(WIDTH, PX_300);
} else if (v.getValue() instanceof Integer intValue) { add(nf);
final NumberField nf = new NumberField(k, (double) intValue, event -> { } else if (v.getValue() instanceof Integer intValue) {
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest(); final NumberField nf = new NumberField(k, (double) intValue, event -> {
vre.setValue(event.getValue()); MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
configValue.put(k, vre); vre.setValue(event.getValue());
}); configValue.put(k, vre);
nf.getElement().getStyle().set(WIDTH, PX_300); });
value = nf; nf.getElement().getStyle().set(WIDTH, PX_300);
} else { add(nf);
log.debug("Unexpected value type: {} -> {} (class: {})", k, v.getValue(), } else {
v.getValue() == null ? "null" : v.getValue().getClass()); log.debug("Unexpected value type: {} -> {} (class: {})",
} k, v.getValue(), v.getValue() == null ? "null" : v.getValue().getClass());
if (value != null) { }
add(value); }));
}
});
saveButton.addClickListener(click -> saveButton.addClickListener(click -> configValue.forEach(
configValue.forEach((key, value) -> (key, value) -> hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value)));
hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value)));
saveButton.addClickShortcut(Key.ENTER); saveButton.addClickShortcut(Key.ENTER);
add(saveButton); add(saveButton);
} }

View File

@@ -9,11 +9,13 @@
*/ */
package org.eclipse.hawkbit.ui.simple.view; package org.eclipse.hawkbit.ui.simple.view;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -38,6 +40,7 @@ import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.renderer.ComponentRenderer; import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSetRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSetRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType; import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
@@ -75,12 +78,11 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
() -> details, DistributionSetDetails::setItem)); () -> details, DistributionSetDetails::setItem));
} }
}, },
(query, rsqlFilter) -> hawkbitClient.getDistributionSetRestApi() (query, rsqlFilter) -> Optional.ofNullable(
.getDistributionSets( hawkbitClient.getDistributionSetRestApi()
query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter) .getDistributionSets(query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter)
.getBody() .getBody())
.getContent() .stream().flatMap(body -> body.getContent().stream()),
.stream(),
e -> new CreateDialog(hawkbitClient).result(), e -> new CreateDialog(hawkbitClient).result(),
selectionGrid -> { selectionGrid -> {
selectionGrid.getSelectedItems().forEach( selectionGrid.getSelectedItems().forEach(
@@ -115,17 +117,19 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
private DistributionSetFilter(final HawkbitMgmtClient hawkbitClient) { private DistributionSetFilter(final HawkbitMgmtClient hawkbitClient) {
name.setPlaceholder("<name filter>"); name.setPlaceholder("<name filter>");
type.setItemLabelGenerator(MgmtDistributionSetType::getName); type.setItemLabelGenerator(MgmtDistributionSetType::getName);
type.setItems( type.setItems(Optional.ofNullable(
hawkbitClient.getDistributionSetTypeRestApi() hawkbitClient.getDistributionSetTypeRestApi()
.getDistributionSetTypes(0, 20, Constants.NAME_ASC, null) .getDistributionSetTypes(0, 20, Constants.NAME_ASC, null)
.getBody() .getBody())
.getContent()); .map(PagedList::getContent)
.orElseGet(Collections::emptyList));
tag.setItemLabelGenerator(MgmtTag::getName); tag.setItemLabelGenerator(MgmtTag::getName);
tag.setItems( tag.setItems(Optional.ofNullable(
hawkbitClient.getDistributionSetTagRestApi() hawkbitClient.getDistributionSetTagRestApi()
.getDistributionSetTags(0, 20, Constants.NAME_ASC, null) .getDistributionSetTags(0, 20, Constants.NAME_ASC, null)
.getBody() .getBody())
.getContent()); .map(PagedList::getContent)
.orElseGet(Collections::emptyList));
} }
@Override @Override
@@ -181,14 +185,12 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
lastModifiedBy.setValue(distributionSet.getLastModifiedBy()); lastModifiedBy.setValue(distributionSet.getLastModifiedBy());
lastModifiedAt.setValue(new Date(distributionSet.getLastModifiedAt()).toString()); lastModifiedAt.setValue(new Date(distributionSet.getLastModifiedAt()).toString());
softwareModulesGrid.setItems(query -> softwareModulesGrid.setItems(query -> Optional.ofNullable(
hawkbitClient.getDistributionSetRestApi() hawkbitClient.getDistributionSetRestApi()
.getAssignedSoftwareModules( .getAssignedSoftwareModules(
distributionSet.getDsId(), distributionSet.getDsId(),
query.getOffset(), query.getLimit(), Constants.NAME_ASC) query.getOffset(), query.getLimit(), Constants.NAME_ASC)
.getBody() .getBody()).stream().flatMap(body -> body.getContent().stream()));
.getContent()
.stream());
softwareModulesGrid.setSelectionMode(Grid.SelectionMode.NONE); softwareModulesGrid.setSelectionMode(Grid.SelectionMode.NONE);
} }
} }
@@ -211,11 +213,12 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
type = new Select<>( type = new Select<>(
"Type", "Type",
this::readyToCreate, this::readyToCreate,
hawkbitClient.getDistributionSetTypeRestApi() Optional.ofNullable(
.getDistributionSetTypes(0, 30, Constants.NAME_ASC, null) hawkbitClient.getDistributionSetTypeRestApi()
.getBody() .getDistributionSetTypes(0, 30, Constants.NAME_ASC, null)
.getContent() .getBody())
.toArray(new MgmtDistributionSetType[0])); .map(body -> body.getContent().toArray(new MgmtDistributionSetType[0]))
.orElseGet(() -> new MgmtDistributionSetType[0]));
type.focus(); type.focus();
type.setWidthFull(); type.setWidthFull();
type.setRequiredIndicatorVisible(true); type.setRequiredIndicatorVisible(true);
@@ -258,16 +261,18 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
private void addCreateClickListener() { private void addCreateClickListener() {
create.addClickListener(e -> { create.addClickListener(e -> {
close(); close();
final long distributionSetId = hawkbitClient.getDistributionSetRestApi() final long distributionSetId = Optional.ofNullable(
.createDistributionSets( hawkbitClient.getDistributionSetRestApi()
List.of((MgmtDistributionSetRequestBodyPost) new MgmtDistributionSetRequestBodyPost() .createDistributionSets(
.setType(type.getValue().getKey()) List.of((MgmtDistributionSetRequestBodyPost) new MgmtDistributionSetRequestBodyPost()
.setName(name.getValue()) .setType(type.getValue().getKey())
.setVersion(version.getValue()) .setName(name.getValue())
.setDescription(description.getValue()) .setVersion(version.getValue())
.setRequiredMigrationStep(requiredMigrationStep.getValue()))) .setDescription(description.getValue())
.getBody() .setRequiredMigrationStep(requiredMigrationStep.getValue())))
.getBody())
.stream() .stream()
.flatMap(Collection::stream)
.findFirst() .findFirst()
.orElseThrow() .orElseThrow()
.getDsId(); .getDsId();

View File

@@ -13,6 +13,7 @@ import java.time.ZoneOffset;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -86,12 +87,11 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
() -> details, RolloutDetails::setItem)); () -> details, RolloutDetails::setItem));
} }
}, },
(query, rsqlFilter) -> hawkbitClient.getRolloutRestApi() (query, rsqlFilter) -> Optional.ofNullable(
.getRollouts( hawkbitClient.getRolloutRestApi()
query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter, "full") .getRollouts(
.getBody() query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter, "full")
.getContent() .getBody()).stream().flatMap(page -> page.getContent().stream()),
.stream(),
selectionGrid -> new CreateDialog(hawkbitClient).result(), selectionGrid -> new CreateDialog(hawkbitClient).result(),
selectionGrid -> { selectionGrid -> {
selectionGrid.getSelectedItems().forEach( selectionGrid.getSelectedItems().forEach(
@@ -163,7 +163,10 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
private void refresh() { private void refresh() {
removeAll(); removeAll();
init(hawkbitClient.getRolloutRestApi().getRollout(rolloutId).getBody()); final MgmtRolloutResponseBody body = hawkbitClient.getRolloutRestApi().getRollout(rolloutId).getBody();
if (body != null) {
init(body);
}
} }
} }
@@ -236,7 +239,11 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
targetFilter.setValue(rollout.getTargetFilterQuery()); targetFilter.setValue(rollout.getTargetFilterQuery());
final MgmtDistributionSet distributionSetMgmt = hawkbitClient.getDistributionSetRestApi() final MgmtDistributionSet distributionSetMgmt = hawkbitClient.getDistributionSetRestApi()
.getDistributionSet(rollout.getDistributionSetId()).getBody(); .getDistributionSet(rollout.getDistributionSetId()).getBody();
distributionSet.setValue(distributionSetMgmt.getName() + ":" + distributionSetMgmt.getVersion()); if (distributionSetMgmt == null) { // should not be here
distributionSet.setValue("n/a (null)");
} else {
distributionSet.setValue(distributionSetMgmt.getName() + ":" + distributionSetMgmt.getVersion());
}
actonType.setValue(switch (rollout.getType()) { actonType.setValue(switch (rollout.getType()) {
case SOFT -> Constants.SOFT; case SOFT -> Constants.SOFT;
case FORCED -> Constants.FORCED; case FORCED -> Constants.FORCED;
@@ -246,15 +253,16 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
startAt.setValue(ObjectUtils.isEmpty(rollout.getStartAt()) ? "" : new Date(rollout.getStartAt()).toString()); startAt.setValue(ObjectUtils.isEmpty(rollout.getStartAt()) ? "" : new Date(rollout.getStartAt()).toString());
dynamic.setValue(rollout.isDynamic()); dynamic.setValue(rollout.isDynamic());
groupGrid.setItems(query -> groupGrid.setItems(query -> Optional.ofNullable(
hawkbitClient.getRolloutRestApi() hawkbitClient.getRolloutRestApi()
.getRolloutGroups( .getRolloutGroups(
rollout.getRolloutId(), rollout.getRolloutId(),
query.getOffset(), query.getPageSize(), query.getOffset(), query.getPageSize(),
null, null, "full") null, null, "full")
.getBody().getContent().stream() .getBody())
.skip(query.getOffset()) .stream().flatMap(body -> body.getContent().stream())
.limit(query.getPageSize())); .skip(query.getOffset())
.limit(query.getPageSize()));
groupGrid.setSelectionMode(Grid.SelectionMode.NONE); groupGrid.setSelectionMode(Grid.SelectionMode.NONE);
} }
} }
@@ -283,11 +291,12 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
distributionSet = new Select<>( distributionSet = new Select<>(
"Distribution Set", "Distribution Set",
this::readyToCreate, this::readyToCreate,
hawkbitClient.getDistributionSetRestApi() Optional.ofNullable(
.getDistributionSets(0, 30, Constants.NAME_ASC, null) hawkbitClient.getDistributionSetRestApi()
.getBody() .getDistributionSets(0, 30, Constants.NAME_ASC, null)
.getContent() .getBody())
.toArray(new MgmtDistributionSet[0])); .map(body -> body.getContent().toArray(new MgmtDistributionSet[0]))
.orElseGet(() -> new MgmtDistributionSet[0]));
distributionSet.setRequiredIndicatorVisible(true); distributionSet.setRequiredIndicatorVisible(true);
distributionSet.setItemLabelGenerator(distributionSetO -> distributionSet.setItemLabelGenerator(distributionSetO ->
distributionSetO.getName() + ":" + distributionSetO.getVersion()); distributionSetO.getName() + ":" + distributionSetO.getVersion());
@@ -295,11 +304,12 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
targetFilter = new Select<>( targetFilter = new Select<>(
"Target Filter", "Target Filter",
this::readyToCreate, this::readyToCreate,
hawkbitClient.getTargetFilterQueryRestApi() Optional.ofNullable(
.getFilters(0, 30, Constants.NAME_ASC, null, null) hawkbitClient.getTargetFilterQueryRestApi()
.getBody() .getFilters(0, 30, Constants.NAME_ASC, null, null)
.getContent() .getBody())
.toArray(new MgmtTargetFilterQuery[0])); .map(body -> body.getContent().toArray(new MgmtTargetFilterQuery[0]))
.orElseGet(() -> new MgmtTargetFilterQuery[0]));
targetFilter.setRequiredIndicatorVisible(true); targetFilter.setRequiredIndicatorVisible(true);
targetFilter.setItemLabelGenerator(MgmtTargetFilterQuery::getName); targetFilter.setItemLabelGenerator(MgmtTargetFilterQuery::getName);
targetFilter.setWidthFull(); targetFilter.setWidthFull();

View File

@@ -12,11 +12,13 @@ package org.eclipse.hawkbit.ui.simple.view;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -43,6 +45,7 @@ import com.vaadin.flow.component.upload.receivers.FileBuffer;
import com.vaadin.flow.data.renderer.ComponentRenderer; import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPost;
@@ -87,12 +90,12 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
} }
}, },
(query, rsqlFilter) -> hawkbitClient.getSoftwareModuleRestApi() (query, rsqlFilter) -> Optional.ofNullable(
.getSoftwareModules( hawkbitClient.getSoftwareModuleRestApi()
query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter) .getSoftwareModules(
.getBody() query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter)
.getContent() .getBody())
.stream(), .stream().flatMap(body -> body.getContent().stream()),
isParent ? v -> new CreateDialog(hawkbitClient).result() : null, isParent ? v -> new CreateDialog(hawkbitClient).result() : null,
isParent ? selectionGrid -> { isParent ? selectionGrid -> {
selectionGrid.getSelectedItems().forEach( selectionGrid.getSelectedItems().forEach(
@@ -127,11 +130,11 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
private SoftwareModuleFilter(final HawkbitMgmtClient hawkbitClient) { private SoftwareModuleFilter(final HawkbitMgmtClient hawkbitClient) {
name.setPlaceholder("<name filter>"); name.setPlaceholder("<name filter>");
type.setItemLabelGenerator(MgmtSoftwareModuleType::getName); type.setItemLabelGenerator(MgmtSoftwareModuleType::getName);
type.setItems( type.setItems(Optional.ofNullable(
hawkbitClient.getSoftwareModuleTypeRestApi() hawkbitClient.getSoftwareModuleTypeRestApi()
.getTypes(0, 20, Constants.NAME_ASC, null) .getTypes(0, 20, Constants.NAME_ASC, null)
.getBody() .getBody()).map(PagedList::getContent)
.getContent()); .orElseGet(Collections::emptyList));
} }
@Override @Override
@@ -188,13 +191,14 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
lastModifiedBy.setValue(softwareModule.getLastModifiedBy()); lastModifiedBy.setValue(softwareModule.getLastModifiedBy());
lastModifiedAt.setValue(new Date(softwareModule.getLastModifiedAt()).toString()); lastModifiedAt.setValue(new Date(softwareModule.getLastModifiedAt()).toString());
artifactGrid.setItems(query -> artifactGrid.setItems(query -> Optional.ofNullable(
hawkbitClient.getSoftwareModuleRestApi() hawkbitClient.getSoftwareModuleRestApi()
.getArtifacts( .getArtifacts(
softwareModule.getModuleId(), null, null) softwareModule.getModuleId(), null, null)
.getBody().stream() .getBody())
.skip(query.getOffset()) .stream().flatMap(Collection::stream)
.limit(query.getPageSize())); .skip(query.getOffset())
.limit(query.getPageSize()));
artifactGrid.setSelectionMode(Grid.SelectionMode.NONE); artifactGrid.setSelectionMode(Grid.SelectionMode.NONE);
} }
} }
@@ -215,11 +219,11 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
type = new Select<>( type = new Select<>(
Constants.TYPE, Constants.TYPE,
this::readyToCreate, this::readyToCreate,
hawkbitClient.getSoftwareModuleTypeRestApi() Optional.ofNullable(
.getTypes(0, 30, Constants.NAME_ASC, null) hawkbitClient.getSoftwareModuleTypeRestApi()
.getBody() .getTypes(0, 30, Constants.NAME_ASC, null)
.getContent() .getBody()).map(body -> body.getContent().toArray(new MgmtSoftwareModuleType[0]))
.toArray(new MgmtSoftwareModuleType[0])); .orElseGet(() -> new MgmtSoftwareModuleType[0]));
type.setWidthFull(); type.setWidthFull();
type.setRequiredIndicatorVisible(true); type.setRequiredIndicatorVisible(true);
type.setItemLabelGenerator(MgmtSoftwareModuleType::getName); type.setItemLabelGenerator(MgmtSoftwareModuleType::getName);
@@ -261,16 +265,17 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
private void addCreateClickListener(final HawkbitMgmtClient hawkbitClient) { private void addCreateClickListener(final HawkbitMgmtClient hawkbitClient) {
create.addClickListener(e -> { create.addClickListener(e -> {
close(); close();
final long softwareModuleId = hawkbitClient.getSoftwareModuleRestApi().createSoftwareModules( final long softwareModuleId = Optional.ofNullable(
List.of(new MgmtSoftwareModuleRequestBodyPost() hawkbitClient.getSoftwareModuleRestApi().createSoftwareModules(
.setType(type.getValue().getKey()) List.of(new MgmtSoftwareModuleRequestBodyPost()
.setName(name.getValue()) .setType(type.getValue().getKey())
.setVersion(version.getValue()) .setName(name.getValue())
.setVendor(vendor.getValue()) .setVersion(version.getValue())
.setDescription(description.getValue()) .setVendor(vendor.getValue())
.setEncrypted(enableArtifactEncryption.getValue()))) .setDescription(description.getValue())
.getBody() .setEncrypted(enableArtifactEncryption.getValue())))
.stream() .getBody())
.stream().flatMap(Collection::stream)
.findFirst() .findFirst()
.orElseThrow() .orElseThrow()
.getModuleId(); .getModuleId();