use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class RoleServiceImpl method query.
@Override
public RoleListResult query(KapuaQuery<Role> 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(RoleDomain.ROLE, Actions.read, query.getScopeId()));
//
// Do query
RoleListResult result = null;
EntityManager em = AuthorizationEntityManagerFactory.getEntityManager();
try {
result = RoleDAO.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 AbstractUserServiceTest method scriptSession.
public static void scriptSession(String path, String fileFilter) {
EntityManager em = null;
try {
logger.info("Running database scripts...");
em = UserEntityManagerFactory.getInstance().createEntityManager();
em.beginTransaction();
SimpleSqlScriptExecutor sqlScriptExecutor = new SimpleSqlScriptExecutor();
sqlScriptExecutor.scanScripts(path, fileFilter);
sqlScriptExecutor.executeUpdate(em);
em.commit();
logger.info("...database scripts done!");
} catch (KapuaException e) {
logger.error("Database scripts failed: {}", e.getMessage());
if (em != null)
em.rollback();
} finally {
if (em != null)
em.close();
}
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class KapuaTest method setUp.
@Before
public void setUp() {
LOG.debug("Setting up test...");
if (!isInitialized) {
LOG.debug("Kapua test context is not initialized. Initializing...");
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();
} catch (KapuaException exc) {
exc.printStackTrace();
}
isInitialized = true;
}
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class KapuaTest method tearDown.
@AfterClass
public static void tearDown() {
LOG.debug("Stopping Kapua test context.");
isInitialized = false;
try {
KapuaLocator locator = KapuaLocator.getInstance();
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
authenticationService.logout();
} catch (KapuaException exc) {
exc.printStackTrace();
}
}
use of org.eclipse.kapua.KapuaException in project kapua by eclipse.
the class UserRolesServiceImpl method count.
@Override
public long count(KapuaQuery<UserRoles> 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(RoleDomain.ROLE, Actions.read, query.getScopeId()));
//
// Do count
long count = 0;
EntityManager em = AuthorizationEntityManagerFactory.getEntityManager();
try {
count = UserRolesDAO.count(em, query);
} catch (Exception e) {
throw KapuaExceptionUtils.convertPersistenceException(e);
} finally {
em.close();
}
return count;
}
Aggregations