Search in sources :

Example 1 with UnicoreJobSubmission

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

the class UnicoreJobSubmissionResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> unicoreSubmissionResourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(UNICORE_JOB_SUBMISSION);
        List results;
        if (fieldName.equals(UnicoreJobSubmissionConstants.UNICORE_ENDPOINT_URL)) {
            generator.setParameter(UnicoreJobSubmissionConstants.UNICORE_ENDPOINT_URL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UnicoreJobSubmission unicoreJobSubmission = (UnicoreJobSubmission) result;
                    UnicoreJobSubmissionResource unicoreJobSubmissionResource = (UnicoreJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_JOB_SUBMISSION, unicoreJobSubmission);
                    unicoreSubmissionResourceList.add(unicoreJobSubmissionResource);
                }
            }
        } else if (fieldName.equals(UnicoreJobSubmissionConstants.SECURITY_PROTOCAL)) {
            generator.setParameter(UnicoreJobSubmissionConstants.SECURITY_PROTOCAL, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UnicoreJobSubmission unicoreJobSubmission = (UnicoreJobSubmission) result;
                    UnicoreJobSubmissionResource unicoreJobSubmissionResource = (UnicoreJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_JOB_SUBMISSION, unicoreJobSubmission);
                    unicoreSubmissionResourceList.add(unicoreJobSubmissionResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Unicore submission resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Unicore Submission 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 unicoreSubmissionResourceList;
}
Also used : 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) UnicoreJobSubmission(org.apache.airavata.registry.core.app.catalog.model.UnicoreJobSubmission) 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 2 with UnicoreJobSubmission

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

the class UnicoreJobSubmissionResource method isExists.

public boolean isExists(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        UnicoreJobSubmission unicoreJobSubmission = em.find(UnicoreJobSubmission.class, identifier);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return unicoreJobSubmission != 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) EntityManager(javax.persistence.EntityManager) UnicoreJobSubmission(org.apache.airavata.registry.core.app.catalog.model.UnicoreJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Example 3 with UnicoreJobSubmission

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

the class UnicoreJobSubmissionResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        UnicoreJobSubmission existingUnicoreSubmission = em.find(UnicoreJobSubmission.class, jobSubmissionInterfaceId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingUnicoreSubmission != null) {
            existingUnicoreSubmission.setSubmissionID(jobSubmissionInterfaceId);
            ;
            existingUnicoreSubmission.setUnicoreEndpointUrl(unicoreEndpointUrl);
            existingUnicoreSubmission.setSecurityProtocol(securityProtocol);
            em.merge(existingUnicoreSubmission);
        } else {
            UnicoreJobSubmission unicoreJobSubmission = new UnicoreJobSubmission();
            unicoreJobSubmission.setSubmissionID(jobSubmissionInterfaceId);
            unicoreJobSubmission.setUnicoreEndpointUrl(unicoreEndpointUrl);
            unicoreJobSubmission.setSecurityProtocol(securityProtocol);
            em.persist(unicoreJobSubmission);
        }
        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) UnicoreJobSubmission(org.apache.airavata.registry.core.app.catalog.model.UnicoreJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 4 with UnicoreJobSubmission

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

the class UnicoreJobSubmissionResource method get.

public AppCatalogResource get(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(UNICORE_JOB_SUBMISSION);
        generator.setParameter(UnicoreJobSubmissionConstants.SUBMISSION_ID, identifier);
        Query q = generator.selectQuery(em);
        UnicoreJobSubmission unicoreJobSubmission = (UnicoreJobSubmission) q.getSingleResult();
        UnicoreJobSubmissionResource unicoreSubmissionResource = (UnicoreJobSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.UNICORE_JOB_SUBMISSION, unicoreJobSubmission);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return unicoreSubmissionResource;
    } 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) EntityManager(javax.persistence.EntityManager) UnicoreJobSubmission(org.apache.airavata.registry.core.app.catalog.model.UnicoreJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Aggregations

EntityManager (javax.persistence.EntityManager)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 UnicoreJobSubmission (org.apache.airavata.registry.core.app.catalog.model.UnicoreJobSubmission)4 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)4 Query (javax.persistence.Query)2 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1