Search in sources :

Example 1 with LocalDataMovement

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

the class LocalDataMovementResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> localDataMovementResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_DATA_MOVEMENT);
        Query q;
        if ((fieldName.equals(LocalDataMovementConstants.DATA_MOVEMENT_INTERFACE_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                LocalDataMovement localDataMovement = (LocalDataMovement) result;
                LocalDataMovementResource localDataMovementResource = (LocalDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_DATA_MOVEMENT, localDataMovement);
                localDataMovementResources.add(localDataMovementResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Local Data Movement Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Local Data Movement 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 localDataMovementResources;
}
Also used : 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) LocalDataMovement(org.apache.airavata.registry.core.app.catalog.model.LocalDataMovement) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 2 with LocalDataMovement

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

the class LocalDataMovementResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_DATA_MOVEMENT);
        generator.setParameter(LocalDataMovementConstants.DATA_MOVEMENT_INTERFACE_ID, identifier);
        Query q = generator.selectQuery(em);
        LocalDataMovement localDataMovement = (LocalDataMovement) q.getSingleResult();
        LocalDataMovementResource localDataMovementResource = (LocalDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_DATA_MOVEMENT, localDataMovement);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return localDataMovementResource;
    } 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) LocalDataMovement(org.apache.airavata.registry.core.app.catalog.model.LocalDataMovement) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 3 with LocalDataMovement

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

the class LocalDataMovementResource method getIds.

@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> localDataMovementResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_DATA_MOVEMENT);
        Query q;
        if ((fieldName.equals(LocalDataMovementConstants.DATA_MOVEMENT_INTERFACE_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                LocalDataMovement localDataMovement = (LocalDataMovement) result;
                LocalDataMovementResource localDataMovementResource = (LocalDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_DATA_MOVEMENT, localDataMovement);
                localDataMovementResourceIDs.add(localDataMovementResource.getDataMovementInterfaceId());
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Local Data Movement Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Local Data Movement 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 localDataMovementResourceIDs;
}
Also used : 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) LocalDataMovement(org.apache.airavata.registry.core.app.catalog.model.LocalDataMovement) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 4 with LocalDataMovement

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

the class LocalDataMovementResource method isExists.

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

Example 5 with LocalDataMovement

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

the class LocalDataMovementResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        LocalDataMovement existingLocalDataMovement = em.find(LocalDataMovement.class, dataMovementInterfaceId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        LocalDataMovement localDataMovement;
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingLocalDataMovement == null) {
            localDataMovement = new LocalDataMovement();
        } else {
            localDataMovement = existingLocalDataMovement;
        }
        localDataMovement.setDataMovementInterfaceId(getDataMovementInterfaceId());
        if (existingLocalDataMovement == null) {
            em.persist(localDataMovement);
        } else {
            em.merge(localDataMovement);
        }
        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) LocalDataMovement(org.apache.airavata.registry.core.app.catalog.model.LocalDataMovement) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

EntityManager (javax.persistence.EntityManager)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)5 LocalDataMovement (org.apache.airavata.registry.core.app.catalog.model.LocalDataMovement)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