Search in sources :

Example 1 with StorageResource

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

the class StorageResourceResource method isExists.

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

Example 2 with StorageResource

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

the class StorageResourceResource method getAllIds.

@Override
public List<String> getAllIds() throws AppCatalogException {
    List<String> storageResourceResources = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        for (Object result : results) {
            StorageResource storageResource = (StorageResource) result;
            storageResourceResources.add(storageResource.getStorageResourceId());
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } 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();
        }
    }
    return storageResourceResources;
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 3 with StorageResource

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

the class StorageResourceResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        generator.setParameter(StorageResourceConstants.RESOURCE_ID, identifier);
        Query q = generator.selectQuery(em);
        StorageResource storageResource = (StorageResource) q.getSingleResult();
        StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return storageResourceResource;
    } 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 : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) 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)

Example 4 with StorageResource

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

the class StorageResourceResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> storageResourceResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        for (Object result : results) {
            StorageResource storageResource = (StorageResource) result;
            StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
            storageResourceResources.add(storageResourceResource);
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } 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();
        }
    }
    return storageResourceResources;
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 5 with StorageResource

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

the class StorageResourceResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> storageResourceResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
        Query q;
        if ((fieldName.equals(StorageResourceConstants.RESOURCE_DESCRIPTION)) || (fieldName.equals(StorageResourceConstants.RESOURCE_ID)) || (fieldName.equals(StorageResourceConstants.HOST_NAME))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                StorageResource storageResource = (StorageResource) result;
                StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
                storageResourceResources.add(storageResourceResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Storage Resource Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Storage Resource Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } 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();
        }
    }
    return storageResourceResources;
}
Also used : StorageResource(org.apache.airavata.registry.core.app.catalog.model.StorageResource) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Aggregations

EntityManager (javax.persistence.EntityManager)7 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)7 StorageResource (org.apache.airavata.registry.core.app.catalog.model.StorageResource)7 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)7 Query (javax.persistence.Query)5 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)5 ArrayList (java.util.ArrayList)4