use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorAppCommandKapuaKura method translate.
@Override
public KuraRequestMessage translate(CommandRequestMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
kuraRequestChannel.setScope(account.getName());
kuraRequestChannel.setClientId(device.getClientId());
//
// Kura payload
KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
// return Kura Message
return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorAppBundleKapuaKura method translate.
@Override
public KuraRequestMessage translate(BundleRequestMessage kapuaMessage) throws KapuaException {
//
// Kura channel
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(kapuaMessage.getScopeId());
DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
kuraRequestChannel.setScope(account.getName());
kuraRequestChannel.setClientId(device.getClientId());
//
// Kura payload
KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
// Return Kura Message
return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorLifeAppsKuraKapua method translate.
@Override
public KapuaAppsMessage translate(KuraAppsMessage kuraAppsMessage) throws KapuaException {
KapuaAppsMessage kapuaAppsMessage = new KapuaAppsMessageImpl();
kapuaAppsMessage.setChannel(translate(kuraAppsMessage.getChannel()));
kapuaAppsMessage.setPayload(translate(kuraAppsMessage.getPayload()));
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraAppsMessage.getChannel().getScope());
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(account.getId(), kuraAppsMessage.getChannel().getClientId());
if (device == null) {
throw new KapuaEntityNotFoundException(Device.class.toString(), kuraAppsMessage.getChannel().getClientId());
}
kapuaAppsMessage.setDeviceId(device.getId());
kapuaAppsMessage.setScopeId(account.getId());
kapuaAppsMessage.setCapturedOn(kuraAppsMessage.getPayload().getTimestamp());
kapuaAppsMessage.setSentOn(kuraAppsMessage.getPayload().getTimestamp());
kapuaAppsMessage.setReceivedOn(kuraAppsMessage.getTimestamp());
kapuaAppsMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraAppsMessage.getPayload().getPosition()));
return kapuaAppsMessage;
}
use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class TranslatorLifeBirthKuraKapua method translate.
@Override
public KapuaBirthMessage translate(KuraBirthMessage kuraBirthMessage) throws KapuaException {
KapuaBirthMessage kapuaBirthMessage = new KapuaBirthMessageImpl();
kapuaBirthMessage.setChannel(translate(kuraBirthMessage.getChannel()));
kapuaBirthMessage.setPayload(translate(kuraBirthMessage.getPayload()));
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.findByName(kuraBirthMessage.getChannel().getScope());
DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
Device device = deviceRegistryService.findByClientId(account.getId(), kuraBirthMessage.getChannel().getClientId());
kapuaBirthMessage.setScopeId(account.getId());
if (device != null) {
kapuaBirthMessage.setDeviceId(device.getId());
} else {
kapuaBirthMessage.setClientId(kuraBirthMessage.getChannel().getClientId());
}
kapuaBirthMessage.setCapturedOn(kuraBirthMessage.getPayload().getTimestamp());
kapuaBirthMessage.setSentOn(kuraBirthMessage.getPayload().getTimestamp());
kapuaBirthMessage.setReceivedOn(kuraBirthMessage.getTimestamp());
kapuaBirthMessage.setPosition(TranslatorKuraKapuaUtils.translate(kuraBirthMessage.getPayload().getPosition()));
return kapuaBirthMessage;
}
use of org.eclipse.kapua.service.device.registry.Device in project kapua by eclipse.
the class Devices method postDevice.
/**
* Creates a new Device based on the information provided in DeviceCreator parameter.
*
* @param deviceCreator
* Provides the information for the new Device to be created.
* @return The newly created Device object.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Device postDevice(DeviceCreator deviceCreator) {
Device device = null;
try {
deviceCreator.setScopeId(KapuaSecurityUtils.getSession().getScopeId());
device = deviceRegistryService.create(deviceCreator);
} catch (Throwable t) {
handleException(t);
}
return returnNotNullEntity(device);
}
Aggregations