Skip to content

Commit

Permalink
💥 concrete DeviceAsset and DeviceAssetChannel
Browse files Browse the repository at this point in the history
Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Feb 6, 2025
1 parent f571665 commit 8ad5ba2
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.kapua.app.console.module.device.shared.model.management.assets.GwtDeviceAssets;
import org.eclipse.kapua.app.console.module.device.shared.model.management.registry.GwtDeviceManagementOperationQuery;
import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.model.query.FieldSortCriteria;
import org.eclipse.kapua.model.query.SortOrder;
Expand All @@ -38,7 +37,6 @@
import org.eclipse.kapua.service.device.management.asset.DeviceAsset;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetChannel;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetChannelMode;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetFactory;
import org.eclipse.kapua.service.device.management.asset.DeviceAssets;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationAttributes;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationQuery;
Expand All @@ -54,10 +52,6 @@

public class GwtKapuaDeviceModelConverter {

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();

private static final DeviceAssetFactory ASSET_FACTORY = LOCATOR.getFactory(DeviceAssetFactory.class);

private GwtKapuaDeviceModelConverter() {
}

Expand Down Expand Up @@ -126,7 +120,7 @@ public static DeviceAssets convertDeviceAssets(GwtDeviceAssets deviceAssets) {

public static DeviceAsset convertDeviceAsset(GwtDeviceAsset gwtDeviceAsset) {

DeviceAsset deviceAsset = ASSET_FACTORY.newDeviceAsset();
DeviceAsset deviceAsset = new DeviceAsset();
deviceAsset.setName(gwtDeviceAsset.getName());
for (GwtDeviceAssetChannel gwtDeviceAssetChannel : gwtDeviceAsset.getChannels()) {
deviceAsset.getChannels().add(convertDeviceAssetChannel(gwtDeviceAssetChannel));
Expand All @@ -136,7 +130,7 @@ public static DeviceAsset convertDeviceAsset(GwtDeviceAsset gwtDeviceAsset) {

public static DeviceAssetChannel convertDeviceAssetChannel(GwtDeviceAssetChannel gwtDeviceAssetChannel) {

DeviceAssetChannel channel = ASSET_FACTORY.newDeviceAssetChannel();
DeviceAssetChannel channel = new DeviceAssetChannel();
channel.setName(gwtDeviceAssetChannel.getName());
try {
channel.setType(ObjectTypeConverter.fromString(gwtDeviceAssetChannel.getType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.eclipse.kapua.service.device.call.kura.model.inventory.system.KuraInventorySystemPackage;
import org.eclipse.kapua.service.device.call.kura.model.inventory.system.KuraInventorySystemPackages;
import org.eclipse.kapua.service.device.call.kura.model.snapshot.KuraSnapshotIds;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetXmlRegistry;
import org.eclipse.kapua.service.device.management.asset.DeviceAssets;
import org.eclipse.kapua.service.device.management.bundle.DeviceBundle;
import org.eclipse.kapua.service.device.management.bundle.DeviceBundles;
Expand Down Expand Up @@ -207,7 +206,6 @@ public JAXBContext getJAXBContext() throws KapuaException {

// Device Management Assets
DeviceAssets.class,
DeviceAssetXmlRegistry.class,

// Job
JobTargetSublist.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
import org.eclipse.kapua.service.KapuaService;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetChannel;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetFactory;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetManagementService;
import org.eclipse.kapua.service.device.management.asset.DeviceAssets;
import org.eclipse.kapua.service.device.management.asset.store.DeviceAssetStoreService;
Expand All @@ -43,8 +42,6 @@ public class DeviceManagementAssets extends AbstractKapuaResource {
@Inject
public DeviceAssetManagementService deviceManagementAssetService;
@Inject
public DeviceAssetFactory deviceAssetFilter;
@Inject
public DeviceAssetStoreService deviceAssetStoreService;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*******************************************************************************/
package org.eclipse.kapua.service.device.management.asset;

import org.eclipse.kapua.service.device.management.asset.xml.DeviceAssetChannelXmlAdapter;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand All @@ -21,7 +22,8 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.List;

import org.eclipse.kapua.service.device.management.asset.xml.DeviceAssetChannelXmlAdapter;

/**
* {@link DeviceAsset} definition.
Expand All @@ -32,8 +34,11 @@
*/
@XmlRootElement(name = "deviceAsset")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = DeviceAssetXmlRegistry.class, factoryMethod = "newDeviceAsset")
public interface DeviceAsset {
@XmlType
public class DeviceAsset {

private String name;
private List<DeviceAssetChannel> channels;

/**
* Gets the name.
Expand All @@ -42,15 +47,20 @@ public interface DeviceAsset {
* @since 1.0.0
*/
@XmlElement(name = "name")
String getName();
public String getName() {
return name;
}

/**
* Sets the name.
*
* @param name The name.
* @param name
* The name.
* @since 1.0.0
*/
void setName(String name);
public void setName(String name) {
this.name = name;
}

/**
* Gets the {@link DeviceAssetChannel} available.
Expand All @@ -61,13 +71,23 @@ public interface DeviceAsset {
@XmlElementWrapper(name = "channels")
@XmlElement(name = "channel")
@XmlJavaTypeAdapter(DeviceAssetChannelXmlAdapter.class)
List<DeviceAssetChannel> getChannels();
public List<DeviceAssetChannel> getChannels() {
if (channels == null) {
channels = new ArrayList<>();
}

return channels;
}

/**
* Sets the {@link DeviceAssetChannel} available.
*
* @param channels The {@link DeviceAssetChannel} available.
* @param channels
* The {@link DeviceAssetChannel} available.
* @since 1.0.0
*/
void setChannels(List<DeviceAssetChannel> channels);
public void setChannels(List<DeviceAssetChannel> channels) {
this.channels = channels;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,35 @@
*
* @since 1.0.0
*/
public interface DeviceAssetChannel {
public class DeviceAssetChannel {

private String name;
private Class<?> clazz;
private DeviceAssetChannelMode mode;
private Object value;
private String error;
private Date timestamp;

/**
* Gets the name.
*
* @return The name.
* @since 1.0.0
*/
String getName();
public String getName() {
return name;
}

/**
* Gets the name.
*
* @param name The name.
* @param name
* The name.
* @since 1.0.0
*/
void setName(String name);
public void setName(String name) {
this.name = name;
}

/**
* Gets the {@link Class} type.
Expand All @@ -47,90 +59,115 @@ public interface DeviceAssetChannel {
* @return The channel value type.
* @since 1.0.0
*/
Class<?> getType();
public Class<?> getType() {
return clazz;
}

/**
* Sets the {@link Class} type.
* This type must be coherent with the value given to {@link #setValue(Object)}.
* If not, errors will occur during the interaction with the device.
* Sets the {@link Class} type. This type must be coherent with the value given to {@link #setValue(Object)}. If not, errors will occur during the interaction with the device.
*
* @param type The {@link Class} type.
* @param type
* The {@link Class} type.
* @since 1.0.0
*/
void setType(Class<?> type);
public void setType(Class<?> type) {
this.clazz = type;
}

/**
* Gets the {@link DeviceAssetChannelMode}.
*
* @return The {@link DeviceAssetChannelMode}.
* @since 1.0.0
*/
DeviceAssetChannelMode getMode();
public DeviceAssetChannelMode getMode() {
return mode;
}

/**
* Sets the {@link DeviceAssetChannelMode}.
*
* @param deviceAssetChannelMode The {@link DeviceAssetChannelMode}.
* @param deviceAssetChannelMode
* The {@link DeviceAssetChannelMode}.
* @since 1.0.0
*/
void setMode(DeviceAssetChannelMode deviceAssetChannelMode);
public void setMode(DeviceAssetChannelMode deviceAssetChannelMode) {
this.mode = deviceAssetChannelMode;
}

/**
* Gets the value channel.
* <p>
* Depending on the {@link DeviceAssetChannelMode} this can be a value {@link DeviceAssetChannelMode#READ} from the channel or
* to {@link DeviceAssetChannelMode#WRITE} into the channel.
* This is mutually exclusive with {@link #getError()}
* Depending on the {@link DeviceAssetChannelMode} this can be a value {@link DeviceAssetChannelMode#READ} from the channel or to {@link DeviceAssetChannelMode#WRITE} into the channel. This is
* mutually exclusive with {@link #getError()}
*
* @return The value channel.
* @since 1.0.0
*/
Object getValue();
public Object getValue() {
return value;
}

/**
* Sets the value channel.
* <p>
* Depending on the {@link DeviceAssetChannelMode} this can be a value {@link DeviceAssetChannelMode#READ} from the channel or
* to {@link DeviceAssetChannelMode#WRITE} into the channel.
* Depending on the {@link DeviceAssetChannelMode} this can be a value {@link DeviceAssetChannelMode#READ} from the channel or to {@link DeviceAssetChannelMode#WRITE} into the channel.
*
* @param value The value channel.
* @param value
* The value channel.
* @since 1.0.0
*/
void setValue(Object value);
public void setValue(Object value) {
this.value = value;

if (value != null) {
setType(value.getClass());
}
}

/**
* Gets the error message.
* <p>
* When reading from or writing to a channel, if any error occurs it will be reported here.
* This is mutually exclusive with {@link #getValue()}
* When reading from or writing to a channel, if any error occurs it will be reported here. This is mutually exclusive with {@link #getValue()}
*
* @return The error message, if error has occurred.
* @since 1.0.0
*/
String getError();
public String getError() {
return error;
}

/**
* Sets the error message.
* <p>
* This must be set if error has occurred during reading from/wrtiting to
*
* @param error The error message.
* @param error
* The error message.
*/
void setError(String error);
public void setError(String error) {
this.error = error;
}

/**
* Gets the {@link Date} of the time when the value was read from the channel.
*
* @return The {@link Date} of the time when the value was read from the channel.
* @since 1.0.0
*/
Date getTimestamp();
public Date getTimestamp() {
return timestamp;
}

/**
* Sets the {@link Date} of the time when the value was read from the channel.
*
* @param timestamp The {@link Date} of the time when the value was read from the channel.
* @param timestamp
* The {@link Date} of the time when the value was read from the channel.
* @since 1.0.0
*/
void setTimestamp(Date timestamp);
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}

}

This file was deleted.

Loading

0 comments on commit 8ad5ba2

Please sign in to comment.