use of org.apache.airavata.registry.core.experiment.catalog.model.ExperimentStatus in project airavata by apache.
the class ExperimentStatusResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
ExperimentStatus experimentStatus;
if (experimentId == null || statusId == null) {
throw new RegistryException("Does not have the experiment id or status id");
}
ExperimentStatusPK experimentStatusPK = new ExperimentStatusPK();
experimentStatusPK.setStatusId(statusId);
experimentStatusPK.setExperimentId(experimentId);
ExperimentStatus existingStatus = em.find(ExperimentStatus.class, experimentStatusPK);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingStatus == null) {
experimentStatus = new ExperimentStatus();
} else {
experimentStatus = existingStatus;
}
experimentStatus.setStatusId(statusId);
experimentStatus.setExperimentId(experimentId);
experimentStatus.setState(state);
experimentStatus.setReason(reason);
experimentStatus.setTimeOfStateChange(timeOfStateChange);
if (existingStatus == null) {
em.persist(experimentStatus);
} else {
em.merge(experimentStatus);
}
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