Search in sources :

Example 1 with GSISSHExportPK

use of org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK in project airavata by apache.

the class GSISSHExportResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        GSISSHExport existingGSIExport = em.find(GSISSHExport.class, new GSISSHExportPK(submissionID, export));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        GSISSHSubmission gsisshSubmission = em.find(GSISSHSubmission.class, submissionID);
        if (existingGSIExport != null) {
            existingGSIExport.setSubmissionID(submissionID);
            existingGSIExport.setExport(export);
            existingGSIExport.setGsisshJobSubmission(gsisshSubmission);
            em.merge(existingGSIExport);
        } else {
            GSISSHExport gsisshExport = new GSISSHExport();
            gsisshExport.setSubmissionID(submissionID);
            gsisshExport.setExport(export);
            gsisshExport.setGsisshJobSubmission(gsisshSubmission);
            em.persist(gsisshExport);
        }
        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 AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) GSISSHExportPK(org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GSISSHExport(org.apache.airavata.registry.core.app.catalog.model.GSISSHExport) GSISSHSubmission(org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 2 with GSISSHExportPK

use of org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK in project airavata by apache.

the class GSISSHExportResource method isExists.

public boolean isExists(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new AppCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        GSISSHExport gsisshExport = em.find(GSISSHExport.class, new GSISSHExportPK(ids.get(GSISSHExportConstants.SUBMISSION_ID), ids.get(GSISSHExportConstants.EXPORT)));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return gsisshExport != null;
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) GSISSHExportPK(org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK) GSISSHExport(org.apache.airavata.registry.core.app.catalog.model.GSISSHExport) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

EntityManager (javax.persistence.EntityManager)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 GSISSHExport (org.apache.airavata.registry.core.app.catalog.model.GSISSHExport)2 GSISSHExportPK (org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK)2 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GSISSHSubmission (org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission)1