Commit 705863c5 authored by Aleksandr Sharaban's avatar Aleksandr Sharaban

FileRepo: inclusion in genesys2-server.

parent 345451c8
...@@ -480,6 +480,11 @@ ...@@ -480,6 +480,11 @@
<artifactId>pgr-ontology-model</artifactId> <artifactId>pgr-ontology-model</artifactId>
<version>0.7.2-SNAPSHOT</version> <version>0.7.2-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository</artifactId>
<version>0.3-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>
......
package org.genesys2.server.servlet.controller;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;
@Controller
public class FileRepositoryController extends BaseController {
@Autowired
private RepositoryService repositoryService;
@RequestMapping(value = "/repository/{path}/{uuid}.{ext}", method = RequestMethod.GET)
public void downloadFile(@PathVariable String path, @PathVariable String uuid,
@PathVariable String ext, HttpServletResponse response)
throws NoSuchRepositoryFileException, IOException {
RepositoryFile repositoryFile = repositoryService.getFile(UUID.fromString(uuid));
byte[] data = repositoryService.getFileBytes(path, repositoryFile.getOriginalFilename());
response.setContentType(repositoryFile.getMimeType());
response.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"",
repositoryFile.getOriginalFilename()));
response.getOutputStream().write(data);
response.flushBuffer();
}
}
package org.genesys2.server.servlet.controller.admin;
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.service.RepositoryService;
import org.genesys2.server.servlet.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/admin/repository")
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class RepositoryController extends BaseController {
public static final Log LOG = LogFactory.getLog(RepositoryController.class);
@Autowired
private RepositoryService repositoryService;
@RequestMapping(value = "/files", method = RequestMethod.GET)
public String listAllFiles(@RequestParam String repositoryPath, ModelMap model) {
List<RepositoryFile> fileList = repositoryService.getFiles(repositoryPath);
model.addAttribute("fileList", fileList);
return "/admin/index";
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void uploadFile(@RequestParam MultipartFile file, @RequestParam String repositoryPath) throws IOException,
InvalidRepositoryPathException, InvalidRepositoryFileDataException {
String mimeType = file.getContentType();
if (mimeType.startsWith("image")) {
repositoryService.addImage(repositoryPath, file.getOriginalFilename(), file.getContentType(),
file.getBytes(), null);
}
repositoryService.addFile(repositoryPath, file.getOriginalFilename(), file.getContentType(),
file.getBytes(), null);
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public void updateMetadata(@ModelAttribute RepositoryFile repositoryFile) throws NoSuchRepositoryFileException {
repositoryService.updateFile(repositoryFile);
}
}
package org.genesys2.spring.config;
import org.genesys2.server.filerepository.service.BytesStorageService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys2.server.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys2.server.filerepository.service.impl.RepositoryServiceImpl;
import org.genesys2.server.filerepository.service.impl.S3StorageServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.File;
@Configuration
public class FileRepositoryConfig {
@Bean(name = "fileSystemStorage")
public BytesStorageService bytesStorageService() {
File repoDir = new File(System.getProperty("java.io.tmpdir")); //FIXME Set root directory for the service
FilesystemStorageServiceImpl storageService = new FilesystemStorageServiceImpl();
storageService.setRepositoryBaseDirectory(repoDir);
return storageService;
}
@Bean(name = "s3Storage")
public BytesStorageService S3StorageService() {
return new S3StorageServiceImpl();
}
@Bean
public RepositoryService fileRepositoryService() {
return new RepositoryServiceImpl();
}
}
...@@ -34,7 +34,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; ...@@ -34,7 +34,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableJpaRepositories(basePackages = { "org.genesys2.server.persistence.domain", "org.genesys2.server.persistence.acl" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl") @EnableJpaRepositories(basePackages = { "org.genesys2.server.persistence.domain", "org.genesys2.server.persistence.acl", "org.genesys2.server.filerepository.persistence" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl")
// @EnableJpaAuditing(auditorAwareRef = "auditorAware") // @EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EnableTransactionManagement @EnableTransactionManagement
@Configuration @Configuration
...@@ -93,7 +93,7 @@ public class SpringDataBaseConfig { ...@@ -93,7 +93,7 @@ public class SpringDataBaseConfig {
System.err.println("JPA: " + key + " = " + jpaProperties.get(key)); System.err.println("JPA: " + key + " = " + jpaProperties.get(key));
} }
entityManager.setJpaProperties(jpaProperties); entityManager.setJpaProperties(jpaProperties);
entityManager.setPackagesToScan("org.genesys2.server.model"); entityManager.setPackagesToScan("org.genesys2.server.model", "org.genesys2.server.filerepository.model");
return entityManager; return entityManager;
} }
......
...@@ -154,3 +154,9 @@ transifex.content.template=<html xmlns="http://www.w3.org/1999/xhtml">\ ...@@ -154,3 +154,9 @@ transifex.content.template=<html xmlns="http://www.w3.org/1999/xhtml">\
</head>\ </head>\
<body>%s</body>\ <body>%s</body>\
</html> </html>
#S3 parameter values
s3.accessKey=
s3.secretKey=
s3.bucket=
s3.region=
\ No newline at end of file
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