Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating Kura component configurations #4166

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
*
* 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
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.console.module.api.shared.model;

import java.io.Serializable;

public class GwtConfigComponentCreator extends KapuaBaseModel implements Serializable {

private static final long serialVersionUID = -6388356998309026758L;

private static final String COMPONENT_FACTORY_ID = "componentFactoryId";
private static final String COMPONENT_ID = "componentId";

public String getComponentFactoryId() {
return get(COMPONENT_FACTORY_ID);
}

public String getUnescapedComponentFactoryId() {
return getUnescaped(COMPONENT_FACTORY_ID);
}

public void setComponentFactoryId(String componentFactoryId) {
set(COMPONENT_FACTORY_ID, componentFactoryId);
}

public String getComponentId() {
return get(COMPONENT_ID);
}

public String getUnescapedComponentId() {
return getUnescaped(COMPONENT_ID);
}

public void setComponentId(String componentId) {
set(COMPONENT_ID, componentId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2025 Eurotech and/or its affiliates and others
*
* 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
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.console.module.api.shared.model;

import java.io.Serializable;

public class GwtConfigComponentFactory extends KapuaBaseModel implements Serializable {

private static final long serialVersionUID = -6388356998309026758L;

private static final String ID = "id";

public GwtConfigComponentFactory() {}

public GwtConfigComponentFactory(String id) {
setId(id);
}

public String getId() {
return get(ID);
}

public void setId(String id) {
set(ID, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*******************************************************************************
* Copyright (c) 2025 Eurotech and/or its affiliates and others
*
* 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
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.console.module.device.client.device.configuration;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.kapua.app.console.module.api.client.messages.ConsoleMessages;
import org.eclipse.kapua.app.console.module.api.client.ui.dialog.entity.EntityAddEditDialog;
import org.eclipse.kapua.app.console.module.api.client.ui.panel.FormPanel;
import org.eclipse.kapua.app.console.module.api.client.ui.widget.KapuaTextField;
import org.eclipse.kapua.app.console.module.api.client.util.ConsoleInfo;
import org.eclipse.kapua.app.console.module.api.client.util.DialogUtils;
import org.eclipse.kapua.app.console.module.api.client.util.FailureHandler;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtConfigComponentCreator;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtConfigComponentFactory;
import org.eclipse.kapua.app.console.module.api.shared.model.session.GwtSession;
import org.eclipse.kapua.app.console.module.device.client.messages.ConsoleDeviceMessages;
import org.eclipse.kapua.app.console.module.device.shared.model.GwtDevice;
import org.eclipse.kapua.app.console.module.device.shared.service.GwtDeviceManagementService;
import org.eclipse.kapua.app.console.module.device.shared.service.GwtDeviceManagementServiceAsync;

public class DeviceConfigAddDialog extends EntityAddEditDialog {

private static final ConsoleDeviceMessages MSGS = GWT.create(ConsoleDeviceMessages.class);
private static final ConsoleMessages CONSOLE_MSGS = GWT.create(ConsoleMessages.class);

private static final GwtDeviceManagementServiceAsync GWT_DEVICE_MANAGEMENT_SERVICE = GWT.create(GwtDeviceManagementService.class);

private final GwtDevice device;

private ComboBox<GwtConfigComponentFactory> componentFactoryCombo;
private KapuaTextField<String> componentIdField;

public DeviceConfigAddDialog(GwtSession currentSession, GwtDevice device) {
super(currentSession);
this.device = device;
DialogUtils.resizeDialog(this, 600, 200);
}

@Override
public void createBody() {
submitButton.disable();
FormPanel roleFormPanel = new FormPanel(FORM_LABEL_WIDTH);
Listener<BaseEvent> comboBoxListener = new Listener<BaseEvent>() {

@Override
public void handleEvent(BaseEvent be) {
DeviceConfigAddDialog.this.formPanel.fireEvent(Events.OnClick);
}
};
// Component Factory
componentFactoryCombo = new ComboBox<GwtConfigComponentFactory>();
componentFactoryCombo.setStore(new ListStore<GwtConfigComponentFactory>());
componentFactoryCombo.setEditable(false);
componentFactoryCombo.setTypeAhead(false);
componentFactoryCombo.setAllowBlank(false);
componentFactoryCombo.disable();
componentFactoryCombo.setEmptyText(MSGS.dialogDeviceConfigComponentAddFieldFactoryEmptyText());
componentFactoryCombo.setFieldLabel("* " + MSGS.dialogDeviceConfigComponentAddComponentFactoryFieldName());
componentFactoryCombo.setTriggerAction(ComboBox.TriggerAction.ALL);
componentFactoryCombo.setDisplayField("id");
componentFactoryCombo.setTemplate("<tpl for=\".\"><div role=\"listitem\" class=\"x-combo-list-item\" title={id}>{id}</div></tpl>");
componentFactoryCombo.addListener(Events.Select, comboBoxListener);

GWT_DEVICE_MANAGEMENT_SERVICE.findComponentConfigurationFactories(device, new AsyncCallback<List<GwtConfigComponentFactory>>() {

@Override
public void onFailure(Throwable caught) {
exitStatus = false;
if (!isPermissionErrorMessage(caught)) {
exitMessage = MSGS.dialogDeviceConfigComponentAddFieldFactoryLoadingError(caught.getLocalizedMessage());
}
hide();
}

@Override
public void onSuccess(List<GwtConfigComponentFactory> result) {
Collections.sort(result, new Comparator<GwtConfigComponentFactory>() {

@Override
public int compare(GwtConfigComponentFactory factory1, GwtConfigComponentFactory factory2) {
return factory1.getId().compareTo(factory2.getId());
}
});

componentFactoryCombo.getStore().add(result);

componentFactoryCombo.setEmptyText(result.isEmpty() ? MSGS.dialogDeviceConfigComponentAddFieldFactoryEmptyTextNoFactory() : MSGS.dialogDeviceConfigComponentAddFieldFactoryEmptyText());

componentFactoryCombo.enable();
}
});

roleFormPanel.add(componentFactoryCombo);

// Component
componentIdField = new KapuaTextField<String>();
componentIdField.setAllowBlank(false);
componentIdField.setMaxLength(255);
componentIdField.setFieldLabel("* " + MSGS.dialogDeviceConfigComponentAddComponentIdFieldName());
roleFormPanel.add(componentIdField);

bodyPanel.add(roleFormPanel);
}

@Override
protected void preSubmit() {
if (componentFactoryCombo.getValue() == null || componentIdField.getValue() == null) {
ConsoleInfo.display("Error", CONSOLE_MSGS.allFieldsRequired());
}
super.preSubmit();
}

@Override
public void submit() {
GwtConfigComponentCreator creator = new GwtConfigComponentCreator();
creator.setComponentFactoryId(componentFactoryCombo.getValue().getId());
creator.setComponentId(componentIdField.getValue());

GWT_DEVICE_MANAGEMENT_SERVICE.createComponentConfiguration(xsrfToken, device, creator, new AsyncCallback<Void>() {

@Override
public void onSuccess(Void result) {
exitStatus = true;
exitMessage = MSGS.dialogDeviceConfigComponentAddConfirmation();
hide();
}

@Override
public void onFailure(Throwable cause) {
exitStatus = false;
status.hide();
formPanel.getButtonBar().enable();
unmask();
submitButton.enable();
cancelButton.enable();

FailureHandler.handleFormException(formPanel, cause);
}

});
}

@Override
public String getHeaderMessage() {
return MSGS.dialogDeviceConfigComponentAddHeader();
}

@Override
public String getInfoMessage() {
return MSGS.dialogDeviceConfigComponentAddInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
Expand All @@ -45,15 +46,19 @@
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaErrorCode;
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException;
import org.eclipse.kapua.app.console.module.api.client.messages.ConsoleMessages;
import org.eclipse.kapua.app.console.module.api.client.resources.icons.IconSet;
import org.eclipse.kapua.app.console.module.api.client.resources.icons.KapuaIcon;
import org.eclipse.kapua.app.console.module.api.client.ui.button.AddButton;
import org.eclipse.kapua.app.console.module.api.client.ui.button.DiscardButton;
import org.eclipse.kapua.app.console.module.api.client.ui.button.KapuaButton;
import org.eclipse.kapua.app.console.module.api.client.ui.button.RefreshButton;
import org.eclipse.kapua.app.console.module.api.client.ui.button.SaveButton;
import org.eclipse.kapua.app.console.module.api.client.ui.dialog.ActionDialog;
import org.eclipse.kapua.app.console.module.api.client.ui.dialog.InfoDialog;
import org.eclipse.kapua.app.console.module.api.client.ui.dialog.InfoDialog.InfoDialogType;
import org.eclipse.kapua.app.console.module.api.client.ui.dialog.KapuaMessageBox;
Expand All @@ -75,9 +80,6 @@
import org.eclipse.kapua.app.console.module.device.shared.service.GwtDeviceService;
import org.eclipse.kapua.app.console.module.device.shared.service.GwtDeviceServiceAsync;

import java.util.ArrayList;
import java.util.List;

public class DeviceConfigComponents extends LayoutContainer {

private static final ConsoleMessages MSGS = GWT.create(ConsoleMessages.class);
Expand All @@ -97,6 +99,9 @@ public class DeviceConfigComponents extends LayoutContainer {
private Button refreshButton;
private boolean refreshProcess;

private Button addButton;
private boolean addProcess;

private Button apply;
private Button reset;

Expand Down Expand Up @@ -211,6 +216,14 @@ public void componentSelected(ButtonEvent ce) {
}
});

addButton = new AddButton(new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent buttonEvent) {
add();
}
});

apply = new SaveButton(new SelectionListener<ButtonEvent>() {

@Override
Expand Down Expand Up @@ -259,6 +272,8 @@ public void componentSelected(ButtonEvent buttonEvent) {

toolBar.add(refreshButton);
toolBar.add(new SeparatorToolItem());
toolBar.add(addButton);
toolBar.add(new SeparatorToolItem());
toolBar.add(apply);
toolBar.add(new SeparatorToolItem());
toolBar.add(reset);
Expand Down Expand Up @@ -501,6 +516,36 @@ public void handleEvent(BaseEvent be) {
}
}

public void add() {
if (addProcess) {
return;
}
addButton.setEnabled(false);
addProcess = true;

DeviceConfigAddDialog dialog = new DeviceConfigAddDialog(gwtSession, selectedDevice);
dialog.addListener(Events.Hide, new Listener<ComponentEvent>() {
@Override
public void handleEvent(ComponentEvent be) {
addProcess = false;
addButton.setEnabled(true);

// Show exit popup
ActionDialog dialog = be.getComponent();
Boolean exitStatus = dialog.getExitStatus();
if (exitStatus == null) {
return;
}
if (exitStatus) {
ConsoleInfo.display(MSGS.popupInfo(), dialog.getExitMessage());
} else {
ConsoleInfo.display(MSGS.popupError(), dialog.getExitMessage());
}
}
});
dialog.show();
}

public void apply() {
if (!devConfPanel.isValid()) {
InfoDialog exitDialog = new InfoDialog(InfoDialogType.ERROR, DEVICE_MSGS.deviceConfigError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setEntity(GwtDevice gwtDevice) {

if (gwtDevice != null) {
setEnabled(gwtDevice.isOnline() && currentSession.hasPermission(DeviceManagementSessionPermission.read()));
getHeader().setVisible(gwtDevice.hasApplication(GwtDevice.GwtDeviceApplication.APP_CONFIGURATION));
getHeader().setVisible(gwtDevice.hasApplication(GwtDevice.GwtDeviceApplication.APP_CONFIGURATION_V1) || gwtDevice.hasApplication(GwtDevice.GwtDeviceApplication.APP_CONFIGURATION_V2));
setText(MSGS.tabConfiguration());

if (!gwtDevice.isOnline()) {
Expand Down
Loading