Skip to content

Commit

Permalink
Bring in commit from develop that fixes webdav uuid overwrite bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sppigot committed Sep 4, 2014
1 parent bd38090 commit 7020a80
Showing 1 changed file with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,35 +158,60 @@ private void addMetadata(RemoteFile rf) throws Exception {
}
//--- schema handled check already done
String schema = dataMan.autodetectSchema(md);
String uuid = UUID.randomUUID().toString();

if(log.isDebugEnabled()) log.debug(" - Setting uuid for metadata with remote path : "+ rf.getPath());

//--- set uuid inside metadata and get new xml
try {
md = dataMan.setUUID(schema, uuid, md);
} catch(Exception e) {
log.error(" - Failed to set uuid for metadata with remote path : "+ rf.getPath());
return;
}

if(log.isDebugEnabled()) log.debug(" - Adding metadata with remote path : "+ rf.getPath());
// 1.- Look for the file identifier on the metadata xml
String uuid = dataMan.extractUUID(schema, md);

// 2.- If there is no file identifier, then use the name of the file
if (uuid == null) {
String path = rf.getPath();
int start = path.lastIndexOf("/") + 1;
uuid = path.substring(start, path.length() - 4);
}

// 3.- If there is a collision of uuid with existent metadata, use a
// random one
if (dataMan.existsMetadataUuid(dbms, uuid)) {
uuid = null;
}

// 4.- If we still don't have a clear UUID, use a random one (backup
// plan)
if (uuid == null) {
uuid = UUID.randomUUID().toString();
log.debug(" - Setting uuid for metadata with remote path : "
+ rf.getPath());

// --- set uuid inside metadata and get new xml
try {
md = dataMan.setUUID(schema, uuid, md);
} catch (Exception e) {
log.error(" - Failed to set uuid for metadata with remote path : "
+ rf.getPath());
result.badFormat++;
return;
}
}

log.debug(" - Adding metadata with remote path : " + rf.getPath());

if(log.isDebugEnabled()) log.debug(" - Adding metadata with remote path : "+ rf.getPath());

//
// insert metadata
//
String group = null, isTemplate = null, docType = null, title = null, category = null;
boolean ufo = false, indexImmediate = false;
String id = dataMan.insertMetadata(context, dbms, schema, md, context.getSerialFactory().getSerial(dbms, "Metadata"), uuid, Integer.parseInt(params.ownerId), group, params.uuid,
isTemplate, docType, title, category, rf.getChangeDate(), rf.getChangeDate(), ufo, indexImmediate);
// insert metadata
//
String group = null, isTemplate = null, docType = null, title = null, category = null;
boolean ufo = false, indexImmediate = false;
String id = dataMan.insertMetadata(context, dbms, schema, md, context.getSerialFactory().getSerial(dbms, "Metadata"), uuid, Integer.parseInt(params.ownerId), group, params.uuid, isTemplate, docType, title, category, rf.getChangeDate(), rf.getChangeDate(), ufo, indexImmediate);


int iId = Integer.parseInt(id);

dataMan.setTemplateExt(dbms, iId, "n", null);
dataMan.setHarvestedExt(dbms, iId, params.uuid, rf.getPath());

addPrivileges(id, params.getPrivileges(), localGroups, dataMan, context, dbms, log);
addPrivileges(id, params.getPrivileges(), localGroups, dataMan, context, dbms, log);
addCategories(id);

dbms.commit();
Expand Down Expand Up @@ -278,7 +303,12 @@ private void updateMetadata(RemoteFile rf, RecordInfo record) throws Exception {
//--- In update we should use db uuid to update the xml uuid and keep in sych both.
try {
String schema = dataMan.autodetectSchema(md);
md = dataMan.setUUID(schema, record.uuid, md);

//Update only if different
String uuid = dataMan.extractUUID(schema, md);
if (!record.uuid.equals(uuid)) {
md = dataMan.setUUID(schema, record.uuid, md);
}
} catch(Exception e) {
log.error(" - Failed to set uuid for metadata with remote path : "+ rf.getPath());
return;
Expand Down

0 comments on commit 7020a80

Please sign in to comment.