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