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