Search in sources :

Example 6 with GatewayProfile

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

the class GatewayProfileResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> gatewayProfileResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
        List results;
        if (fieldName.equals(GatewayProfileConstants.GATEWAY_ID)) {
            generator.setParameter(GatewayProfileConstants.GATEWAY_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    GatewayProfile gatewayProfile = (GatewayProfile) result;
                    GatewayProfileResource gatewayProfileResource = (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
                    gatewayProfileResources.add(gatewayProfileResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Gateway Profile resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Gateway Profile 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 gatewayProfileResources;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) GatewayProfile(org.apache.airavata.registry.core.app.catalog.model.GatewayProfile) 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)

Aggregations

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