Search in sources :

Example 6 with DataProduct

use of org.apache.airavata.registry.core.replica.catalog.model.DataProduct in project airavata by apache.

the class ReplicaCatalogImpl method searchDataProductsByName.

@Override
public List<DataProductModel> searchDataProductsByName(String gatewayId, String userId, String productName, int limit, int offset) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        String query = "SELECT dp FROM DataProduct dp " + "WHERE dp.gatewayId = '" + gatewayId + "' AND dp.ownerName='" + userId + "' AND dp.productName LIKE '%" + productName + "%' ORDER BY dp.creationTime DESC";
        em = ReplicaCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        // pagination
        if (offset >= 0 && limit >= 0) {
            q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
        } else {
            q = em.createQuery(query);
        }
        ArrayList<DataProductModel> returnModels = new ArrayList<>();
        List resultList = q.getResultList();
        for (Object o : resultList) {
            DataProduct dataProduct = (DataProduct) o;
            returnModels.add(ThriftDataModelConversion.getDataProductModel(dataProduct));
        }
        em.getTransaction().commit();
        em.close();
        return returnModels;
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage(), e);
        throw new ReplicaCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DataProduct(org.apache.airavata.registry.core.replica.catalog.model.DataProduct) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel)

Example 7 with DataProduct

use of org.apache.airavata.registry.core.replica.catalog.model.DataProduct in project airavata by apache.

the class ReplicaCatalogImpl method getAllReplicaLocations.

@Override
public List<DataReplicaLocationModel> getAllReplicaLocations(String productUri) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productUri);
        if (dataProduct == null)
            return null;
        ArrayList<DataReplicaLocationModel> dataReplicaLocationModels = new ArrayList<>();
        dataProduct.getDataReplicaLocations().stream().forEach(rl -> dataReplicaLocationModels.add(ThriftDataModelConversion.getDataReplicaLocationModel(rl)));
        return dataReplicaLocationModels;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new ReplicaCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) DataReplicaLocationModel(org.apache.airavata.model.data.replica.DataReplicaLocationModel) DataProduct(org.apache.airavata.registry.core.replica.catalog.model.DataProduct) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException)

Example 8 with DataProduct

use of org.apache.airavata.registry.core.replica.catalog.model.DataProduct in project airavata by apache.

the class ReplicaCatalogImpl method isExists.

@Override
public boolean isExists(String productUri) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productUri);
        return dataProduct != null;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new ReplicaCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) DataProduct(org.apache.airavata.registry.core.replica.catalog.model.DataProduct) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException)

Example 9 with DataProduct

use of org.apache.airavata.registry.core.replica.catalog.model.DataProduct in project airavata by apache.

the class ReplicaCatalogImpl method getChildDataProducts.

@Override
public List<DataProductModel> getChildDataProducts(String productUri) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productUri);
        Collection<DataProduct> childProducts = dataProduct.getChildDataProducts();
        ArrayList<DataProductModel> returnModels = new ArrayList<>();
        childProducts.stream().forEach(cp -> {
            returnModels.add(ThriftDataModelConversion.getDataProductModel(cp));
        });
        return returnModels;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new ReplicaCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) DataProduct(org.apache.airavata.registry.core.replica.catalog.model.DataProduct) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel)

Aggregations

EntityManager (javax.persistence.EntityManager)9 DataProduct (org.apache.airavata.registry.core.replica.catalog.model.DataProduct)9 ReplicaCatalogException (org.apache.airavata.registry.cpi.ReplicaCatalogException)9 ArrayList (java.util.ArrayList)3 DataProductModel (org.apache.airavata.model.data.replica.DataProductModel)2 List (java.util.List)1 Query (javax.persistence.Query)1 DataReplicaLocationModel (org.apache.airavata.model.data.replica.DataReplicaLocationModel)1