Commit 77cc81e5 authored by Matija Obreza's avatar Matija Obreza
Browse files

ImageGallery auto-management

parent 00e5a331
......@@ -63,7 +63,7 @@ public class ImageGallery extends AuditedVersionedModel implements Copyable<Imag
private String description;
/** The images. */
@ManyToMany(cascade = { CascadeType.REMOVE, CascadeType.REFRESH })
@ManyToMany(cascade = { CascadeType.REFRESH })
@JoinTable(name = "repositorygalleryimage", joinColumns = @JoinColumn(name = "galleryId"), inverseJoinColumns = @JoinColumn(name = "imageId"))
@OrderColumn(name = "position")
private List<RepositoryImage> images;
......
......@@ -173,9 +173,7 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements En
*/
@Transient
public String getUrl() {
final StringBuffer sb = new StringBuffer();
sb.append(path).append(getFilename());
return sb.toString();
return getStorageFullPath();
}
/**
......
......@@ -60,9 +60,7 @@ public class ImageGalleryAspects {
@AfterReturning(value = "execution(* org.genesys.filerepository.persistence.RepositoryImagePersistence.save(*))", returning = "repositoryImages")
public Object afterRepositoryImageSaveIterable(final JoinPoint joinPoint, final Iterable<RepositoryImage> repositoryImages) throws Throwable {
if (LOG.isDebugEnabled()) {
LOG.debug("Many images were saved: " + repositoryImages);
}
LOG.debug("Many images were saved: {}", repositoryImages);
if (repositoryImages != null) {
repositoryImages.forEach(ri -> addImageToGallery(ri));
......@@ -83,7 +81,7 @@ public class ImageGalleryAspects {
public Object afterRepositoryImageSave(final JoinPoint joinPoint, final RepositoryImage repositoryImage) throws Throwable {
if (LOG.isTraceEnabled()) {
LOG.trace("1 image was saved: " + repositoryImage);
LOG.trace("1 image was saved: {}", repositoryImage);
}
if (repositoryImage != null) {
......@@ -104,7 +102,7 @@ public class ImageGalleryAspects {
@Around(value = "execution(* org.genesys.filerepository.persistence.RepositoryImagePersistence.delete(*)) && args(repositoryImage)")
public Object aroundRepositoryImageDelete(final ProceedingJoinPoint joinPoint, final RepositoryImage repositoryImage) throws Throwable {
if (LOG.isTraceEnabled() && repositoryImage != null) {
if (repositoryImage != null) {
LOG.trace("1 image is being deleted path={} originalFilename={}", repositoryImage.getPath(), repositoryImage.getOriginalFilename());
}
......@@ -114,9 +112,7 @@ public class ImageGalleryAspects {
joinPoint.proceed();
} catch (final Throwable e) {
if (LOG.isInfoEnabled()) {
LOG.info("Putting image back to gallery.");
}
LOG.info("Putting image back to gallery.");
addImageToGallery(repositoryImage);
throw e;
}
......@@ -138,7 +134,7 @@ public class ImageGalleryAspects {
if (imageGallery == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No gallery at path=" + repositoryImage.getPath());
LOG.debug("No gallery at path={}", repositoryImage.getPath());
}
return;
}
......
......@@ -197,8 +197,8 @@ public class FilesystemStorageServiceImpl implements BytesStorageService {
final File destinationDir = new File(repoDir, path);
if (destinationDir.exists() && destinationDir.isDirectory()) {
LOG.info("Returning empty files list for nonexistent dir=" + destinationDir.getAbsolutePath());
if (! destinationDir.exists() || ! destinationDir.isDirectory()) {
LOG.info("Returning empty files list for nonexistent dir={}", destinationDir.getAbsolutePath());
return Collections.emptyList();
}
......
......@@ -49,7 +49,8 @@ public class FileRepositoryTestUtil {
assertThat("RepositoryFile#originalFilename doesn't match", repoFile.getOriginalFilename(), equalTo(originalFilename));
assertThat("RepositoryFile#extension doesn't match", repoFile.getExtension(), equalTo(extension));
assertThat("RepositoryFile#contentType doesn't match", repoFile.getContentType(), equalTo(contentType));
assertThat("RepositoryFile#URL doesn't match", repoFile.getUrl(), equalTo(path + repoFile.getUuid().toString() + (extension != null ? extension : "")));
assertThat("RepositoryFile#filename doesn't match", repoFile.getFilename(), equalTo(repoFile.getUuid().toString() + (extension != null ? extension : "")));
assertThat("RepositoryFile#URL doesn't match", repoFile.getUrl(), equalTo("/" + repoFile.getUuid().toString().substring(0, 3) + "/" + repoFile.getUuid().toString() + (extension != null ? extension : "")));
return 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