Search in sources :

Example 1 with AccountFactory

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

the class AccountServiceTest method getTestAccountCreator.

private AccountCreator getTestAccountCreator(KapuaId scopeId, long random) {
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    String testAccount = String.format("test-%d", accountSerial);
    AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
    AccountCreator accountCreator = accountFactory.newAccountCreator(scopeId, testAccount);
    accountCreator.setAccountPassword("!aA1234567890");
    accountCreator.setOrganizationName(testAccount);
    accountCreator.setOrganizationEmail(String.format("theuser@%s.com", testAccount));
    return accountCreator;
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AccountFactory(org.eclipse.kapua.service.account.AccountFactory) Date(java.util.Date)

Example 2 with AccountFactory

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

the class DeviceCommandManagementServiceTest method setUpClass.

// @BeforeClass
public static void setUpClass() {
    try {
        // 
        // Login
        String username = "kapua-sys";
        String password = "kapua-password";
        AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
        UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
        authenticationService.login(credentialsFactory.newInstance(username, password.toCharArray()));
        // 
        // Get current user Id
        adminUserId = KapuaSecurityUtils.getSession().getUserId();
        adminScopeId = KapuaSecurityUtils.getSession().getScopeId();
        // 
        // Create test account
        KapuaLocator locator = KapuaLocator.getInstance();
        // 
        // Account creation
        String accountName = String.format("test-acct-%d", (new Date()).getTime());
        AccountService accountService = locator.getService(AccountService.class);
        AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
        AccountCreator accountCreator = accountFactory.newAccountCreator(adminScopeId, accountName);
        accountCreator.setAccountPassword("!bV0123456789");
        accountCreator.setOrganizationName(accountName);
        accountCreator.setOrganizationEmail(accountName + "@m.com");
        account = accountService.create(accountCreator);
    } catch (KapuaException exc) {
        exc.printStackTrace();
    }
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AccountFactory(org.eclipse.kapua.service.account.AccountFactory) KapuaException(org.eclipse.kapua.KapuaException) UsernamePasswordTokenFactory(org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date)

Example 3 with AccountFactory

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

the class GwtAccountServiceImpl method findChildren.

public ListLoadResult<GwtAccount> findChildren(String parentAccountId, boolean recoursive) throws GwtKapuaException {
    KapuaId scopeId = KapuaEid.parseShortId(parentAccountId);
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
    List<GwtAccount> gwtAccountList = new ArrayList<GwtAccount>();
    try {
        AccountQuery query = accountFactory.newQuery(scopeId);
        KapuaListResult<Account> list = accountService.query(query);
        for (Account account : list.getItems()) {
            gwtAccountList.add(KapuaGwtConverter.convert(account));
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtAccount>(gwtAccountList);
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) 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) ArrayList(java.util.ArrayList) 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) AccountQuery(org.eclipse.kapua.service.account.AccountQuery)

Example 4 with AccountFactory

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

the class GwtAccountServiceImpl method findAll.

public ListLoadResult<GwtAccount> findAll(String scopeIdString) throws GwtKapuaException {
    List<GwtAccount> gwtAccountList = new ArrayList<GwtAccount>();
    KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        AccountService accountService = locator.getService(AccountService.class);
        AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
        AccountQuery query = accountFactory.newQuery(scopeId);
        KapuaListResult<Account> list = accountService.query(query);
        for (Account account : list.getItems()) {
            gwtAccountList.add(KapuaGwtConverter.convert(account));
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtAccount>(gwtAccountList);
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) 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) ArrayList(java.util.ArrayList) 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) AccountQuery(org.eclipse.kapua.service.account.AccountQuery)

Example 5 with AccountFactory

use of org.eclipse.kapua.service.account.AccountFactory 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)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)6 AccountFactory (org.eclipse.kapua.service.account.AccountFactory)6 AccountCreator (org.eclipse.kapua.service.account.AccountCreator)4 AccountService (org.eclipse.kapua.service.account.AccountService)4 Date (java.util.Date)3 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)3 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)3 KapuaId (org.eclipse.kapua.model.id.KapuaId)3 Account (org.eclipse.kapua.service.account.Account)3 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)2 ArrayList (java.util.ArrayList)2 AccountQuery (org.eclipse.kapua.service.account.AccountQuery)2 KapuaException (org.eclipse.kapua.KapuaException)1 GwtAccountCreator (org.eclipse.kapua.app.console.shared.model.GwtAccountCreator)1 AuthenticationService (org.eclipse.kapua.service.authentication.AuthenticationService)1 UsernamePasswordTokenFactory (org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory)1