use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.
the class GwtDeviceServiceImpl method createDevice.
public GwtDevice createDevice(GwtXSRFToken xsrfToken, GwtDeviceCreator gwtDeviceCreator) throws GwtKapuaException {
//
// Checking validity of the given XSRF Token
checkXSRFToken(xsrfToken);
KapuaLocator locator = KapuaLocator.getInstance();
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
DeviceFactory deviceFactory = locator.getFactory(DeviceFactory.class);
GwtDevice gwtDevice = null;
try {
KapuaId scopeId = KapuaEid.parseShortId(gwtDeviceCreator.getScopeId());
DeviceCreator deviceCreator = deviceFactory.newCreator(scopeId, gwtDeviceCreator.getClientId());
deviceCreator.setDisplayName(gwtDeviceCreator.getDisplayName());
deviceCreator.setCredentialsMode(DeviceCredentialsMode.valueOf(gwtDeviceCreator.getGwtCredentialsTight().name()));
deviceCreator.setCustomAttribute1(gwtDeviceCreator.getCustomAttribute1());
deviceCreator.setCustomAttribute2(gwtDeviceCreator.getCustomAttribute2());
deviceCreator.setCustomAttribute3(gwtDeviceCreator.getCustomAttribute3());
deviceCreator.setCustomAttribute4(gwtDeviceCreator.getCustomAttribute4());
deviceCreator.setCustomAttribute5(gwtDeviceCreator.getCustomAttribute5());
Device device = deviceRegistryService.create(deviceCreator);
gwtDevice = KapuaGwtConverter.convert(device);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtDevice;
}
use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.
the class GwtDeviceServiceImpl method findDevice.
public GwtDevice findDevice(String scopeIdString, String clientId) throws GwtKapuaException {
GwtDevice gwtDevice = null;
try {
KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
KapuaLocator locator = KapuaLocator.getInstance();
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(scopeId, clientId);
gwtDevice = KapuaGwtConverter.convert(device);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtDevice;
}
use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.
the class GwtDeviceServiceImpl method updateAttributes.
public GwtDevice updateAttributes(GwtXSRFToken xsrfToken, GwtDevice gwtDevice) throws GwtKapuaException {
//
// Checking validity of the given XSRF Token
checkXSRFToken(xsrfToken);
KapuaLocator locator = KapuaLocator.getInstance();
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = null;
GwtDevice gwtDeviceUpdated = null;
try {
//
// Find original device
KapuaId scopeId = KapuaEid.parseShortId(gwtDevice.getScopeId());
KapuaId deviceId = KapuaEid.parseShortId(gwtDevice.getId());
device = deviceRegistryService.find(scopeId, deviceId);
//
// Updated values
// Gerenal info
device.setDisplayName(gwtDevice.getUnescapedDisplayName());
device.setStatus(DeviceStatus.valueOf(gwtDevice.getGwtDeviceStatus()));
// Security Stuff
device.setCredentialsMode(DeviceCredentialsMode.valueOf(gwtDevice.getCredentialsTight()));
KapuaId deviceUserId = KapuaEid.parseShortId(gwtDevice.getDeviceUserId());
device.setPreferredUserId(deviceUserId);
// Custom attributes
device.setCustomAttribute1(gwtDevice.getUnescapedCustomAttribute1());
device.setCustomAttribute2(gwtDevice.getUnescapedCustomAttribute2());
device.setCustomAttribute3(gwtDevice.getUnescapedCustomAttribute3());
device.setCustomAttribute4(gwtDevice.getUnescapedCustomAttribute4());
device.setCustomAttribute5(gwtDevice.getUnescapedCustomAttribute5());
device.setOptlock(gwtDevice.getOptlock());
// Do the update
device = deviceRegistryService.update(device);
// Convert to gwt object
gwtDeviceUpdated = KapuaGwtConverter.convert(device);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtDeviceUpdated;
}
use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.
the class DeviceConfigComponents method refreshWhenOnline.
// --------------------------------------------------------------------------------------
//
// Device Configuration Management
//
// --------------------------------------------------------------------------------------
public void refreshWhenOnline() {
final int PERIOD_MILLIS = 1000;
Timer timer = new Timer() {
private int TIMEOUT_MILLIS = 30000;
private int countdownMillis = TIMEOUT_MILLIS;
public void run() {
if (m_selectedDevice != null) {
countdownMillis -= PERIOD_MILLIS;
//
// Poll the current status of the device until is online again or timeout.
gwtDeviceService.findDevice(m_selectedDevice.getScopeId(), m_selectedDevice.getUnescapedClientId(), new AsyncCallback<GwtDevice>() {
@Override
public void onFailure(Throwable t) {
done();
}
@Override
public void onSuccess(GwtDevice gwtDevice) {
if (countdownMillis <= 0 || // Allow the device to disconnect before checking if it's online again.
((TIMEOUT_MILLIS - countdownMillis) > 5000 && gwtDevice.isOnline())) {
done();
}
}
private void done() {
cancel();
refresh();
if (m_devConfPanel != null) {
m_devConfPanel.unmask();
}
}
});
}
}
};
m_devConfPanel.mask(MSGS.waiting());
timer.scheduleRepeating(PERIOD_MILLIS);
}
use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.
the class DeviceConfigSnapshots method refreshWhenOnline.
// --------------------------------------------------------------------------------------
//
// Device Event List Management
//
// --------------------------------------------------------------------------------------
public void refreshWhenOnline() {
final int PERIOD_MILLIS = 1000;
Timer timer = new Timer() {
private int TIMEOUT_MILLIS = 30000;
private int countdownMillis = TIMEOUT_MILLIS;
public void run() {
if (m_selectedDevice != null) {
countdownMillis -= PERIOD_MILLIS;
//
// Poll the current status of the device until is online again or timeout.
gwtDeviceService.findDevice(m_selectedDevice.getScopeId(), m_selectedDevice.getClientId(), new AsyncCallback<GwtDevice>() {
@Override
public void onFailure(Throwable t) {
done();
}
@Override
public void onSuccess(GwtDevice gwtDevice) {
if (countdownMillis <= 0 || // Allow the device to disconnect before checking if it's online again.
((TIMEOUT_MILLIS - countdownMillis) > 5000 && gwtDevice.isOnline())) {
done();
}
}
private void done() {
cancel();
// force a dirty on both tabs
m_tabConfig.setDevice(m_selectedDevice);
refresh();
}
});
}
}
};
m_grid.mask(MSGS.waiting());
timer.scheduleRepeating(PERIOD_MILLIS);
}
Aggregations