Commit 5cae107c authored by Matija Obreza's avatar Matija Obreza
Browse files

Updated for changes in application-blocks 1.1-SNAPSHOT

parent cf8c0cd8
......@@ -19,6 +19,7 @@ package org.genesys.filerepository.model;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
......@@ -62,7 +63,7 @@ public class ImageGallery extends AuditedVersionedModel implements Copyable<Imag
private String description;
/** The images. */
@ManyToMany(cascade = {})
@ManyToMany(cascade = { CascadeType.REMOVE, CascadeType.REFRESH })
@JoinTable(name = "repositorygalleryimage", joinColumns = @JoinColumn(name = "galleryId"), inverseJoinColumns = @JoinColumn(name = "imageId"))
@OrderColumn(name = "position")
private List<RepositoryImage> images;
......@@ -141,13 +142,19 @@ public class ImageGallery extends AuditedVersionedModel implements Copyable<Imag
@Override
public ImageGallery apply(ImageGallery source) {
this.active = source.active;
this.description = source.description;
// TODO does this make sense?
this.images = new ArrayList<>(source.images);
this.path = source.path;
this.title = source.title;
return null;
return this;
}
@Override
public ImageGallery copy() {
ImageGallery copy = new ImageGallery();
copy.apply(this);
copy.images = new ArrayList<>(this.images);
return copy;
}
}
......@@ -21,6 +21,9 @@ import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
......@@ -31,8 +34,10 @@ import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.model.AuditedVersionedModelWithoutId;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.EntityId;
import org.genesys.blocks.model.InMemoryIdGenerator;
import org.genesys.filerepository.metadata.BaseMetadata;
// TODO: Auto-generated Javadoc
......@@ -46,11 +51,16 @@ import org.genesys.filerepository.metadata.BaseMetadata;
// unique
, uniqueConstraints = { @UniqueConstraint(columnNames = { "path", "originalFilename" }) })
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class RepositoryFile extends AuditedVersionedModel implements BaseMetadata, Copyable<RepositoryFile> {
public class RepositoryFile extends AuditedVersionedModelWithoutId implements EntityId, BaseMetadata, Copyable<RepositoryFile> {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -4816923593950502695L;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "id", unique = true, nullable = false, length = 20)
private Long id = InMemoryIdGenerator.nextId();
/** The uuid. */
@Column(name = "uuid", unique = true, nullable = false, updatable = false, columnDefinition = "binary(16)")
private UUID uuid;
......@@ -189,6 +199,15 @@ public class RepositoryFile extends AuditedVersionedModel implements BaseMetadat
return sb.toString();
}
@Override
public Long getId() {
return id;
}
public void setId(final Long id) {
this.id = id;
}
/**
* Gets the uuid.
*
......@@ -591,7 +610,7 @@ public class RepositoryFile extends AuditedVersionedModel implements BaseMetadat
@Override
public RepositoryFile apply(RepositoryFile source) {
this.active = source.active;
this.accessRights = source.accessRights;
this.bibliographicCitation = source.bibliographicCitation;
this.contentType = source.contentType;
......@@ -615,4 +634,46 @@ public class RepositoryFile extends AuditedVersionedModel implements BaseMetadat
return this;
}
@Override
public RepositoryFile copy() {
RepositoryFile copy = new RepositoryFile();
copy.apply(this);
return copy;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
RepositoryFile other = (RepositoryFile) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
......@@ -51,6 +51,7 @@ public class RepositoryImage extends RepositoryFile implements ImageMetadata {
@Enumerated(EnumType.ORDINAL)
private Orientation orientation;
/*
* (non-Javadoc)
*
......@@ -132,7 +133,7 @@ public class RepositoryImage extends RepositoryFile implements ImageMetadata {
public RepositoryImage apply(RepositoryImage source) {
super.apply(source);
this.height = source.height;
this.orientation = source.orientation;
this.width = source.width;
......
......@@ -249,7 +249,7 @@ public class ImageGalleryTest {
@Test
public void autoRemoveImagesOnPathWithLargeGallery() throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, NoSuchRepositoryFileException, IOException {
final ImageGallery imageGallery = imageGalleryService.createImageGallery(initialPath, DEFAULT_GALLERY_TITLE, DEFAULT_GALLERY_DESCRIPTION);
ImageGallery imageGallery = imageGalleryService.createImageGallery(initialPath, DEFAULT_GALLERY_TITLE, DEFAULT_GALLERY_DESCRIPTION);
final TestImage image1 = new TestImage("10x10.png", "image/png");
final List<RepositoryImage> images = new ArrayList<>();
......@@ -260,10 +260,11 @@ public class ImageGalleryTest {
images.add(repoImg);
}
assertThat("Image gallery must have 20 images", imageGalleryService.loadImageGallery(imageGallery.getPath()).getImages(), hasSize(20));
imageGallery = imageGalleryService.loadImageGallery(imageGallery.getPath());
assertThat("Image gallery must have 20 images", imageGallery.getImages(), hasSize(20));
// Remove something in the middle of the gallery
fileRepoService.removeFile(images.remove(4));
fileRepoService.removeImage(images.remove(4));
// Test order
assertThat("Images must be reordered!", imageGalleryService.loadImageGallery(imageGallery.getPath()).getImages(), contains(images.toArray(EMPTY_REPOSITORYIMAGE_ARRAY)));
......
......@@ -127,6 +127,6 @@ public class ImageGalleryThumbnailsTest {
assertThat("Thumbnail height mismatch", imageData.getHeight(), equalTo(200));
}
fileRepoService.removeFile(repoImage1);
fileRepoService.removeImage(repoImage1);
}
}
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