diff --git a/src/main/java/org/genesys2/server/api/v0/InstituteGalleriesController.java b/src/main/java/org/genesys2/server/api/v0/InstituteGalleriesController.java index 285aaea04ee0bbf9431ee7556bb74c43f7159c35..8cc3f186320bd2c52eb72c88c31f66cb018c16ca 100644 --- a/src/main/java/org/genesys2/server/api/v0/InstituteGalleriesController.java +++ b/src/main/java/org/genesys2/server/api/v0/InstituteGalleriesController.java @@ -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 listAccessionGalleries(@PathVariable("instCode") final String instCode, @RequestParam(name = "page", required = false, defaultValue = "1") final int page) { + public @ResponseBody Page 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) { diff --git a/src/main/java/org/genesys2/server/aspect/GenesysImageGalleryAspects.java b/src/main/java/org/genesys2/server/aspect/GenesysImageGalleryAspects.java index aaf6ba290ae6374b5903b935e821c2774cb53c63..b9979ec212c80a33ca047ae421a25f6b7011db92 100644 --- a/src/main/java/org/genesys2/server/aspect/GenesysImageGalleryAspects.java +++ b/src/main/java/org/genesys2/server/aspect/GenesysImageGalleryAspects.java @@ -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()); } diff --git a/src/main/java/org/genesys2/server/mvc/RepositoryDownloadController.java b/src/main/java/org/genesys2/server/mvc/RepositoryDownloadController.java index c72a87cfdc5511f2be09a1dac1c940b1266b9340..a3c95ddfd5aa61ec52b07f82f1b5e732051c5383 100644 --- a/src/main/java/org/genesys2/server/mvc/RepositoryDownloadController.java +++ b/src/main/java/org/genesys2/server/mvc/RepositoryDownloadController.java @@ -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); diff --git a/src/main/java/org/genesys2/server/mvc/WiewsController.java b/src/main/java/org/genesys2/server/mvc/WiewsController.java index 272e419056faa0b0684929c1ec77ecefb396a7d1..87ab8f3201f8c339262a7552621e3cbaa73eeef7 100644 --- a/src/main/java/org/genesys2/server/mvc/WiewsController.java +++ b/src/main/java/org/genesys2/server/mvc/WiewsController.java @@ -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 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()); } diff --git a/src/main/java/org/genesys2/server/mvc/admin/RepositoryGalleryController.java b/src/main/java/org/genesys2/server/mvc/admin/RepositoryGalleryController.java index 7059c9b0840dc86416e052f4887defdabf1f8382..e5bfb658ab19a166e81b0b30fe7e245db7e5f4e5 100644 --- a/src/main/java/org/genesys2/server/mvc/admin/RepositoryGalleryController.java +++ b/src/main/java/org/genesys2/server/mvc/admin/RepositoryGalleryController.java @@ -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()); } diff --git a/src/main/java/org/genesys2/server/service/InstituteFilesService.java b/src/main/java/org/genesys2/server/service/InstituteFilesService.java index f36710c3d62a9b5c62136814955026f02ca2ed04..ae965d7c9fb22c2473992c5eaf05947b82935943 100644 --- a/src/main/java/org/genesys2/server/service/InstituteFilesService.java +++ b/src/main/java/org/genesys2/server/service/InstituteFilesService.java @@ -52,12 +52,10 @@ public interface InstituteFilesService { byte[] getFileBytes(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException; - Page listImageGalleries(FaoInstitute institute, Pageable pageable); + Page 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; diff --git a/src/main/java/org/genesys2/server/service/impl/InstituteFilesServiceImpl.java b/src/main/java/org/genesys2/server/service/impl/InstituteFilesServiceImpl.java index 7d4b02eac7c385e2b6be8f56eed6fd0300fa12d8..11a2433eecdfe78a74634ea8a7ba98001a1c4a75 100644 --- a/src/main/java/org/genesys2/server/service/impl/InstituteFilesServiceImpl.java +++ b/src/main/java/org/genesys2/server/service/impl/InstituteFilesServiceImpl.java @@ -82,7 +82,7 @@ public class InstituteFilesServiceImpl implements InstituteFilesService { } @Override - public Page listImageGalleries(FaoInstitute institute, Pageable pageable) { + public Page 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 diff --git a/src/main/resources/liquibase/liquibase-changeLog.yml b/src/main/resources/liquibase/liquibase-changeLog.yml index 334e011e87565e7d6c1581d1e36c821935c47db5..58a71e227c849d423c42ba295698b948486666a9 100644 --- a/src/main/resources/liquibase/liquibase-changeLog.yml +++ b/src/main/resources/liquibase/liquibase-changeLog.yml @@ -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 diff --git a/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/details.jsp b/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/details.jsp index 39f47d34a86a03bb18a902beb7d11aa2175cb007..551cd1547f2b2733f5d6d0e43a50fabca45da3f3 100644 --- a/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/details.jsp +++ b/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/details.jsp @@ -15,7 +15,7 @@
-
" class="col-xs-6 col-sm-3 col-md-2 col-lg-2"> +
" class="col-xs-6 col-sm-3 col-md-2 col-lg-2"> " alt="${image.title}" />
diff --git a/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/edit.jsp b/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/edit.jsp index 38cfcc4266bdbb2e3d25b1305e16eb6df0337558..4441052373efb43898a9b736c1c8c8c9e3254f05 100644 --- a/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/edit.jsp +++ b/src/main/webapp/WEB-INF/jsp/admin/repository/gallery/edit.jsp @@ -18,7 +18,7 @@
" method="post"> - "> + ">