use of org.apache.airavata.registry.core.experiment.catalog.model.ProcessStatus 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();
}
}
}
Aggregations