Search in sources :

Example 1 with GSISSHExport

use of org.apache.airavata.registry.core.app.catalog.model.GSISSHExport 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 GSISSHExport

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

the class GSISSHExportResource method get.

public AppCatalogResource get(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();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GSISSH_EXPORT);
        generator.setParameter(GSISSHExportConstants.SUBMISSION_ID, ids.get(GSISSHExportConstants.SUBMISSION_ID));
        generator.setParameter(GSISSHExportConstants.EXPORT, ids.get(GSISSHExportConstants.EXPORT));
        Query q = generator.selectQuery(em);
        GSISSHExport gsisshExport = (GSISSHExport) q.getSingleResult();
        GSISSHExportResource gsisshExportResource = (GSISSHExportResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GSISSH_EXPORT, gsisshExport);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return gsisshExportResource;
    } 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) GSISSHExport(org.apache.airavata.registry.core.app.catalog.model.GSISSHExport) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with GSISSHExport

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

the class GSISSHExportResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> gsiSSHExportResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GSISSH_EXPORT);
        List results;
        if (fieldName.equals(GSISSHExportConstants.EXPORT)) {
            generator.setParameter(GSISSHExportConstants.EXPORT, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHExport gsisshExport = (GSISSHExport) result;
                    GSISSHExportResource gsisshExportResource = (GSISSHExportResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GSISSH_EXPORT, gsisshExport);
                    gsiSSHExportResources.add(gsisshExportResource);
                }
            }
        } else if (fieldName.equals(GSISSHExportConstants.SUBMISSION_ID)) {
            generator.setParameter(GSISSHExportConstants.SUBMISSION_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHExport gsisshExport = (GSISSHExport) result;
                    GSISSHExportResource gsisshExportResource = (GSISSHExportResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GSISSH_EXPORT, gsisshExport);
                    gsiSSHExportResources.add(gsisshExportResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for GSISSH Export Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for GSISSH Export Resource.");
        }
        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();
        }
    }
    return gsiSSHExportResources;
}
Also used : GSISSHExport(org.apache.airavata.registry.core.app.catalog.model.GSISSHExport) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 4 with GSISSHExport

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

the class GSISSHExportResource method getIds.

public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> gsiSSHExportIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GSISSH_EXPORT);
        List results;
        if (fieldName.equals(GSISSHExportConstants.SUBMISSION_ID)) {
            generator.setParameter(GSISSHExportConstants.SUBMISSION_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHExport gsisshExport = (GSISSHExport) result;
                    gsiSSHExportIDs.add(gsisshExport.getSubmissionID());
                }
            }
        } else if (fieldName.equals(GSISSHExportConstants.EXPORT)) {
            generator.setParameter(GSISSHExportConstants.EXPORT, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GSISSHExport gsisshExport = (GSISSHExport) result;
                    gsiSSHExportIDs.add(gsisshExport.getSubmissionID());
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for GSISSH Export resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for GSISSH Export Resource.");
        }
        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();
        }
    }
    return gsiSSHExportIDs;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GSISSHExport(org.apache.airavata.registry.core.app.catalog.model.GSISSHExport) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 5 with GSISSHExport

use of org.apache.airavata.registry.core.app.catalog.model.GSISSHExport 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)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)5 GSISSHExport (org.apache.airavata.registry.core.app.catalog.model.GSISSHExport)5 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)5 Query (javax.persistence.Query)3 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 GSISSHExportPK (org.apache.airavata.registry.core.app.catalog.model.GSISSHExportPK)2 GSISSHSubmission (org.apache.airavata.registry.core.app.catalog.model.GSISSHSubmission)1