Fix Sonar findings (#1750)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.ui.simple.view;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.hawkbit.ui.simple.HawkbitMgmtClient;
|
import org.eclipse.hawkbit.ui.simple.HawkbitMgmtClient;
|
||||||
import org.eclipse.hawkbit.ui.simple.MainLayout;
|
import org.eclipse.hawkbit.ui.simple.MainLayout;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
|
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
|
||||||
@@ -30,60 +31,61 @@ import jakarta.annotation.security.RolesAllowed;
|
|||||||
@PageTitle("Config")
|
@PageTitle("Config")
|
||||||
@Route(value = "config", layout = MainLayout.class)
|
@Route(value = "config", layout = MainLayout.class)
|
||||||
@RolesAllowed({ "CONFIG_READ" })
|
@RolesAllowed({ "CONFIG_READ" })
|
||||||
|
@Slf4j
|
||||||
public class ConfigView extends VerticalLayout {
|
public class ConfigView extends VerticalLayout {
|
||||||
private final Map<String, MgmtSystemTenantConfigurationValueRequest> configValue = new HashMap();
|
|
||||||
|
private static final String WIDTH = "width";
|
||||||
|
private static final String PX_300 = "300px";
|
||||||
|
|
||||||
|
private final Map<String, MgmtSystemTenantConfigurationValueRequest> configValue = new HashMap<>();
|
||||||
|
|
||||||
public ConfigView(final HawkbitMgmtClient hawkbitClient) {
|
public ConfigView(final HawkbitMgmtClient hawkbitClient) {
|
||||||
setSpacing(false);
|
setSpacing(false);
|
||||||
Button saveButton = new Button("Save");
|
final Button saveButton = new Button("Save");
|
||||||
hawkbitClient.getTenantManagementRestApi().getTenantConfiguration().getBody().forEach((k, v) -> {
|
hawkbitClient.getTenantManagementRestApi().getTenantConfiguration().getBody().forEach((k, v) -> {
|
||||||
Component value = null;
|
Component value = null;
|
||||||
if (v.getValue() instanceof String) {
|
if (v.getValue() instanceof String strValue) {
|
||||||
TextField tf = new TextField(k, v.getValue().toString(), event -> {
|
TextField tf = new TextField(k, strValue, event -> {
|
||||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||||
vre.setValue(event.getValue());
|
vre.setValue(event.getValue());
|
||||||
configValue.put(k, vre);
|
configValue.put(k, vre);
|
||||||
});
|
});
|
||||||
tf.getElement().getStyle().set("width", "300px");
|
tf.getElement().getStyle().set(WIDTH, PX_300);
|
||||||
value = tf;
|
value = tf;
|
||||||
} else if (v.getValue() instanceof Boolean) {
|
} else if (v.getValue() instanceof Boolean boolValue) {
|
||||||
value = new Checkbox(k, (Boolean) v.getValue(), event -> {
|
value = new Checkbox(k, boolValue, event -> {
|
||||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||||
vre.setValue(event.getValue());
|
vre.setValue(event.getValue());
|
||||||
configValue.put(k, vre);
|
configValue.put(k, vre);
|
||||||
});
|
});
|
||||||
} else if (v.getValue() instanceof Long) {
|
} else if (v.getValue() instanceof Long longValue) {
|
||||||
Double d = (double) ((Long) v.getValue());
|
final NumberField nf = new NumberField(k, (double) longValue, event -> {
|
||||||
NumberField nf = new NumberField(k, d, event -> {
|
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
|
||||||
vre.setValue(event.getValue());
|
vre.setValue(event.getValue());
|
||||||
configValue.put(k, vre);
|
configValue.put(k, vre);
|
||||||
});
|
});
|
||||||
nf.getElement().getStyle().set("width", "300px");
|
nf.getElement().getStyle().set(WIDTH, PX_300);
|
||||||
value = nf;
|
value = nf;
|
||||||
} else if (v.getValue() instanceof Integer) {
|
} else if (v.getValue() instanceof Integer intValue) {
|
||||||
Double d = (double) ((Integer) v.getValue());
|
final NumberField nf = new NumberField(k, (double) intValue, event -> {
|
||||||
NumberField nf = new NumberField(k, d, event -> {
|
|
||||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||||
vre.setValue(event.getValue());
|
vre.setValue(event.getValue());
|
||||||
configValue.put(k, vre);
|
configValue.put(k, vre);
|
||||||
});
|
});
|
||||||
nf.getElement().getStyle().set("width", "300px");
|
nf.getElement().getStyle().set(WIDTH, PX_300);
|
||||||
value = nf;
|
value = nf;
|
||||||
} else {
|
} else {
|
||||||
System.out.println(k + ":" + v);
|
log.debug("Unexpected value type: {} -> {} (class: {})", k, v.getValue(), v.getValue() == null ? "null" : v.getValue().getClass());
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
add(value);
|
add(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
saveButton.addClickListener(click -> {
|
saveButton.addClickListener(click ->
|
||||||
configValue.forEach((key, value) -> {
|
configValue.forEach((key, value) ->
|
||||||
hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value);
|
hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value)));
|
||||||
});
|
|
||||||
});
|
|
||||||
saveButton.addClickShortcut(Key.ENTER);
|
saveButton.addClickShortcut(Key.ENTER);
|
||||||
add(saveButton);
|
add(saveButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user