use of org.eclipse.kapua.locator.KapuaLocator in project kapua by eclipse.
the class AbstractKapuaConfigurableService method setConfigValues.
@Override
public void setConfigValues(KapuaId scopeId, Map<String, Object> values) throws KapuaException {
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.write, scopeId));
KapuaTocd ocd = this.getConfigMetadata();
validateConfigurations(this.pid, ocd, values);
Properties props = toProperties(values);
AndPredicate predicate = new AndPredicate().and(new AttributePredicate<String>("pid", this.pid, Operator.EQUAL)).and(new AttributePredicate<KapuaId>("scopeId", scopeId, Operator.EQUAL));
ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId);
query.setPredicate(predicate);
ServiceConfig serviceConfig = null;
EntityManager em = this.entityManagerFactory.createEntityManager();
ServiceConfigListResultImpl result = ServiceConfigDAO.query(em, ServiceConfig.class, ServiceConfigImpl.class, new ServiceConfigListResultImpl(), query);
// In not exists create then return
if (result == null || result.getSize() == 0) {
ServiceConfigImpl serviceConfigNew = new ServiceConfigImpl(scopeId);
serviceConfigNew.setPid(this.pid);
serviceConfigNew.setConfigurations(props);
serviceConfig = this.create(em, serviceConfigNew);
return;
}
// If exists update it
serviceConfig = result.getItem(0);
serviceConfig.setConfigurations(props);
this.update(em, serviceConfig);
return;
}
use of org.eclipse.kapua.locator.KapuaLocator in project kapua by eclipse.
the class AbstractKapuaConfigurableService method getConfigValues.
@Override
public Map<String, Object> getConfigValues(KapuaId scopeId) throws KapuaException {
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
AndPredicate predicate = new AndPredicate().and(new AttributePredicate<String>("pid", this.pid, Operator.EQUAL)).and(new AttributePredicate<KapuaId>("scopeId", scopeId, Operator.EQUAL));
ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId);
query.setPredicate(predicate);
Properties properties = null;
EntityManager em = this.entityManagerFactory.createEntityManager();
ServiceConfigListResult result = ServiceConfigDAO.query(em, ServiceConfig.class, ServiceConfigImpl.class, new ServiceConfigListResultImpl(), query);
if (result != null && result.getSize() > 0)
properties = result.getItem(0).getConfigurations();
KapuaTocd ocd = this.getConfigMetadata();
return toValues(ocd, properties);
}
use of org.eclipse.kapua.locator.KapuaLocator in project kapua by eclipse.
the class AbstractKapuaConfigurableService method getConfigMetadata.
@Override
public KapuaTocd getConfigMetadata() throws KapuaException {
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
KapuaId scopeId = KapuaSecurityUtils.getSession().getScopeId();
authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
try {
TmetadataImpl metadata = readMetadata(this.pid);
if (metadata.getOCD() != null && metadata.getOCD().size() > 0) {
for (KapuaTocd ocd : metadata.getOCD()) {
if (ocd.getId() != null && ocd.getId().equals(pid)) {
return ocd;
}
}
}
return null;
} catch (Exception e) {
throw KapuaConfigurationException.internalError(e);
}
}
use of org.eclipse.kapua.locator.KapuaLocator in project kapua by eclipse.
the class AccountServiceTest method testCreate.
@Test
public void testCreate() 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 asserts
assertNotNull(account);
assertNotNull(account.getId());
assertNotNull(account.getId().getId());
assertTrue(account.getOptlock() >= 0);
assertTrue(account.getScopeId().equals(scopeId));
assertTrue(account.getName().equals(accountCreator.getOrganizationName()));
assertNotNull(account.getOrganization());
assertTrue(account.getOrganization().getEmail().equals(accountCreator.getOrganizationEmail()));
assertNotNull(account.getCreatedOn());
assertNotNull(account.getCreatedBy());
assertNotNull(account.getModifiedOn());
assertNotNull(account.getModifiedBy());
}
use of org.eclipse.kapua.locator.KapuaLocator 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;
}
Aggregations