Search in sources :

Example 1 with TaskErrorPK

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

the class TaskErrorResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        TaskError taskError;
        if (taskId == null || errorId == null) {
            throw new RegistryException("Does not have the task id or error id");
        }
        TaskErrorPK taskErrorPK = new TaskErrorPK();
        taskErrorPK.setTaskId(taskId);
        taskErrorPK.setErrorId(errorId);
        TaskError existingTaskError = em.find(TaskError.class, taskErrorPK);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingTaskError == null) {
            taskError = new TaskError();
        } else {
            taskError = existingTaskError;
        }
        taskError.setTaskId(taskId);
        taskError.setErrorId(errorId);
        taskError.setActualErrorMessage(actualErrorMessage);
        taskError.setUserFriendlyMessage(userFriendlyMessage);
        taskError.setRootCauseErrorIdList(rootCauseErrorIdList);
        taskError.setTransientOrPersistent(transientOrPersistent);
        if (existingTaskError == null) {
            em.persist(taskError);
        } else {
            em.merge(taskError);
        }
        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) TaskErrorPK(org.apache.airavata.registry.core.experiment.catalog.model.TaskErrorPK) TaskError(org.apache.airavata.registry.core.experiment.catalog.model.TaskError) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

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