Search in sources :

Example 26 with KapuaId

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);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) PackageResponseMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Date(java.util.Date) PackageRequestChannel(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestChannel) DeviceCallExecutor(org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PackageRequestMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestMessage) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId) PackageRequestPayload(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestPayload)

Example 27 with KapuaId

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) AccountService(org.eclipse.kapua.service.account.AccountService) GwtAccountService(org.eclipse.kapua.app.console.shared.service.GwtAccountService)

Example 28 with KapuaId

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) KapuaId(org.eclipse.kapua.model.id.KapuaId) AccountService(org.eclipse.kapua.service.account.AccountService) GwtAccountService(org.eclipse.kapua.app.console.shared.service.GwtAccountService)

Example 29 with KapuaId

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);
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DeviceBundles(org.eclipse.kapua.service.device.management.bundle.DeviceBundles) ArrayList(java.util.ArrayList) KapuaId(org.eclipse.kapua.model.id.KapuaId) DeviceBundle(org.eclipse.kapua.service.device.management.bundle.DeviceBundle) DeviceBundleManagementService(org.eclipse.kapua.service.device.management.bundle.DeviceBundleManagementService) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair)

Example 30 with KapuaId

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);
    }
}
Also used : DevicePackageManagementService(org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageFactory(org.eclipse.kapua.service.device.management.packages.DevicePackageFactory) DevicePackageUninstallRequest(org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Aggregations

KapuaId (org.eclipse.kapua.model.id.KapuaId)75 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)54 Account (org.eclipse.kapua.service.account.Account)14 AccountService (org.eclipse.kapua.service.account.AccountService)14 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 Device (org.eclipse.kapua.service.device.registry.Device)11 Test (org.junit.Test)11 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)10 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)9 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)9 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)9 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)8 IdGeneratorService (org.eclipse.kapua.service.generator.id.IdGeneratorService)8 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)7 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)7 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)7 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)7 User (org.eclipse.kapua.service.user.User)7 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)6