Search in sources :

Example 6 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogImpl method updateDataProduct.

@Override
public boolean updateDataProduct(DataProductModel productModel) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productModel.getProductUri());
        if (dataProduct == null)
            return false;
        em.getTransaction().begin();
        productModel.setCreationTime(dataProduct.getCreationTime().getTime());
        productModel.setLastModifiedTime(System.currentTimeMillis());
        em.merge(ThriftDataModelConversion.getUpdatedDataProduct(productModel, dataProduct));
        em.getTransaction().commit();
        em.close();
    } 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();
        }
    }
    return true;
}
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 7 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogImpl method removeReplicaLocation.

@Override
public boolean removeReplicaLocation(String replicaId) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataReplicaLocation replicaLocation = em.find(DataReplicaLocation.class, replicaId);
        if (replicaLocation == null)
            return false;
        em.getTransaction().begin();
        em.remove(replicaLocation);
        em.getTransaction().commit();
        em.close();
    } 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();
        }
    }
    return true;
}
Also used : EntityManager(javax.persistence.EntityManager) DataReplicaLocation(org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException)

Example 8 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogImpl method getDataProduct.

@Override
public DataProductModel getDataProduct(String productUri) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productUri);
        return ThriftDataModelConversion.getDataProductModel(dataProduct);
    } 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 ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException 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 10 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException 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)

Aggregations

ReplicaCatalogException (org.apache.airavata.registry.cpi.ReplicaCatalogException)14 EntityManager (javax.persistence.EntityManager)13 DataProduct (org.apache.airavata.registry.core.replica.catalog.model.DataProduct)9 DataReplicaLocation (org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation)4 ArrayList (java.util.ArrayList)3 DataProductModel (org.apache.airavata.model.data.replica.DataProductModel)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Query (javax.persistence.Query)1 DataReplicaLocationModel (org.apache.airavata.model.data.replica.DataReplicaLocationModel)1 Initialize (org.apache.airavata.replica.catalog.util.Initialize)1 BeforeClass (org.junit.BeforeClass)1