Commit 473831a1 authored by Matija Obreza's avatar Matija Obreza

Genesys FTP continued

parent 3a95717f
...@@ -40,7 +40,7 @@ public interface InstituteFilesService { ...@@ -40,7 +40,7 @@ public interface InstituteFilesService {
RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, UUID uuid, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException; RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, UUID uuid, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException;
byte[] getFileBytes(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException; 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);
......
...@@ -113,8 +113,8 @@ public class InstituteFilesServiceImpl implements InstituteFilesService { ...@@ -113,8 +113,8 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override @Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')") @PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage) throws NoSuchRepositoryFileException { public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException {
return this.repositoryService.getFileBytes(getGalleryPath(institute, accession), repositoryImage.getFilename()); return this.repositoryService.getFileBytes(repositoryImage);
} }
@Override @Override
......
/** /*
* Copyright 2016 Global Crop Diversity Trust * Copyright 2017 Global Crop Diversity Trust
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,13 +22,14 @@ import java.util.UUID; ...@@ -22,13 +22,14 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.exception.ResourceNotFoundException;
import org.genesys.filerepository.NoSuchRepositoryFileException; import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile; import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.BytesStorageService; import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService; import org.genesys.filerepository.service.RepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -41,7 +42,7 @@ import org.springframework.web.servlet.HandlerMapping; ...@@ -41,7 +42,7 @@ import org.springframework.web.servlet.HandlerMapping;
@Controller @Controller
public class RepositoryDownloadController extends BaseController { public class RepositoryDownloadController extends BaseController {
public static final Log LOG = LogFactory.getLog(RepositoryDownloadController.class); public static final Logger LOG = LoggerFactory.getLogger(RepositoryDownloadController.class);
@Autowired @Autowired
private RepositoryService repositoryService; private RepositoryService repositoryService;
...@@ -52,7 +53,7 @@ public class RepositoryDownloadController extends BaseController { ...@@ -52,7 +53,7 @@ public class RepositoryDownloadController extends BaseController {
private void downloadFile(final String path, final String uuid, final String ext, final HttpServletResponse response) throws IOException { private void downloadFile(final String path, final String uuid, final String ext, final HttpServletResponse response) throws IOException {
byte[] data; byte[] data;
if (path.endsWith("_thumb/") && ext.equals(".png")) { if (path.startsWith(ImageGalleryService.THUMB_PATH) && ext.equals(ImageGalleryService.THUMB_EXT)) {
final String filename = uuid + ext; final String filename = uuid + ext;
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("_thumb path=" + path + " filename=" + filename); LOG.debug("_thumb path=" + path + " filename=" + filename);
...@@ -68,7 +69,7 @@ public class RepositoryDownloadController extends BaseController { ...@@ -68,7 +69,7 @@ public class RepositoryDownloadController extends BaseController {
sanityCheck(path, ext, repositoryFile); sanityCheck(path, ext, repositoryFile);
data = this.repositoryService.getFileBytes(repositoryFile.getPath(), repositoryFile.getFilename()); data = this.repositoryService.getFileBytes(repositoryFile.getStoragePath(), repositoryFile.getFilename());
response.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=3600, s-maxage=3600, public, no-transform"); response.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=3600, s-maxage=3600, public, no-transform");
response.setHeader(HttpHeaders.PRAGMA, ""); response.setHeader(HttpHeaders.PRAGMA, "");
...@@ -78,10 +79,10 @@ public class RepositoryDownloadController extends BaseController { ...@@ -78,10 +79,10 @@ public class RepositoryDownloadController extends BaseController {
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
LOG.warn("404 - UUID in wrong format."); LOG.warn("404 - UUID in wrong format.");
throw new ResourceNotFoundException("No such thing"); throw new ResourceNotFoundException("No such thing", e);
} catch (final NoSuchRepositoryFileException e) { } catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e); LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing"); throw new ResourceNotFoundException("No such thing", e);
} }
} }
...@@ -97,8 +98,8 @@ public class RepositoryDownloadController extends BaseController { ...@@ -97,8 +98,8 @@ public class RepositoryDownloadController extends BaseController {
throw new ResourceNotFoundException("No such thing"); throw new ResourceNotFoundException("No such thing");
} }
if (!repositoryFile.getPath().equals(path) || !repositoryFile.getExtension().equals(ext)) { if (!repositoryFile.getStoragePath().equals(path) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn(repositoryFile.getPath() + "!=" + path); LOG.warn(repositoryFile.getStoragePath() + "!=" + path);
LOG.warn(repositoryFile.getExtension() + "!=" + ext); LOG.warn(repositoryFile.getExtension() + "!=" + ext);
throw new ResourceNotFoundException("No such thing"); throw new ResourceNotFoundException("No such thing");
} }
...@@ -116,7 +117,7 @@ public class RepositoryDownloadController extends BaseController { ...@@ -116,7 +117,7 @@ public class RepositoryDownloadController extends BaseController {
final String ext = fullpath.substring(fullpath.lastIndexOf(".")); final String ext = fullpath.substring(fullpath.lastIndexOf("."));
final String uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf(".")); final String uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/") + 1); final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/"));
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext); LOG.debug(path + " " + uuid + ext);
...@@ -132,9 +133,7 @@ public class RepositoryDownloadController extends BaseController { ...@@ -132,9 +133,7 @@ public class RepositoryDownloadController extends BaseController {
public @ResponseBody RepositoryFile getMetadata(final HttpServletRequest request) throws IOException, NoSuchRepositoryFileException { public @ResponseBody RepositoryFile getMetadata(final HttpServletRequest request) throws IOException, NoSuchRepositoryFileException {
final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
if (LOG.isTraceEnabled()) { LOG.debug("Fullname: {}", fullpath);
LOG.trace("Fullname: " + fullpath);
}
String path; String path;
String uuid; String uuid;
...@@ -142,7 +141,7 @@ public class RepositoryDownloadController extends BaseController { ...@@ -142,7 +141,7 @@ public class RepositoryDownloadController extends BaseController {
try { try {
ext = fullpath.substring(fullpath.lastIndexOf(".")); ext = fullpath.substring(fullpath.lastIndexOf("."));
uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf(".")); uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/") + 1); path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/"));
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext); LOG.debug(path + " " + uuid + ext);
} }
......
...@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException; import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery; import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService; import org.genesys.filerepository.service.ImageGalleryService;
...@@ -109,7 +110,7 @@ public class RepositoryGalleryController extends BaseController { ...@@ -109,7 +110,7 @@ public class RepositoryGalleryController extends BaseController {
} }
@RequestMapping(value = "/delete", method = RequestMethod.POST) @RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteFile(@RequestParam String galleryPath, RedirectAttributes redirectAttributes) { public String deleteFile(@RequestParam String galleryPath, RedirectAttributes redirectAttributes) throws InvalidRepositoryPathException {
ImageGallery imageGallery = imageGalleryService.loadImageGallery(galleryPath); ImageGallery imageGallery = imageGalleryService.loadImageGallery(galleryPath);
imageGalleryService.removeGallery(imageGallery); imageGalleryService.removeGallery(imageGallery);
......
...@@ -231,7 +231,7 @@ public class FileRepositoryConfig implements InitializingBean { ...@@ -231,7 +231,7 @@ public class FileRepositoryConfig implements InitializingBean {
org.genesys2.server.model.impl.User user = userService.getUserByEmail(upauth.getUsername()); org.genesys2.server.model.impl.User user = userService.getUserByEmail(upauth.getUsername());
if (user == null) { if (user == null || ! user.isActive() || user.isAccountLocked() || user.isAccountExpired() || ! user.isEnabled() || user.isPasswordExpired()) {
// user not found // user not found
throw new AuthenticationFailedException("Authentication failed"); throw new AuthenticationFailedException("Authentication failed");
} }
......
...@@ -450,6 +450,16 @@ databaseChangeLog: ...@@ -450,6 +450,16 @@ databaseChangeLog:
id: 1506155384557-5 id: 1506155384557-5
author: mobreza (generated) author: mobreza (generated)
changes: changes:
- dropForeignKeyConstraint:
baseTableName: repositorygalleryimage
constraintName: FK_rl4ttk3kctjy2nedwwlh8os3p
- addAutoIncrement: - addAutoIncrement:
tableName: repositorygallery tableName: repositorygallery
columnName: id columnName: id
columnDataType: BIGINT(20)
- addForeignKeyConstraint:
constraintName: FK_rl4ttk3kctjy2nedwwlh8os3p
baseTableName: repositorygalleryimage
baseColumnNames: galleryId
referencedTableName: repositorygallery
referencedColumnNames: id
...@@ -19,7 +19,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender ...@@ -19,7 +19,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out log4j.appender.stdout.target=System.out
log4j.appender.stdout.encoding=UTF-8 log4j.appender.stdout.encoding=UTF-8
log4j.appender.stdout.layout=org.apache.log4j.EnhancedPatternLayout log4j.appender.stdout.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %t %5p %c{1.} - %m%n log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %t %5p %c{1.}:%L - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %t %5p %.40c{6}:%L - %m%n #log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %t %5p %.40c{6}:%L - %m%n
......
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
</p> </p>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p> <p>
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
</div> </div>
</div> </div>
</c:if> </c:if>
<c:if test="${accession.cropName ne null}"> <c:if test="${accession.cropName ne null}">
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
...@@ -202,7 +202,7 @@ ...@@ -202,7 +202,7 @@
</div> </div>
</div> </div>
</c:if> </c:if>
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p> <p>
...@@ -390,7 +390,7 @@ ...@@ -390,7 +390,7 @@
<c:forEach items="${imageGallery.images}" var="image"> <c:forEach items="${imageGallery.images}" var="image">
<div x-uuid="<c:out value="${image.uuid}" />" x-ext="<c:out value="${image.extension}" />" style="cursor: pointer;" class="col-lg-2 col-md-4 col-sm-4 col-xs-6"> <div x-uuid="<c:out value="${image.uuid}" />" x-ext="<c:out value="${image.extension}" />" style="cursor: pointer;" class="col-lg-2 col-md-4 col-sm-4 col-xs-6">
<div class="img-wrapper"> <div class="img-wrapper">
<img src="<c:url value="/repository/d${image.path}_thumb/${thumbnailFormat}_${image.uuid}.png" />" alt="<c:out value="${image.title}" />" /> <img src="<c:url value="/repository/d/_thumbs${image.thumbnailPath}/${thumbnailFormat}.png" />" alt="<c:out value="${image.title}" />" />
</div> </div>
</div> </div>
</c:forEach> </c:forEach>
...@@ -1081,7 +1081,7 @@ ...@@ -1081,7 +1081,7 @@
precipitationPlot.resize(); precipitationPlot.resize();
precipitationPlot.setupGrid(); precipitationPlot.setupGrid();
precipitationPlot.draw(); precipitationPlot.draw();
temperaturePlot.resize(); temperaturePlot.resize();
temperaturePlot.setupGrid(); temperaturePlot.setupGrid();
temperaturePlot.draw(); temperaturePlot.draw();
...@@ -1111,17 +1111,17 @@ ...@@ -1111,17 +1111,17 @@
var elem = box.find('.downloadLink').show().find('a').first().attr('href', box.parent().parent().find('.theimage').first().attr('src')); var elem = box.find('.downloadLink').show().find('a').first().attr('href', box.parent().parent().find('.theimage').first().attr('src'));
} }
function showImage(imagegalleryFrame, imageUuid, imageExt) { function showImage(imagegalleryFrame, imageUuid, imageExt) {
var baseHref = '<c:url value="/repository/d${imageGallery.path}" />'; var baseHref = '<c:url value="/repository/d" />/';
var imageViewer = $(imagegalleryFrame).find('.theimage').first(); var imageViewer = $(imagegalleryFrame).find('.theimage').first();
var metadataBox = $(imagegalleryFrame).find('.metadata').first(); var metadataBox = $(imagegalleryFrame).find('.metadata').first();
imageViewer.attr('src', baseHref + imageUuid + imageExt); imageViewer.attr('src', baseHref + imageUuid.substring(0, 3) + '/' + imageUuid + imageExt);
// console.log('Image source: ' + imageViewer.src) // console.log('Image source: ' + imageViewer.src)
// console.log(imageViewer.attr('src')); // console.log(imageViewer.attr('src'));
$(imagegalleryFrame).show(); $(imagegalleryFrame).show();
$(metadataBox).hide(); $(metadataBox).hide();
// Load metadata // Load metadata
$.ajax(baseHref + imageUuid + imageExt + "?metadata", { $.ajax(baseHref + imageUuid.substring(0, 3) + '/' + imageUuid + imageExt + "?metadata", {
method: 'get', method: 'get',
dataType : 'json', dataType : 'json',
success : function(respObject) { success : function(respObject) {
...@@ -1137,7 +1137,7 @@ ...@@ -1137,7 +1137,7 @@
} }
$(document).ready(function() { $(document).ready(function() {
var galleryView=$('#accession-image-view')[0]; var galleryView=$('#accession-image-view')[0];
var galleryThumbnails = $('#accession-images-thumbs div'); var galleryThumbnails = $('#accession-images-thumbs > div');
galleryThumbnails.click(function(ev) { galleryThumbnails.click(function(ev) {
showImage(galleryView, $(this).attr('x-uuid'), $(this).attr('x-ext')); showImage(galleryView, $(this).attr('x-uuid'), $(this).attr('x-ext'));
}); });
...@@ -1154,4 +1154,4 @@ ...@@ -1154,4 +1154,4 @@
</script> </script>
</content> </content>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
<div class="row" id="imagegallery-thumbs"> <div class="row" id="imagegallery-thumbs">
<c:forEach items="${imageGallery.images}" var="image"> <c:forEach items="${imageGallery.images}" var="image">
<div x-src="<c:out value="${image.uuid}${image.extension}" />" class="col-xs-6 col-sm-3 col-md-2 col-lg-2"> <div x-src="<c:out value="${image.storageFullPath}" />" 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${image.path}_thumb/${thumbnailFormat}_${image.uuid}.png" />" alt="${image.title}" /> <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> </div>
</c:forEach> </c:forEach>
</div> </div>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<content tag="javascript"> <script type="text/javascript"> <content tag="javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
var imageViewer=$('#imagegallery-image')[0]; var imageViewer=$('#imagegallery-image')[0];
var baseHref = '<c:url value="/repository/d${imageGallery.path}" />'; var baseHref = '<c:url value="/repository/d" />';
var galleryImages = $('#imagegallery-thumbs div'); var galleryImages = $('#imagegallery-thumbs div');
if (galleryImages.length > 0) { if (galleryImages.length > 0) {
imageViewer.src = baseHref + $(galleryImages[0]).attr('x-src'); imageViewer.src = baseHref + $(galleryImages[0]).attr('x-src');
......
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