80218: Add BitstreamService#getThumbnail

This commit is contained in:
Yura Bondarenko
2021-06-22 14:35:42 +02:00
parent bb797f7822
commit b5f49f87bf
2 changed files with 23 additions and 0 deletions

View File

@@ -13,6 +13,8 @@ import java.sql.SQLException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@@ -409,6 +411,25 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
return null; return null;
} }
@Override
public Bitstream getThumbnail(Context context, Bitstream bitstream) throws SQLException {
Pattern pattern = Pattern.compile("^" + bitstream.getName() + ".([^.]+)$");
for (Bundle bundle : bitstream.getBundles()) {
for (Item item : bundle.getItems()) {
for (Bundle thumbnails : itemService.getBundles(item, "THUMBNAIL")) {
for (Bitstream thumbnail : thumbnails.getBitstreams()) {
if (pattern.matcher(thumbnail.getName()).matches()) {
return thumbnail;
}
}
}
}
}
return null;
}
@Override @Override
public BitstreamFormat getFormat(Context context, Bitstream bitstream) throws SQLException { public BitstreamFormat getFormat(Context context, Bitstream bitstream) throws SQLException {
if (bitstream.getBitstreamFormat() == null) { if (bitstream.getBitstreamFormat() == null) {

View File

@@ -209,6 +209,8 @@ public interface BitstreamService extends DSpaceObjectService<Bitstream>, DSpace
public Bitstream getFirstBitstream(Item item, String bundleName) throws SQLException; public Bitstream getFirstBitstream(Item item, String bundleName) throws SQLException;
public Bitstream getThumbnail(Context context, Bitstream bitstream) throws SQLException;
public BitstreamFormat getFormat(Context context, Bitstream bitstream) throws SQLException; public BitstreamFormat getFormat(Context context, Bitstream bitstream) throws SQLException;
public Iterator<Bitstream> findByStoreNumber(Context context, Integer storeNumber) throws SQLException; public Iterator<Bitstream> findByStoreNumber(Context context, Integer storeNumber) throws SQLException;