Skip to content

Commit

Permalink
List Kura component factories
Browse files Browse the repository at this point in the history
  • Loading branch information
reda-alaoui committed Jan 6, 2025
1 parent 7c9f72a commit f5ac35b
Show file tree
Hide file tree
Showing 20 changed files with 495 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 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 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
Expand Up @@ -12,8 +12,16 @@
*******************************************************************************/
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;
Expand All @@ -22,6 +30,7 @@
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;
Expand All @@ -37,26 +46,72 @@ public class DeviceConfigAddDialog extends EntityAddEditDialog {

private final GwtDevice device;

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

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

@Override
public void createBody() {
submitButton.disable();
FormPanel roleFormPanel = new FormPanel(FORM_LABEL_WIDTH);
// Name
componentFactoryIdField = new KapuaTextField<String>();
componentFactoryIdField.setAllowBlank(false);
componentFactoryIdField.setMaxLength(255);
componentFactoryIdField.setFieldLabel("* " + MSGS.dialogDeviceConfigComponentAddComponentFactoryIdFieldName());
roleFormPanel.add(componentFactoryIdField);
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);
Expand All @@ -68,7 +123,7 @@ public void createBody() {

@Override
protected void preSubmit() {
if (componentFactoryIdField.getValue() == null || componentIdField.getValue() == null) {
if (componentFactoryCombo.getValue() == null || componentIdField.getValue() == null) {
ConsoleInfo.display("Error", CONSOLE_MSGS.allFieldsRequired());
}
super.preSubmit();
Expand All @@ -77,7 +132,7 @@ protected void preSubmit() {
@Override
public void submit() {
GwtConfigComponentCreator creator = new GwtConfigComponentCreator();
creator.setComponentFactoryId(componentFactoryIdField.getValue());
creator.setComponentFactoryId(componentFactoryCombo.getValue().getId());
creator.setComponentId(componentIdField.getValue());

GWT_DEVICE_MANAGEMENT_SERVICE.createComponentConfiguration(xsrfToken, device, creator, new AsyncCallback<Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.kapua.app.console.module.api.setting.ConsoleSettingKeys;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtConfigComponent;
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.GwtConfigParameter;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtConfigParameter.GwtConfigParameterType;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtXSRFToken;
Expand Down Expand Up @@ -448,6 +449,25 @@ public void updateComponentConfiguration(GwtXSRFToken xsrfToken, GwtDevice gwtDe
}
}

@Override
public List<GwtConfigComponentFactory> findComponentConfigurationFactories(GwtDevice gwtDevice) throws GwtKapuaException {

// execute
try {
KapuaId scopeId = KapuaEid.parseCompactId(gwtDevice.getScopeId());
KapuaId deviceId = KapuaEid.parseCompactId(gwtDevice.getId());

List<String> factoryIds = CONFIGURATION_MANAGEMENT_SERVICE.getFactories(scopeId, deviceId, null).getIds();
List<GwtConfigComponentFactory> factories = new ArrayList<GwtConfigComponentFactory>();
for (String factoryId : factoryIds) {
factories.add(new GwtConfigComponentFactory(factoryId));
}
return factories;
} catch (Throwable t) {
throw KapuaExceptionHandler.buildExceptionFromError(t);
}
}

@Override
public void createComponentConfiguration(GwtXSRFToken xsrfToken, GwtDevice gwtDevice, GwtConfigComponentCreator command) throws GwtKapuaException {
// Checking validity of the given XSRF Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import java.util.List;
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtConfigComponent;
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.GwtXSRFToken;
import org.eclipse.kapua.app.console.module.device.shared.model.GwtDevice;
import org.eclipse.kapua.app.console.module.device.shared.model.management.bundles.GwtBundle;
Expand All @@ -29,8 +31,6 @@
import org.eclipse.kapua.app.console.module.device.shared.model.management.packages.GwtPackageOperation;
import org.eclipse.kapua.app.console.module.device.shared.model.management.packages.GwtPackageUninstallRequest;

import java.util.List;

/**
* The client side stub for the RPC service.
*/
Expand Down Expand Up @@ -110,6 +110,8 @@ void updateComponentConfiguration(GwtXSRFToken xsrfToken, GwtDevice device, GwtC
throws GwtKapuaException;

//
List<GwtConfigComponentFactory> findComponentConfigurationFactories(GwtDevice device) throws GwtKapuaException;

void createComponentConfiguration(GwtXSRFToken xsrfToken, GwtDevice device, GwtConfigComponentCreator creator) throws GwtKapuaException;

// Snapshots
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,8 @@ dialogDeviceAddInfoMessage=Create a new device providing Client ID, Display Name
dialogDeviceConfigComponentAddHeader=New Configuration
dialogDeviceConfigComponentAddInfo=Create a new device component configuration.
dialogDeviceConfigComponentAddConfirmation=Configuration successfully created.
dialogDeviceConfigComponentAddComponentFactoryIdFieldName=Component Factory ID
dialogDeviceConfigComponentAddComponentIdFieldName=Component ID
dialogDeviceConfigComponentAddComponentFactoryFieldName=Component Factory
dialogDeviceConfigComponentAddComponentIdFieldName=Component ID
dialogDeviceConfigComponentAddFieldFactoryEmptyText=Select A Factory
dialogDeviceConfigComponentAddFieldFactoryEmptyTextNoFactory=No Factory found...
dialogDeviceConfigComponentAddFieldFactoryLoadingError=Unable to load the factory list: {0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 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.service.device.management.configuration;

import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

@XmlRootElement(name = "configurationFactories")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = DeviceConfigurationXmlRegistry.class, factoryMethod = "newComponentConfigurationFactories")
public interface DeviceComponentConfigurationFactories {

@XmlElement(name = "ids")
@XmlJavaTypeAdapter(DeviceXmlConfigPropertiesAdapter.class)
List<String> getIds();

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface DeviceConfigurationFactory extends KapuaObjectFactory {
* @return
*/
DeviceConfiguration newConfigurationInstance();

DeviceComponentConfigurationFactories newComponentConfigurationFactories();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ DeviceConfiguration get(KapuaId scopeId, KapuaId deviceId,
Long timeout)
throws KapuaException;

DeviceComponentConfigurationFactories getFactories(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException;

void create(KapuaId scopeId, KapuaId deviceId, String componentFactoryId, String componentId, Long timeout) throws KapuaException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ public DeviceConfiguration newConfiguration() {
public DeviceComponentConfiguration newComponentConfiguration() {
return DEVICE_CONFIGURATION_FACTORY.newComponentConfigurationInstance(null);
}

public DeviceComponentConfigurationFactories newComponentConfigurationFactories() {
return DEVICE_CONFIGURATION_FACTORY.newComponentConfigurationFactories();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 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.service.device.management.configuration.internal;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactories;

public class DeviceComponentConfigurationFactoriesImpl implements DeviceComponentConfigurationFactories {

private final List<String> ids = new ArrayList<>();

@Override
public List<String> getIds() {
return ids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.kapua.locator.KapuaProvider;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactories;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationFactory;

Expand All @@ -35,4 +36,9 @@ public DeviceConfiguration newConfigurationInstance() {
return new DeviceConfigurationImpl();
}

@Override
public DeviceComponentConfigurationFactories newComponentConfigurationFactories() {
return new DeviceComponentConfigurationFactoriesImpl();
}

}
Loading

0 comments on commit f5ac35b

Please sign in to comment.