try {
if(log.isDebugEnabled()) log.debug("Before transform: "+Xml.getString(md));
md = Xml.transform(md, thisXslt);
if(log.isDebugEnabled()) log.debug("After transform: "+Xml.getString(md));
} catch (Exception e) {
HarvestError error = new HarvestError(e, log);
error.setDescription("Cannot transform XML, ignoring. Error was: "+e.getMessage());
this.errors.add(error);
error.printLog(log);
result.badFormat++;
continue; // skip this one
}
}
// detect schema, extract uuid and add
String schema = dataMan.autodetectSchema(md, null);
if (schema == null) {
log.warning("Skipping metadata with unknown schema.");
result.unknownSchema++;
continue;
}
String uuid = null;
try {
uuid = dataMan.extractUUID(schema, md);
} catch (Exception e) {
HarvestError error = new HarvestError(e, log);
error.setDescription("Unable to extract UUID. " + e.getMessage());
this.errors.add(error);
error.printLog(log);
}
if (uuid == null || uuid.equals("")) {
log.warning("Skipping metadata due to failure extracting uuid (uuid null or empty).");
result.unretrievable++;
continue;
}
log.info(" - Adding metadata with " + uuid);
//--- generate a new metadata id
String docType = "";
if (!transformIt && (doc.getDocType() != null)) {
docType = Xml.getString(doc.getDocType());
}
//--- check for duplicate uuid - violates constraints on metadata table
//--- if we attempt insert
boolean alreadyAdded = !newUuids.add(uuid);
boolean alreadyInDb = (dataMan.getMetadataId(uuid) != null);
if (alreadyAdded || alreadyInDb) {
log.error("Uuid "+uuid+" already exists in this set/database - cannot insert");
result.couldNotInsert++;
continue;
}
final String id;
//
// insert metadata
//
try {
String groupOwner = "1", isTemplate = "n", title = null;
int owner = 1;
String category = null, createDate = new ISODate().toString(), changeDate = createDate;
boolean ufo = false, indexImmediate = false;
id = dataMan.insertMetadata(context, schema, md, uuid, owner, groupOwner, params.uuid,
isTemplate, docType, category, createDate, changeDate, ufo, indexImmediate);
}
catch (Exception e) {
HarvestError error = new HarvestError(e, log);
error.setDescription("Unable to insert metadata. "+e.getMessage());
this.errors.add(error);
error.printLog(log);
result.couldNotInsert++;
continue;
}
addPrivileges(id, params.getPrivileges(), localGroups, dataMan, context, log);