Search in sources :

Example 26 with KapuaException

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) UserPermissionListResult(org.eclipse.kapua.service.authorization.user.permission.UserPermissionListResult) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaException(org.eclipse.kapua.KapuaException)

Example 27 with KapuaException

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaException(org.eclipse.kapua.KapuaException) UserPermission(org.eclipse.kapua.service.authorization.user.permission.UserPermission)

Example 28 with KapuaException

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaException(org.eclipse.kapua.KapuaException) UserPermission(org.eclipse.kapua.service.authorization.user.permission.UserPermission)

Example 29 with KapuaException

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;
}
Also used : EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaIllegalArgumentException(org.eclipse.kapua.KapuaIllegalArgumentException) KapuaException(org.eclipse.kapua.KapuaException) UserListResult(org.eclipse.kapua.service.user.UserListResult)

Example 30 with KapuaException

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;
}
Also used : EntityManager(org.eclipse.kapua.commons.jpa.EntityManager) User(org.eclipse.kapua.service.user.User) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaIllegalArgumentException(org.eclipse.kapua.KapuaIllegalArgumentException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

KapuaException (org.eclipse.kapua.KapuaException)99 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)53 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)50 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)50 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)48 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)48 KapuaIllegalArgumentException (org.eclipse.kapua.KapuaIllegalArgumentException)19 LocalServicePlan (org.eclipse.kapua.service.datastore.internal.elasticsearch.LocalServicePlan)17 DeviceManagementSetting (org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSetting)12 Date (java.util.Date)11 KapuaIllegalAccessException (org.eclipse.kapua.KapuaIllegalAccessException)10 Account (org.eclipse.kapua.service.account.Account)9 DeviceCallExecutor (org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor)8 DeviceManagementException (org.eclipse.kapua.service.device.management.commons.exception.DeviceManagementException)8 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)8 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)8 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)8 IOException (java.io.IOException)7 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)7 UnknownHostException (java.net.UnknownHostException)6