Removed deprecated configurations and added additional RDA Common Standards for dataset Templates

(cherry picked from commit 5b0a66ce06)
This commit is contained in:
George Kalampokis 2020-05-29 11:57:21 +03:00 committed by Diamantis Tziotzios
parent 9373d3e038
commit 9519300dc4
9 changed files with 17 additions and 207 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -22,7 +22,6 @@ import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.helpers.FileStorageService;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Comparator; import java.util.Comparator;
@ -37,14 +36,14 @@ public class GrantManager {
private ApiContext apiContext; private ApiContext apiContext;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
private FileStorageService fileStorageService; // private FileStorageService fileStorageService;
private RemoteFetcher remoteFetcher; private RemoteFetcher remoteFetcher;
private ListHelper listHelper; private ListHelper listHelper;
public GrantManager(ApiContext apiContext, ListHelper listHelper) { public GrantManager(ApiContext apiContext, ListHelper listHelper) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.fileStorageService = apiContext.getOperationsContext().getFileStorageService(); // this.fileStorageService = apiContext.getOperationsContext().getFileStorageService();
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher(); this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
this.listHelper = listHelper; this.listHelper = listHelper;
} }

View File

@ -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;
}

View File

@ -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 "";
}
}

View File

@ -4,7 +4,6 @@ import eu.eudat.elastic.repository.DatasetRepository;
import eu.eudat.elastic.repository.DmpRepository; import eu.eudat.elastic.repository.DmpRepository;
import eu.eudat.logic.builders.BuilderFactory; import eu.eudat.logic.builders.BuilderFactory;
import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.logic.services.helpers.FileStorageService;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
/** /**
@ -20,7 +19,7 @@ public interface OperationsContext {
RemoteFetcher getRemoteFetcher(); RemoteFetcher getRemoteFetcher();
FileStorageService getFileStorageService(); // FileStorageService getFileStorageService();
ElasticRepository getElasticRepository(); ElasticRepository getElasticRepository();
} }

View File

@ -4,7 +4,6 @@ import eu.eudat.elastic.repository.DatasetRepository;
import eu.eudat.elastic.repository.DmpRepository; import eu.eudat.elastic.repository.DmpRepository;
import eu.eudat.logic.builders.BuilderFactory; import eu.eudat.logic.builders.BuilderFactory;
import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.logic.services.helpers.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -19,17 +18,17 @@ public class OperationsContextImpl implements OperationsContext {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final RemoteFetcher remoteFetcher; private final RemoteFetcher remoteFetcher;
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final FileStorageService fileStorageService; // private final FileStorageService fileStorageService;
private final ElasticRepository elasticRepository; private final ElasticRepository elasticRepository;
@Autowired @Autowired
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher
, BuilderFactory builderFactory, FileStorageService fileStorageService, ElasticRepository elasticRepository) { , BuilderFactory builderFactory, /*FileStorageService fileStorageService,*/ ElasticRepository elasticRepository) {
this.databaseRepository = databaseRepository; this.databaseRepository = databaseRepository;
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.remoteFetcher = remoteFetcher; this.remoteFetcher = remoteFetcher;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.fileStorageService = fileStorageService; // this.fileStorageService = fileStorageService;
this.elasticRepository = elasticRepository; this.elasticRepository = elasticRepository;
} }
@ -53,10 +52,10 @@ public class OperationsContextImpl implements OperationsContext {
return builderFactory; return builderFactory;
} }
@Override // @Override
public FileStorageService getFileStorageService() { // public FileStorageService getFileStorageService() {
return fileStorageService; // return fileStorageService;
} // }
@Override @Override
public ElasticRepository getElasticRepository() { public ElasticRepository getElasticRepository() {

View File

@ -38,3 +38,7 @@ dataset.technical_resource.technical_resource
dataset.technical_resource.technical_resource.description dataset.technical_resource.technical_resource.description
dataset.technical_resource.technical_resource.name dataset.technical_resource.technical_resource.name
dataset.type dataset.type
dataset.issued
dataset.dataset_id
dataset.dataset_id.identifier
dataset.dataset_id.type

View File

@ -2,7 +2,7 @@ server.port=8081
server.tomcat.max-threads = 20 server.tomcat.max-threads = 20
server.tomcat.max-connections = 10000 server.tomcat.max-connections = 10000
logging.file=/logs/spring-boot-logging.log 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 eu.eudat.logic.proxy.allowed.host=https://eestore.paas2.uninett.no
####################INVITATION MAIL CONFIGURATIONS############## ####################INVITATION MAIL CONFIGURATIONS##############
@ -59,10 +59,6 @@ b2access.externallogin.redirect_uri=http://opendmp.eu/api/oauth/authorized/b2acc
b2access.externallogin.clientid= b2access.externallogin.clientid=
b2access.externallogin.clientSecret= b2access.externallogin.clientSecret=
#############FILE STORAGE CONFIGURATIONS#########
files.storage.temp = temp
files.storage.final = final
#############DYNAMIC PROJECT CONFIGURATIONS######### #############DYNAMIC PROJECT CONFIGURATIONS#########
project.configuration.project.name = Project project.configuration.project.name = Project
project.configuration.funder.name = Funder 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 notification.modifiedFinalised.subject=[OpenDMP] The {name} has been modified and finalised
#############LOGGING######### #############LOGGING#########
logging.config=file:logging/logback-${spring.profiles.active}.xml logging.config=classpath:logging/logback-${spring.profiles.active}.xml
#############TEMP######### #############TEMP#########
temp.temp=tmp/ temp.temp=tmp/