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();
}
}
Aggregations