From 37d91d835f57a1d644f1fcb5b7f365143828be72 Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Thu, 10 Oct 2024 13:55:49 +0200 Subject: [PATCH] removed config var from basic funct, removed converting to lower case --- .../java/org/dspace/handle/HandlePlugin.java | 27 ++++++++++-------- .../test/data/dspaceFolder/config/local.cfg | 2 +- .../HdlResolverRestController.java | 28 +++++-------------- .../HdlResolverRestControllerIT.java | 10 +++---- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/handle/HandlePlugin.java b/dspace-api/src/main/java/org/dspace/handle/HandlePlugin.java index 67cd2b12ffca..a22736c179bb 100644 --- a/dspace-api/src/main/java/org/dspace/handle/HandlePlugin.java +++ b/dspace-api/src/main/java/org/dspace/handle/HandlePlugin.java @@ -255,23 +255,19 @@ public void scanNAs(ScanCallback callback) throws HandleException { //////////////////////////////////////// /** - * Extracts a DSpaceObject based on the given handle. + * Resolve the given handle to DSpace object. * * @param context the context * @param handle the handle to resolve - * @return the resolved DSpaceObject or null if not resolved + * @return the resolved DSpaceObject * @throws HandleException if an error occurs during resolution */ - private static DSpaceObject extractDSpaceObject(Context context, String handle) throws HandleException { - boolean resolveMetadata = configurationService.getBooleanProperty("lr.pid.resolvemetadata", true); + private static DSpaceObject resolveHandleToObject(Context context, String handle) throws HandleException { try { - if (resolveMetadata) { - return handleClarinService.resolveToObject(context, handle); - } - return null; + return handleClarinService.resolveToObject(context, handle); } catch (Exception e) { if (log.isDebugEnabled()) { - log.debug("Exception in extractDSpaceObject", e); + log.debug("Exception in resolveHandleToObject", e); } throw new HandleException(HandleException.INTERNAL_ERROR); } @@ -291,7 +287,12 @@ public static Map getMapHandleValues(String handle) throws Handl loadServices(); Context context = new Context(); try { - return extractMetadata(extractDSpaceObject(context, handle)); + DSpaceObject dso = null; + boolean resolveMetadata = configurationService.getBooleanProperty("lr.pid.resolvemetadata", true); + if (resolveMetadata) { + dso = resolveHandleToObject(context, handle); + } + return extractMetadata(dso); } finally { try { context.complete(); @@ -371,7 +372,11 @@ public byte[][] getRawHandleValues(byte[] theHandle, int[] indexList, rh = new ResolvedHandle(url, splits[1], splits[2], splits[3], splits[4], splits[5], splits[6], splits[7]); } else { - DSpaceObject dso = extractDSpaceObject(context, handle); + DSpaceObject dso = null; + boolean resolveMetadata = configurationService.getBooleanProperty("lr.pid.resolvemetadata", true); + if (resolveMetadata) { + dso = resolveHandleToObject(context, handle); + } rh = new ResolvedHandle(url, dso); } log.info(String.format("Handle [%s] resolved to [%s]", handle, url)); diff --git a/dspace-api/src/test/data/dspaceFolder/config/local.cfg b/dspace-api/src/test/data/dspaceFolder/config/local.cfg index 6b0ef5bbb180..cc9ccb26bbb2 100644 --- a/dspace-api/src/test/data/dspaceFolder/config/local.cfg +++ b/dspace-api/src/test/data/dspaceFolder/config/local.cfg @@ -306,4 +306,4 @@ sync.storage.service.enabled = false signposting.enabled = true # Test configuration has only EN locale (submission-forms.xml) -webui.supported.locales = en +webui.supported.locales = en \ No newline at end of file diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java index f82cecaeae24..eae2c44f365b 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/hdlresolver/HdlResolverRestController.java @@ -106,7 +106,7 @@ public ResponseEntity resolveHandle(HttpServletRequest request, String h if (!handleResolver.isValid()) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } else { - return new ResponseEntity<>(this.resolveToMtd(request, handleResolver), HttpStatus.OK); + return new ResponseEntity<>(this.resolveToURL(request, handleResolver), HttpStatus.OK); } } @@ -169,38 +169,24 @@ public ResponseEntity listHandles(HttpServletRequest request, @PathVaria } /** - * Maps the handle to url. - * - * @param request HttpServletRequest - * @param handleResolver HdlResolverDTO - Handle resolver - * @return String if found, else null String. - */ - private String resolveToURL(HttpServletRequest request, HdlResolverDTO handleResolver) { - return this.hdlResolverService.resolveToURL(ContextUtil.obtainContext(request), handleResolver); - } - - /** - * Resolves the metadata based on the given request and handle resolver. + * Maps the handle to a correct response. + * If the metadata parameter is provided, return additional handle values. * * @param request the HTTP request containing the metadata parameter * @param handleResolver the handle resolver containing the handle * @return a JSON representation of the URL or the handle values map, or "null" in case of an error */ - private String resolveToMtd(HttpServletRequest request, HdlResolverDTO handleResolver) { - Map result = new HashMap<>(); - String url = resolveToURL(request, handleResolver); + private String resolveToURL(HttpServletRequest request, HdlResolverDTO handleResolver) { + String url = this.hdlResolverService.resolveToURL(ContextUtil.obtainContext(request), handleResolver); String param = request.getParameter("metadata"); if (StringUtils.isBlank(param)) { return mapAsJson(url); } - result.put("url", url); String handle = handleResolver.getHandle(); try { Map metadata = HandlePlugin.getMapHandleValues(handle); - for (Map.Entry entry : metadata.entrySet()) { - result.put(entry.getKey().toLowerCase(), entry.getValue()); - } - return mapAsJson(result); + metadata.put("URL", url); + return mapAsJson(metadata); } catch (HandleException e) { log.error("Failed to resolve handle values for handle: " + handle, e); } diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/hdlresolver/HdlResolverRestControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/hdlresolver/HdlResolverRestControllerIT.java index 83c6b5cbad1e..f19f4944478e 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/hdlresolver/HdlResolverRestControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/hdlresolver/HdlResolverRestControllerIT.java @@ -108,13 +108,13 @@ public void givenMappedIdentifierWhenCallHdlresolverThenReturnsMappedParams() th .perform(get(HdlResolverRestController.RESOLVE + publicItem1.getHandle()) .param("metadata", "true")) .andExpect(status().isOk()) - .andExpect(jsonPath("$.url", + .andExpect(jsonPath("$.URL", StringContains.containsString("123456789/testHdlResolver"))) - .andExpect(jsonPath("$.title", StringContains.containsString("Public item 1"))) - .andExpect(jsonPath("$.repository", is(configurationService.getProperty("dspace.name")))) - .andExpect(jsonPath("$.reportemail", + .andExpect(jsonPath("$.TITLE", StringContains.containsString("Public item 1"))) + .andExpect(jsonPath("$.REPOSITORY", is(configurationService.getProperty("dspace.name")))) + .andExpect(jsonPath("$.REPORTEMAIL", StringContains.containsString("dspace-help@ufal.mff.cuni.cz"))) - .andExpect(jsonPath("$.submitdate").exists()); + .andExpect(jsonPath("$.SUBMITDATE").exists()); } @Test