Fix Sonar findings of Simple UI (#1507)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2023-12-10 00:52:28 +02:00
committed by GitHub
parent 5468218615
commit dfd4edb7e6
12 changed files with 225 additions and 170 deletions

View File

@@ -47,7 +47,7 @@ public class MainLayout extends AppLayout {
private H2 viewTitle; private H2 viewTitle;
private final AuthenticatedUser authenticatedUser; private final transient AuthenticatedUser authenticatedUser;
private final AccessAnnotationChecker accessChecker; private final AccessAnnotationChecker accessChecker;
public MainLayout(final AuthenticatedUser authenticatedUser, final AccessAnnotationChecker accessChecker) { public MainLayout(final AuthenticatedUser authenticatedUser, final AccessAnnotationChecker accessChecker) {

View File

@@ -83,7 +83,11 @@ public class SimpleUIApp implements AppShellConfigurator {
return new UsernamePasswordAuthenticationToken( return new UsernamePasswordAuthenticationToken(
username, password, username, password,
roles.stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role)).toList()) { roles.stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role)).toList()) {
public void eraseCredentials() {} @Override
public void eraseCredentials() {
// don't erase credentials because they will be used
// to authenticate to the hawkBit update server / mgmt server
}
}; };
}; };
} }

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package com.eclipse.hawkbit.ui.view;
public interface Constants {
// properties
String ID = "Id";
String NAME = "Name";
String DESCRIPTION = "Description";
String VERSION = "Version";
String VENDOR = "Vendor";
String TYPE = "Type";
String CREATED_BY = "Created by";
String CREATED_AT = "Created at";
String LAST_MODIFIED_BY = "Last modified by";
String LAST_MODIFIED_AT = "Last modified at";
// rollout
String GROUP_COUNT = "Group Count";
String TARGET_COUNT = "Target Count";
String STATS = "Stats";
String STATUS = "Status";
String ACTIONS = "Actions";
// create rollout
String TARGET_FILTER = "Target Filter";
String DISTRIBUTION_SET = "Distribution Set";
String ACTION_TYPE = "Action Type";
String START_AT = "Start At";
String SOFT = "Soft";
String FORCED = "Forced";
String DOWNLOAD_ONLY = "Download Only";
String START_TYPE = "Start Type";
String MANUAL = "Manual";
String AUTO = "Auto";
String NAME_ASC = "name:asc";
}

View File

