use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class UserPermissionServiceImpl method query.
@Override
public UserPermissionListResult query(KapuaQuery<UserPermission> query) throws KapuaException {
ArgumentValidator.notNull(query, "query");
ArgumentValidator.notNull(query.getScopeId(), "query.scopeId");
//
// Check Access
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(UserPermissionDomain.USER_PERMISSION, Actions.read, query.getScopeId()));
//
// Do query
UserPermissionListResult result = null;
EntityManager em = AuthorizationEntityManagerFactory.getEntityManager();
try {
result = UserPermissionDAO.query(em, query);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return result;
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class UserPermissionServiceImpl method find.
@Override
public UserPermission find(KapuaId scopeId, KapuaId permissionId) throws KapuaException {
ArgumentValidator.notNull(scopeId, "accountId");
ArgumentValidator.notNull(permissionId, "permissionId");
//
// Check Access
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(UserPermissionDomain.USER_PERMISSION, Actions.read, scopeId));
//
// Do find
UserPermission permission = null;
EntityManager em = AuthorizationEntityManagerFactory.getEntityManager();
try {
permission = UserPermissionDAO.find(em, permissionId);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return permission;
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class UserPermissionServiceImpl method create.
@Override
public UserPermission create(UserPermissionCreator userPermissionCreator) throws KapuaException {
ArgumentValidator.notNull(userPermissionCreator, "userPermissionCreator");
ArgumentValidator.notNull(userPermissionCreator.getPermission(), "userPermissionCreator.permission");
//
// Check Access
KapuaLocator locator = KapuaLocator.getInstance();
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(UserPermissionDomain.USER_PERMISSION, Actions.write, userPermissionCreator.getScopeId()));
//
// Do create
UserPermission permission = null;
EntityManager em = AuthorizationEntityManagerFactory.getEntityManager();
try {
em.beginTransaction();
permission = UserPermissionDAO.create(em, userPermissionCreator);
em.commit();
} catch (Exception e) {
em.rollback();
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return permission;
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class UserServiceImpl method query.
@Override
public UserListResult query(KapuaQuery<User> query) throws KapuaException {
//
// Argument Validation
ArgumentValidator.notNull(query, "query");
ArgumentValidator.notNull(query.getScopeId(), "query.scopeId");
//
// Check Access
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(UserDomain.USER, Actions.read, query.getScopeId()));
//
// Do count
UserListResult result = null;
EntityManager em = UserEntityManagerFactory.getInstance().createEntityManager();
;
try {
result = UserDAO.query(em, query);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return result;
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class UserServiceImpl method find.
@Override
public User find(KapuaId accountId, KapuaId userId) throws KapuaException {
// Validation of the fields
ArgumentValidator.notNull(accountId.getId(), "accountId");
ArgumentValidator.notNull(userId.getId(), "id");
//
// Check Access
AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
authorizationService.checkPermission(permissionFactory.newPermission(UserDomain.USER, Actions.read, accountId));
// Do the find
User user = null;
EntityManager em = UserEntityManagerFactory.getInstance().createEntityManager();
;
try {
user = UserDAO.find(em, userId);
} catch (Exception pe) {
throw KapuaExceptionUtils.convertPersistenceException(pe);
} finally {
em.close();
}
return user;
}
Aggregations