From ed049820800be27f9927a5addcc0d3d0891f9f77 Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Tue, 26 Nov 2024 16:14:52 +0100 Subject: [PATCH 1/8] added fn for embargo --- .../org/dspace/utils/SpecialItemService.java | 112 ++++++++++++++++++ .../resources/DSpaceResourceResolver.java | 3 +- .../resources/functions/GetAvailableFn.java | 22 ++++ .../functions/StringXSLFunction.java | 1 - .../oai/metadataFormats/datacite_openaire.xsl | 17 +-- 5 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java diff --git a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java index d62cbc481fcb..3c09a6347c6b 100644 --- a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java +++ b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java @@ -11,6 +11,10 @@ import java.io.InputStreamReader; import java.io.Reader; +import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.Objects; import javax.xml.parsers.DocumentBuilder; @@ -18,17 +22,27 @@ import javax.xml.parsers.ParserConfigurationException; import org.dspace.app.util.DCInput; +import org.dspace.authorize.ResourcePolicy; +import org.dspace.authorize.factory.AuthorizeServiceFactory; +import org.dspace.authorize.service.ResourcePolicyService; import org.dspace.content.Bitstream; +import org.dspace.content.Bundle; import org.dspace.content.DSpaceObject; import org.dspace.content.Item; +import org.dspace.content.MetadataField; import org.dspace.content.MetadataValue; +import org.dspace.content.factory.ClarinServiceFactory; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.ItemService; +import org.dspace.content.service.MetadataFieldService; +import org.dspace.content.service.clarin.ClarinItemService; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.service.HandleService; +import org.dspace.xoai.exceptions.InvalidMetadataFieldException; +import org.dspace.xoai.services.impl.DSpaceFieldResolver; import org.springframework.stereotype.Component; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -267,6 +281,104 @@ public static Node getAuthor(String mdValue) { } } + // Helper method to find the item by its handle + private static Item findItemByHandle(ClarinItemService clarinItemService, + Context context, MetadataField metadataField, String handle) { + try { + List itemList = clarinItemService.findByHandle(context, metadataField, handle); + return (itemList.isEmpty()) ? null : itemList.get(0); + } catch (SQLException e) { + log.error("Error retrieving item by handle.", e); + return null; + } + } + + // Helper method to get the embargo start date from the resource policies + private static Date getEmbargoStartDate(Context context, Item item) throws SQLException { + ResourcePolicyService resPolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); + Date startDate = null; + for (Bundle bundle : item.getBundles()) { + for (Bitstream bitstream : bundle.getBitstreams()) { + List resPolList = resPolicyService.find(context, bitstream, Constants.READ); + for (ResourcePolicy resPol : resPolList) { + Date date = resPol.getStartDate(); + if (startDate == null || (date != null && date.compareTo(startDate) > 0)) { + startDate = date; + } + } + } + } + return startDate; + } + + public static String getAvailable(String identifierUri) { + Context context = new Context(); + ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService(); + try { + // Find the metadata field for "dc.identifier.uri" + MetadataField metadataField = findMetadataField(context, "dc.identifier.uri"); + if (metadataField == null) { + log.error("Metadata field for 'dc.identifier.uri' not found."); + return null; + } + + // Retrieve the item using the handle + Item item = findItemByHandle(clarinItemService, context, metadataField, identifierUri); + if (item == null) { + log.error(String.format("Item for handle %s doesn't exist!", identifierUri)); + return null; + } + + // Check if there is an embargo or get the earliest available date + Date startDate = getEmbargoStartDate(context, item); + if (startDate == null) { + startDate = getAvailableDate(context, item); + } + return (startDate != null) ? startDate.toString() : null; + } catch (SQLException | InvalidMetadataFieldException ex) { + log.error("Error in getAvailable method: ", ex); + } + return null; + } + + // Helper method to find the metadata field "dc.identifier.uri" + private static MetadataField findMetadataField(Context context, String mtd) throws SQLException { + MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService(); + return metadataFieldService.findByString(context, mtd, '.'); + } + + // Helper method to get the available date from the metadata values + private static Date getAvailableDate(Context context, Item item) + throws SQLException, InvalidMetadataFieldException { + DSpaceFieldResolver dSpaceFieldResolver = new DSpaceFieldResolver(); + List metadataValueList = item.getMetadata(); + int fieldID = dSpaceFieldResolver.getFieldID(context, "dc.date.available"); + Date startDate = null; + + for (MetadataValue mtd : metadataValueList) { + if (mtd.getMetadataField().getID() == fieldID) { + Date availableDate = parseDate(mtd.getValue()); + if (startDate == null || (availableDate != null && availableDate.compareTo(startDate) > 0)) { + startDate = availableDate; + } + } + } + return startDate; + } + + // Helper method to parse a date from a string + private static Date parseDate(String dateString) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // Example format + dateFormat.setLenient(false); // Set lenient to false to avoid parsing incorrect dates + + try { + return dateFormat.parse(dateString); // Attempt to parse the date + } catch (ParseException e) { + return null; + } + } + + public static boolean hasOwnMetadata(List metadataValues) { if (metadataValues.size() == 1 && metadataValues.get(0).getValue().equalsIgnoreCase("true")) { return true; diff --git a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/DSpaceResourceResolver.java b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/DSpaceResourceResolver.java index 9d4790b9ff47..c0e540b9576c 100644 --- a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/DSpaceResourceResolver.java +++ b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/DSpaceResourceResolver.java @@ -26,6 +26,7 @@ import org.dspace.xoai.services.impl.resources.functions.BibtexifyFn; import org.dspace.xoai.services.impl.resources.functions.FormatFn; import org.dspace.xoai.services.impl.resources.functions.GetAuthorFn; +import org.dspace.xoai.services.impl.resources.functions.GetAvailableFn; import org.dspace.xoai.services.impl.resources.functions.GetContactFn; import org.dspace.xoai.services.impl.resources.functions.GetFundingFn; import org.dspace.xoai.services.impl.resources.functions.GetLangForCodeFn; @@ -54,7 +55,7 @@ public class DSpaceResourceResolver implements ResourceResolver { new UriToLicenseFn(), new LogMissingMsgFn(), new UriToRestrictionsFn(), new ShortestIdFn(), new GetContactFn(), new GetAuthorFn(), new GetFundingFn(), new GetLangForCodeFn(), new GetPropertyFn(), new GetSizeFn(), new GetUploadedMetadataFn(), new LogMissingFn(), - new BibtexifyFn(), new FormatFn() + new BibtexifyFn(), new FormatFn(), new GetAvailableFn() ); SaxonTransformerFactory saxonTransformerFactory = (SaxonTransformerFactory) transformerFactory; diff --git a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java new file mode 100644 index 000000000000..b10c554cce52 --- /dev/null +++ b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java @@ -0,0 +1,22 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.xoai.services.impl.resources.functions; + +import org.dspace.utils.SpecialItemService; + +public class GetAvailableFn extends StringXSLFunction { + @Override + protected String getFnName() { + return "getAvailable"; + } + + @Override + protected String getStringResult(String param) { + return SpecialItemService.getAvailable(param); + } +} diff --git a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java index 163a9eb49ca1..ed260c8b2d4a 100644 --- a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java +++ b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java @@ -74,7 +74,6 @@ final public XdmValue call(XdmValue[] xdmValues) throws SaxonApiException { log.warn("Empty value in call of function of StringXslFunction type"); val = ""; } - return new XdmAtomicValue(checks(getStringResult(val))); } diff --git a/dspace/config/crosswalks/oai/metadataFormats/datacite_openaire.xsl b/dspace/config/crosswalks/oai/metadataFormats/datacite_openaire.xsl index d6823c6f2c12..64cfda7f20ee 100644 --- a/dspace/config/crosswalks/oai/metadataFormats/datacite_openaire.xsl +++ b/dspace/config/crosswalks/oai/metadataFormats/datacite_openaire.xsl @@ -141,19 +141,10 @@ - - - - - - - - - - - - - + + + + From 57e785ea040d268eb8bcdd776fa2c8b39180f375 Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 08:24:03 +0100 Subject: [PATCH 2/8] using of res policy end_date and added comments --- .../org/dspace/utils/SpecialItemService.java | 161 ++++++++++++------ .../resources/functions/GetAvailableFn.java | 9 + 2 files changed, 117 insertions(+), 53 deletions(-) diff --git a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java index 3c09a6347c6b..a7f16aeb73ba 100644 --- a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java +++ b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java @@ -281,9 +281,66 @@ public static Node getAuthor(String mdValue) { } } - // Helper method to find the item by its handle - private static Item findItemByHandle(ClarinItemService clarinItemService, - Context context, MetadataField metadataField, String handle) { + /** + * Retrieves the earliest available date for an item identified by the given identifier URI. + * This method checks for any embargo date first and then retrieves the "dc.date.available" + * metadata value as a fallback if no embargo date is found. + * + * @param identifierUri The identifier URI of the item whose available date is to be retrieved. + * @return A string representation of the earliest available date, or null if no date is found or an error occurs. + */ + public static String getAvailable(String identifierUri) { + Context context = new Context(); + // Find the metadata field for "dc.identifier.uri" + String mtdField = "dc.identifier.uri"; + MetadataField metadataField = findMetadataField(context, mtdField); + if (Objects.isNull(metadataField)) { + log.error(String.format("Metadata field for %s not found.", mtdField)); + return null; + } + + // Retrieve the item using the handle + Item item = findItemByHandle(context, metadataField, identifierUri); + if (Objects.isNull(item)) { + log.error(String.format("Item for handle %s doesn't exist!", identifierUri)); + return null; + } + + // Check if there is an embargo or get the earliest available date + Date startDate = getEmbargoDate(context, item); + if (Objects.isNull(startDate)) { + startDate = getAvailableDate(context, item); + } + return (Objects.nonNull(startDate)) ? startDate.toString() : null; + } + + /** + * Finds the metadata field corresponding to the provided string. + * + * @param context The DSpace context + * @param mtd The metadata field string + * @return The MetadataField object, or null if not found. + */ + private static MetadataField findMetadataField(Context context, String mtd){ + MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService(); + try { + return metadataFieldService.findByString(context, mtd, '.'); + } catch (SQLException e) { + log.error(String.format("Error finding metadata field %s.", mtd), e); + return null; + } + } + + /** + * Finds an item in DSpace using the provided handle and metadata field. + * + * @param context The DSpace context + * @param metadataField The metadata field used for item search + * @param handle The handle (identifier) of the item. + * @return The Item object, or null if no item is found. + */ + private static Item findItemByHandle(Context context, MetadataField metadataField, String handle) { + ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService(); try { List itemList = clarinItemService.findByHandle(context, metadataField, handle); return (itemList.isEmpty()) ? null : itemList.get(0); @@ -293,16 +350,33 @@ private static Item findItemByHandle(ClarinItemService clarinItemService, } } - // Helper method to get the embargo start date from the resource policies - private static Date getEmbargoStartDate(Context context, Item item) throws SQLException { + /** + * Retrieves the embargo start date for the given item bitstreams. If an embargo has ended, the end date is returned. + * + * @param context The DSpace context + * @param item The item whose embargo date is to be retrieved. + * @return The start or end date of the embargo, or null if no embargo exists. + */ + private static Date getEmbargoDate(Context context, Item item){ ResourcePolicyService resPolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); Date startDate = null; for (Bundle bundle : item.getBundles()) { for (Bitstream bitstream : bundle.getBitstreams()) { - List resPolList = resPolicyService.find(context, bitstream, Constants.READ); + List resPolList; + try { + resPolList = resPolicyService.find(context, bitstream, Constants.READ); + } catch (SQLException e) { + log.error(String.format("Error during finding resource policies READ for bitstream %s"), + bitstream.getID()); + return null; + } for (ResourcePolicy resPol : resPolList) { Date date = resPol.getStartDate(); - if (startDate == null || (date != null && date.compareTo(startDate) > 0)) { + // If the embargo has already ended, use the date of its end. + if (Objects.nonNull(date) && Objects.nonNull(resPol.getEndDate())) { + date = resPol.getEndDate(); + } + if (Objects.isNull(startDate) || (Objects.nonNull(date) && date.compareTo(startDate) > 0)) { startDate = date; } } @@ -311,54 +385,30 @@ private static Date getEmbargoStartDate(Context context, Item item) throws SQLEx return startDate; } - public static String getAvailable(String identifierUri) { - Context context = new Context(); - ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService(); - try { - // Find the metadata field for "dc.identifier.uri" - MetadataField metadataField = findMetadataField(context, "dc.identifier.uri"); - if (metadataField == null) { - log.error("Metadata field for 'dc.identifier.uri' not found."); - return null; - } - - // Retrieve the item using the handle - Item item = findItemByHandle(clarinItemService, context, metadataField, identifierUri); - if (item == null) { - log.error(String.format("Item for handle %s doesn't exist!", identifierUri)); - return null; - } - - // Check if there is an embargo or get the earliest available date - Date startDate = getEmbargoStartDate(context, item); - if (startDate == null) { - startDate = getAvailableDate(context, item); - } - return (startDate != null) ? startDate.toString() : null; - } catch (SQLException | InvalidMetadataFieldException ex) { - log.error("Error in getAvailable method: ", ex); - } - return null; - } - - // Helper method to find the metadata field "dc.identifier.uri" - private static MetadataField findMetadataField(Context context, String mtd) throws SQLException { - MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService(); - return metadataFieldService.findByString(context, mtd, '.'); - } - - // Helper method to get the available date from the metadata values - private static Date getAvailableDate(Context context, Item item) - throws SQLException, InvalidMetadataFieldException { + /** + * Retrieves the available date for the given item by checking the "dc.date.available" metadata. + * + * @param context The DSpace context + * @param item The item whose available date is to be retrieved. + * @return The available date, or null if no available date is found. + */ + private static Date getAvailableDate(Context context, Item item) { DSpaceFieldResolver dSpaceFieldResolver = new DSpaceFieldResolver(); List metadataValueList = item.getMetadata(); - int fieldID = dSpaceFieldResolver.getFieldID(context, "dc.date.available"); + String mtdField = "dc.date.available"; + int fieldID; + try { + fieldID = dSpaceFieldResolver.getFieldID(context, mtdField); + } catch (SQLException | InvalidMetadataFieldException e) { + log.error(String.format("Error during finding ID of metadata field %s.", mtdField)); + return null; + } Date startDate = null; - for (MetadataValue mtd : metadataValueList) { if (mtd.getMetadataField().getID() == fieldID) { Date availableDate = parseDate(mtd.getValue()); - if (startDate == null || (availableDate != null && availableDate.compareTo(startDate) > 0)) { + if (Objects.isNull(startDate) || (Objects.nonNull(availableDate) + && availableDate.compareTo(startDate) > 0)) { startDate = availableDate; } } @@ -366,19 +416,24 @@ private static Date getAvailableDate(Context context, Item item) return startDate; } - // Helper method to parse a date from a string + /** + * Parses a date string in the format "yyyy-MM-dd" into a Date object. + * + * @param dateString The date string to be parsed. + * @return A Date object representing the parsed date, or null if parsing fails. + */ private static Date parseDate(String dateString) { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // Example format + String format = "yyyy-MM-dd"; + SimpleDateFormat dateFormat = new SimpleDateFormat(format); // Example format dateFormat.setLenient(false); // Set lenient to false to avoid parsing incorrect dates - try { return dateFormat.parse(dateString); // Attempt to parse the date } catch (ParseException e) { + log.warn(String.format("Date %s cannot be parsed using the format %s.", dateString, format)); return null; } } - public static boolean hasOwnMetadata(List metadataValues) { if (metadataValues.size() == 1 && metadataValues.get(0).getValue().equalsIgnoreCase("true")) { return true; diff --git a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java index b10c554cce52..f7843abed51c 100644 --- a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java +++ b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/GetAvailableFn.java @@ -9,6 +9,15 @@ import org.dspace.utils.SpecialItemService; +/** + * The GetAvailableFn class extends the StringXSLFunction to provide a custom function + * that retrieves the availability status of an item based on its identifier. + * It uses the SpecialItemService to fetch the available information. + * This function is intended to be used in XSL transformations where the + * "getAvailable" function is called with an item's identifier as a parameter. + * + * @author Michaela Paurikova(michaela.paurikova at dataquest.sk) + */ public class GetAvailableFn extends StringXSLFunction { @Override protected String getFnName() { From 4e0e7a42e6be3e16f81c5b481c92b92f8464b2b2 Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 09:35:37 +0100 Subject: [PATCH 3/8] fix string format problem with %s --- .../src/main/java/org/dspace/utils/SpecialItemService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java index a7f16aeb73ba..1d08e291a205 100644 --- a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java +++ b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java @@ -366,8 +366,8 @@ private static Date getEmbargoDate(Context context, Item item){ try { resPolList = resPolicyService.find(context, bitstream, Constants.READ); } catch (SQLException e) { - log.error(String.format("Error during finding resource policies READ for bitstream %s"), - bitstream.getID()); + log.error(String.format("Error during finding resource policies READ for bitstream %s", + bitstream.getID().toString())); return null; } for (ResourcePolicy resPol : resPolList) { From d92e27dbab76557e7d63b34c1fc7cb8cc44d972d Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 10:09:36 +0100 Subject: [PATCH 4/8] integration tests are falling down --- .../dspace/identifier/VersionedHandleIdentifierProviderIT.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/dspace-api/src/test/java/org/dspace/identifier/VersionedHandleIdentifierProviderIT.java b/dspace-api/src/test/java/org/dspace/identifier/VersionedHandleIdentifierProviderIT.java index 57acf1f1c453..a28a5a4c7508 100644 --- a/dspace-api/src/test/java/org/dspace/identifier/VersionedHandleIdentifierProviderIT.java +++ b/dspace-api/src/test/java/org/dspace/identifier/VersionedHandleIdentifierProviderIT.java @@ -62,9 +62,6 @@ public void setUp() throws Exception { @Override public void destroy() throws Exception { super.destroy(); - // After this test has finished running, refresh application context and - // set the expected 'default' versioned handle provider back to ensure other tests don't fail - DSpaceServicesFactory.getInstance().getServiceManager().getApplicationContext().refresh(); } private void registerProvider(Class type) { From 33f3260f0dc98231de59d672fd739affc73b2e22 Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 10:10:17 +0100 Subject: [PATCH 5/8] checkstyle violations --- .../src/main/java/org/dspace/utils/SpecialItemService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java index 1d08e291a205..1b402de34671 100644 --- a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java +++ b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java @@ -321,7 +321,7 @@ public static String getAvailable(String identifierUri) { * @param mtd The metadata field string * @return The MetadataField object, or null if not found. */ - private static MetadataField findMetadataField(Context context, String mtd){ + private static MetadataField findMetadataField(Context context, String mtd) { MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService(); try { return metadataFieldService.findByString(context, mtd, '.'); @@ -351,13 +351,14 @@ private static Item findItemByHandle(Context context, MetadataField metadataFiel } /** - * Retrieves the embargo start date for the given item bitstreams. If an embargo has ended, the end date is returned. + * Retrieves the embargo start date for the given item bitstreams. + * If an embargo has ended, the end date is returned. * * @param context The DSpace context * @param item The item whose embargo date is to be retrieved. * @return The start or end date of the embargo, or null if no embargo exists. */ - private static Date getEmbargoDate(Context context, Item item){ + private static Date getEmbargoDate(Context context, Item item) { ResourcePolicyService resPolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService(); Date startDate = null; for (Bundle bundle : item.getBundles()) { From f209b4b3d22b3a92b431c6f63ada637a64bd399a Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 10:52:20 +0100 Subject: [PATCH 6/8] removed findHandle duplicity --- .../org/dspace/utils/SpecialItemService.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java index 1b402de34671..c801ccc156a6 100644 --- a/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java +++ b/dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java @@ -300,7 +300,15 @@ public static String getAvailable(String identifierUri) { } // Retrieve the item using the handle - Item item = findItemByHandle(context, metadataField, identifierUri); + ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService(); + Item item; + try { + List itemList = clarinItemService.findByHandle(context, metadataField, identifierUri); + item = itemList.isEmpty() ? null : itemList.get(0); + } catch (SQLException e) { + log.error("Error retrieving item by handle.", e); + return null; + } if (Objects.isNull(item)) { log.error(String.format("Item for handle %s doesn't exist!", identifierUri)); return null; @@ -331,25 +339,6 @@ private static MetadataField findMetadataField(Context context, String mtd) { } } - /** - * Finds an item in DSpace using the provided handle and metadata field. - * - * @param context The DSpace context - * @param metadataField The metadata field used for item search - * @param handle The handle (identifier) of the item. - * @return The Item object, or null if no item is found. - */ - private static Item findItemByHandle(Context context, MetadataField metadataField, String handle) { - ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService(); - try { - List itemList = clarinItemService.findByHandle(context, metadataField, handle); - return (itemList.isEmpty()) ? null : itemList.get(0); - } catch (SQLException e) { - log.error("Error retrieving item by handle.", e); - return null; - } - } - /** * Retrieves the embargo start date for the given item bitstreams. * If an embargo has ended, the end date is returned. From 58f8c15c951fa2b29779495628911678f011c508 Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 11:11:14 +0100 Subject: [PATCH 7/8] added deleted line --- .../services/impl/resources/functions/StringXSLFunction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java index ed260c8b2d4a..2b7af8a9c70c 100644 --- a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java +++ b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java @@ -74,6 +74,7 @@ final public XdmValue call(XdmValue[] xdmValues) throws SaxonApiException { log.warn("Empty value in call of function of StringXslFunction type"); val = ""; } + return new XdmAtomicValue(checks(getStringResult(val))); } From 6f432bc5876e03380ed823c12f82ad97f8736a8a Mon Sep 17 00:00:00 2001 From: Paurikova2 Date: Wed, 27 Nov 2024 12:20:53 +0100 Subject: [PATCH 8/8] checkstyle violations --- .../services/impl/resources/functions/StringXSLFunction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java index 2b7af8a9c70c..ed260c8b2d4a 100644 --- a/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java +++ b/dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/StringXSLFunction.java @@ -74,7 +74,6 @@ final public XdmValue call(XdmValue[] xdmValues) throws SaxonApiException { log.warn("Empty value in call of function of StringXslFunction type"); val = ""; } - return new XdmAtomicValue(checks(getStringResult(val))); }