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.Map;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.ui.simple.HawkbitMgmtClient;
|
||||
import org.eclipse.hawkbit.ui.simple.MainLayout;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
|
||||
@@ -30,60 +31,61 @@ import jakarta.annotation.security.RolesAllowed;
|
||||
@PageTitle("Config")
|
||||
@Route(value = "config", layout = MainLayout.class)
|
||||
@RolesAllowed({ "CONFIG_READ" })
|
||||
@Slf4j
|
||||
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) {
|
||||
setSpacing(false);
|
||||
Button saveButton = new Button("Save");
|
||||
final Button saveButton = new Button("Save");
|
||||
hawkbitClient.getTenantManagementRestApi().getTenantConfiguration().getBody().forEach((k, v) -> {
|
||||
Component value = null;
|
||||
if (v.getValue() instanceof String) {
|
||||
TextField tf = new TextField(k, v.getValue().toString(), event -> {
|
||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
if (v.getValue() instanceof String strValue) {
|
||||
TextField tf = new TextField(k, strValue, event -> {
|
||||
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
vre.setValue(event.getValue());
|
||||
configValue.put(k, vre);
|
||||
});
|
||||
tf.getElement().getStyle().set("width", "300px");
|
||||
tf.getElement().getStyle().set(WIDTH, PX_300);
|
||||
value = tf;
|
||||
} else if (v.getValue() instanceof Boolean) {
|
||||
value = new Checkbox(k, (Boolean) v.getValue(), event -> {
|
||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
} else if (v.getValue() instanceof Boolean boolValue) {
|
||||
value = new Checkbox(k, boolValue, event -> {
|
||||
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
vre.setValue(event.getValue());
|
||||
configValue.put(k, vre);
|
||||
});
|
||||
} else if (v.getValue() instanceof Long) {
|
||||
Double d = (double) ((Long) v.getValue());
|
||||
NumberField nf = new NumberField(k, d, event -> {
|
||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
} else if (v.getValue() instanceof Long longValue) {
|
||||
final NumberField nf = new NumberField(k, (double) longValue, event -> {
|
||||
final MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
vre.setValue(event.getValue());
|
||||
configValue.put(k, vre);
|
||||
});
|
||||
nf.getElement().getStyle().set("width", "300px");
|
||||
nf.getElement().getStyle().set(WIDTH, PX_300);
|
||||
value = nf;
|
||||
} else if (v.getValue() instanceof Integer) {
|
||||
Double d = (double) ((Integer) v.getValue());
|
||||
NumberField nf = new NumberField(k, d, event -> {
|
||||
} else if (v.getValue() instanceof Integer intValue) {
|
||||
final NumberField nf = new NumberField(k, (double) intValue, event -> {
|
||||
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
|
||||
vre.setValue(event.getValue());
|
||||
configValue.put(k, vre);
|
||||
});
|
||||
nf.getElement().getStyle().set("width", "300px");
|
||||
nf.getElement().getStyle().set(WIDTH, PX_300);
|
||||
value = nf;
|
||||
} 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) {
|
||||
add(value);
|
||||
}
|
||||
});
|
||||
|
||||
saveButton.addClickListener(click -> {
|
||||
configValue.forEach((key, value) -> {
|
||||
hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value);
|
||||
});
|
||||
});
|
||||
saveButton.addClickListener(click ->
|
||||
configValue.forEach((key, value) ->
|
||||
hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value)));
|
||||
saveButton.addClickShortcut(Key.ENTER);
|
||||
add(saveButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user