Search in sources :

Example 1 with ProcessStatusPK

use of org.apache.airavata.registry.core.experiment.catalog.model.ProcessStatusPK in project airavata by apache.

the class ProcessStatusResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        if (processId == null || statusId == null) {
            throw new RegistryException("Does not have the process id or status id");
        }
        em = ExpCatResourceUtils.getEntityManager();
        ProcessStatus processStatus;
        ProcessStatusPK processStatusPK = new ProcessStatusPK();
        processStatusPK.setStatusId(statusId);
        processStatusPK.setProcessId(processId);
        ProcessStatus existingStatus = em.find(ProcessStatus.class, processStatusPK);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingStatus == null) {
            processStatus = new ProcessStatus();
        } else {
            processStatus = existingStatus;
        }
        processStatus.setStatusId(statusId);
        processStatus.setProcessId(processId);
        processStatus.setState(state);
        processStatus.setReason(reason);
        if (timeOfStateChange == null) {
            timeOfStateChange = AiravataUtils.getCurrentTimestamp();
        }
        processStatus.setTimeOfStateChange(timeOfStateChange);
        if (existingStatus == null) {
            em.persist(processStatus);
        } else {
            em.merge(processStatus);
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ProcessStatus(org.apache.airavata.registry.core.experiment.catalog.model.ProcessStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ProcessStatusPK(org.apache.airavata.registry.core.experiment.catalog.model.ProcessStatusPK) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

EntityManager (javax.persistence.EntityManager)1 ProcessStatus (org.apache.airavata.registry.core.experiment.catalog.model.ProcessStatus)1 ProcessStatusPK (org.apache.airavata.registry.core.experiment.catalog.model.ProcessStatusPK)1 RegistryException (org.apache.airavata.registry.cpi.RegistryException)1