Skip to content

Commit

Permalink
Error catching when removing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Delawen committed Jul 24, 2015
1 parent e2ed1dc commit 86d51b8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
17 changes: 10 additions & 7 deletions core/src/main/java/org/fao/geonet/kernel/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2167,13 +2167,16 @@ public javax.persistence.criteria.Path<String> getPath(Root<MetadataFileUpload>
*/
public synchronized void deleteMetadata(ServiceContext context, String metadataId) throws Exception {
String uuid = getMetadataUuid(metadataId);
boolean isMetadata = getMetadataRepository().findOne(metadataId).getDataInfo().getType() == MetadataType.METADATA;

deleteMetadataFromDB(context, metadataId);

// Notifies the metadata change to metatada notifier service
if (isMetadata) {
context.getBean(MetadataNotifierManager.class).deleteMetadata(metadataId, uuid, context);
Metadata findOne = getMetadataRepository().findOne(metadataId);
if(findOne != null) {
boolean isMetadata = findOne.getDataInfo().getType() == MetadataType.METADATA;

deleteMetadataFromDB(context, metadataId);

// Notifies the metadata change to metatada notifier service
if (isMetadata) {
context.getBean(MetadataNotifierManager.class).deleteMetadata(metadataId, uuid, context);
}
}

//--- update search criteria
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ public HarvestResult align(Set<RecordInfo> records, List<HarvestError> errors) t
localGroups= new GroupMapper(context);
localUuids = new UUIDMapper(context.getBean(MetadataRepository.class), params.getUuid());

dataMan.flush();

Pair<String, Map<String, Object>> filter =
HarvesterUtil.parseXSLFilter(params.xslfilter, log);
processName = filter.one();
Expand All @@ -166,20 +164,23 @@ public HarvestResult align(Set<RecordInfo> records, List<HarvestError> errors) t
//--- remove old metadata

for (String uuid : localUuids.getUUIDs()) {
//FIXME can we do it on one step?
if (cancelMonitor.get()) {
return this.result;
}

if (!exists(records, uuid)) {
String id = localUuids.getID(uuid);

if (log.isDebugEnabled()) log.debug(" - Removing old metadata with id:" + id);
dataMan.deleteMetadata(context, id);

dataMan.flush();

result.locallyRemoved++;
try{
if (!exists(records, uuid)) {
String id = localUuids.getID(uuid);

if (log.isDebugEnabled()) log.debug(" - Removing old metadata with id:" + id);
dataMan.deleteMetadata(context, id);

result.locallyRemoved++;
}
}catch (Throwable t) {
log.error("Couldn't remove metadata with uuid " + uuid);
log.error(t);
result.unchangedMetadata++;
}
}
//-----------------------------------------------------------------------
Expand All @@ -194,30 +195,37 @@ public HarvestResult align(Set<RecordInfo> records, List<HarvestError> errors) t
if (cancelMonitor.get()) {
return this.result;
}

try{

result.totalMetadata++;

// Mef full format provides ISO19139 records in both the profile
// and ISO19139 so we could be able to import them as far as
// ISO19139 schema is installed by default.
if (!dataMan.existsSchema(ri.schema) && !ri.schema.startsWith("iso19139.")) {
if(log.isDebugEnabled())
log.debug(" - Metadata skipped due to unknown schema. uuid:"+ ri.uuid
+", schema:"+ ri.schema);
result.unknownSchema++;
} else {
String id = dataMan.getMetadataId(ri.uuid);

// look up value of localrating/enable
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
SettingManager settingManager = gc.getBean(SettingManager.class);
boolean localRating = settingManager.getValueAsBool("system/localrating/enable", false);

if (id == null) {
addMetadata(ri, localRating);
result.totalMetadata++;

// Mef full format provides ISO19139 records in both the profile
// and ISO19139 so we could be able to import them as far as
// ISO19139 schema is installed by default.
if (!dataMan.existsSchema(ri.schema) && !ri.schema.startsWith("iso19139.")) {
if(log.isDebugEnabled())
log.debug(" - Metadata skipped due to unknown schema. uuid:"+ ri.uuid
+", schema:"+ ri.schema);
result.unknownSchema++;
} else {
updateMetadata(ri, id, localRating, params.useChangeDateForUpdate(), localUuids.getChangeDate(ri.uuid));
String id = dataMan.getMetadataId(ri.uuid);

// look up value of localrating/enable
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
SettingManager settingManager = gc.getBean(SettingManager.class);
boolean localRating = settingManager.getValueAsBool("system/localrating/enable", false);

if (id == null) {
addMetadata(ri, localRating);
} else {
updateMetadata(ri, id, localRating, params.useChangeDateForUpdate(), localUuids.getChangeDate(ri.uuid));
}
}
}catch(Throwable t) {
log.error("Couldn't insert or update metadata with uuid " + ri.uuid);
log.error(t);
result.unchangedMetadata++;
}
}

Expand Down

0 comments on commit 86d51b8

Please sign in to comment.