}
}
public TransactionReceipt ingest(Metadata metadata) throws CatalogServiceException {
if (this.restrictIngestPermissions)
throw new CatalogServiceException("Ingest permissions are restricted for this CatalogService -- request denied");
try {
boolean performUpdate = false;
TransactionId<?> catalogServiceTransactionId = this.getCatalogServiceTransactionId(metadata);
if (performUpdate = this.ingestMapper.hasCatalogServiceTransactionId(catalogServiceTransactionId))
LOG.log(Level.INFO, "TransactionId '" + catalogServiceTransactionId + "' is an existing TransactionId, switching to update mode");
List<CatalogReceipt> catalogReceipts = new Vector<CatalogReceipt>();
for (Catalog catalog : this.getFilteredCatalogList(metadata)) {
if (catalog.isIngestable()) {
this.ingestMapperLock.writeLock().lock();
try {
// perform update
if (performUpdate) {
if (!Boolean.parseBoolean(metadata.getMetadata(ENABLE_UPDATE_MET_KEY)))
throw new CatalogServiceException("TransactionId '" + catalogServiceTransactionId + "' already exists -- enable update by setting metadata key '" + ENABLE_UPDATE_MET_KEY + "'=true");
TransactionId<?> catalogTransactionId = this.ingestMapper.getCatalogTransactionId(catalogServiceTransactionId, catalog.getId());
if (catalogTransactionId != null) {
CatalogReceipt catalogReceipt = catalog.update(catalogTransactionId, metadata);
if (catalogReceipt != null) {
if (!catalogReceipt.getTransactionId().equals(catalogTransactionId)) {
this.ingestMapper.deleteTransactionIdMapping(catalogTransactionId, catalog.getId());
this.ingestMapper.storeTransactionIdMapping(catalogServiceTransactionId, this.transactionIdFactory, catalogReceipt, catalog.getTransactionIdFactory());
}
catalogReceipts.add(catalogReceipt);
LOG.log(Level.INFO, "Successfully updated metadata to catalog '" + catalog + "' for TransactionId '" + catalogServiceTransactionId + "'");
}else {
LOG.log(Level.SEVERE, "Update attempt to catalog '" + catalog + "' failed for TransactionId '" + catalogServiceTransactionId + "' -- update returned false");
}
}else {
LOG.log(Level.INFO, "Catalog '" + catalog + "' was not on ingest list for TransactionId '" + catalogServiceTransactionId + "' -- skipping");
}
// perform ingest
}else {
LOG.log(Level.INFO, "Performing ingest for TransactionId '" + catalogServiceTransactionId + "' to catalog '" + catalog + "'");
CatalogReceipt catalogReceipt = catalog.ingest(metadata);
if (catalogReceipt != null) {
LOG.log(Level.INFO, "Successfully ingested metadata -- Indexing TransactionId information for ingest (CatalogService TransactionId = '" + catalogServiceTransactionId + "', Catalog TransactionId = '" + catalogReceipt.getTransactionId() + "', catalog = '" + catalogReceipt.getCatalogId() + "')");
this.ingestMapper.storeTransactionIdMapping(catalogServiceTransactionId, this.transactionIdFactory, catalogReceipt, catalog.getTransactionIdFactory());
catalogReceipts.add(catalogReceipt);
}else {
LOG.log(Level.WARNING, "Catalog '" + catalog + "' not interested in any Metadata for TransactionId '" + catalogServiceTransactionId + "'");
}
}
}catch (Exception e) {
LOG.log(Level.WARNING, "Failed to add metadata to catalog '" + catalog.getId() + "' : " + e.getMessage(), e);
if (this.oneCatalogFailsAllFail)
throw new CatalogServiceException("Failed to add metadata to catalog '" + catalog.getId() + "' : " + e.getMessage(), e);
}finally {
this.ingestMapperLock.writeLock().unlock();
}
}else {
LOG.log(Level.WARNING, "Ingest not permitted to catalog '" + catalog + "' -- skipping over catalog");
}
}
return (catalogReceipts.size() > 0) ? new TransactionReceipt(catalogServiceTransactionId, catalogReceipts) : null;
}catch (Exception e) {
throw new CatalogServiceException("Error occured during Metadata ingest attempt : " + e.getMessage(), e);
}
}