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;
}
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();
}
}
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);
}
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);
}
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;
}
Aggregations