Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,15 @@ public boolean canPreview(Context context, Bitstream bitstream) throws SQLExcept

@Override
public List<FileInfo> getFilePreviewContent(Context context, Bitstream bitstream)
throws SQLException, AuthorizeException, IOException {
throws Exception {
InputStream inputStream = null;
List<FileInfo> fileInfos = null;
try {
inputStream = bitstreamService.retrieve(context, bitstream);
} catch (MissingLicenseAgreementException e) { /* Do nothing */ }

if (Objects.nonNull(inputStream)) {
try {
fileInfos = processInputStreamToFilePreview(context, bitstream, inputStream);
} catch (IllegalStateException e) {
log.error("Cannot process Input Stream to file preview because: " + e.getMessage());
}
fileInfos = processInputStreamToFilePreview(context, bitstream, inputStream);
}
return fileInfos;
}
Expand Down Expand Up @@ -193,7 +189,7 @@ public FileInfo createFileInfo(PreviewContent pc) {
@Override
public List<FileInfo> processInputStreamToFilePreview(Context context, Bitstream bitstream,
InputStream inputStream)
throws SQLException, IOException {
throws Exception {
List<FileInfo> fileInfos = new ArrayList<>();
String bitstreamMimeType = bitstream.getFormat(context).getMIMEType();
if (bitstreamMimeType.equals("text/plain")) {
Expand All @@ -216,12 +212,8 @@ public List<FileInfo> processInputStreamToFilePreview(Context context, Bitstream

String mimeType = bitstream.getFormat(context).getMIMEType();
if (archiveTypes.containsKey(mimeType)) {
try {
data = extractFile(inputStream, archiveTypes.get(mimeType));
fileInfos = FileTreeViewGenerator.parse(data);
} catch (Exception e) {
log.error("Cannot extract file content because: {}", e.getMessage());
}
data = extractFile(inputStream, archiveTypes.get(mimeType));
fileInfos = FileTreeViewGenerator.parse(data);
}
}
return fileInfos;
Expand Down Expand Up @@ -420,7 +412,7 @@ private String buildXmlResponse(List<String> filePaths) {
* @param fileType the type of file to extract ("tar" or "zip")
* @return an XML string representing the extracted file paths
*/
private String extractFile(InputStream inputStream, String fileType) {
private String extractFile(InputStream inputStream, String fileType) throws Exception {
List<String> filePaths = new ArrayList<>();
Path tempFile = null;
FileSystem zipFileSystem = null;
Expand All @@ -439,8 +431,6 @@ private String extractFile(InputStream inputStream, String fileType) {
zipFileSystem = FileSystems.newFileSystem(tempFile, (ClassLoader) null);
processZipFile(filePaths, zipFileSystem);
}
} catch (IOException e) {
log.error(String.format("An error occurred while extracting file of type %s.", fileType), e);
} finally {
closeFileSystem(zipFileSystem);
deleteTempFile(tempFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.dspace.content.service;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;
Expand Down Expand Up @@ -116,8 +115,7 @@ PreviewContent create(Context context, Bitstream bitstream, String name, String
* @param bitstream ZIP file bitstream
* @return List of FileInfo classes where is wrapped ZIP file content
*/
List<FileInfo> getFilePreviewContent(Context context, Bitstream bitstream)
throws SQLException, AuthorizeException, IOException;
List<FileInfo> getFilePreviewContent(Context context, Bitstream bitstream) throws Exception;

/**
* Create preview content from file info for bitstream.
Expand Down Expand Up @@ -153,5 +151,5 @@ List<FileInfo> getFilePreviewContent(Context context, Bitstream bitstream)
* @return List of FileInfo classes where is wrapped ZIP file content
*/
List<FileInfo> processInputStreamToFilePreview(Context context, Bitstream bitstream, InputStream inputStream)
throws SQLException, IOException;
throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
*/
package org.dspace.scripts.filepreview;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.cli.ParseException;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.lang3.StringUtils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
Expand All @@ -30,7 +25,6 @@
import org.dspace.scripts.DSpaceRunnable;
import org.dspace.util.FileInfo;
import org.dspace.utils.DSpace;
import org.xml.sax.SAXException;

/**
* This class is used to generate a preview for every file in DSpace that should have a preview.
Expand Down Expand Up @@ -99,8 +93,7 @@ public void internalRun() throws Exception {
Item item = items.next();
try {
generateItemFilePreviews(context, item.getID());
} catch (SQLException | AuthorizeException | IOException | ParserConfigurationException |
ArchiveException | SAXException e) {
} catch (Exception e) {
handler.logError("Error while generating preview for item with UUID: " + item.getID());
handler.logError(e.getMessage());
}
Expand All @@ -115,8 +108,7 @@ public void internalRun() throws Exception {
context.complete();
}

private void generateItemFilePreviews(Context context, UUID itemUUID) throws SQLException, AuthorizeException,
IOException, ParserConfigurationException, ArchiveException, SAXException {
private void generateItemFilePreviews(Context context, UUID itemUUID) throws Exception {
Item item = itemService.find(context, itemUUID);
if (Objects.isNull(item)) {
handler.logError("Item with UUID: " + itemUUID + " not found.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
*/
package org.dspace.app.rest.repository;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.Parameter;
Expand All @@ -26,7 +22,6 @@
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.MetadataBitstreamWrapperRest;
import org.dspace.app.rest.model.wrapper.MetadataBitstreamWrapper;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.DSpaceObject;
Expand All @@ -43,7 +38,6 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.xml.sax.SAXException;

/**
* This controller returns content of the bitstream to the `Preview` box in the Item View.
Expand All @@ -68,8 +62,7 @@ public class MetadataBitstreamRestRepository extends DSpaceRestRepository<Metada
public Page<MetadataBitstreamWrapperRest> findByHandle(@Parameter(value = "handle", required = true) String handle,
@Parameter(value = "fileGrpType") String fileGrpType,
Pageable pageable)
throws SQLException, ParserConfigurationException, IOException, SAXException, AuthorizeException,
ArchiveException {
throws Exception {
if (StringUtils.isBlank(handle)) {
throw new DSpaceBadRequestException("handle cannot be null!");
}
Expand Down