Commit 1b2d3325 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'update_apply_function' into 'master'

- updated org.genesys.filerepository.model.RepositoryFile.apply for set null in nullable field

See merge request !19
parents 973671ce 1fd22f7d
......@@ -34,6 +34,7 @@ import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.AuditedVersionedModelWithoutId;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.EntityId;
......@@ -657,6 +658,12 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
*/
@Override
public RepositoryFile apply(final RepositoryFile source) {
this.path = StringUtils.defaultIfBlank(source.path, this.path);
if (StringUtils.isNotBlank(source.originalFilename)) {
// also updates extension
setOriginalFilename(source.originalFilename);
}
this.active = source.active;
this.accessRights = source.accessRights;
this.bibliographicCitation = source.bibliographicCitation;
......@@ -665,19 +672,12 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
this.creator = source.creator;
this.dateRetrieved = source.dateRetrieved;
this.description = source.description;
this.extension = source.extension;
this.extent = source.extent;
this.license = source.license;
this.md5Sum = source.md5Sum;
this.sha1Sum = source.sha1Sum;
this.originalFilename = source.originalFilename;
this.originalUrl = source.originalUrl;
this.path = source.path;
this.rightsHolder = source.rightsHolder;
this.subject = source.subject;
this.title = source.title;
this.uuid = source.uuid;
this.size = source.size;
return this;
}
......@@ -690,6 +690,16 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
public RepositoryFile copy() {
final RepositoryFile copy = new RepositoryFile();
copy.apply(this);
// copy.id=this.id;
// copy.uuid=this.uuid;
// copy.setVersion(this.getVersion());
copy.sha1Sum = this.sha1Sum;
copy.md5Sum = this.md5Sum;
copy.size = this.size;
copy.extension = this.extension;
return copy;
}
......
......@@ -108,6 +108,7 @@ public class FileRepositoryExtensionTest {
public void extensionIsNullOnUpdate() throws NoSuchRepositoryFileException, InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException {
RepositoryFile repoFile = fileRepoService.addFile(initialPath, initialOriginalFilename, initialContentType, EMPTY_BYTES, null);
FileRepositoryTestUtil.checkFile(repoFile, initialPath, initialOriginalFilename, initialExtension, initialContentType);
repoFile = updateAndCheck(repoFile, "no extension here", null);
fileRepoService.removeFile(repoFile);
......
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