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

Genesys FTP continued

parent 3a95717f
......@@ -40,7 +40,7 @@ public interface InstituteFilesService {
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);
......
......@@ -113,8 +113,8 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override
@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 {
return this.repositoryService.getFileBytes(getGalleryPath(institute, accession), repositoryImage.getFilename());
public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException {
return this.repositoryService.getFileBytes(repositoryImage);
}
@Override
......
/**
* Copyright 2016 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,13 +22,14 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
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.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
......@@ -41,7 +42,7 @@ import org.springframework.web.servlet.HandlerMapping;
@Controller
public class RepositoryDownloadController extends BaseController {
public static final Log LOG = LogFactory.getLog(RepositoryDownloadController.class);
public static final Logger LOG = LoggerFactory.getLogger(RepositoryDownloadController.class);
@Autowired
private RepositoryService repositoryService;
......@@ -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 {
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;
if (LOG.isDebugEnabled()) {
LOG.debug("_thumb path=" + path + " filename=" + filename);
......@@ -68,7 +69,7 @@ public class RepositoryDownloadController extends BaseController {
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.PRAGMA, "");
......@@ -78,10 +79,10 @@ public class RepositoryDownloadController extends BaseController {
} catch (final NumberFormatException e) {
LOG.warn("404 - UUID in wrong format.");
throw new ResourceNotFoundException("No such thing");
throw new ResourceNotFoundException("No such thing", e);
} catch (final NoSuchRepositoryFileException 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 {
throw new ResourceNotFoundException("No such thing");
}
if (!repositoryFile.getPath().equals(path) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn(repositoryFile.getPath() + "!=" + path);
if (!repositoryFile.getStoragePath().equals(path) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn(repositoryFile.getStoragePath() + "!=" + path);
LOG.warn(repositoryFile.getExtension() + "!=" + ext);
throw new ResourceNotFoundException("No such thing");
}
......@@ -116,7 +117,7 @@ public class RepositoryDownloadController extends BaseController {
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("/") + 1);
final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/"));
if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext);
......@@ -132,9 +133,7 @@ public class RepositoryDownloadController extends BaseController {
public @ResponseBody RepositoryFile getMetadata(final HttpServletRequest request) throws IOException, NoSuchRepositoryFileException {
final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
if (LOG.isTraceEnabled()) {
LOG.trace("Fullname: " + fullpath);
}
LOG.debug("Fullname: {}", fullpath);
String path;
String uuid;
......@@ -142,7 +141,7 @@ public class RepositoryDownloadController extends BaseController {
try {
ext = fullpath.substring(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()) {
LOG.debug(path + " " + uuid + ext);
}
......
......@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
......@@ -109,7 +110,7 @@ public class RepositoryGalleryController extends BaseController {
}
@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);
imageGalleryService.removeGallery(imageGallery);
......
......@@ -231,7 +231,7 @@ public class FileRepositoryConfig implements InitializingBean {
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
throw new AuthenticationFailedException("Authentication failed");
}
......
......@@ -450,6 +450,16 @@ databaseChangeLog:
id: 1506155384557-5
author: mobreza (generated)
changes:
- dropForeignKeyConstraint:
baseTableName: repositorygalleryimage
constraintName: FK_rl4ttk3kctjy2nedwwlh8os3p
- addAutoIncrement:
tableName: repositorygallery
columnName: id
tableName: repositorygallery
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
log4j.appender.stdout.target=System.out
log4j.appender.stdout.encoding=UTF-8
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
......
......@@ -157,7 +157,7 @@
</p>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
......@@ -189,7 +189,7 @@
</div>
</div>
</c:if>
<c:if test="${accession.cropName ne null}">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
......@@ -202,7 +202,7 @@
</div>
</div>
</c:if>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
......@@ -390,7 +390,7 @@
<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 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>
</c:forEach>
......@@ -1081,7 +1081,7 @@
precipitationPlot.resize();
precipitationPlot.setupGrid();
precipitationPlot.draw();
temperaturePlot.resize();
temperaturePlot.setupGrid();
temperaturePlot.draw();
......@@ -1111,17 +1111,17 @@
var elem = box.find('.downloadLink').show().find('a').first().attr('href', box.parent().parent().find('.theimage').first().attr('src'));
}
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 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(imageViewer.attr('src'));
$(imagegalleryFrame).show();
$(metadataBox).hide();
// Load metadata
$.ajax(baseHref + imageUuid + imageExt + "?metadata", {
$.ajax(baseHref + imageUuid.substring(0, 3) + '/' + imageUuid + imageExt + "?metadata", {
method: 'get',
dataType : 'json',
success : function(respObject) {
......@@ -1137,7 +1137,7 @@
}
$(document).ready(function() {
var galleryView=$('#accession-image-view')[0];
var galleryThumbnails = $('#accession-images-thumbs div');
var galleryThumbnails = $('#accession-images-thumbs > div');
galleryThumbnails.click(function(ev) {
showImage(galleryView, $(this).attr('x-uuid'), $(this).attr('x-ext'));
});
......@@ -1154,4 +1154,4 @@
</script>
</content>
</body>
</html>
\ No newline at end of file
</html>
......@@ -15,8 +15,8 @@
<div class="row" id="imagegallery-thumbs">
<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">
<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}" />
<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/_thumbs${image.thumbnailPath}/${thumbnailFormat}.png" />" alt="${image.title}" />
</div>
</c:forEach>
</div>
......@@ -28,7 +28,7 @@
<content tag="javascript"> <script type="text/javascript">
$(document).ready(function() {
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');
if (galleryImages.length > 0) {
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