Search in sources :

Example 1 with GatewayProfile

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

the class GatewayProfileResource method getIds.

public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> gatewayProfileResourceIDs = new ArrayList<String>();
    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;
                    gatewayProfileResourceIDs.add(gatewayProfile.getGatewayID());
                }
            }
        } 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 gatewayProfileResourceIDs;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) 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) GatewayProfile(org.apache.airavata.registry.core.app.catalog.model.GatewayProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 2 with GatewayProfile

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

the class GatewayProfileResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
        Query q = generator.selectQuery(em);
        List results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                GatewayProfile gatewayProfile = (GatewayProfile) result;
                GatewayProfileResource gatewayProfileResource = (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
                resourceList.add(gatewayProfileResource);
            }
        }
        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 resourceList;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) 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) GatewayProfile(org.apache.airavata.registry.core.app.catalog.model.GatewayProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 3 with GatewayProfile

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

the class GatewayProfileResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        GatewayProfile existingGatewayProfile = em.find(GatewayProfile.class, gatewayID);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingGatewayProfile != null) {
            existingGatewayProfile.setUpdateTime(AiravataUtils.getCurrentTimestamp());
            if (credentialStoreToken != null) {
                existingGatewayProfile.setCredentialStoreToken(credentialStoreToken);
            }
            if (identityServerTenant != null) {
                existingGatewayProfile.setIdentityServerTenant(identityServerTenant);
            }
            if (identityServerPwdCredToken != null) {
                existingGatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
            }
            em.merge(existingGatewayProfile);
        } else {
            GatewayProfile gatewayProfile = new GatewayProfile();
            gatewayProfile.setGatewayID(gatewayID);
            gatewayProfile.setCreationTime(AiravataUtils.getCurrentTimestamp());
            if (credentialStoreToken != null) {
                gatewayProfile.setCredentialStoreToken(credentialStoreToken);
            }
            if (identityServerTenant != null) {
                gatewayProfile.setIdentityServerTenant(identityServerTenant);
            }
            if (identityServerPwdCredToken != null) {
                gatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
            }
            em.persist(gatewayProfile);
        }
        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) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GatewayProfile(org.apache.airavata.registry.core.app.catalog.model.GatewayProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 4 with GatewayProfile

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

the class GatewayProfileResource method isExists.

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

Example 5 with GatewayProfile

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

the class GatewayProfileResource method get.

public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
        generator.setParameter(GatewayProfileConstants.GATEWAY_ID, identifier);
        Query q = generator.selectQuery(em);
        GatewayProfile gatewayProfile = (GatewayProfile) q.getSingleResult();
        GatewayProfileResource gatewayProfileResource = (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return gatewayProfileResource;
    } 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) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) GatewayProfile(org.apache.airavata.registry.core.app.catalog.model.GatewayProfile)

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