Skip to content

Commit

Permalink
Update db search and replace to allow replacements on working copies
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjmchugh committed Nov 25, 2024
1 parent 97bdd7b commit 5bcd1ee
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -348,6 +354,7 @@ static final class BatchDatabaseUpdateMetadataReindexer extends
MetadataIndexerProcessor {
private final boolean index;
private final boolean updateDateStamp;
private final boolean approved;
Set<String> records;
boolean useRegexp;
String search;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 5bcd1ee

Please sign in to comment.