Removed deprecated configurations and added additional RDA Common Standards for dataset Templates
This commit is contained in:
parent
1c91103781
commit
5b0a66ce06
|
@ -1,52 +0,0 @@
|
|||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.logic.managers.FileManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.files.ContentFile;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/15/2018.
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = {"/api/files"})
|
||||
public class FileController extends BaseController {
|
||||
|
||||
private FileManager fileManager;
|
||||
@Autowired
|
||||
public FileController(ApiContext apiContext, FileManager fileManager) {
|
||||
super(apiContext);
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
||||
public ResponseEntity<ResponseItem<List<ContentFile>>> handleFileUpload(@RequestParam("file") MultipartFile[] files) throws IOException {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(
|
||||
new ResponseItem<List<ContentFile>>().status(ApiMessageCode.NO_MESSAGE).payload(fileManager.saveTempFile(files)));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"})
|
||||
public ResponseEntity<Resource> handleFileUpload(@PathVariable(name = "id") String id,
|
||||
@RequestParam(name = "type") String type,
|
||||
@RequestParam(name = "location", required = false, defaultValue = "final") String location) throws IOException {
|
||||
Resource resource = fileManager.getFile(id, type, location);
|
||||
if (!resource.exists())
|
||||
resource = new UrlResource(FileController.class.getClassLoader().getResource("images/default.png"));
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "." + type + "\"")
|
||||
.body(resource);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import eu.eudat.models.data.files.ContentFile;
|
||||
import eu.eudat.logic.services.helpers.FileStorageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/15/2018.
|
||||
*/
|
||||
@Component
|
||||
public class FileManager {
|
||||
|
||||
private FileStorageService fileStorageService;
|
||||
|
||||
@Autowired
|
||||
public FileManager(FileStorageService fileStorageService) {
|
||||
this.fileStorageService = fileStorageService;
|
||||
}
|
||||
|
||||
public List<ContentFile> saveTempFile(MultipartFile file[]) throws IOException {
|
||||
return fileStorageService.writeToTempFileSystem(file);
|
||||
}
|
||||
|
||||
public Resource getFile(String filename, String type, String location) throws IOException {
|
||||
return fileStorageService.readFromFilesystem(filename, type, location);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
|||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.helpers.FileStorageService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -37,14 +36,14 @@ public class GrantManager {
|
|||
|
||||
private ApiContext apiContext;
|
||||
private DatabaseRepository databaseRepository;
|
||||
private FileStorageService fileStorageService;
|
||||
// private FileStorageService fileStorageService;
|
||||
private RemoteFetcher remoteFetcher;
|
||||
private ListHelper listHelper;
|
||||
|
||||
public GrantManager(ApiContext apiContext, ListHelper listHelper) {
|
||||
this.apiContext = apiContext;
|
||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||
this.fileStorageService = apiContext.getOperationsContext().getFileStorageService();
|
||||
// this.fileStorageService = apiContext.getOperationsContext().getFileStorageService();
|
||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||
this.listHelper = listHelper;
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package eu.eudat.logic.services.helpers;
|
||||
|
||||
import eu.eudat.models.data.files.ContentFile;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/15/2018.
|
||||
*/
|
||||
public interface FileStorageService {
|
||||
List<ContentFile> writeToTempFileSystem(MultipartFile[] multipartFiles) throws IOException;
|
||||
|
||||
ContentFile copyFromTempFileSystem(ContentFile file) throws IOException;
|
||||
|
||||
Resource readFromFilesystem(String filename, String type, String location) throws IOException;
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package eu.eudat.logic.services.helpers;
|
||||
|
||||
import eu.eudat.exceptions.files.TempFileNotFoundException;
|
||||
import eu.eudat.models.data.files.ContentFile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/15/2018.
|
||||
*/
|
||||
@Service("fileStorageService")
|
||||
public class FileStorageServiceImpl implements FileStorageService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FileStorageServiceImpl.class);
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
public FileStorageServiceImpl(Environment environment) {
|
||||
this.environment = environment;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public List<ContentFile> writeToTempFileSystem(MultipartFile[] multipartFiles) throws IOException {
|
||||
List<ContentFile> contentFileList = new LinkedList<>();
|
||||
for (MultipartFile multipartFile : Arrays.asList(multipartFiles)) {
|
||||
UUID id = UUID.randomUUID();
|
||||
Files.copy(multipartFile.getInputStream(), Paths.get(environment.getProperty("files.storage.temp")).resolve(id.toString()));
|
||||
ContentFile contentFile = new ContentFile(multipartFile.getOriginalFilename(), id, "temp", getFileExtension(multipartFile.getOriginalFilename()));
|
||||
contentFileList.add(contentFile);
|
||||
}
|
||||
return contentFileList;
|
||||
}
|
||||
|
||||
public ContentFile copyFromTempFileSystem(ContentFile file) throws IOException, TempFileNotFoundException {
|
||||
UUID id = UUID.randomUUID();
|
||||
if (!Files.exists(Paths.get(environment.getProperty("files.storage.temp") + "/" + file.getId())))
|
||||
throw new TempFileNotFoundException();
|
||||
Files.copy(Paths.get(environment.getProperty("files.storage.temp") + "/" + file.getId()), Paths.get(environment.getProperty("files.storage.final")).resolve(id.toString()));
|
||||
ContentFile contentFile = new ContentFile(file.getFilename(), id, file.getLocation(), file.getType());
|
||||
return contentFile;
|
||||
}
|
||||
|
||||
public Resource readFromFilesystem(String filename, String type, String location) throws IOException {
|
||||
if (location.equals("temp")) {
|
||||
return new UrlResource(Paths.get(environment.getProperty("files.storage.temp") + '/' + filename).toUri());
|
||||
} else {
|
||||
return new UrlResource(Paths.get(environment.getProperty("files.storage.final") + '/' + filename).toUri());
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
try {
|
||||
if (!Files.exists(Paths.get(environment.getProperty("files.storage.temp")))) {
|
||||
Files.createDirectory(Paths.get(environment.getProperty("files.storage.temp")));
|
||||
}
|
||||
if (!Files.exists(Paths.get(environment.getProperty("files.storage.final")))) {
|
||||
Files.createDirectory(Paths.get(environment.getProperty("files.storage.final")));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFileExtension(String fileName) {
|
||||
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0)
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
else return "";
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import eu.eudat.elastic.repository.DatasetRepository;
|
|||
import eu.eudat.elastic.repository.DmpRepository;
|
||||
import eu.eudat.logic.builders.BuilderFactory;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.services.helpers.FileStorageService;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,7 @@ public interface OperationsContext {
|
|||
|
||||
RemoteFetcher getRemoteFetcher();
|
||||
|
||||
FileStorageService getFileStorageService();
|
||||
// FileStorageService getFileStorageService();
|
||||
|
||||
ElasticRepository getElasticRepository();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import eu.eudat.elastic.repository.DatasetRepository;
|
|||
import eu.eudat.elastic.repository.DmpRepository;
|
||||
import eu.eudat.logic.builders.BuilderFactory;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.services.helpers.FileStorageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -19,17 +18,17 @@ public class OperationsContextImpl implements OperationsContext {
|
|||
private final ApplicationContext applicationContext;
|
||||
private final RemoteFetcher remoteFetcher;
|
||||
private final BuilderFactory builderFactory;
|
||||
private final FileStorageService fileStorageService;
|
||||
// private final FileStorageService fileStorageService;
|
||||
private final ElasticRepository elasticRepository;
|
||||
|
||||
@Autowired
|
||||
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher
|
||||
, BuilderFactory builderFactory, FileStorageService fileStorageService, ElasticRepository elasticRepository) {
|
||||
, BuilderFactory builderFactory, /*FileStorageService fileStorageService,*/ ElasticRepository elasticRepository) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.applicationContext = applicationContext;
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
this.builderFactory = builderFactory;
|
||||
this.fileStorageService = fileStorageService;
|
||||
// this.fileStorageService = fileStorageService;
|
||||
this.elasticRepository = elasticRepository;
|
||||
}
|
||||
|
||||
|
@ -53,10 +52,10 @@ public class OperationsContextImpl implements OperationsContext {
|
|||
return builderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStorageService getFileStorageService() {
|
||||
return fileStorageService;
|
||||
}
|
||||
// @Override
|
||||
// public FileStorageService getFileStorageService() {
|
||||
// return fileStorageService;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public ElasticRepository getElasticRepository() {
|
||||
|
|
|
@ -38,3 +38,7 @@ dataset.technical_resource.technical_resource
|
|||
dataset.technical_resource.technical_resource.description
|
||||
dataset.technical_resource.technical_resource.name
|
||||
dataset.type
|
||||
dataset.issued
|
||||
dataset.dataset_id
|
||||
dataset.dataset_id.identifier
|
||||
dataset.dataset_id.type
|
|
@ -2,7 +2,7 @@ server.port=8081
|
|||
server.tomcat.max-threads = 20
|
||||
server.tomcat.max-connections = 10000
|
||||
logging.file=/logs/spring-boot-logging.log
|
||||
spring.profiles.active=staging
|
||||
spring.profiles.active=devel
|
||||
eu.eudat.logic.proxy.allowed.host=https://eestore.paas2.uninett.no
|
||||
|
||||
####################INVITATION MAIL CONFIGURATIONS##############
|
||||
|
@ -59,10 +59,6 @@ b2access.externallogin.redirect_uri=http://opendmp.eu/api/oauth/authorized/b2acc
|
|||
b2access.externallogin.clientid=
|
||||
b2access.externallogin.clientSecret=
|
||||
|
||||
#############FILE STORAGE CONFIGURATIONS#########
|
||||
files.storage.temp = temp
|
||||
files.storage.final = final
|
||||
|
||||
#############DYNAMIC PROJECT CONFIGURATIONS#########
|
||||
project.configuration.project.name = Project
|
||||
project.configuration.funder.name = Funder
|
||||
|
@ -90,7 +86,7 @@ notification.finalised.subject=[OpenDMP] The {name} has been finalised
|
|||
notification.modifiedFinalised.subject=[OpenDMP] The {name} has been modified and finalised
|
||||
|
||||
#############LOGGING#########
|
||||
logging.config=file:logging/logback-${spring.profiles.active}.xml
|
||||
logging.config=classpath:logging/logback-${spring.profiles.active}.xml
|
||||
|
||||
#############TEMP#########
|
||||
temp.temp=tmp/
|
Loading…
Reference in New Issue