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