Search in sources :

Example 21 with KapuaEntityNotFoundException

use of org.eclipse.kapua.KapuaEntityNotFoundException in project kapua by eclipse.

the class DeviceConnectionServiceImpl method delete.

@Override
public void delete(KapuaId scopeId, KapuaId deviceConnectionId) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(deviceConnectionId, "deviceConnection.id");
    ArgumentValidator.notNull(scopeId, "deviceConnection.scopeId");
    // 
    // Check Access
    KapuaLocator locator = KapuaLocator.getInstance();
    AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    authorizationService.checkPermission(permissionFactory.newPermission(DeviceConnectionDomain.DEVICE_CONNECTION, Actions.write, scopeId));
    // 
    // Do delete
    EntityManager em = DeviceEntityManagerFactory.getEntityManager();
    try {
        if (DeviceConnectionDAO.find(em, deviceConnectionId) == null) {
            throw new KapuaEntityNotFoundException(DeviceConnection.TYPE, deviceConnectionId);
        }
        em.beginTransaction();
        DeviceConnectionDAO.delete(em, deviceConnectionId);
        em.commit();
    } catch (Exception e) {
        em.rollback();
        throw KapuaExceptionUtils.convertPersistenceException(e);
    } finally {
        em.close();
    }
}
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) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)21 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)17 KapuaException (org.eclipse.kapua.KapuaException)13 EntityManager (org.eclipse.kapua.commons.jpa.EntityManager)13 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)12 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)12 Account (org.eclipse.kapua.service.account.Account)7 KapuaIllegalAccessException (org.eclipse.kapua.KapuaIllegalAccessException)6 KapuaIllegalArgumentException (org.eclipse.kapua.KapuaIllegalArgumentException)5 Device (org.eclipse.kapua.service.device.registry.Device)5 AccountService (org.eclipse.kapua.service.account.AccountService)4 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)4 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 KapuaUnauthenticatedException (org.eclipse.kapua.KapuaUnauthenticatedException)3 FileItem (org.apache.commons.fileupload.FileItem)2 FileUploadException (org.apache.commons.fileupload.FileUploadException)2 User (org.eclipse.kapua.service.user.User)2 Date (java.util.Date)1 StringTokenizer (java.util.StringTokenizer)1