Commit b55f11c4 authored by Matija Obreza's avatar Matija Obreza

Mapped 1-to-1 RepositoryFolder to ImageGallery

- relationship is now on both sides
parent 822f08c8
Pipeline #8914 passed with stage
in 2 minutes and 34 seconds
......@@ -28,6 +28,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Transient;
......@@ -84,12 +85,13 @@ public class RepositoryFolder extends UuidModel implements AclAwareModel {
/** List of files in this folder. */
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "folder")
// @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
// property = "originalFilename")
// @JsonIdentityReference(alwaysAsId = true)
@JsonIgnore
private List<RepositoryFile> files;
@OneToOne(cascade = {}, fetch = FetchType.LAZY, optional = true, mappedBy = "folder")
@JsonIgnore
private ImageGallery gallery;
/**
* The name of the folder within parent Folder. It is immutable and must not be
* updated.
......@@ -310,6 +312,24 @@ public class RepositoryFolder extends UuidModel implements AclAwareModel {
this.files = files;
}
/**
* Gets the gallery.
*
* @return the gallery
*/
public ImageGallery getGallery() {
return gallery;
}
/**
* Sets the gallery.
*
* @param gallery the new gallery
*/
protected void setGallery(ImageGallery gallery) {
this.gallery = gallery;
}
/*
* (non-Javadoc)
* @see org.genesys.blocks.model.VersionedModel#toString()
......
......@@ -20,6 +20,7 @@ import java.nio.file.Path;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -45,6 +46,15 @@ public interface ImageGalleryService {
*/
ImageGallery loadImageGallery(Path path) throws InvalidRepositoryPathException;
/**
* Get gallery with the specified folder. Use within existing transactions only.
*
* @param folder The folder holding gallery images
* @return the ImageGallery or <code>null</code> if no gallery exists at the
* specified path.
*/
ImageGallery getImageGallery(RepositoryFolder folder);
/**
* Create a gallery at the specified path if it does not exist. Path of the
* gallery must be unique in the repository.
......@@ -120,4 +130,5 @@ public interface ImageGalleryService {
*/
Page<ImageGallery> listImageGalleries(Path root, Pageable pageable) throws InvalidRepositoryPathException;
}
......@@ -96,6 +96,12 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
final ImageGallery imageGallery = imageGalleryPersistence.findByFolder(repositoryService.getFolder(path));
return deepLoad(imageGallery);
}
@Override
@PostAuthorize("returnObject == null or hasRole('ADMINISTRATOR') or hasPermission(returnObject, 'read')")
public ImageGallery getImageGallery(RepositoryFolder folder) {
return imageGalleryPersistence.findByFolder(folder);
}
/**
* Loads {@link ImageGallery#getImages()} when not null.
......
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