diff --git a/services/src/main/java/org/fao/geonet/api/processing/DatabaseProcessApi.java b/services/src/main/java/org/fao/geonet/api/processing/DatabaseProcessApi.java index afd1f15d037..c2989a64a67 100644 --- a/services/src/main/java/org/fao/geonet/api/processing/DatabaseProcessApi.java +++ b/services/src/main/java/org/fao/geonet/api/processing/DatabaseProcessApi.java @@ -46,6 +46,7 @@ import org.fao.geonet.kernel.datamanager.IMetadataUtils; import org.fao.geonet.kernel.setting.SettingManager; import org.fao.geonet.kernel.setting.Settings; +import org.fao.geonet.repository.MetadataRepository; import org.fao.geonet.util.UserUtil; import org.fao.geonet.utils.Diff; import org.fao.geonet.utils.DiffType; @@ -310,6 +311,11 @@ public XsltMetadataProcessingReport processSearchAndReplace( example = "false") @RequestParam(required = false, defaultValue = "true") boolean index, + @Parameter(description = "Use approved version or not", + required = false, + example = "false") + @RequestParam(required = false, defaultValue = "false") + boolean approved, @Parameter(hidden = true) HttpSession httpSession, @Parameter(hidden = true) @@ -332,7 +338,7 @@ public XsltMetadataProcessingReport processSearchAndReplace( BatchDatabaseUpdateMetadataReindexer m = new BatchDatabaseUpdateMetadataReindexer( serviceContext, dataMan, records, useRegexp, search, replace, regexpFlags, httpSession, siteURL, - processingReport, request, index, updateDateStamp, userSession.getUserIdAsInt()); + processingReport, request, index, updateDateStamp, approved, userSession.getUserIdAsInt()); m.process(settingManager.getSiteId()); } catch (Exception exception) { @@ -348,6 +354,7 @@ static final class BatchDatabaseUpdateMetadataReindexer extends MetadataIndexerProcessor { private final boolean index; private final boolean updateDateStamp; + private final boolean approved; Set records; boolean useRegexp; String search; @@ -370,7 +377,7 @@ public BatchDatabaseUpdateMetadataReindexer(ServiceContext context, HttpSession session, String siteURL, MetadataReplacementProcessingReport processingReport, - HttpServletRequest request, boolean index, + HttpServletRequest request, boolean index, boolean approved, boolean updateDateStamp, int userId) { super(dm); this.records = records; @@ -381,6 +388,7 @@ public BatchDatabaseUpdateMetadataReindexer(ServiceContext context, this.session = session; this.index = index; this.updateDateStamp = updateDateStamp; + this.approved = approved; this.siteURL = siteURL; this.request = request; this.processingReport = processingReport; @@ -393,7 +401,12 @@ public void process(String catalogueId) throws Exception { DataManager dataMan = context.getBean(DataManager.class); ApplicationContext appContext = ApplicationContextHolder.get(); for (String uuid : this.records) { - String id = getDataManager().getMetadataId(uuid); + String id; + if (this.approved) { + id = String.valueOf(context.getBean(MetadataRepository.class).findOneByUuid(uuid).getId()); + } else { + id = String.valueOf(context.getBean(IMetadataUtils.class).findOneByUuid(uuid).getId()); + } Log.info("org.fao.geonet.services.metadata", "Processing metadata with id:" + id);