Skip to content

Commit

Permalink
removed findHandle duplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
Paurikova2 committed Nov 27, 2024
1 parent 33f3260 commit f209b4b
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> 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;
Expand Down Expand Up @@ -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<Item> 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.
Expand Down

0 comments on commit f209b4b

Please sign in to comment.