@@ -65,10 +65,10 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
@Override @Override
protected void addColumns(Grid<MgmtDistributionSet> grid) { protected void addColumns(Grid<MgmtDistributionSet> grid) {
grid.addColumn(MgmtDistributionSet::getDsId).setHeader("Id").setAutoWidth(true); grid.addColumn(MgmtDistributionSet::getDsId).setHeader(ID).setAutoWidth(true);
grid.addColumn(MgmtDistributionSet::getName).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtDistributionSet::getName).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtDistributionSet::getVersion).setHeader("Version").setAutoWidth(true); grid.addColumn(MgmtDistributionSet::getVersion).setHeader(VERSION).setAutoWidth(true);
grid.addColumn(MgmtDistributionSet::getTypeName).setHeader("Type").setAutoWidth(true); grid.addColumn(MgmtDistributionSet::getTypeName).setHeader(TYPE).setAutoWidth(true);
grid.setItemDetailsRenderer(new ComponentRenderer<>( grid.setItemDetailsRenderer(new ComponentRenderer<>(
() -> details, DistributionSetDetails::setItem)); () -> details, DistributionSetDetails::setItem));
@@ -76,7 +76,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
}, },
(query, rsqlFilter) -> hawkbitClient.getDistributionSetRestApi() (query, rsqlFilter) -> hawkbitClient.getDistributionSetRestApi()
.getDistributionSets( .getDistributionSets(
query.getOffset(), query.getPageSize(), "name:asc", rsqlFilter) query.getOffset(), query.getPageSize(), NAME_ASC, rsqlFilter)
.getBody() .getBody()
.getContent() .getContent()
.stream(), .stream(),
@@ -95,10 +95,11 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
MgmtSoftwareModule.class, MgmtSoftwareModule::getModuleId) { MgmtSoftwareModule.class, MgmtSoftwareModule::getModuleId) {
@Override @Override
protected void addColumns(Grid<MgmtSoftwareModule> grid) { protected void addColumns(Grid<MgmtSoftwareModule> grid) {
grid.addColumn(MgmtSoftwareModule::getModuleId).setHeader("Id").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getModuleId).setHeader(ID).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getVersion).setHeader("Version").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getName).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getTypeName).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getVersion).setHeader(VERSION).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getVendor).setHeader("Vendor").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getTypeName).setHeader(TYPE).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getVendor).setHeader(VENDOR).setAutoWidth(true);
} }
}); });
} }
@@ -114,13 +115,13 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
type.setItemLabelGenerator(MgmtDistributionSetType::getName); type.setItemLabelGenerator(MgmtDistributionSetType::getName);
type.setItems( type.setItems(
hawkbitClient.getDistributionSetTypeRestApi() hawkbitClient.getDistributionSetTypeRestApi()
.getDistributionSetTypes(0, 20, "name:asc", null) .getDistributionSetTypes(0, 20, NAME_ASC, null)
.getBody() .getBody()
.getContent()); .getContent());
tag.setItemLabelGenerator(MgmtTag::getName); tag.setItemLabelGenerator(MgmtTag::getName);
tag.setItems( tag.setItems(
hawkbitClient.getDistributionSetTagRestApi() hawkbitClient.getDistributionSetTagRestApi()
.getDistributionSetTags(0, 20, "name:asc", null) .getDistributionSetTags(0, 20, NAME_ASC, null)
.getBody() .getBody()
.getContent()); .getContent());
} }
@@ -143,7 +144,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
private static class DistributionSetDetails extends FormLayout { private static class DistributionSetDetails extends FormLayout {
private final HawkbitClient hawkbitClient; private final transient HawkbitClient hawkbitClient;
private final TextArea description = new TextArea("Description"); private final TextArea description = new TextArea("Description");
private final TextField createdBy = Utils.textField("Created by"); private final TextField createdBy = Utils.textField("Created by");
@@ -182,7 +183,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
hawkbitClient.getDistributionSetRestApi() hawkbitClient.getDistributionSetRestApi()
.getAssignedSoftwareModules( .getAssignedSoftwareModules(
distributionSet.getDsId(), distributionSet.getDsId(),
query.getOffset(), query.getLimit(), "name:asc") query.getOffset(), query.getLimit(), NAME_ASC)
.getBody() .getBody()
.getContent() .getContent()
.stream()); .stream());
@@ -192,7 +193,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
private static class CreateDialog extends Utils.BaseDialog<Void> { private static class CreateDialog extends Utils.BaseDialog<Void> {
private final HawkbitClient hawkbitClient; private final transient HawkbitClient hawkbitClient;
private final Select<MgmtDistributionSetType> type; private final Select<MgmtDistributionSetType> type;
private final TextField name; private final TextField name;
@@ -209,7 +210,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
"Type", "Type",
this::readyToCreate, this::readyToCreate,
hawkbitClient.getDistributionSetTypeRestApi() hawkbitClient.getDistributionSetTypeRestApi()
.getDistributionSetTypes(0, 30, "name:asc", null) .getDistributionSetTypes(0, 30, NAME_ASC, null)
.getBody() .getBody()
.getContent() .getContent()
.toArray(new MgmtDistributionSetType[0])); .toArray(new MgmtDistributionSetType[0]));
@@ -217,13 +218,13 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
type.setWidthFull(); type.setWidthFull();
type.setRequiredIndicatorVisible(true); type.setRequiredIndicatorVisible(true);
type.setItemLabelGenerator(MgmtDistributionSetType::getName); type.setItemLabelGenerator(MgmtDistributionSetType::getName);
name = Utils.textField("Name", this::readyToCreate); name = Utils.textField(NAME, this::readyToCreate);
version = Utils.textField("Version", this::readyToCreate); version = Utils.textField(VERSION, this::readyToCreate);
final TextField vendor = Utils.textField("Vendor"); final TextField vendor = Utils.textField(VENDOR);
description = new TextArea("Description"); description = new TextArea(DESCRIPTION);
description.setWidthFull(); description.setWidthFull();
description.setMinLength(2); description.setMinLength(2);
requiredMigrationStep = new Checkbox("Reguired Migration Step"); requiredMigrationStep = new Checkbox("Required Migration Step");
create = Utils.tooltip(new Button("Create"), "Create (Enter)"); create = Utils.tooltip(new Button("Create"), "Create (Enter)");
create.setEnabled(false); create.setEnabled(false);
@@ -275,7 +276,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
private static class AddSoftwareModulesDialog extends Utils.BaseDialog<Void> { private static class AddSoftwareModulesDialog extends Utils.BaseDialog<Void> {
private final Set<MgmtSoftwareModule> softwareModules = Collections.synchronizedSet(new HashSet<>()); private final transient Set<MgmtSoftwareModule> softwareModules = Collections.synchronizedSet(new HashSet<>());
private AddSoftwareModulesDialog(final long distributionSetId, final HawkbitClient hawkbitClient) { private AddSoftwareModulesDialog(final long distributionSetId, final HawkbitClient hawkbitClient) {
super("Add Software Modules"); super("Add Software Modules");
@@ -304,7 +305,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
softwareModulesGrid.refreshGrid(false); softwareModulesGrid.refreshGrid(false);
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
}, },
softwareModulesGrid, true).get(); softwareModulesGrid, true);
final Button finishBtn = Utils.tooltip(new Button("Finish"), "Finish (Esc)"); final Button finishBtn = Utils.tooltip(new Button("Finish"), "Finish (Esc)");
finishBtn.addClickListener(e -> { finishBtn.addClickListener(e -> {
hawkbitClient.getDistributionSetRestApi().assignSoftwareModules( hawkbitClient.getDistributionSetRestApi().assignSoftwareModules(

View File

@@ -25,7 +25,7 @@ import com.vaadin.flow.server.auth.AnonymousAllowed;
@Route(value = "login") @Route(value = "login")
public class LoginView extends LoginOverlay implements BeforeEnterObserver { public class LoginView extends LoginOverlay implements BeforeEnterObserver {
private final AuthenticatedUser authenticatedUser; private final transient AuthenticatedUser authenticatedUser;
public LoginView(final AuthenticatedUser authenticatedUser) { public LoginView(final AuthenticatedUser authenticatedUser) {
this.authenticatedUser = authenticatedUser; this.authenticatedUser = authenticatedUser;

View File

@@ -62,21 +62,21 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
public RolloutView(final HawkbitClient hawkbitClient) { public RolloutView(final HawkbitClient hawkbitClient) {
super( super(
new RolloutFilter(hawkbitClient), new RolloutFilter(),
new SelectionGrid.EntityRepresentation<>( new SelectionGrid.EntityRepresentation<>(
MgmtRolloutResponseBody.class, MgmtRolloutResponseBody::getRolloutId) { MgmtRolloutResponseBody.class, MgmtRolloutResponseBody::getRolloutId) {
private final RolloutDetails details = new RolloutDetails(hawkbitClient); private final RolloutDetails details = new RolloutDetails(hawkbitClient);
@Override @Override
protected void addColumns(final Grid<MgmtRolloutResponseBody> grid) { protected void addColumns(final Grid<MgmtRolloutResponseBody> grid) {
grid.addColumn(MgmtRolloutResponseBody::getRolloutId).setHeader("Id").setAutoWidth(true); grid.addColumn(MgmtRolloutResponseBody::getRolloutId).setHeader(ID).setAutoWidth(true);
grid.addColumn(MgmtRolloutResponseBody::getName).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtRolloutResponseBody::getName).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtRolloutResponseBody::getTotalGroups).setHeader("Group Count").setAutoWidth(true); grid.addColumn(MgmtRolloutResponseBody::getTotalGroups).setHeader(GROUP_COUNT).setAutoWidth(true);
grid.addColumn(MgmtRolloutResponseBody::getTotalTargets).setHeader("Target Count").setAutoWidth(true); grid.addColumn(MgmtRolloutResponseBody::getTotalTargets).setHeader(TARGET_COUNT).setAutoWidth(true);
grid.addColumn(MgmtRolloutResponseBody::getTotalTargetsPerStatus).setHeader("Stats").setAutoWidth(true); grid.addColumn(MgmtRolloutResponseBody::getTotalTargetsPerStatus).setHeader(STATS).setAutoWidth(true);
grid.addColumn(MgmtRolloutResponseBody::getStatus).setHeader("Status").setAutoWidth(true); grid.addColumn(MgmtRolloutResponseBody::getStatus).setHeader(STATUS).setAutoWidth(true);
grid.addComponentColumn(rollout -> new Actions(rollout, grid, hawkbitClient)).setHeader("Actions").setAutoWidth(true); grid.addComponentColumn(rollout -> new Actions(rollout, grid, hawkbitClient)).setHeader(ACTIONS).setAutoWidth(true);
grid.setItemDetailsRenderer(new ComponentRenderer<>( grid.setItemDetailsRenderer(new ComponentRenderer<>(
() -> details, RolloutDetails::setItem)); () -> details, RolloutDetails::setItem));
@@ -84,7 +84,7 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
}, },
(query, rsqlFilter) -> hawkbitClient.getRolloutRestApi() (query, rsqlFilter) -> hawkbitClient.getRolloutRestApi()
.getRollouts( .getRollouts(
query.getOffset(), query.getPageSize(), "name:asc", rsqlFilter, null) query.getOffset(), query.getPageSize(), NAME_ASC, rsqlFilter, null)
.getBody() .getBody()
.getContent() .getContent()
.stream(), .stream(),
@@ -102,11 +102,11 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
new SelectionGrid.EntityRepresentation<>(MgmtRolloutGroupResponseBody.class, MgmtRolloutGroupResponseBody::getRolloutGroupId) { new SelectionGrid.EntityRepresentation<>(MgmtRolloutGroupResponseBody.class, MgmtRolloutGroupResponseBody::getRolloutGroupId) {
@Override @Override
protected void addColumns(final Grid<MgmtRolloutGroupResponseBody> grid) { protected void addColumns(final Grid<MgmtRolloutGroupResponseBody> grid) {
grid.addColumn(MgmtRolloutGroupResponseBody::getRolloutGroupId).setHeader("Id").setAutoWidth(true); grid.addColumn(MgmtRolloutGroupResponseBody::getRolloutGroupId).setHeader(ID).setAutoWidth(true);
grid.addColumn(MgmtRolloutGroupResponseBody::getName).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtRolloutGroupResponseBody::getName).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtRolloutGroupResponseBody::getTotalTargets).setHeader("Target Count").setAutoWidth(true); grid.addColumn(MgmtRolloutGroupResponseBody::getTotalTargets).setHeader(TARGET_COUNT).setAutoWidth(true);
grid.addColumn(MgmtRolloutGroupResponseBody::getTotalTargetsPerStatus).setHeader("Stats").setAutoWidth(true); grid.addColumn(MgmtRolloutGroupResponseBody::getTotalTargetsPerStatus).setHeader(STATS).setAutoWidth(true);
grid.addColumn(MgmtRolloutGroupResponseBody::getStatus).setHeader("Status").setAutoWidth(true); grid.addColumn(MgmtRolloutGroupResponseBody::getStatus).setHeader(STATUS).setAutoWidth(true);
} }
}); });
} }
@@ -115,7 +115,7 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
private final long rolloutId; private final long rolloutId;
private final Grid<MgmtRolloutResponseBody> grid; private final Grid<MgmtRolloutResponseBody> grid;
private final HawkbitClient hawkbitClient; private final transient HawkbitClient hawkbitClient;
private Actions(final MgmtRolloutResponseBody rollout, final Grid<MgmtRolloutResponseBody> grid, final HawkbitClient hawkbitClient) { private Actions(final MgmtRolloutResponseBody rollout, final Grid<MgmtRolloutResponseBody> grid, final HawkbitClient hawkbitClient) {
this.rolloutId = rollout.getRolloutId(); this.rolloutId = rollout.getRolloutId();
@@ -163,9 +163,9 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
private static class RolloutFilter implements Filter.Rsql { private static class RolloutFilter implements Filter.Rsql {
private final TextField name = Utils.textField("Name"); private final TextField name = Utils.textField(NAME);
private RolloutFilter(final HawkbitClient hawkbitClient) { private RolloutFilter() {
name.setPlaceholder("<name filter>"); name.setPlaceholder("<name filter>");
} }
@@ -182,17 +182,17 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
private static class RolloutDetails extends FormLayout { private static class RolloutDetails extends FormLayout {
private final HawkbitClient hawkbitClient; private final transient HawkbitClient hawkbitClient;
private final TextArea description = new TextArea("Description"); private final TextArea description = new TextArea(DESCRIPTION);
private final TextField createdBy = Utils.textField("Created by"); private final TextField createdBy = Utils.textField(CREATED_BY);
private final TextField createdAt = Utils.textField("Created at"); private final TextField createdAt = Utils.textField(CREATED_AT);
private final TextField lastModifiedBy = Utils.textField("Last modified by"); private final TextField lastModifiedBy = Utils.textField(LAST_MODIFIED_BY);
private final TextField lastModifiedAt = Utils.textField("Last modified at"); private final TextField lastModifiedAt = Utils.textField(LAST_MODIFIED_AT);
private final TextField targetFilter = Utils.textField("Target Filter"); private final TextField targetFilter = Utils.textField(TARGET_FILTER);
private final TextField distributionSet = Utils.textField("Distribution Set"); private final TextField distributionSet = Utils.textField(DISTRIBUTION_SET);
private final TextField actonType = Utils.textField("Action Type"); private final TextField actonType = Utils.textField(ACTION_TYPE);
private final TextField startAt = Utils.textField("Start At"); private final TextField startAt = Utils.textField(START_AT);
private final SelectionGrid<MgmtRolloutGroupResponseBody, Long> groupGrid; private final SelectionGrid<MgmtRolloutGroupResponseBody, Long> groupGrid;
private RolloutDetails(final HawkbitClient hawkbitClient) { private RolloutDetails(final HawkbitClient hawkbitClient) {
@@ -228,9 +228,9 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
.getDistributionSet(rollout.getDistributionSetId()).getBody(); .getDistributionSet(rollout.getDistributionSetId()).getBody();
distributionSet.setValue(distributionSetMgmt.getName() + ":" + distributionSetMgmt.getVersion()); distributionSet.setValue(distributionSetMgmt.getName() + ":" + distributionSetMgmt.getVersion());
actonType.setValue(switch (rollout.getType()) { actonType.setValue(switch (rollout.getType()) {
case SOFT -> "Soft"; case SOFT -> SOFT;
case FORCED -> "Forced"; case FORCED -> FORCED;
case DOWNLOAD_ONLY -> "Download Only"; case DOWNLOAD_ONLY -> DOWNLOAD_ONLY;
case TIMEFORCED -> "Scheduled at " + new Date(rollout.getForcetime()); case TIMEFORCED -> "Scheduled at " + new Date(rollout.getForcetime());
}); });
startAt.setValue(ObjectUtils.isEmpty(rollout.getStartAt()) ? "" : new Date(rollout.getStartAt()).toString()); startAt.setValue(ObjectUtils.isEmpty(rollout.getStartAt()) ? "" : new Date(rollout.getStartAt()).toString());
@@ -261,7 +261,7 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
private final Select<MgmtActionType> actionType; private final Select<MgmtActionType> actionType;
private final DateTimePicker forceTime = new DateTimePicker("Force Time"); private final DateTimePicker forceTime = new DateTimePicker("Force Time");
private final Select<StartType> startType; private final Select<StartType> startType;
private final DateTimePicker startAt = new DateTimePicker("Start At"); private final DateTimePicker startAt = new DateTimePicker(START_AT);
private final NumberField groupNumber; private final NumberField groupNumber;
private final NumberField triggerThreshold; private final NumberField triggerThreshold;
private final NumberField errorThreshold; private final NumberField errorThreshold;
@@ -277,66 +277,66 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
"Distribution Set", "Distribution Set",
this::readyToCreate, this::readyToCreate,
hawkbitClient.getDistributionSetRestApi() hawkbitClient.getDistributionSetRestApi()
.getDistributionSets(0, 30, "name:asc", null) .getDistributionSets(0, 30, NAME_ASC, null)
.getBody() .getBody()
.getContent() .getContent()
.toArray(new MgmtDistributionSet[0])); .toArray(new MgmtDistributionSet[0]));
distributionSet.setRequiredIndicatorVisible(true); distributionSet.setRequiredIndicatorVisible(true);
distributionSet.setItemLabelGenerator(distributionSet -> distributionSet.setItemLabelGenerator(distributionSetO ->
distributionSet.getName() + ":" + distributionSet.getVersion()); distributionSetO.getName() + ":" + distributionSetO.getVersion());
distributionSet.setWidthFull(); distributionSet.setWidthFull();
targetFilter = new Select<>( targetFilter = new Select<>(
"Target Filter", "Target Filter",
this::readyToCreate, this::readyToCreate,
hawkbitClient.getTargetFilterQueryRestApi() hawkbitClient.getTargetFilterQueryRestApi()
.getFilters(0, 30, "name:asc", null, null) .getFilters(0, 30, NAME_ASC, null, null)
.getBody() .getBody()
.getContent() .getContent()
.toArray(new MgmtTargetFilterQuery[0])); .toArray(new MgmtTargetFilterQuery[0]));
targetFilter.setRequiredIndicatorVisible(true); targetFilter.setRequiredIndicatorVisible(true);
targetFilter.setItemLabelGenerator(MgmtTargetFilterQuery::getName); targetFilter.setItemLabelGenerator(MgmtTargetFilterQuery::getName);
targetFilter.setWidthFull(); targetFilter.setWidthFull();
description = new TextArea("Description"); description = new TextArea(DESCRIPTION);
description.setMinLength(2); description.setMinLength(2);
description.setWidthFull(); description.setWidthFull();
actionType = new Select<>(); actionType = new Select<>();
actionType.setLabel("Action Type"); actionType.setLabel(ACTION_TYPE);
actionType.setItems(MgmtActionType.values()); actionType.setItems(MgmtActionType.values());
actionType.setValue(MgmtActionType.FORCED); actionType.setValue(MgmtActionType.FORCED);
final ComponentRenderer<Component, MgmtActionType> actionTypeRenderer = new ComponentRenderer<>(actionType -> final ComponentRenderer<Component, MgmtActionType> actionTypeRenderer = new ComponentRenderer<>(actionTypeO ->
switch (actionType) { switch (actionTypeO) {
case SOFT -> new Text("Soft"); case SOFT -> new Text(SOFT);
case FORCED -> new Text("Forced"); case FORCED -> new Text(FORCED);
case DOWNLOAD_ONLY -> new Text("Download Only"); case DOWNLOAD_ONLY -> new Text(DOWNLOAD_ONLY);
case TIMEFORCED -> forceTime; case TIMEFORCED -> forceTime;
}); });
actionType.addValueChangeListener(e -> actionType.setRenderer(actionTypeRenderer)); actionType.addValueChangeListener(e -> actionType.setRenderer(actionTypeRenderer));
actionType.setItemLabelGenerator(startType -> actionType.setItemLabelGenerator(startTypeO ->
switch (startType) { switch (startTypeO) {
case SOFT -> "Soft"; case SOFT -> SOFT;
case FORCED -> "Forced"; case FORCED -> FORCED;
case DOWNLOAD_ONLY -> "Download Only"; case DOWNLOAD_ONLY -> DOWNLOAD_ONLY;
case TIMEFORCED -> "Time Forced at " + (forceTime.isEmpty() ? "" : " " + forceTime.getValue()); case TIMEFORCED -> "Time Forced at " + (forceTime.isEmpty() ? "" : " " + forceTime.getValue());
}); });
actionType.setWidthFull(); actionType.setWidthFull();
startType = new Select<>(); startType = new Select<>();
startType.setValue(StartType.MANUAL); startType.setValue(StartType.MANUAL);
startType.setLabel("Start Type"); startType.setLabel(START_TYPE);
startType.setItems(StartType.values()); startType.setItems(StartType.values());
startType.setValue(StartType.MANUAL); startType.setValue(StartType.MANUAL);
final ComponentRenderer<Component, StartType> startTypeRenderer = new ComponentRenderer<>(startType -> final ComponentRenderer<Component, StartType> startTypeRenderer = new ComponentRenderer<>(startTypeO ->
switch (startType) { switch (startTypeO) {
case MANUAL -> new Text("Manual"); case MANUAL -> new Text(MANUAL);
case AUTO -> new Text("Auto"); case AUTO -> new Text(AUTO);
case SCHEDULED -> startAt; case SCHEDULED -> startAt;
}); });
startType.setRenderer(startTypeRenderer); startType.setRenderer(startTypeRenderer);
startType.addValueChangeListener(e -> startType.setRenderer(startTypeRenderer)); startType.addValueChangeListener(e -> startType.setRenderer(startTypeRenderer));
startType.setItemLabelGenerator(startType -> startType.setItemLabelGenerator(startType ->
switch (startType) { switch (startType) {
case MANUAL -> "Manual"; case MANUAL -> MANUAL;
case AUTO -> "Auto"; case AUTO -> AUTO;
case SCHEDULED -> "Scheduled" + (startAt.isEmpty() ? "" : " at " + startAt.getValue()); case SCHEDULED -> "Scheduled" + (startAt.isEmpty() ? "" : " at " + startAt.getValue());
}); });
startType.setWidthFull(); startType.setWidthFull();
@@ -396,17 +396,26 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
final MgmtRolloutRestRequestBody request = new MgmtRolloutRestRequestBody(); final MgmtRolloutRestRequestBody request = new MgmtRolloutRestRequestBody();
request.setName(name.getValue()); request.setName(name.getValue());
request.setDistributionSetId(distributionSet.getValue().getDsId()); request.setDistributionSetId(distributionSet.getValue().getDsId());
request.setTargetFilterQuery(targetFilter.getValue().getName()); request.setTargetFilterQuery(targetFilter.getValue().getQuery());
request.setDescription(description.getValue()); request.setDescription(description.getValue());
request.setType(actionType.getValue()); request.setType(actionType.getValue());
if (actionType.getValue() == MgmtActionType.FORCED) { if (actionType.getValue() == MgmtActionType.TIMEFORCED) {
request.setForcetime(forceTime.getValue().toEpochSecond(ZoneOffset.UTC) * 1000); request.setForcetime(
forceTime.isEmpty() ?
System.currentTimeMillis() :
forceTime.getValue().toEpochSecond(ZoneOffset.UTC) * 1000);
} }
switch (startType.getValue()) { switch (startType.getValue()) {
case AUTO -> request.setStartAt(System.currentTimeMillis()); case AUTO -> request.setStartAt(System.currentTimeMillis());
case SCHEDULED -> request.setStartAt(startAt.getValue().toEpochSecond(ZoneOffset.UTC) * 1000); case SCHEDULED -> request.setStartAt(
} // else - manual, do not start startAt.isEmpty() ?
System.currentTimeMillis() :
startAt.getValue().toEpochSecond(ZoneOffset.UTC) * 1000);
case MANUAL -> {
// do nothing, will be started manually
}
}
request.setAmountGroups(groupNumber.getValue().intValue()); request.setAmountGroups(groupNumber.getValue().intValue());
request.setSuccessCondition( request.setSuccessCondition(

View File

@@ -60,7 +60,7 @@ import java.util.stream.Stream;
@Route(value = "software_modules", layout = MainLayout.class) @Route(value = "software_modules", layout = MainLayout.class)
@RolesAllowed({"SOFTWARE_MODULE_READ"}) @RolesAllowed({"SOFTWARE_MODULE_READ"})
@Uses(Icon.class) @Uses(Icon.class)
public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> { public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long>{
@Autowired @Autowired
public SoftwareModuleView(final HawkbitClient hawkbitClient) { public SoftwareModuleView(final HawkbitClient hawkbitClient) {
@@ -75,11 +75,11 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
private final SoftwareModuleDetails details = new SoftwareModuleDetails(hawkbitClient); private final SoftwareModuleDetails details = new SoftwareModuleDetails(hawkbitClient);
@Override @Override
protected void addColumns(final Grid<MgmtSoftwareModule> grid) { protected void addColumns(final Grid<MgmtSoftwareModule> grid) {
grid.addColumn(MgmtSoftwareModule::getModuleId).setHeader("Id").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getModuleId).setHeader(ID).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getName).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getName).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getVersion).setHeader("Version").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getVersion).setHeader(VERSION).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getTypeName).setHeader("Type").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getTypeName).setHeader(TYPE).setAutoWidth(true);
grid.addColumn(MgmtSoftwareModule::getVendor).setHeader("Vendor").setAutoWidth(true); grid.addColumn(MgmtSoftwareModule::getVendor).setHeader(VENDOR).setAutoWidth(true);
grid.setItemDetailsRenderer(new ComponentRenderer<>( grid.setItemDetailsRenderer(new ComponentRenderer<>(
() -> details, SoftwareModuleDetails::setItem)); () -> details, SoftwareModuleDetails::setItem));
@@ -88,7 +88,7 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
}, },
(query, rsqlFilter) -> hawkbitClient.getSoftwareModuleRestApi() (query, rsqlFilter) -> hawkbitClient.getSoftwareModuleRestApi()
.getSoftwareModules( .getSoftwareModules(
query.getOffset(), query.getPageSize(), "name:asc", rsqlFilter) query.getOffset(), query.getPageSize(), NAME_ASC, rsqlFilter)
.getBody() .getBody()
.getContent() .getContent()
.stream(), .stream(),
@@ -110,25 +110,24 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
new SelectionGrid.EntityRepresentation<>(MgmtArtifact.class, MgmtArtifact::getArtifactId) { new SelectionGrid.EntityRepresentation<>(MgmtArtifact.class, MgmtArtifact::getArtifactId) {
@Override @Override
protected void addColumns(final Grid<MgmtArtifact> grid) { protected void addColumns(final Grid<MgmtArtifact> grid) {
grid.addColumn(MgmtArtifact::getArtifactId).setHeader("Id").setAutoWidth(true); grid.addColumn(MgmtArtifact::getArtifactId).setHeader(ID).setAutoWidth(true);
grid.addColumn(MgmtArtifact::getProvidedFilename).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtArtifact::getProvidedFilename).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtArtifact::getSize).setHeader("Size").setAutoWidth(true); grid.addColumn(MgmtArtifact::getSize).setHeader("Size").setAutoWidth(true);
grid.addColumn(MgmtArtifact::getHashes).setHeader("Hashes").setAutoWidth(true);
} }
}); });
} }
private static class SoftwareModuleFilter implements Filter.Rsql { private static class SoftwareModuleFilter implements Filter.Rsql {
private final TextField name = Utils.textField("Name"); private final TextField name = Utils.textField(NAME);
private final CheckboxGroup<MgmtSoftwareModuleType> type = new CheckboxGroup<>("Type"); private final CheckboxGroup<MgmtSoftwareModuleType> type = new CheckboxGroup<>(TYPE);
private SoftwareModuleFilter(final HawkbitClient hawkbitClient) { private SoftwareModuleFilter(final HawkbitClient hawkbitClient) {
name.setPlaceholder("<name filter>"); name.setPlaceholder("<name filter>");
type.setItemLabelGenerator(MgmtSoftwareModuleType::getName); type.setItemLabelGenerator(MgmtSoftwareModuleType::getName);
type.setItems( type.setItems(
hawkbitClient.getSoftwareModuleTypeRestApi() hawkbitClient.getSoftwareModuleTypeRestApi()
.getTypes(0, 20, "name:asc", null) .getTypes(0, 20, NAME_ASC, null)
.getBody() .getBody()
.getContent()); .getContent());
} }
@@ -151,13 +150,13 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
private static class SoftwareModuleDetails extends FormLayout { private static class SoftwareModuleDetails extends FormLayout {
private final HawkbitClient hawkbitClient; private final transient HawkbitClient hawkbitClient;
private final TextArea description = new TextArea("Description"); private final TextArea description = new TextArea(DESCRIPTION);
private final TextField createdBy = Utils.textField("Created by"); private final TextField createdBy = Utils.textField(CREATED_BY);
private final TextField createdAt = Utils.textField("Created at"); private final TextField createdAt = Utils.textField(CREATED_AT);
private final TextField lastModifiedBy = Utils.textField("Last modified by"); private final TextField lastModifiedBy = Utils.textField(LAST_MODIFIED_BY);
private final TextField lastModifiedAt = Utils.textField("Last modified at"); private final TextField lastModifiedAt = Utils.textField(LAST_MODIFIED_AT);
private final SelectionGrid<MgmtArtifact, Long> artifactGrid; private final SelectionGrid<MgmtArtifact, Long> artifactGrid;
private SoftwareModuleDetails(final HawkbitClient hawkbitClient) { private SoftwareModuleDetails(final HawkbitClient hawkbitClient) {
@@ -212,10 +211,10 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
super("Create Software Module"); super("Create Software Module");
type = new Select<>( type = new Select<>(
"Type", TYPE,
this::readyToCreate, this::readyToCreate,
hawkbitClient.getSoftwareModuleTypeRestApi() hawkbitClient.getSoftwareModuleTypeRestApi()
.getTypes(0, 30, "name:asc", null) .getTypes(0, 30, NAME_ASC, null)
.getBody() .getBody()
.getContent() .getContent()
.toArray(new MgmtSoftwareModuleType[0])); .toArray(new MgmtSoftwareModuleType[0]));
@@ -223,10 +222,10 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
type.setRequiredIndicatorVisible(true); type.setRequiredIndicatorVisible(true);
type.setItemLabelGenerator(MgmtSoftwareModuleType::getName); type.setItemLabelGenerator(MgmtSoftwareModuleType::getName);
type.focus(); type.focus();
name = Utils.textField("Name", this::readyToCreate); name = Utils.textField(NAME, this::readyToCreate);
version = Utils.textField("Version", this::readyToCreate); version = Utils.textField(VERSION, this::readyToCreate);
vendor = Utils.textField("Vendor"); vendor = Utils.textField(VENDOR);
description = new TextArea("Description"); description = new TextArea(DESCRIPTION);
description.setWidthFull(); description.setWidthFull();
description.setMinLength(2); description.setMinLength(2);
enableArtifactEncryption = new Checkbox("Enable artifact encryption"); enableArtifactEncryption = new Checkbox("Enable artifact encryption");
@@ -280,7 +279,7 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
private static class AddArtifactsDialog extends Utils.BaseDialog<Void> { private static class AddArtifactsDialog extends Utils.BaseDialog<Void> {
private final Set<MgmtArtifact> artifacts = Collections.synchronizedSet(new HashSet<>()); private final transient Set<MgmtArtifact> artifacts = Collections.synchronizedSet(new HashSet<>());
private AddArtifactsDialog( private AddArtifactsDialog(
final long softwareModuleId, final long softwareModuleId,

View File

@@ -40,10 +40,6 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery; import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody; import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType; import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.Collections; import java.util.Collections;
@@ -61,12 +57,8 @@ import java.util.stream.Stream;
@Uses(Icon.class) @Uses(Icon.class)
public class TargetView extends TableView<MgmtTarget, String> { public class TargetView extends TableView<MgmtTarget, String> {
private final HawkbitClient hawkbitClient; public static final String CONTROLLER_ID = "Controller Id";
public static final String TAG = "Tag";
private final MgmtTargetRestApi targetRestApi;
private final MgmtTargetTypeRestApi targetTypeRestApi;
private final MgmtTargetTagRestApi targetTagRestApi;
private final MgmtTargetFilterQueryRestApi targetFilterQueryRestApi;
public TargetView(final HawkbitClient hawkbitClient) { public TargetView(final HawkbitClient hawkbitClient) {
super( super(
@@ -75,9 +67,9 @@ public class TargetView extends TableView<MgmtTarget, String> {
@Override @Override
protected void addColumns(final Grid<MgmtTarget> grid) { protected void addColumns(final Grid<MgmtTarget> grid) {
grid.addColumn(MgmtTarget::getControllerId).setHeader("Controller Id").setAutoWidth(true); grid.addColumn(MgmtTarget::getControllerId).setHeader(CONTROLLER_ID).setAutoWidth(true);
grid.addColumn(MgmtTarget::getName).setHeader("Name").setAutoWidth(true); grid.addColumn(MgmtTarget::getName).setHeader(NAME).setAutoWidth(true);
grid.addColumn(MgmtTarget::getTargetTypeName).setHeader("Type").setAutoWidth(true); grid.addColumn(MgmtTarget::getTargetTypeName).setHeader(TYPE).setAutoWidth(true);
grid.setItemDetailsRenderer(new ComponentRenderer<>( grid.setItemDetailsRenderer(new ComponentRenderer<>(
TargetDetails::new, TargetDetails::setItem)); TargetDetails::new, TargetDetails::setItem));
@@ -85,7 +77,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
}, },
(query, filter) -> hawkbitClient.getTargetRestApi() (query, filter) -> hawkbitClient.getTargetRestApi()
.getTargets( .getTargets(
query.getOffset(), query.getPageSize(), "name:asc", query.getOffset(), query.getPageSize(), NAME_ASC,
filter) filter)
.getBody() .getBody()
.getContent() .getContent()
@@ -96,11 +88,6 @@ public class TargetView extends TableView<MgmtTarget, String> {
hawkbitClient.getTargetRestApi().deleteTarget(toDelete.getControllerId())); hawkbitClient.getTargetRestApi().deleteTarget(toDelete.getControllerId()));
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
}); });
this.hawkbitClient = hawkbitClient;
this.targetRestApi = hawkbitClient.getTargetRestApi();
this.targetTypeRestApi = hawkbitClient.getTargetTypeRestApi();
this.targetTagRestApi = hawkbitClient.getTargetTagRestApi();
this.targetFilterQueryRestApi = hawkbitClient.getTargetFilterQueryRestApi();
} }
private static class SimpleFilter implements Filter.Rsql { private static class SimpleFilter implements Filter.Rsql {
@@ -114,11 +101,11 @@ public class TargetView extends TableView<MgmtTarget, String> {
private SimpleFilter(final HawkbitClient hawkbitClient) { private SimpleFilter(final HawkbitClient hawkbitClient) {
this.hawkbitClient = hawkbitClient; this.hawkbitClient = hawkbitClient;
controllerId = Utils.textField("Controller Id"); controllerId = Utils.textField(CONTROLLER_ID);
controllerId.setPlaceholder("<controller id filter>"); controllerId.setPlaceholder("<controller id filter>");
type = new CheckboxGroup<>("Type"); type = new CheckboxGroup<>(TYPE);
type.setItemLabelGenerator(MgmtTargetType::getName); type.setItemLabelGenerator(MgmtTargetType::getName);
tag = new CheckboxGroup<>("Tag"); tag = new CheckboxGroup<>(TAG);
tag.setItemLabelGenerator(MgmtTag::getName); tag.setItemLabelGenerator(MgmtTag::getName);
} }
@@ -126,11 +113,11 @@ public class TargetView extends TableView<MgmtTarget, String> {
public List<Component> components() { public List<Component> components() {
final List<Component> components = new LinkedList<>(); final List<Component> components = new LinkedList<>();
components.add(controllerId); components.add(controllerId);
type.setItems(hawkbitClient.getTargetTypeRestApi().getTargetTypes(0, 20, "name:asc", null).getBody().getContent()); type.setItems(hawkbitClient.getTargetTypeRestApi().getTargetTypes(0, 20, NAME_ASC, null).getBody().getContent());
if (!type.getValue().isEmpty()) { if (!type.getValue().isEmpty()) {
components.add(type); components.add(type);
} }
tag.setItems(hawkbitClient.getTargetTagRestApi().getTargetTags(0, 20, "name:asc", null).getBody().getContent()); tag.setItems(hawkbitClient.getTargetTagRestApi().getTargetTags(0, 20, NAME_ASC, null).getBody().getContent());
if (!tag.isEmpty()) { if (!tag.isEmpty()) {
components.add(tag); components.add(tag);
} }
@@ -150,14 +137,10 @@ public class TargetView extends TableView<MgmtTarget, String> {
private static class RawFilter implements Filter.Rsql { private static class RawFilter implements Filter.Rsql {
private final HawkbitClient hawkbitClient;
private final TextField textFilter = new TextField("Raw Filter"); private final TextField textFilter = new TextField("Raw Filter");
private final VerticalLayout layout = new VerticalLayout(); private final VerticalLayout layout = new VerticalLayout();
private RawFilter(final HawkbitClient hawkbitClient) { private RawFilter(final HawkbitClient hawkbitClient) {
this.hawkbitClient = hawkbitClient;
textFilter.setPlaceholder("<raw filter>"); textFilter.setPlaceholder("<raw filter>");
final Select<MgmtTargetFilterQuery> savedFilters = new Select<>( final Select<MgmtTargetFilterQuery> savedFilters = new Select<>(
"Saved Filters", "Saved Filters",
@@ -178,12 +161,12 @@ public class TargetView extends TableView<MgmtTarget, String> {
textFilter.setWidthFull(); textFilter.setWidthFull();
final Button saveBtn = Utils.tooltip(new Button(VaadinIcon.ARCHIVE.create()), "Save (Enter)"); final Button saveBtn = Utils.tooltip(new Button(VaadinIcon.ARCHIVE.create()), "Save (Enter)");
saveBtn.addClickListener(e -> { saveBtn.addClickListener(e ->
new Utils.BaseDialog("Save Filter") {{ new Utils.BaseDialog<Void>("Save Filter") {{
setHeight("40%"); setHeight("40%");
final Button finishBtn = Utils.tooltip(new Button("Save"), "Save (Enter)"); final Button finishBtn = Utils.tooltip(new Button("Save"), "Save (Enter)");
final TextField name = Utils.textField( final TextField name = Utils.textField(
"Name", NAME,
e -> finishBtn.setEnabled(!e.getHasValue().isEmpty())); e -> finishBtn.setEnabled(!e.getHasValue().isEmpty()));
name.focus(); name.focus();
finishBtn.addClickShortcut(Key.ENTER); finishBtn.addClickShortcut(Key.ENTER);
@@ -200,8 +183,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
}); });
add(name, finishBtn); add(name, finishBtn);
open(); open();
}}; }});
});
saveBtn.addClickShortcut(Key.ENTER); saveBtn.addClickShortcut(Key.ENTER);
layout.setSpacing(false); layout.setSpacing(false);
@@ -224,11 +206,11 @@ public class TargetView extends TableView<MgmtTarget, String> {
private static class TargetDetails extends FormLayout { private static class TargetDetails extends FormLayout {
private final TextArea description = new TextArea("Description"); private final TextArea description = new TextArea(DESCRIPTION);
private final TextField createdBy = Utils.textField("Created by"); private final TextField createdBy = Utils.textField(CREATED_BY);
private final TextField createdAt = Utils.textField("Created at"); private final TextField createdAt = Utils.textField(CREATED_AT);
private final TextField lastModifiedBy = Utils.textField("Last modified by"); private final TextField lastModifiedBy = Utils.textField(LAST_MODIFIED_BY);
private final TextField lastModifiedAt = Utils.textField("Last modified at"); private final TextField lastModifiedAt = Utils.textField(LAST_MODIFIED_AT);
private TargetDetails() { private TargetDetails() {
description.setMinLength(2); description.setMinLength(2);
@@ -254,7 +236,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
} }
} }
private static class RegisterDialog extends Utils.BaseDialog { private static class RegisterDialog extends Utils.BaseDialog<Void> {
private final Select<MgmtTargetType> type; private final Select<MgmtTargetType> type;
private final TextField controllerId; private final TextField controllerId;
@@ -269,20 +251,19 @@ public class TargetView extends TableView<MgmtTarget, String> {
"Type", "Type",
e -> {}, e -> {},
hawkbitClient.getTargetTypeRestApi() hawkbitClient.getTargetTypeRestApi()
.getTargetTypes(0, 30, "name:asc", null) .getTargetTypes(0, 30, NAME_ASC, null)
.getBody() .getBody()
.getContent() .getContent()
.toArray(new MgmtTargetType[0])); .toArray(new MgmtTargetType[0]));
type.setWidthFull(); type.setWidthFull();
type.setEmptySelectionAllowed(true); type.setEmptySelectionAllowed(true);
type.setItemLabelGenerator(item -> item == null ? "" : item.getName()); type.setItemLabelGenerator(item -> item == null ? "" : item.getName());
controllerId = Utils.textField( controllerId = Utils.textField(CONTROLLER_ID,
"Controller Id",
e -> register.setEnabled(!e.getHasValue().isEmpty())); e -> register.setEnabled(!e.getHasValue().isEmpty()));
controllerId.focus(); controllerId.focus();
name = Utils.textField("Name"); name = Utils.textField(NAME);
name.setWidthFull(); name.setWidthFull();
description = new TextArea("Description"); description = new TextArea(DESCRIPTION);
description.setMinLength(2); description.setMinLength(2);
description.setWidthFull(); description.setWidthFull();

View File

@@ -30,7 +30,7 @@ import java.util.stream.Stream;
public class Filter extends Div { public class Filter extends Div {
private Rsql rsql; private transient Rsql rsql;
public Filter(final Consumer<String> changeListener, final Rsql primaryRsql, final Rsql secondaryOptionalRsql) { public Filter(final Consumer<String> changeListener, final Rsql primaryRsql, final Rsql secondaryOptionalRsql) {
rsql = primaryRsql; rsql = primaryRsql;
@@ -89,7 +89,7 @@ public class Filter extends Div {
.entrySet() .entrySet()
.stream() .stream()
.filter(e -> { .filter(e -> {
if (e.getValue() instanceof Optional opt) { if (e.getValue() instanceof Optional<?> opt) {
return opt.isPresent(); return opt.isPresent();
} else { } else {
return e.getValue() != null; return e.getValue() != null;
@@ -100,13 +100,14 @@ public class Filter extends Div {
if (normalized.isEmpty()) { if (normalized.isEmpty()) {
return null; return null;
} else if (normalized.size() == 1) { } else if (normalized.size() == 1) {
return normalized.entrySet().stream().findFirst().map(e -> filter(e.getKey(), e.getValue())).get(); return normalized.entrySet().stream()
.findFirst().map(e -> filter(e.getKey(), e.getValue())).orElse(null); // never return null!
} else { } else {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
normalized.forEach((k, v) -> { normalized.forEach((k, v) -> {
if (v instanceof Collection<?>) { if (v instanceof Collection<?>) {
sb.append('(').append(filter(k, v)).append(')'); sb.append('(').append(filter(k, v)).append(')');
} else if (v instanceof Optional opt) { } else if (v instanceof Optional<?> opt) {
sb.append(filter(k, opt.get())); sb.append(filter(k, opt.get()));
} else { } else {
sb.append(filter(k, v)); sb.append(filter(k, v));
@@ -118,16 +119,20 @@ public class Filter extends Div {
} }
private static String filter(final String key, final Object value) { private static String filter(final String key, final Object value) {
if (value == null || (value instanceof Collection coll && coll.isEmpty())) { if (value == null || (value instanceof Collection<?> coll && coll.isEmpty())) {
return null; return null;
} }
if (value instanceof Collection coll) { if (value instanceof Collection<?> coll) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
coll.stream().forEach(next -> sb.append(key).append("==").append(next).append(',')); coll.stream().forEach(next -> sb.append(key).append("==").append(next).append(','));
return sb.substring(0, sb.length() - 1); return sb.substring(0, sb.length() - 1);
} else if (value instanceof Optional opt) { } else if (value instanceof Optional<?> opt) {
return key + "==" + opt.get(); if (opt.isEmpty()) {
return null;
} else {
return key + "==" + opt.get();
}
} else { } else {
return key + "==" + value; return key + "==" + value;
} }

View File

@@ -51,7 +51,10 @@ public class SelectionGrid<T,ID> extends Grid<T> {
return fetch; return fetch;
} else { } else {
final Set<ID> selectedIds = new HashSet<>(); final Set<ID> selectedIds = new HashSet<>();
selected.stream().forEach(next -> selectedIds.add(entityRepresentation.idFn.apply(next))); selected.forEach(next -> selectedIds.add(entityRepresentation.idFn.apply(next)));
// if matching keeps old entries instead of new the new ones in order to
// select them in case refresh is made with keepSelection
// this however means that if they are changed the old state will be shown!!!
return Streams.concat(selected.stream(), return Streams.concat(selected.stream(),
fetch.filter(next -> !selectedIds.contains(entityRepresentation.idFn.apply(next)))); fetch.filter(next -> !selectedIds.contains(entityRepresentation.idFn.apply(next))));
} }
@@ -70,7 +73,7 @@ public class SelectionGrid<T,ID> extends Grid<T> {
if (keepSelection) { if (keepSelection) {
final Set<T> selected = getSelectedItems(); final Set<T> selected = getSelectedItems();
getDataProvider().refreshAll(); getDataProvider().refreshAll();
if (selected == null || selected.isEmpty()) { if (selected != null && !selected.isEmpty()) {
selected.forEach(this::select); selected.forEach(this::select);
} }
} else { } else {

View File

@@ -9,6 +9,7 @@
*/ */
package com.eclipse.hawkbit.ui.view.util; package com.eclipse.hawkbit.ui.view.util;
import com.eclipse.hawkbit.ui.view.Constants;
import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.provider.Query; import com.vaadin.flow.data.provider.Query;
@@ -18,7 +19,7 @@ import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
public class TableView<T, ID> extends Div { public class TableView<T, ID> extends Div implements Constants {
protected SelectionGrid<T, ID> selectionGrid; protected SelectionGrid<T, ID> selectionGrid;
private final Filter filter; private final Filter filter;
@@ -58,7 +59,9 @@ public class TableView<T, ID> extends Div {
layout.setSizeFull(); layout.setSizeFull();
layout.setPadding(false); layout.setPadding(false);
layout.setSpacing(false); layout.setSpacing(false);
Utils.addRemoveControls(addHandler, removeHandler, selectionGrid, false).ifPresent(layout::add); if (addHandler != null || removeHandler != null) {
layout.add(Utils.addRemoveControls(addHandler, removeHandler, selectionGrid, false));
}
add(layout); add(layout);
} }
} }

View File

@@ -39,6 +39,10 @@ import java.util.function.Function;
public class Utils { public class Utils {
private Utils() {
// prevent initialization
}
public static TextField textField(final String label) { public static TextField textField(final String label) {
return textField(label, null); return textField(label, null);
} }
@@ -69,12 +73,12 @@ public class Utils {
return numberField; return numberField;
} }
public static <T, ID> Optional<HorizontalLayout> addRemoveControls( public static <T, ID> HorizontalLayout addRemoveControls(
final Function<SelectionGrid<T, ID>, CompletionStage<Void>> addHandler, final Function<SelectionGrid<T, ID>, CompletionStage<Void>> addHandler,
final Function<SelectionGrid<T, ID>, CompletionStage<Void>> removeHandler, final Function<SelectionGrid<T, ID>, CompletionStage<Void>> removeHandler,
final SelectionGrid<T, ID> selectionGrid, final boolean noPadding) { final SelectionGrid<T, ID> selectionGrid, final boolean noPadding) {
if (addHandler == null && removeHandler == null) { if (addHandler == null && removeHandler == null) {
return Optional.empty(); throw new IllegalArgumentException("At least one of add or remove handlers must not be null!");
} }
final HorizontalLayout layout = new HorizontalLayout(); final HorizontalLayout layout = new HorizontalLayout();
@@ -100,7 +104,7 @@ public class Utils {
.thenAccept(v -> selectionGrid.refreshGrid(false))); .thenAccept(v -> selectionGrid.refreshGrid(false)));
layout.add(removeBtn); layout.add(removeBtn);
} }
return Optional.of(layout); return layout;
} }
public static <T> void remove(final Collection<T> remove, final Set<T> from, final Function<T, ?> idFn) { public static <T> void remove(final Collection<T> remove, final Set<T> from, final Function<T, ?> idFn) {
@@ -144,7 +148,7 @@ public class Utils {
public static class BaseDialog<T> extends Dialog { public static class BaseDialog<T> extends Dialog {
protected final CompletableFuture<T> result = new CompletableFuture<>(); protected final transient CompletableFuture<T> result = new CompletableFuture<>();
protected BaseDialog(final String headerTitle) { protected BaseDialog(final String headerTitle) {
setHeaderTitle(headerTitle); setHeaderTitle(headerTitle);