Search in sources :

Example 1 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method getTransactionId.

@Override
public String getTransactionId(String source) throws NotFoundException, SchedulerServiceDatabaseException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        String orgId = securityService.getOrganization().getId();
        Query q = em.createNamedQuery("Transaction.findBySource").setParameter("source", source).setParameter("org", orgId);
        TransactionDto dto = (TransactionDto) q.getSingleResult();
        return dto.getId();
    } catch (NoResultException e) {
        throw new NotFoundException("Transaction with source " + source + " does not exist");
    } catch (Exception e) {
        logger.error("Could not retrieve id for transaction with source '{}': {}", source, getStackTrace(e));
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 2 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method countConfirmedResponses.

public long countConfirmedResponses() throws SchedulerServiceDatabaseException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("ExtendedEvent.countConfirmed");
        Number countResult = (Number) q.getSingleResult();
        return countResult.longValue();
    } catch (Exception e) {
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 3 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method deleteEvent.

@Override
public void deleteEvent(String mediapackageId) throws NotFoundException, SchedulerServiceDatabaseException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        Opt<ExtendedEventDto> entity = getExtendedEventDto(mediapackageId, em);
        if (entity.isNone()) {
            throw new NotFoundException("Event with ID " + mediapackageId + " does not exist");
        }
        em.remove(entity.get());
        tx.commit();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        if (tx.isActive())
            tx.rollback();
        logger.error("Could not delete extended event: {}", getStackTrace(e));
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 4 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method getTransactionSource.

@Override
public String getTransactionSource(String id) throws NotFoundException, SchedulerServiceDatabaseException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Opt<TransactionDto> entity = getTransactionDto(id, em);
        if (entity.isNone())
            throw new NotFoundException("Transaction with ID " + id + " does not exist");
        return entity.get().getSource();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not retrieve source for transaction with id '{}': {}", id, getStackTrace(e));
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 5 with SchedulerServiceDatabaseException

use of org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException in project opencast by opencast.

the class SchedulerServiceDatabaseImpl method getLastModifiedDates.

@Override
@SuppressWarnings("unchecked")
public Map<String, Date> getLastModifiedDates() throws SchedulerServiceDatabaseException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("LastModified.findAll");
        List<LastModifiedDto> resultList = q.getResultList();
        Map<String, Date> dates = new HashMap<String, Date>();
        for (LastModifiedDto dto : resultList) {
            dates.put(dto.getCaptureAgentId(), dto.getLastModifiedDate());
        }
        return dates;
    } catch (Exception e) {
        logger.error("Could not retrieve last modified dates: {}", getStackTrace(e));
        throw new SchedulerServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) HashMap(java.util.HashMap) Date(java.util.Date) NoResultException(javax.persistence.NoResultException) SchedulerServiceDatabaseException(org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

EntityManager (javax.persistence.EntityManager)17 NoResultException (javax.persistence.NoResultException)17 SchedulerServiceDatabaseException (org.opencastproject.scheduler.impl.SchedulerServiceDatabaseException)17 NotFoundException (org.opencastproject.util.NotFoundException)17 Query (javax.persistence.Query)10 EntityTransaction (javax.persistence.EntityTransaction)4 Date (java.util.Date)3 Fn (com.entwinemedia.fn.Fn)1 HashMap (java.util.HashMap)1