Commit dbff36cf authored by Matija Obreza's avatar Matija Obreza

file-repository:0.9-SNAPSHOT

parent 6b5655ec
......@@ -496,8 +496,8 @@
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository</artifactId>
<version>0.8.1</version>
<artifactId>file-repository-ftpserver</artifactId>
<version>0.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
......@@ -779,7 +779,7 @@
</attributes>
</configuration>
</plugin>
<plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.9</version>
......@@ -802,13 +802,14 @@
<configuration>
<sortArtifactByName>true</sortArtifactByName>
</configuration>
</plugin>
</plugin> -->
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
......
......@@ -19,12 +19,11 @@ package org.genesys2.server.service;
import java.io.IOException;
import java.util.UUID;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
......@@ -39,7 +38,7 @@ public interface InstituteFilesService {
RepositoryImage getImage(FaoInstitute institute, Accession accession, UUID uuid) throws NoSuchRepositoryFileException;
RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, UUID uuid, RepositoryImageData 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;
......
......@@ -21,15 +21,14 @@ import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.InstituteFilesService;
......@@ -103,7 +102,7 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public RepositoryImage updateImageMetadata(final FaoInstitute institute, Accession accession, final UUID uuid, final RepositoryImageData imageData) throws NoSuchRepositoryFileException {
public RepositoryImage updateImageMetadata(final FaoInstitute institute, Accession accession, final UUID uuid, final RepositoryImage imageData) throws NoSuchRepositoryFileException {
final RepositoryFile repositoryFile = this.repositoryService.getFile(uuid);
if (!repositoryFile.getPath().equals(getGalleryPath(institute, accession))) {
LOG.warn(repositoryFile.getPath() + "!=" + getGalleryPath(institute, accession));
......
......@@ -25,8 +25,8 @@ import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
......
......@@ -25,10 +25,10 @@ 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.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.service.BytesStorageService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
......
......@@ -27,13 +27,12 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.model.RepositoryFileData;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.servlet.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
......@@ -124,7 +123,7 @@ public class RepositoryController extends BaseController {
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateMetadata(@ModelAttribute RepositoryFileData fileData, @RequestParam String uuid, RedirectAttributes redirectAttributes)
public String updateMetadata(@ModelAttribute RepositoryFile fileData, @RequestParam String uuid, RedirectAttributes redirectAttributes)
throws NoSuchRepositoryFileException {
RepositoryFile updatedFile = repositoryService.getFile(UUID.fromString(uuid));
......
......@@ -20,9 +20,9 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.servlet.controller.BaseController;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -26,12 +26,11 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.GenesysService;
......@@ -131,7 +130,7 @@ public class InstituteGalleriesController extends RestController {
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/{uuid}/_metadata", method = { RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody RepositoryImage updateImageMetadata(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode,
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid, @RequestBody final RepositoryImageData imageData)
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid, @RequestBody final RepositoryImage imageData)
throws IOException, NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
......
/**
* 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.
......@@ -17,12 +17,40 @@
package org.genesys2.spring.config;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.filerepository.service.BytesStorageService;
import org.genesys2.server.filerepository.service.aspect.ImageGalleryAspects;
import org.genesys2.server.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys2.server.filerepository.service.impl.S3StorageServiceImpl;
import org.apache.ftpserver.ftplet.Authentication;
import org.apache.ftpserver.ftplet.AuthenticationFailedException;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.usermanager.AnonymousAuthentication;
import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication;
import org.apache.ftpserver.usermanager.impl.AbstractUserManager;
import org.apache.ftpserver.usermanager.impl.ConcurrentLoginPermission;
import org.apache.ftpserver.usermanager.impl.WritePermission;
import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys.filerepository.service.ThumbnailGenerator;
import org.genesys.filerepository.service.aspect.ImageGalleryAspects;
import org.genesys.filerepository.service.ftp.FtpUser;
import org.genesys.filerepository.service.ftp.RepositoryFileSystemFactory;
import org.genesys.filerepository.service.ftp.RepositoryFtpServer;
import org.genesys.filerepository.service.ftp.TemporaryBytesManager;
import org.genesys.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys.filerepository.service.impl.ImageGalleryServiceImpl;
import org.genesys.filerepository.service.impl.RepositoryServiceImpl;
import org.genesys.filerepository.service.impl.S3StorageServiceImpl;
import org.genesys.filerepository.service.impl.ThumbnailGenerator1;
import org.genesys2.server.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -33,7 +61,10 @@ import org.springframework.web.multipart.commons.CommonsMultipartResolver;
* Instatiates and configures the storage mechanism for the FileRepository.
*/
@Configuration
public class FileRepositoryConfig {
public class FileRepositoryConfig implements InitializingBean {
private static final String DEFAULT_REPOSITORY_KEYSTORE_RESOURCE = "/repository/ftpserver.jks";
private static final String DEFAULT_REPOSITORY_KEYSTORE_PASSWORD = "changeit!";
@Value("${file.repository.dir}")
private String fileRepositoryDir;
......@@ -41,6 +72,22 @@ public class FileRepositoryConfig {
@Value("${s3.accessKey}")
private String s3AccessKey;
@Value("${repository.ftp.keystore.path}")
private String ftpKeystorePath;
@Value("${repository.ftp.keystore.password}")
private String ftpKeystorePwd;
/**
* File repository service.
*
* @return the repository service
*/
@Bean
public RepositoryService fileRepositoryService() {
return new RepositoryServiceImpl();
}
@Bean(name = "fileSystemStorage")
@Primary
public BytesStorageService bytesStorageService() {
......@@ -74,8 +121,27 @@ public class FileRepositoryConfig {
}
/**
* Register ImageGallery aspects for automatic registration of new images in
* galleries
* ImageGallery service.
*
* @return the thing!
*/
@Bean
public ImageGalleryService imageGalleryService() {
return new ImageGalleryServiceImpl();
}
/**
* One Thumbnail generator.
*
* @return the thumbnail generator
*/
@Bean
public ThumbnailGenerator thumbnailGenerator() {
return new ThumbnailGenerator1();
}
/**
* Register ImageGallery aspects!.
*
* @return the image gallery aspects
*/
......@@ -84,4 +150,122 @@ public class FileRepositoryConfig {
return new ImageGalleryAspects();
}
@Bean
public TemporaryBytesManager temporaryBytesManager() {
return new TemporaryBytesManager();
}
@Bean
public RepositoryFileSystemFactory repositoryFileSystemFactory() {
return new RepositoryFileSystemFactory();
}
@Bean
public RepositoryFtpServer ftpServer() {
RepositoryFtpServer ftpServer = new RepositoryFtpServer();
ftpServer.setFtpPort(8022);
ftpServer.setUserManager(ftpUserManager());
// TODO configurable!
ftpServer.setKeystorePath(ftpKeystorePath);
ftpServer.setKeystorePsw(ftpKeystorePwd);
// external IP address
// ftpServer.setExternalAddress("127.0.0.1");
ftpServer.setPassivePorts("2300-2301");
return ftpServer;
}
@Bean
public UserManager ftpUserManager() {
return new AbstractUserManager() {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserService userService;
@Override
public void save(User user) throws FtpException {
// Noop
}
@Override
public User getUserByName(String username) throws FtpException {
FtpUser user = new FtpUser(username);
// user.setPassword(username + "1!");
user.setEnabled(true);
List<Authority> authorities = new ArrayList<>();
authorities.add(new ConcurrentLoginPermission(10, 0));
authorities.add(new WritePermission());
user.setAuthorities(authorities);
user.setHomeDirectory("/");
return user;
}
@Override
public String[] getAllUserNames() throws FtpException {
return new String[] {};
}
@Override
public boolean doesExist(String username) throws FtpException {
return userService.getUserByEmail(username) != null;
}
@Override
public void delete(String username) throws FtpException {
// Noop
}
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
String username = upauth.getUsername();
String password = upauth.getPassword();
org.genesys2.server.model.impl.User user = userService.getUserByEmail(upauth.getUsername());
if (user == null) {
// user not found
throw new AuthenticationFailedException("Authentication failed");
}
if (password == null) {
password = "";
}
if (!userService.checkPasswordsMatch(password, user.getFtpPassword())) {
// password mismatch
throw new AuthenticationFailedException("Authentication failed");
} else {
try {
return getUserByName(username);
} catch (FtpException e) {
LOG.warn("FTP login failed", e);
throw new AuthenticationFailedException(e.getMessage(), e);
}
}
} else if (authentication instanceof AnonymousAuthentication) {
throw new AuthenticationFailedException("Authentication failed");
} else {
throw new IllegalArgumentException("Authentication not supported by this user manager");
}
}
};
}
@Override
public void afterPropertiesSet() throws Exception {
if (StringUtils.isBlank(ftpKeystorePath)) {
System.err.println("Using built-in keystore for FTP server /repository/ftpserver.jks");
ftpKeystorePath = getClass().getResource(DEFAULT_REPOSITORY_KEYSTORE_RESOURCE).getPath();
}
if (StringUtils.isBlank(ftpKeystorePwd)) {
System.err.println("Using built-in keystore password");
ftpKeystorePwd = DEFAULT_REPOSITORY_KEYSTORE_PASSWORD;
}
}
}
......@@ -38,7 +38,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import liquibase.integration.spring.SpringLiquibase;
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence", "org.genesys2.server.persistence.domain", "org.genesys2.server.persistence.acl",
"org.genesys2.server.filerepository.persistence" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl")
"org.genesys.filerepository.persistence" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl")
// @EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EnableTransactionManagement
@Configuration
......@@ -132,7 +132,7 @@ public class SpringDataBaseConfig {
System.err.println("JPA: " + key + " = " + jpaProperties.get(key));
}
entityManager.setJpaProperties(jpaProperties);
entityManager.setPackagesToScan("org.genesys.blocks.model", "org.genesys.blocks.security.model", "org.genesys2.server.model", "org.genesys2.server.filerepository.model");
entityManager.setPackagesToScan("org.genesys.blocks.model", "org.genesys.blocks.security.model", "org.genesys2.server.model", "org.genesys.filerepository.model");
return entityManager;
}
......
changeLogFile=src/main/resources/liquibase/liquibase-changeLog.yml
diffChangeLogFile=src/main/resources/liquibase/liquibase-diff-changeLog.yml
# Current database
url=jdbc:mysql://localhost/genesys201703?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
username=root
password=
driver=com.mysql.jdbc.Driver
# Updated database
referenceUrl=hibernate:spring:org.genesys2.server.model?dialect=org.hibernate.dialect.MySQL5InnoDBDialect
# &hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
## Uncomment all lines below for mvn liquibase:diff
## Current database
#url=jdbc:mysql://localhost/genesys201709?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false&hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
#username=root
#password=
#driver=com.mysql.jdbc.Driver
#
## Base database
#referenceUrl=jdbc:mysql://localhost/genesys?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false&hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
#referenceDriver=com.mysql.jdbc.Driver
#referenceUsername=root
#referencePassword=
......@@ -227,4 +227,221 @@ databaseChangeLog:
columns:
- column:
name: ftpPassword
type: varchar(60)
\ No newline at end of file
type: varchar(60)
# file-repository:0.9-SNAPSHOT
- changeSet:
id: 1506155384557-1
author: mobreza (generated)
changes:
- addColumn:
columns:
- column:
constraints:
nullable: false
name: active
type: BIT(1)
- column:
constraints:
nullable: false
name: size
type: INT(10)
- column:
name: lastModifiedBy
type: BIGINT(19)
- column:
name: createdBy
type: BIGINT(19)
tableName: repositorydocument
- addNotNullConstraint:
columnDataType: varchar(32)
columnName: md5Sum
tableName: repositorydocument
- addNotNullConstraint:
columnDataType: varchar(40)
columnName: sha1Sum
tableName: repositorydocument
- addUniqueConstraint:
columnNames: path, originalFilename
constraintName: UK_iubmgqa5xckodr6fbg6vnne0d
tableName: repositorydocument
rollback:
- dropUniqueConstraint:
tableName: repositorydocument
constraintName: UK_iubmgqa5xckodr6fbg6vnne0d
- dropNotNullConstraint:
tableName: repositorydocument
columnName: sha1Sum
- dropNotNullConstraint:
tableName: repositorydocument
columnName: md5Sum
- dropColumn:
tableName: repositorydocument
columnName: active
- dropColumn:
tableName: repositorydocument
columnName: size
- dropColumn:
tableName: repositorydocument
columnName: lastModifiedBy
- dropColumn:
tableName: repositorydocument
columnName: createdBy
- changeSet:
id: 1506155384557-2
author: mobreza (generated)
changes:
- addColumn:
columns:
- column:
constraints:
nullable: false
name: active
type: BIT(1)
- column:
constraints:
nullable: false
name: size
type: INT(10)
- column:
name: lastModifiedBy
type: BIGINT(19)
- column:
name: createdBy
type: BIGINT(19)
tableName: repositoryfile
- addNotNullConstraint:
columnDataType: varchar(32)
columnName: md5Sum
tableName: repositoryfile
- addNotNullConstraint:
columnDataType: varchar(40)
columnName: sha1Sum
tableName: repositoryfile
- addUniqueConstraint:
columnNames: path, originalFilename
constraintName: UK_27590ja5w3amn2yj2dryogm6n
tableName: repositoryfile
rollback:
- dropUniqueConstraint:
tableName: repositoryfile
constraintName: UK_27590ja5w3amn2yj2dryogm6n
- dropNotNullConstraint:
tableName: repositoryfile
columnName: sha1Sum
- dropNotNullConstraint:
tableName: repositoryfile
columnName: md5Sum
- dropColumn:
tableName: repositoryfile
columnName: active
- dropColumn:
tableName: repositoryfile
columnName: size
- dropColumn:
tableName: repositoryfile
columnName: lastModifiedBy
- dropColumn:
tableName: repositoryfile
columnName: createdBy
- changeSet:
id: 1506155384557-3
author: mobreza (generated)
changes:
- addColumn:
columns:
- column:
constraints:
nullable: false
name: active
type: BIT(1)
- column:
name: createdDate
type: DATETIME(19)