Commit 6de69d47 authored by Matija Obreza's avatar Matija Obreza

Fixed image galleries

parent 315b1747
......@@ -79,9 +79,10 @@ public class InstituteGalleriesController extends ApiBaseController {
/**
* List existing image galleries for INSTCODE
* @throws InvalidRepositoryPathException
*/
@RequestMapping(value = "/{instCode}/_galleries", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Page<ImageGallery> listAccessionGalleries(@PathVariable("instCode") final String instCode, @RequestParam(name = "page", required = false, defaultValue = "1") final int page) {
public @ResponseBody Page<ImageGallery> listAccessionGalleries(@PathVariable("instCode") final String instCode, @RequestParam(name = "page", required = false, defaultValue = "1") final int page) throws InvalidRepositoryPathException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
if (institute == null) {
......
......@@ -30,6 +30,8 @@ import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.aspect.AbstractImageGalleryAspects;
import org.genesys.filerepository.service.aspect.ImageGalleryAspectsImpl;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.service.InstituteFilesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -60,6 +62,9 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
/** The image gallery service. */
@Autowired
private ImageGalleryService imageGalleryService;
@Autowired
private AccessionRepository accessionRepository;
/**
* Instantiates a new genesys image gallery aspects.
......@@ -121,7 +126,10 @@ public class GenesysImageGalleryAspects extends AbstractImageGalleryAspects impl
if (matcher.matches()) {
LOG.debug("Path {} is within institute accession images prefix instCode={} acceNumb={}", repositoryImage.getFolder().getPath(), matcher.group(1), matcher.group(2));
try {
instituteFilesService.createImageGallery(matcher.group(1), matcher.group(2));
Accession accession = accessionRepository.findByInstituteCodeAndAccessionNumber(matcher.group(1), matcher.group(2));
if (accession != null) {
instituteFilesService.createImageGallery(accession.getInstitute(), accession);
}
} catch (InvalidRepositoryPathException e) {
LOG.warn("Error creating accession image gallery at {}, error is {}", repositoryImage.getFolder().getPath(), e.getMessage());
}
......
......@@ -100,8 +100,8 @@ public class RepositoryDownloadController extends BaseController {
throw new ResourceNotFoundException("No such thing");
}
if (!repositoryFile.getStoragePath().equals(path) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn("{}!={}", repositoryFile.getStoragePath(), path);
if (!repositoryFile.getStorageFolder().equals(path.toString()) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn("{}!={}", repositoryFile.getStorageFolder(), path);
LOG.warn("{}!={}", repositoryFile.getExtension(), ext);
throw new ResourceNotFoundException("No such thing");
}
......@@ -112,14 +112,14 @@ public class RepositoryDownloadController extends BaseController {
*/
@RequestMapping(value = "/repository/d/**", method = RequestMethod.GET)
public void downloadFile(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
final String fullpath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring("/repository/d".length());
if (LOG.isTraceEnabled()) {
LOG.trace("Fullname: {}", fullpath);
}
final String ext = fullpath.substring(fullpath.lastIndexOf("."));
final String uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/"));
final String path = fullpath.substring(0, fullpath.lastIndexOf('/'));
if (LOG.isDebugEnabled()) {
LOG.debug("{} {}", path, uuid + ext);
......@@ -152,7 +152,6 @@ public class RepositoryDownloadController extends BaseController {
throw new ResourceNotFoundException("No such resource " + fullpath);
}
final RepositoryFile repositoryFile = this.repositoryService.getFile(UUID.fromString(uuid));
sanityCheck(Paths.get(path), ext, repositoryFile);
......
......@@ -533,7 +533,9 @@ public class WiewsController extends BaseController {
path = UriUtils.decode(path, "UTF-8");
path = path.substring(path.indexOf("/files", 1) + 6);
final Path repositoryPath = Paths.get("/wiews/", wiewsCode, path);
final Path institutePath = Paths.get("/wiews/", wiewsCode);
final Path repositoryPath = Paths.get(institutePath.toString(), path);
if (LOG.isDebugEnabled()) {
LOG.debug("Listing files in repo={} for path={}", repositoryPath, path);
......@@ -542,7 +544,7 @@ public class WiewsController extends BaseController {
List<String> subPaths = new ArrayList<>();
for (RepositoryFolder subPath : repositoryService.listPaths(repositoryPath)) {
if (!subPath.getFolderPath().equals(repositoryPath)) {
subPaths.add(repositoryPath.relativize(subPath.getFolderPath()).toString());
subPaths.add(institutePath.relativize(subPath.getFolderPath()).toString());
}
}
......@@ -636,7 +638,7 @@ public class WiewsController extends BaseController {
}
@GetMapping(value = "/{wiewsCode}/files/gallery/{page:\\d+}")
public String listInstituteGallery(ModelMap model, @PathVariable("page") int page, @PathVariable("wiewsCode") String wiewsCode) {
public String listInstituteGallery(ModelMap model, @PathVariable("page") int page, @PathVariable("wiewsCode") String wiewsCode) throws InvalidRepositoryPathException {
// check user permissions
instituteService.getInstituteForEdit(wiewsCode);
......@@ -687,15 +689,14 @@ public class WiewsController extends BaseController {
}
@PostMapping(value = "{wiewsCode}/files/gallery/update")
public String updateGallery(@PathVariable("wiewsCode") String wiewsCode, @ModelAttribute ImageGallery imageGallery, RedirectAttributes redirectAttributes)
throws NoSuchRepositoryFileException {
public String updateGallery(@PathVariable("wiewsCode") String wiewsCode, @RequestParam String galleryPath, @ModelAttribute ImageGallery imageGallery, RedirectAttributes redirectAttributes)
throws NoSuchRepositoryFileException, InvalidRepositoryPathException {
// check user permissions
instituteService.getInstituteForEdit(wiewsCode);
final Path galleryPath = Paths.get(imageGallery.getPath());
ImageGallery updatedGallery = imageGalleryService.loadImageGallery(galleryPath);
ImageGallery updatedGallery = imageGalleryService.loadImageGallery(Paths.get(galleryPath));
if (updatedGallery == null) {
imageGalleryService.createImageGallery(galleryPath, imageGallery.getTitle(), imageGallery.getDescription());
imageGalleryService.createImageGallery(Paths.get(galleryPath), imageGallery.getTitle(), imageGallery.getDescription());
} else {
imageGalleryService.updateImageGalery(updatedGallery, imageGallery.getTitle(), imageGallery.getDescription());
}
......
......@@ -98,11 +98,11 @@ public class RepositoryGalleryController extends BaseController {
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateMetadata(@ModelAttribute ImageGallery imageGallery, RedirectAttributes redirectAttributes) throws NoSuchRepositoryFileException {
public String updateMetadata(@RequestParam String galleryPath, @ModelAttribute ImageGallery imageGallery, RedirectAttributes redirectAttributes) throws NoSuchRepositoryFileException, InvalidRepositoryPathException {
ImageGallery updatedGallery = imageGalleryService.loadImageGallery(imageGallery.getFolderPath());
ImageGallery updatedGallery = imageGalleryService.loadImageGallery(Paths.get(galleryPath));
if (updatedGallery == null) {
updatedGallery = imageGalleryService.createImageGallery(imageGallery.getFolderPath(), imageGallery.getTitle(), imageGallery.getDescription());
updatedGallery = imageGalleryService.createImageGallery(Paths.get(galleryPath), imageGallery.getTitle(), imageGallery.getDescription());
} else {
updatedGallery = imageGalleryService.updateImageGalery(updatedGallery, imageGallery.getTitle(), imageGallery.getDescription());
}
......
......@@ -52,12 +52,10 @@ public interface InstituteFilesService {
byte[] getFileBytes(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException;
Page<ImageGallery> listImageGalleries(FaoInstitute institute, Pageable pageable);
Page<ImageGallery> listImageGalleries(FaoInstitute institute, Pageable pageable) throws InvalidRepositoryPathException;
ImageGallery createImageGallery(FaoInstitute institute, Accession accession) throws InvalidRepositoryPathException;
ImageGallery createImageGallery(String instCode, String acceNumb) throws InvalidRepositoryPathException;
RepositoryImage addImage(FaoInstitute institute, Accession accession, String originalFilename, String contentType, byte[] bytes) throws InvalidRepositoryPathException,
InvalidRepositoryFileDataException, IOException;
......
......@@ -82,7 +82,7 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
}
@Override
public Page<ImageGallery> listImageGalleries(FaoInstitute institute, Pageable pageable) {
public Page<ImageGallery> listImageGalleries(FaoInstitute institute, Pageable pageable) throws InvalidRepositoryPathException {
return imageGalleryService.listImageGalleries(getGalleriesPrefix(institute.getCode()), pageable);
}
......@@ -95,12 +95,7 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public ImageGallery createImageGallery(FaoInstitute institute, Accession accession) throws InvalidRepositoryPathException {
return createImageGallery(institute.getCode(), accession.getAccessionNumber());
}
@Override
public ImageGallery createImageGallery(String instCode, String acceNumb) throws InvalidRepositoryPathException {
return this.imageGalleryService.createImageGallery(getGalleryPath(instCode, acceNumb), String.format(ACCESSION_GALLERY_TITLE_FORMAT, acceNumb), ACCESSION_GALLERY_DESCRIPTION);
return this.imageGalleryService.createImageGallery(getGalleryPath(institute.getCode(), accession.getAccessionNumber()), String.format(ACCESSION_GALLERY_TITLE_FORMAT, accession.getAccessionNumber()), ACCESSION_GALLERY_DESCRIPTION);
}
@Override
......
......@@ -4165,6 +4165,42 @@ databaseChangeLog:
sql: delete from accession_duplsite where duplSite = '';
- changeSet:
id: 1538209535000-1
author: mobreza
comment: file-repository:1.1-SNAPSHOT
changes:
- addColumn:
columns:
- column:
name: folder_id
type: BIGINT
tableName: repository_gallery
- addUniqueConstraint:
columnNames: folder_id
constraintName: UK_1bckkd8l1n6n2hsl1895utix1
tableName: repository_gallery
- addForeignKeyConstraint:
baseColumnNames: folder_id
baseTableName: repository_gallery
constraintName: FK_trk7cw1r3dsxgu8jlia1ecrgk
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: repositoryfolder
validate: true
- dropIndex:
indexName: UK_3sfjllps5cq9307ksvnhctcc9
tableName: repository_gallery
- dropNotNullConstraint:
columnName: path
columnDataType: varchar(255)
tableName: repository_gallery
# ENABLE AFTER SOME TIME
# - changeSet:
# id: 1537463144763-folder
......
......@@ -15,7 +15,7 @@
<div class="row" id="imagegallery-thumbs">
<c:forEach items="${imageGallery.images}" var="image">
<div x-src="<c:out value="${image.storageFullPath}" />" class="col-xs-6 col-sm-3 col-md-2 col-lg-2">
<div x-src="<c:out value="${image.storagePath}" />" class="col-xs-6 col-sm-3 col-md-2 col-lg-2">
<img style="width: 100%; margin-bottom: 15px; margin-top: 15px;" src="<c:url value="/repository/d/_thumbs${image.thumbnailPath}/${thumbnailFormat}.png" />" alt="${image.title}" />
</div>
</c:forEach>
......
......@@ -18,7 +18,7 @@
<form action="<c:url value="/admin/r/g/update" />" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<input type="hidden" name="path" value="<c:out value="${imageGallery.path}" />">
<input type="hidden" name="galleryPath" value="<c:out value="${imageGallery.folder.path}" />">
<div class="form-group">
<label for="title"><spring:message
......
......@@ -19,11 +19,11 @@
<div class="col-xs-6">
<select id="repositoryPathNav" class="form-control" name="repositoryPath">
<option value="<c:url value="/admin/r/files/" />">ROOT</option>
<option selected value="<c:url value="/admin/r/files${currentPath}" />">
<option selected value="<c:url value="/admin/r/files${currentPath}/" />">
<c:out value="${currentPath}" />
</option>
<c:forEach items="${subPaths}" var="folder">
<option value="<c:url value="/admin/r/files${folder.path}" />">
<option value="<c:url value="/admin/r/files${folder.path}/" />">
<c:out value="${folder.path}" />
</option>
</c:forEach>
......
......@@ -19,7 +19,7 @@
</div>
<div class="row" id="imagegallery-thumbs">
<c:forEach items="${imageGallery.images}" var="image">
<div x-src="<c:out value="${image.storageFullPath}" />" class="col-xs-6 col-sm-3 col-md-2 col-lg-2">
<div x-src="<c:out value="${image.storagePath}" />" class="col-xs-6 col-sm-3 col-md-2 col-lg-2">
<img style="width: 100%; margin-bottom: 15px; margin-top: 15px;" src="<c:url value="/repository/d/_thumbs${image.thumbnailPath}/${thumbnailFormat}.png" />"
alt="${image.title}"/>
</div>
......
......@@ -20,7 +20,7 @@
<form action="<c:url value="/wiews/${wiewsCode}/files/gallery/update" />" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<input type="hidden" name="path" value="<c:out value="${imageGallery.path}" />">
<input type="hidden" name="galleryPath" value="<c:out value="${imageGallery.folder.path}" />">
<div class="row">
<div class="col-md-6 margin-top-20">
......
......@@ -15,11 +15,11 @@
</div>
<div class="col-xs-6">
<select id="repositoryPathNav" class="form-control" name="repositoryPath">
<option value="<c:url value="/wiews/${wiewsCode}/files" />">ROOT</option>
<option value="<c:url value="/wiews/${wiewsCode}/files" />">Institute files</option>
<option selected value="<c:url value="/wiews/${wiewsCode}/files${currentPath}" />"><c:out value="${currentPath}" /></option>
<c:forEach items="${subPaths}" var="path">
<option value="<c:url value="/wiews/${wiewsCode}/files${path}" />">
<c:out value="/wiews/${wiewsCode}${path}" />
<option value="<c:url value="/wiews/${wiewsCode}/files/${path}/" />">
<c:out value="/wiews/${wiewsCode}/${path}" />
</option>
</c:forEach>
</select>
......
......@@ -4,7 +4,7 @@
<%@ attribute name="repositoryFile" required="true" description="Repository File" rtexprvalue="true" type="java.lang.Object" %>
<c:if test="${repositoryFile ne null}">
<a href="<c:url value='/repository/d${repositoryFile.storagePath}/${repositoryFile.uuid}${repositoryFile.extension}' />" title="Download file">
<a href="<c:url value='/repository/d${repositoryFile.storagePath}' />" title="Download file">
<c:out value="${repositoryFile.title}" />
<small><c:out value="${repositoryFile.originalFilename}" /></small>
</a>
......
......@@ -55,10 +55,12 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.test.context.support.WithMockUser;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@WithMockUser(username = "admin", password = "admin", roles = "ADMINISTRATOR")
public class DatasetServiceTest extends AbstractDatasetServiceTest {
@Test
......
......@@ -52,6 +52,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
......@@ -63,6 +64,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
@WithMockUser(username = "user", password = "user", roles = "ADMINISTRATOR")
public class ApiImagesDocsTest extends AbstractApiTest {
private static final String ACCENUMB = "ACC001";
......
......@@ -16,14 +16,10 @@
package org.genesys.test.server.api.v1;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.genesys.test.base.AbstractApiTest;
import org.genesys.test.base.WithMockOAuth2Authentication;
......@@ -39,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;
......
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