SoftwareModuleView small improvements (#2377)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-04-28 12:19:11 +03:00
committed by GitHub
parent 88a0ac7256
commit 30c0ae3cc2

View File

@@ -90,17 +90,14 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
grid.addColumn(MgmtSoftwareModule::getTypeName).setHeader(Constants.TYPE).setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getTypeName).setHeader(Constants.TYPE).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getVendor).setHeader(Constants.VENDOR).setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getVendor).setHeader(Constants.VENDOR).setAutoWidth(true);
grid.setItemDetailsRenderer(new ComponentRenderer<>( grid.setItemDetailsRenderer(new ComponentRenderer<>(() -> details, SoftwareModuleDetails::setItem));
() -> details, SoftwareModuleDetails::setItem));
} }
}, },
(query, rsqlFilter) -> Optional.ofNullable( (query, rsqlFilter) -> Optional.ofNullable(
hawkbitClient.getSoftwareModuleRestApi() hawkbitClient.getSoftwareModuleRestApi()
.getSoftwareModules( .getSoftwareModules(query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter)
query.getOffset(), query.getPageSize(), Constants.NAME_ASC, rsqlFilter)
.getBody()) .getBody())
.stream().flatMap(body -> body.getContent().stream()), .stream().map(PagedList::getContent).flatMap(List::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(
@@ -138,7 +135,8 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
type.setItems(Optional.ofNullable( type.setItems(Optional.ofNullable(
hawkbitClient.getSoftwareModuleTypeRestApi() hawkbitClient.getSoftwareModuleTypeRestApi()
.getTypes(0, 20, Constants.NAME_ASC, null) .getTypes(0, 20, Constants.NAME_ASC, null)
.getBody()).map(PagedList::getContent) .getBody())
.map(PagedList::getContent)
.orElseGet(Collections::emptyList)); .orElseGet(Collections::emptyList));
} }
@@ -152,8 +150,7 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
return Filter.filter( return Filter.filter(
Map.of( Map.of(
"name", name.getOptionalValue(), "name", name.getOptionalValue(),
"type", type.getSelectedItems().stream().map(MgmtSoftwareModuleType::getKey) "type", type.getSelectedItems().stream().map(MgmtSoftwareModuleType::getKey).toList()
.toList()
)); ));
} }
} }
@@ -174,14 +171,10 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
description.setMinLength(2); description.setMinLength(2);
artifactGrid = createArtifactGrid(); artifactGrid = createArtifactGrid();
Stream.of( Stream.of(description, createdBy, createdAt, lastModifiedBy, lastModifiedAt).forEach(field -> {
description, field.setReadOnly(true);
createdBy, createdAt, add(field);
lastModifiedBy, lastModifiedAt) });
.forEach(field -> {
field.setReadOnly(true);
add(field);
});
add(artifactGrid); add(artifactGrid);
setResponsiveSteps(new ResponsiveStep("0", 2)); setResponsiveSteps(new ResponsiveStep("0", 2));
@@ -198,10 +191,10 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
artifactGrid.setItems(query -> Optional.ofNullable( artifactGrid.setItems(query -> Optional.ofNullable(
hawkbitClient.getSoftwareModuleRestApi() hawkbitClient.getSoftwareModuleRestApi()
.getArtifacts( .getArtifacts(softwareModule.getId(), null, null)
softwareModule.getId(), null, null)
.getBody()) .getBody())
.stream().flatMap(Collection::stream) .stream()
.flatMap(Collection::stream)
.skip(query.getOffset()) .skip(query.getOffset())
.limit(query.getPageSize())); .limit(query.getPageSize()));
artifactGrid.setSelectionMode(Grid.SelectionMode.NONE); artifactGrid.setSelectionMode(Grid.SelectionMode.NONE);
@@ -230,12 +223,14 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
Optional.ofNullable( Optional.ofNullable(
hawkbitClient.getSoftwareModuleTypeRestApi() hawkbitClient.getSoftwareModuleTypeRestApi()
.getTypes(0, 30, Constants.NAME_ASC, null) .getTypes(0, 30, Constants.NAME_ASC, null)
.getBody()).map(body -> body.getContent().toArray(new MgmtSoftwareModuleType[0])) .getBody())
.map(body -> body.getContent().toArray(new MgmtSoftwareModuleType[0]))
.orElseGet(() -> 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);
type.focus(); type.focus();
name = Utils.textField(Constants.NAME, this::readyToCreate); name = Utils.textField(Constants.NAME, this::readyToCreate);
version = Utils.textField(Constants.VERSION, this::readyToCreate); version = Utils.textField(Constants.VERSION, this::readyToCreate);
vendor = Utils.textField(Constants.VENDOR); vendor = Utils.textField(Constants.VENDOR);
@@ -244,18 +239,7 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
description.setMinLength(2); description.setMinLength(2);
enableArtifactEncryption = new Checkbox("Enable artifact encryption"); enableArtifactEncryption = new Checkbox("Enable artifact encryption");
createDistributionSet = new Checkbox("Also create distribution set"); distType = new Select<>("Distribution Set Type", this::readyToCreate);
createDistributionSet.setHelperText("based on this software module");
distType = new Select<>(
"Distribution Set Type",
this::readyToCreate,
Optional.ofNullable(
hawkbitClient.getDistributionSetTypeRestApi()
.getDistributionSetTypes(0, 30, Constants.NAME_ASC, null)
.getBody())
.map(body -> body.getContent().toArray(new MgmtDistributionSetType[0]))
.orElseGet(() -> new MgmtDistributionSetType[0]));
distType.setWidthFull(); distType.setWidthFull();
distType.setRequiredIndicatorVisible(true); distType.setRequiredIndicatorVisible(true);
distType.setItemLabelGenerator(MgmtDistributionSetType::getName); distType.setItemLabelGenerator(MgmtDistributionSetType::getName);
@@ -264,10 +248,21 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
distRequiredMigrationStep = new Checkbox("Required Migration Step"); distRequiredMigrationStep = new Checkbox("Required Migration Step");
distRequiredMigrationStep.setVisible(false); distRequiredMigrationStep.setVisible(false);
createDistributionSet.addValueChangeListener(evt -> { createDistributionSet = new Checkbox("Create single software module distribution set");
createDistributionSet.setHelperText("Create single software module distribution set with this software module");
createDistributionSet.addValueChangeListener(e -> {
if (Boolean.TRUE.equals(createDistributionSet.getValue()) && distType.isEmpty()) {
distType.setItems(
Optional.ofNullable(
hawkbitClient.getDistributionSetTypeRestApi()
.getDistributionSetTypes(0, 30, Constants.NAME_ASC, null)
.getBody())
.map(body -> body.getContent().toArray(new MgmtDistributionSetType[0]))
.orElseGet(() -> new MgmtDistributionSetType[0]));
}
distType.setVisible(createDistributionSet.getValue()); distType.setVisible(createDistributionSet.getValue());
distRequiredMigrationStep.setVisible(createDistributionSet.getValue()); distRequiredMigrationStep.setVisible(createDistributionSet.getValue());
this.readyToCreate(evt); readyToCreate(e);
}); });
create = Utils.tooltip(new Button("Create"), "Create (Enter)"); create = Utils.tooltip(new Button("Create"), "Create (Enter)");
@@ -284,7 +279,10 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
final VerticalLayout layout = new VerticalLayout(); final VerticalLayout layout = new VerticalLayout();
layout.setSizeFull(); layout.setSizeFull();
layout.setSpacing(false); layout.setSpacing(false);
layout.add(type, name, version, vendor, description, enableArtifactEncryption, createDistributionSet, distType, distRequiredMigrationStep, actions); layout.add(
type, name, version, vendor, description, enableArtifactEncryption,
createDistributionSet, distType, distRequiredMigrationStep,
actions);
add(layout); add(layout);
open(); open();
} }
@@ -316,23 +314,23 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
.getId(); .getId();
if (Boolean.TRUE.equals(createDistributionSet.getValue())) { if (Boolean.TRUE.equals(createDistributionSet.getValue())) {
final long distributionSetId = Optional.ofNullable( final long distributionSetId = Optional.ofNullable(
hawkbitClient.getDistributionSetRestApi() hawkbitClient.getDistributionSetRestApi()
.createDistributionSets( .createDistributionSets(
List.of((MgmtDistributionSetRequestBodyPost) new MgmtDistributionSetRequestBodyPost() List.of((MgmtDistributionSetRequestBodyPost) new MgmtDistributionSetRequestBodyPost()
.setType(distType.getValue().getKey()) .setType(distType.getValue().getKey())
.setName(name.getValue()) .setName(name.getValue())
.setVersion(version.getValue()) .setVersion(version.getValue())
.setDescription(description.getValue()) .setDescription(description.getValue())
.setRequiredMigrationStep(distRequiredMigrationStep.getValue()))) .setRequiredMigrationStep(distRequiredMigrationStep.getValue())))
.getBody()) .getBody())
.stream() .stream()
.flatMap(Collection::stream) .flatMap(Collection::stream)
.findFirst() .findFirst()
.orElseThrow() .orElseThrow()
.getId(); .getId();
hawkbitClient.getDistributionSetRestApi().assignSoftwareModules( hawkbitClient.getDistributionSetRestApi().assignSoftwareModules(
distributionSetId, List.of((MgmtSoftwareModuleAssignment) new MgmtSoftwareModuleAssignment() distributionSetId, List.of((MgmtSoftwareModuleAssignment) new MgmtSoftwareModuleAssignment()
.setId(softwareModuleId))).getBody(); .setId(softwareModuleId))).getBody();
} }
new AddArtifactsDialog(softwareModuleId, hawkbitClient).open(); new AddArtifactsDialog(softwareModuleId, hawkbitClient).open();
}); });
@@ -441,4 +439,4 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
} }
} }
} }
} }