Search in sources :

Example 21 with AccountService

use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.

the class GwtAccountServiceImpl method create.

public GwtAccount create(GwtXSRFToken xsrfToken, GwtAccountCreator gwtAccountCreator) throws GwtKapuaException {
    // 
    // Checking validity of the given XSRF Token
    checkXSRFToken(xsrfToken);
    GwtAccount gwtAccount = null;
    KapuaId parentAccountId = KapuaEid.parseShortId(gwtAccountCreator.getParentAccountId());
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
        AccountCreator accountCreator = accountFactory.newAccountCreator(parentAccountId, gwtAccountCreator.getAccountName());
        accountCreator.setAccountPassword(gwtAccountCreator.getAccountPassword());
        accountCreator.setOrganizationName(gwtAccountCreator.getOrganizationName());
        accountCreator.setOrganizationPersonName(gwtAccountCreator.getOrganizationPersonName());
        accountCreator.setOrganizationEmail(gwtAccountCreator.getOrganizationEmail());
        accountCreator.setOrganizationPhoneNumber(gwtAccountCreator.getOrganizationPhoneNumber());
        accountCreator.setOrganizationAddressLine1(gwtAccountCreator.getOrganizationAddressLine1());
        accountCreator.setOrganizationAddressLine2(gwtAccountCreator.getOrganizationAddressLine2());
        accountCreator.setOrganizationCity(gwtAccountCreator.getOrganizationCity());
        accountCreator.setOrganizationZipPostCode(gwtAccountCreator.getOrganizationZipPostCode());
        accountCreator.setOrganizationStateProvinceCounty(gwtAccountCreator.getOrganizationStateProvinceCounty());
        accountCreator.setOrganizationCountry(gwtAccountCreator.getOrganizationCountry());
        // create the Account
        AccountService accountService = locator.getService(AccountService.class);
        Account account = accountService.create(accountCreator);
        // convert to GwtAccount and return
        gwtAccount = KapuaGwtConverter.convert(account);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtAccount;
}
Also used : GwtAccountCreator(org.eclipse.kapua.app.console.shared.model.GwtAccountCreator) AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AccountFactory(org.eclipse.kapua.service.account.AccountFactory) 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 22 with AccountService

use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.

the class GwtAccountServiceImpl method updateAccountProperties.

public GwtAccount updateAccountProperties(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);
        // update properties
        Properties property = account.getEntityProperties();
        if (property == null) {
            property = new Properties();
        }
        if (gwtAccount.getUnescapedDashboardPreferredTopic() != null) {
            property.put("topic", gwtAccount.getUnescapedDashboardPreferredTopic());
        }
        if (gwtAccount.getUnescapedDashboardPreferredMetric() != null) {
            property.put("metric", gwtAccount.getUnescapedDashboardPreferredMetric());
        }
        account.setEntityProperties(property);
        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) Properties(java.util.Properties) AccountService(org.eclipse.kapua.service.account.AccountService) GwtAccountService(org.eclipse.kapua.app.console.shared.service.GwtAccountService)

Example 23 with AccountService

use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.

the class AccountServiceTest method testDelete.

@Test
public void testDelete() throws Exception {
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.create(accountCreator);
    accountService.delete(scopeId, account.getId());
    try {
        account = accountService.find(account.getScopeId(), account.getId());
    } catch (KapuaEntityNotFoundException ex) {
        account = null;
    }
    assertTrue(account == null);
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) Test(org.junit.Test)

Example 24 with AccountService

use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.

the class AccountServiceTest method testFind.

@Test
public void testFind() throws Exception {
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.create(accountCreator);
    account = accountService.find(account.getScopeId(), account.getId());
    // 
    // Account asserts
    assertNotNull(account);
    assertNotNull(account.getId());
    assertNotNull(account.getId().getId());
    assertTrue(account.getOptlock() >= 0);
    assertTrue(account.getScopeId().equals(accountCreator.getScopeId()));
    assertTrue(account.getName().equals(accountCreator.getName()));
    assertNotNull(account.getOrganization());
    assertTrue(account.getOrganization().getEmail().equals(accountCreator.getOrganizationEmail()));
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date) Test(org.junit.Test)

Example 25 with AccountService

use of org.eclipse.kapua.service.account.AccountService in project kapua by eclipse.

the class AccountServiceTest method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    KapuaTocd ocd = accountService.getConfigMetadata();
    Map<String, Object> values = accountService.getConfigValues(scopeId);
    accountService.setConfigValues(scopeId, values);
    assertTrue(null == null);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) KapuaTocd(org.eclipse.kapua.model.config.metatype.KapuaTocd) AccountService(org.eclipse.kapua.service.account.AccountService) Test(org.junit.Test)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)34 AccountService (org.eclipse.kapua.service.account.AccountService)34 Account (org.eclipse.kapua.service.account.Account)31 KapuaId (org.eclipse.kapua.model.id.KapuaId)14 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)11 Device (org.eclipse.kapua.service.device.registry.Device)11 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)11 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)10 Date (java.util.Date)6 AccountCreator (org.eclipse.kapua.service.account.AccountCreator)6 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)5 KuraRequestChannel (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)5 KuraRequestMessage (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage)5 KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)5 Test (org.junit.Test)5 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)4 ArrayList (java.util.ArrayList)4 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)4 AccountFactory (org.eclipse.kapua.service.account.AccountFactory)4 KapuaException (org.eclipse.kapua.KapuaException)2