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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
Aggregations