Commit b567e8d4 authored by Matija Obreza's avatar Matija Obreza

Fix: Respect metadata information over incoming file information

parent 0fa2de9b
Pipeline #7558 passed with stage
in 3 minutes and 1 second
......@@ -32,6 +32,7 @@ import java.util.stream.StreamSupport;
import javax.imageio.ImageIO;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.tika.Tika;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.model.AclAwareModel;
......@@ -148,13 +149,22 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
@Override
@Transactional(rollbackFor = Throwable.class)
@PreAuthorize("isAuthenticated()")
public RepositoryFile addFile(final Path repositoryPath, final String originalFilename, String contentType, final byte[] bytes, final RepositoryFile metaData)
public RepositoryFile addFile(final Path repositoryPath, String originalFilename, String contentType, final byte[] bytes, final RepositoryFile metaData)
throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException {
PathValidator.checkValidPath(repositoryPath);
RepositoryFolder repositoryFolder = ensureFolder(repositoryPath);
if (metaData != null) {
if (StringUtils.isNotBlank(metaData.getOriginalFilename())) {
originalFilename = metaData.getOriginalFilename();
}
if (StringUtils.isNotBlank(metaData.getContentType())) {
contentType = metaData.getContentType();
}
}
contentType = updateContentTypeIfNecessary(contentType, bytes);
if ((originalFilename == null) || (contentType == null) || (bytes == null)) {
......@@ -210,11 +220,22 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
@Override
@Transactional(rollbackFor = Throwable.class)
@PreAuthorize("isAuthenticated()")
public RepositoryImage addImage(final Path repositoryPath, final String originalFilename, String contentType, final byte[] bytes, final RepositoryImage metaData)
public RepositoryImage addImage(final Path repositoryPath, String originalFilename, String contentType, final byte[] bytes, final RepositoryImage metaData)
throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException {
PathValidator.checkValidPath(repositoryPath);
if (metaData != null) {
if (StringUtils.isNotBlank(metaData.getOriginalFilename())) {
originalFilename = metaData.getOriginalFilename();
}
if (StringUtils.isNotBlank(metaData.getContentType())) {
contentType = metaData.getContentType();
}
}
contentType = updateContentTypeIfNecessary(contentType, bytes);
if ((originalFilename == null) || (contentType == null) || (bytes == null)) {
......@@ -237,7 +258,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
repositoryImage.setOriginalFilename(originalFilename);
repositoryImage.setContentType(contentType);
fillImageProperties(repositoryImage, bytes);
// We need the UUID before we save bytes
......
......@@ -101,11 +101,11 @@ public class FileRepositoryAddTest extends RepositoryServiceTest {
final String created = "created";
final String creator = "creator";
final String description = "description";
final String extension2 = ".extension2";
final String extent = "extent";
final String license = "license";
final String contentType2 = "contentType2";
final String originalFilename2 = "originalFilename2";
final String originalFilename2 = "originalFilename2.foo";
final String extension2 = ".foo";
final String rightsHolder = "rightsHolder";
final String subject = "subject";
final String title = "File Repository Requirements";
......@@ -130,7 +130,7 @@ public class FileRepositoryAddTest extends RepositoryServiceTest {
final RepositoryFile repoFile = repositoryService.addFile(path, originalFilename, contentType, SOME_BYTES, fileData);
FileRepositoryTestUtil.checkFile(repoFile, path, originalFilename, extension, contentType);
FileRepositoryTestUtil.checkFile(repoFile, path, originalFilename2, extension2, contentType2);
FileRepositoryTestUtil.checkMetadata(repoFile, bibliographicCitation, accessRights, created, creator, description, extent, license, rightsHolder, subject, title);
}
......
......@@ -101,11 +101,11 @@ public class RepositoryImageAddTest {
final String created = "created";
final String creator = "creator";
final String description = "description";
final String extension2 = ".extension2";
final String extension2 = ".bar";
final String extent = "extent";
final String license = "license";
final String contentType2 = "contentType2";
final String originalFilename2 = "originalFilename2";
final String originalFilename2 = "originalFilename2.bar";
final String rightsHolder = "rightsHolder";
final String subject = "subject";
final String title = "File Repository Requirements";
......@@ -130,7 +130,7 @@ public class RepositoryImageAddTest {
final RepositoryImage repoImage = fileRepoService.addImage(initialPath, initialOriginalFilename, initialContentType, EMPTY_BYTES, fileData);
FileRepositoryTestUtil.checkImage(repoImage, initialPath, initialOriginalFilename, initialExtension, initialContentType, 0, 0, Orientation.PORTRAIT);
FileRepositoryTestUtil.checkImage(repoImage, initialPath, originalFilename2, extension2, contentType2, 0, 0, Orientation.PORTRAIT);
FileRepositoryTestUtil.checkMetadata(repoImage, bibliographicCitation, accessRights, created, creator, description, extent, license, rightsHolder, subject, title);
fileRepoService.removeFile(repoImage);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment