use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.
the class ReplicaCatalogImpl method updateReplicaLocation.
@Override
public boolean updateReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
EntityManager em = null;
try {
em = ReplicaCatalogJPAUtils.getEntityManager();
DataReplicaLocation dataReplicaLocation = em.find(DataReplicaLocation.class, dataReplicaLocationModel.getReplicaId());
if (dataReplicaLocation == null)
return false;
em.getTransaction().begin();
dataReplicaLocationModel.setCreationTime(dataReplicaLocation.getCreationTime().getTime());
dataReplicaLocationModel.setLastModifiedTime(System.currentTimeMillis());
em.merge(ThriftDataModelConversion.getUpdatedDataReplicaLocation(dataReplicaLocationModel, dataReplicaLocation));
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.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.
the class ReplicaCatalogImpl method getReplicaLocation.
@Override
public DataReplicaLocationModel getReplicaLocation(String replicaId) throws ReplicaCatalogException {
EntityManager em = null;
try {
em = ReplicaCatalogJPAUtils.getEntityManager();
DataReplicaLocation replicaLocation = em.find(DataReplicaLocation.class, replicaId);
return ThriftDataModelConversion.getDataReplicaLocationModel(replicaLocation);
} 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.DataReplicaLocation in project airavata by apache.
the class ThriftDataModelConversion method getUpdatedDataProduct.
public static DataProduct getUpdatedDataProduct(DataProductModel dataProductModel, DataProduct dataProduct) {
dataProduct.setProductUri(dataProductModel.getProductUri());
dataProduct.setGatewayId(dataProductModel.getGatewayId());
dataProduct.setProductName(dataProductModel.getProductName());
dataProduct.setParentProductUri(dataProductModel.getParentProductUri());
if (dataProductModel.getDataProductType() != null)
dataProduct.setDataProductType(dataProductModel.getDataProductType().toString());
else
dataProduct.setDataProductType(DataProductType.FILE.toString());
dataProduct.setProductDescription(dataProductModel.getProductDescription());
dataProduct.setOwnerName(dataProductModel.getOwnerName());
dataProduct.setProductSize(dataProductModel.getProductSize());
if (dataProductModel.getCreationTime() > 0)
dataProduct.setCreationTime(new Timestamp(dataProductModel.getCreationTime()));
if (dataProductModel.getLastModifiedTime() > 0)
dataProduct.setLastModifiedTime(new Timestamp(dataProductModel.getLastModifiedTime()));
ArrayList<DataProductMetaData> dataProductMetaData = new ArrayList<>();
if (dataProductModel.getProductMetadata() != null) {
dataProductModel.getProductMetadata().keySet().stream().forEach(k -> {
String v = dataProductModel.getProductMetadata().get(k);
DataProductMetaData temp = new DataProductMetaData();
temp.setProductUri(dataProduct.getProductUri());
temp.setKey(k);
temp.setValue(v);
dataProductMetaData.add(temp);
});
dataProduct.setDataProductMetaData(dataProductMetaData);
}
if (dataProductModel.getReplicaLocations() != null) {
ArrayList<DataReplicaLocation> dataReplicaLocations = new ArrayList<>();
dataProductModel.getReplicaLocations().stream().forEach(r -> {
DataReplicaLocation dataReplicaLocationModel = getDataReplicaLocation(r);
dataReplicaLocationModel.setProductUri(dataProductModel.getProductUri());
dataReplicaLocations.add(dataReplicaLocationModel);
});
dataProduct.setDataReplicaLocations(dataReplicaLocations);
}
return dataProduct;
}
use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation 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.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.
the class ReplicaCatalogImpl method registerReplicaLocation.
@Override
public String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
String replicaId = UUID.randomUUID().toString();
dataReplicaLocationModel.setReplicaId(replicaId);
long currentTime = System.currentTimeMillis();
dataReplicaLocationModel.setCreationTime(currentTime);
dataReplicaLocationModel.setLastModifiedTime(currentTime);
dataReplicaLocationModel.setCreationTime(System.currentTimeMillis());
dataReplicaLocationModel.setLastModifiedTime(System.currentTimeMillis());
DataReplicaLocation replicaLocation = ThriftDataModelConversion.getDataReplicaLocation(dataReplicaLocationModel);
EntityManager em = null;
try {
em = ReplicaCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
em.persist(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 replicaId;
}
Aggregations