From 8920bb5677712d85febeeebee149d396de939362 Mon Sep 17 00:00:00 2001 From: Ian Allen Date: Fri, 29 Dec 2023 08:15:39 -0400 Subject: [PATCH] API should return a structured object instead of JSONObject Updated indexer to return an object IndexResponse instead of JSONObject --- .../geonet/api/records/MetadataIndexApi.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/services/src/main/java/org/fao/geonet/api/records/MetadataIndexApi.java b/services/src/main/java/org/fao/geonet/api/records/MetadataIndexApi.java index 57303c9be00..b26cfc4bd43 100644 --- a/services/src/main/java/org/fao/geonet/api/records/MetadataIndexApi.java +++ b/services/src/main/java/org/fao/geonet/api/records/MetadataIndexApi.java @@ -29,13 +29,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import jeeves.server.UserSession; -import jeeves.server.context.ServiceContext; import jeeves.services.ReadWriteController; -import net.sf.json.JSONObject; import org.fao.geonet.api.ApiParams; import org.fao.geonet.api.ApiUtils; import org.fao.geonet.kernel.DataManager; -import org.fao.geonet.kernel.SelectionManager; import org.fao.geonet.kernel.datamanager.IMetadataUtils; import org.fao.geonet.kernel.search.index.BatchOpsMetadataReindexer; import org.fao.geonet.kernel.setting.SettingManager; @@ -46,7 +43,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.util.Set; @@ -86,7 +82,7 @@ public class MetadataIndexApi { }) public @ResponseBody - JSONObject index( + IndexResponse index( @Parameter(description = API_PARAM_RECORD_UUIDS_OR_SELECTION, required = false, example = "") @@ -125,11 +121,30 @@ JSONObject index( new BatchOpsMetadataReindexer(dataManager, ids) .process(settingManager.getSiteId(), false); - JSONObject res = new JSONObject(); - res.put("success", true); - res.put("count", index); - - return res; + IndexResponse indexResponse = new IndexResponse(); + indexResponse.setSuccess(true); + indexResponse.setCount(index); + return indexResponse; } + private static class IndexResponse { + private boolean success; + private int count; + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + } }