Search in sources :

Example 1 with DataProduct

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

the class ReplicaCatalogImpl method createDataProduct.

private String createDataProduct(DataProductModel productModel) throws ReplicaCatalogException {
    DataProduct dataProduct = ThriftDataModelConversion.getDataProduct(productModel);
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        em.persist(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 dataProduct.getProductUri();
}
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 2 with DataProduct

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

the class ReplicaCatalogImpl method getParentDataProduct.

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

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

the class ReplicaCatalogImpl method removeDataProduct.

@Override
public boolean removeDataProduct(String productUri) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productUri);
        if (dataProduct == null)
            return false;
        em.getTransaction().begin();
        em.remove(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 4 with DataProduct

use of org.apache.airavata.registry.core.replica.catalog.model.DataProduct 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 5 with DataProduct

use of org.apache.airavata.registry.core.replica.catalog.model.DataProduct 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)

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