use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.
the class DevicePackageManagementServiceImpl method uninstallExec.
@Override
public void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest deployUninstallRequest, Long timeout) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(deviceId, "deviceId");
ArgumentValidator.notNull(deployUninstallRequest, "deployUninstallRequest");
//
// Check Access
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomain.DEVICE_MANAGEMENT, Actions.write, scopeId));
//
// Generate requestId
IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
KapuaId operationId = idGeneratorService.generate();
//
// Prepare the request
PackageRequestChannel packageRequestChannel = new PackageRequestChannel();
packageRequestChannel.setAppName(PackageAppProperties.APP_NAME);
packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION);
packageRequestChannel.setMethod(KapuaMethod.EXECUTE);
packageRequestChannel.setPackageResource(PackageResource.UNINSTALL);
PackageRequestPayload packageRequestPayload = new PackageRequestPayload();
packageRequestPayload.setOperationId(operationId);
packageRequestPayload.setPackageUninstallName(deployUninstallRequest.getName());
packageRequestPayload.setPackageUninstallVersion(deployUninstallRequest.getVersion());
packageRequestPayload.setReboot(deployUninstallRequest.isReboot());
packageRequestPayload.setRebootDelay(deployUninstallRequest.getRebootDelay());
PackageRequestMessage packageRequestMessage = new PackageRequestMessage();
packageRequestMessage.setScopeId(scopeId);
packageRequestMessage.setDeviceId(deviceId);
packageRequestMessage.setCapturedOn(new Date());
packageRequestMessage.setPayload(packageRequestPayload);
packageRequestMessage.setChannel(packageRequestChannel);
//
// Do get
@SuppressWarnings({ "rawtypes", "unchecked" }) DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout);
PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send();
//
// Create event
DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, deviceId, responseMessage.getReceivedOn(), PackageAppProperties.APP_NAME.getValue());
deviceEventCreator.setPosition(responseMessage.getPosition());
deviceEventCreator.setSentOn(responseMessage.getSentOn());
deviceEventCreator.setAction(KapuaMethod.EXECUTE);
deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());
deviceEventService.create(deviceEventCreator);
}
use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.
the class GwtAccountServiceImpl method find.
public GwtAccount find(String accountIdString) throws GwtKapuaException {
KapuaId accountId = KapuaEid.parseShortId(accountIdString);
GwtAccount gwtAccount = null;
try {
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
gwtAccount = KapuaGwtConverter.convert(accountService.find(accountId));
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtAccount;
}
use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.
the class GwtAccountServiceImpl method update.
public GwtAccount update(GwtXSRFToken xsrfToken, GwtAccount gwtAccount) throws GwtKapuaException {
//
// Checking validity of the given XSRF Token
checkXSRFToken(xsrfToken);
GwtAccount gwtAccountUpdated = null;
KapuaId scopeId = KapuaEid.parseShortId(gwtAccount.getId());
try {
KapuaLocator locator = KapuaLocator.getInstance();
AccountService accountService = locator.getService(AccountService.class);
Account account = accountService.find(scopeId);
account.getOrganization().setName(gwtAccount.getGwtOrganization().getName());
account.getOrganization().setPersonName(gwtAccount.getGwtOrganization().getPersonName());
account.getOrganization().setEmail(gwtAccount.getGwtOrganization().getEmailAddress());
account.getOrganization().setPhoneNumber(gwtAccount.getGwtOrganization().getPhoneNumber());
account.getOrganization().setAddressLine1(gwtAccount.getGwtOrganization().getAddressLine1());
account.getOrganization().setAddressLine2(gwtAccount.getGwtOrganization().getAddressLine2());
account.getOrganization().setZipPostCode(gwtAccount.getGwtOrganization().getZipPostCode());
account.getOrganization().setCity(gwtAccount.getGwtOrganization().getCity());
account.getOrganization().setStateProvinceCounty(gwtAccount.getGwtOrganization().getStateProvinceCounty());
account.getOrganization().setCountry(gwtAccount.getGwtOrganization().getCountry());
account.setOptlock(gwtAccount.getOptlock());
account = accountService.update(account);
// convert to GwtAccount and return
gwtAccountUpdated = KapuaGwtConverter.convert(account);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return gwtAccountUpdated;
}
use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.
the class GwtDeviceManagementServiceImpl method findBundles.
//
// Bundles
//
@Override
public ListLoadResult<GwtGroupedNVPair> findBundles(GwtDevice device) throws GwtKapuaException {
List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
try {
// get the configuration
KapuaLocator locator = KapuaLocator.getInstance();
DeviceBundleManagementService deviceBundleManagementService = locator.getService(DeviceBundleManagementService.class);
KapuaId scopeId = KapuaEid.parseShortId(device.getScopeId());
KapuaId id = KapuaEid.parseShortId(device.getId());
DeviceBundles bundles = deviceBundleManagementService.get(scopeId, id, null);
for (DeviceBundle bundle : bundles.getBundles()) {
GwtGroupedNVPair pair = new GwtGroupedNVPair();
pair.setId(String.valueOf(bundle.getId()));
pair.setName(bundle.getName());
pair.setStatus(toStateString(bundle));
pair.setVersion(bundle.getVersion());
pairs.add(pair);
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return new BaseListLoadResult<GwtGroupedNVPair>(pairs);
}
use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.
the class GwtDeviceManagementServiceImpl method uninstallPackage.
@Override
public void uninstallPackage(GwtXSRFToken xsrfToken, GwtPackageUninstallRequest gwtPackageUninstallRequest) throws GwtKapuaException {
//
// Check token
checkXSRFToken(xsrfToken);
// Do install
try {
KapuaId scopeId = KapuaEid.parseShortId(gwtPackageUninstallRequest.getScopeId());
KapuaId deviceId = KapuaEid.parseShortId(gwtPackageUninstallRequest.getDeviceId());
KapuaLocator locator = KapuaLocator.getInstance();
DevicePackageFactory devicePackageFactory = locator.getFactory(DevicePackageFactory.class);
DevicePackageUninstallRequest packageUninstallRequest = devicePackageFactory.newPackageUninstallRequest();
packageUninstallRequest.setName(gwtPackageUninstallRequest.getPackageName());
packageUninstallRequest.setVersion(gwtPackageUninstallRequest.getPackageVersion());
packageUninstallRequest.setReboot(gwtPackageUninstallRequest.isReboot());
packageUninstallRequest.setRebootDelay(gwtPackageUninstallRequest.getRebootDelay());
DevicePackageManagementService packageManagementService = locator.getService(DevicePackageManagementService.class);
packageManagementService.uninstallExec(scopeId, deviceId, packageUninstallRequest, null);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
}
Aggregations