use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class TopicInfoStoreServiceImpl method delete.
//
// @Override
// public StorableId store(KapuaId scopeId, TopicInfoCreator creator)
// throws KapuaException
// {
// // TODO DAOs are ready, need to evaluate if this functionality
// // have to be available or not. Currently entries are added by
// // the message service directy
// throw KapuaException.internalError("Not implemented");
// }
//
// @Override
// public StorableId update(KapuaId scopeId, TopicInfo creator)
// throws KapuaException
// {
// // TODO DAOs are ready, need to evaluate if this functionality
// // have to be available or not. Currently entries are added by
// // the message service directy
// throw KapuaException.internalError("Not implemented");
// }
@Override
public void delete(KapuaId scopeId, StorableId id) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(id, "id");
//
// Check Access
this.checkDataAccess(scopeId, Actions.delete);
//
// Do the find
AccountInfo accountInfo = getAccountServicePlan(scopeId);
String scopeName = accountInfo.getAccount().getName();
LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
logger.debug("Storage not enabled for account {}, return", scopeName);
return;
}
try {
String everyIndex = EsUtils.getAnyIndexName(scopeName);
TopicInfo topicInfo = this.find(scopeId, id);
MessageQueryImpl mqi = new MessageQueryImpl();
TopicMatchPredicateImpl predicate = new TopicMatchPredicateImpl(topicInfo.getFullTopicName());
mqi.setPredicate(predicate);
EsMessageDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.MESSAGE_TYPE_NAME).setListener(null).deleteByQuery(mqi);
MetricInfoQueryImpl miqi = new MetricInfoQueryImpl();
mqi.setPredicate(predicate);
EsMetricDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.METRIC_TYPE_NAME).setListener(null).deleteByQuery(miqi);
EsTopicDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.TOPIC_TYPE_NAME).deleteById(id.toString());
} catch (Exception exc) {
// CassandraUtils.handleException(e);
throw KapuaException.internalError(exc);
}
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class TopicInfoStoreServiceImpl method count.
@Override
public long count(KapuaId scopeId, TopicInfoQuery query) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(query, "query");
//
// Check Access
this.checkDataAccess(scopeId, Actions.read);
//
// Do the find
AccountInfo accountInfo = getAccountServicePlan(scopeId);
String scopeName = accountInfo.getAccount().getName();
LocalServicePlan accountServicePlan = accountInfo.getServicePlan();
long ttl = accountServicePlan.getDataTimeToLive() * DAY_MILLIS;
if (!accountServicePlan.getDataStorageEnabled() || ttl == LocalServicePlan.DISABLED) {
logger.debug("Storage not enabled for account {}, returning empty result", scopeName);
return 0;
}
try {
String everyIndex = EsUtils.getAnyIndexName(scopeName);
long result;
result = EsTopicDAO.connection(EsClient.getcurrent()).instance(everyIndex, EsSchema.TOPIC_TYPE_NAME).count(query);
return result;
} catch (Exception exc) {
// CassandraUtils.handleException(e);
throw KapuaException.internalError(exc);
}
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class AccountServiceImpl method findChildAccountsTrusted.
private List<Account> findChildAccountsTrusted(KapuaId accountId) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(accountId, "accountId");
ArgumentValidator.notNull(accountId.getId(), "accountId.id");
//
// Do the find
List<Account> accounts = null;
EntityManager em = AccountEntityManagerFactory.getInstance().createEntityManager();
try {
TypedQuery<Account> q = em.createNamedQuery("Account.findChildAccounts", Account.class);
q.setParameter("scopeId", accountId);
accounts = q.getResultList();
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return accounts;
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class AccountServiceImpl method findById.
/**
* Find an account without authorization.
*
* @param accountId
* @return
* @throws KapuaException
*/
private Account findById(KapuaId accountId) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(accountId, "accountId");
//
// Do the find
Account account = null;
EntityManager em = AccountEntityManagerFactory.getInstance().createEntityManager();
try {
account = AccountDAO.find(em, accountId);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return account;
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class AccountServiceImpl method update.
@Override
public Account update(Account account) throws KapuaException {
//
// Validation of the fields
ArgumentValidator.notNull(account.getId(), "id");
ArgumentValidator.notNull(account.getId().getId(), "id.id");
ArgumentValidator.notEmptyOrNull(account.getName(), "accountName");
ArgumentValidator.notNull(account.getOrganization(), "organization");
ArgumentValidator.match(account.getOrganization().getEmail(), ArgumentValidator.EMAIL_REGEXP, "organizationEmail");
//
// Check Access
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(AccountDomain.ACCOUNT, Actions.write, account.getScopeId()));
//
// Update the Account
EntityManager em = AccountEntityManagerFactory.getInstance().createEntityManager();
try {
Account oldAccount = AccountDAO.find(em, account.getId());
if (oldAccount == null) {
throw new KapuaEntityNotFoundException(Account.TYPE, account.getId());
}
// Verify unchanged parent account ID and parent account path
if (!oldAccount.getScopeId().equals(account.getScopeId())) {
throw new KapuaAccountException(KapuaAccountErrorCodes.ILLEGAL_ARGUMENT, null, "scopeId");
}
if (oldAccount.getParentAccountPath().compareTo(account.getParentAccountPath()) != 0) {
throw new KapuaAccountException(KapuaAccountErrorCodes.ILLEGAL_ARGUMENT, null, "parentAccountPath");
}
if (oldAccount.getName().compareTo(account.getName()) != 0) {
throw new KapuaAccountException(KapuaAccountErrorCodes.ILLEGAL_ARGUMENT, null, "accountName");
}
// Update
em.beginTransaction();
AccountDAO.update(em, account);
em.commit();
} catch (Exception e) {
em.rollback();
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return find(account.getScopeId(), account.getId());
}
Aggregations