remove old logic
This commit is contained in:
parent
b4ccd71f85
commit
51285f722b
|
@ -1,128 +0,0 @@
|
||||||
package eu.eudat.data.old;
|
|
||||||
|
|
||||||
import eu.eudat.data.UserEntity;
|
|
||||||
import eu.eudat.data.converters.DateToUTCConverter;
|
|
||||||
import eu.eudat.data.old.helpers.EntityBinder;
|
|
||||||
import eu.eudat.data.old.queryableentity.DataEntity;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "\"FileUpload\"")
|
|
||||||
public class FileUpload implements DataEntity<FileUpload, UUID> {
|
|
||||||
public enum EntityType {
|
|
||||||
DATASET, DMP
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
|
||||||
private UUID id;
|
|
||||||
|
|
||||||
@Column(name = "\"Name\"", nullable = false)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Column(name = "\"FileType\"", nullable = false)
|
|
||||||
private String fileType;
|
|
||||||
|
|
||||||
@Column(name = "\"EntityId\"", nullable = false)
|
|
||||||
private UUID entityId;
|
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
@Column(name = "\"EntityType\"", nullable = false)
|
|
||||||
private EntityType entityType;
|
|
||||||
|
|
||||||
@Column(name = "\"CreatedAt\"", nullable = false)
|
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
|
||||||
private Date createdAt;
|
|
||||||
|
|
||||||
@Column(name = "\"IsDeleted\"", nullable = false)
|
|
||||||
private Boolean isDeleted;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "\"Creator\"")
|
|
||||||
private UserEntity creator;
|
|
||||||
|
|
||||||
public UUID getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public void setId(UUID id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileType() {
|
|
||||||
return fileType;
|
|
||||||
}
|
|
||||||
public void setFileType(String fileType) {
|
|
||||||
this.fileType = fileType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getEntityId() {
|
|
||||||
return entityId;
|
|
||||||
}
|
|
||||||
public void setEntityId(UUID entityId) {
|
|
||||||
this.entityId = entityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityType getEntityType() {
|
|
||||||
return entityType;
|
|
||||||
}
|
|
||||||
public void setEntityType(EntityType entityType) {
|
|
||||||
this.entityType = entityType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
|
||||||
return createdAt;
|
|
||||||
}
|
|
||||||
public void setCreatedAt(Date createdAt) {
|
|
||||||
this.createdAt = createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getIsDeleted() {
|
|
||||||
return isDeleted;
|
|
||||||
}
|
|
||||||
public void setIsDeleted(Boolean isDeleted) {
|
|
||||||
this.isDeleted = isDeleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserEntity getCreator() {
|
|
||||||
return creator;
|
|
||||||
}
|
|
||||||
public void setCreator(UserEntity creator) {
|
|
||||||
this.creator = creator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(FileUpload file) {
|
|
||||||
this.name = file.getName();
|
|
||||||
this.fileType = file.getFileType();
|
|
||||||
this.entityId = file.getEntityId();
|
|
||||||
this.entityType = file.getEntityType();
|
|
||||||
this.createdAt = file.getCreatedAt();
|
|
||||||
this.isDeleted = file.getIsDeleted();
|
|
||||||
this.creator = file.getCreator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID getKeys() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileUpload buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
|
||||||
String currentBase = base.isEmpty() ? "" : base + ".";
|
|
||||||
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
|
|
||||||
// this.creator = tuple.stream().map(x -> new UserEntity().buildFromTuple(tuple, fields , base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package eu.eudat.data.dao.entities;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.DatabaseAccessLayer;
|
|
||||||
import eu.eudat.data.old.FileUpload;
|
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface FileUploadDao extends DatabaseAccessLayer<FileUpload, UUID> {
|
|
||||||
List<FileUpload> getFileUploads(UUID entityId) throws InvalidApplicationException;
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package eu.eudat.data.dao.entities;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.DatabaseAccess;
|
|
||||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
|
||||||
import eu.eudat.data.old.FileUpload;
|
|
||||||
import eu.eudat.queryable.QueryableList;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Component("FileUploadDao")
|
|
||||||
public class FileUploadDaoImpl extends DatabaseAccess<FileUpload> implements FileUploadDao {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public FileUploadDaoImpl(DatabaseService<FileUpload> databaseService) {
|
|
||||||
super(databaseService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileUpload createOrUpdate(FileUpload item) {
|
|
||||||
return getDatabaseService().createOrUpdate(item, FileUpload.class);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<FileUpload> createOrUpdateAsync(FileUpload item) {
|
|
||||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileUpload find(UUID id) throws InvalidApplicationException {
|
|
||||||
return getDatabaseService().getQueryable(FileUpload.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FileUpload> getFileUploads(UUID entityId) throws InvalidApplicationException {
|
|
||||||
return this.getDatabaseService().getQueryable(FileUpload.class).where((builder, root) -> builder.equal(root.get("entityId"), entityId)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileUpload find(UUID id, String hint) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(FileUpload item) {
|
|
||||||
this.getDatabaseService().delete(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryableList<FileUpload> asQueryable() {
|
|
||||||
return this.getDatabaseService().getQueryable(FileUpload.class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@ package eu.eudat.data.query.definition;
|
||||||
|
|
||||||
import eu.eudat.data.dao.criteria.Criteria;
|
import eu.eudat.data.dao.criteria.Criteria;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.data.old.queryableentity.DataEntity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 3/21/2018.
|
* Created by ikalyvas on 3/21/2018.
|
||||||
|
|
|
@ -1,183 +0,0 @@
|
||||||
package eu.eudat.controllers;
|
|
||||||
|
|
||||||
import eu.eudat.authorization.AuthorizationFlags;
|
|
||||||
import eu.eudat.authorization.Permission;
|
|
||||||
import eu.eudat.commons.XmlHandlingService;
|
|
||||||
import eu.eudat.commons.enums.DmpAccessType;
|
|
||||||
import eu.eudat.commons.enums.FieldType;
|
|
||||||
import eu.eudat.commons.enums.IsActive;
|
|
||||||
import eu.eudat.commons.scope.user.UserScope;
|
|
||||||
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
|
||||||
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
|
||||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
|
|
||||||
import eu.eudat.data.DescriptionEntity;
|
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
|
||||||
import eu.eudat.data.DmpEntity;
|
|
||||||
import eu.eudat.data.old.FileUpload;
|
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
|
||||||
import eu.eudat.logic.managers.DatasetProfileManager;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
|
||||||
import eu.eudat.model.file.FileEnvelope;
|
|
||||||
import eu.eudat.models.HintedModelFactory;
|
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
||||||
import eu.eudat.query.DescriptionQuery;
|
|
||||||
import eu.eudat.query.DescriptionTemplateQuery;
|
|
||||||
import eu.eudat.query.DmpDescriptionTemplateQuery;
|
|
||||||
import eu.eudat.query.DmpQuery;
|
|
||||||
import eu.eudat.types.ApiMessageCode;
|
|
||||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import jakarta.xml.bind.JAXBException;
|
|
||||||
import org.apache.poi.util.IOUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.util.unit.DataSize;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@CrossOrigin
|
|
||||||
@RequestMapping(value = {"/api/file/"})
|
|
||||||
public class FileController {
|
|
||||||
|
|
||||||
private DatasetProfileManager datasetProfileManager;
|
|
||||||
private final Environment environment;
|
|
||||||
private DatabaseRepository databaseRepository;
|
|
||||||
private final AuthorizationService authorizationService;
|
|
||||||
private final UserScope userScope;
|
|
||||||
private final QueryFactory queryFactory;
|
|
||||||
private final XmlHandlingService xmlHandlingService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public FileController(DatasetProfileManager datasetProfileManager, Environment environment, ApiContext apiContext, AuthorizationService authorizationService, UserScope userScope, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) {
|
|
||||||
this.datasetProfileManager = datasetProfileManager;
|
|
||||||
this.environment = environment;
|
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
|
||||||
this.authorizationService = authorizationService;
|
|
||||||
this.userScope = userScope;
|
|
||||||
this.queryFactory = queryFactory;
|
|
||||||
this.xmlHandlingService = xmlHandlingService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
|
||||||
public ResponseEntity<ResponseItem<String>> upload(
|
|
||||||
@RequestParam("file") MultipartFile file, @RequestParam("datasetProfileId") String datasetProfileId, @RequestParam("fieldId") String fieldId)
|
|
||||||
throws IllegalAccessException, IOException, InvalidApplicationException, JAXBException, ParserConfigurationException, InstantiationException, SAXException {
|
|
||||||
this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole);
|
|
||||||
|
|
||||||
String uuid = UUID.randomUUID().toString();
|
|
||||||
|
|
||||||
DescriptionTemplateEntity descriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).ids(UUID.fromString(datasetProfileId)).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).first();
|
|
||||||
DefinitionEntity definition = descriptionTemplate == null ? null : this.xmlHandlingService.fromXml(DefinitionEntity.class, descriptionTemplate.getDefinition());
|
|
||||||
|
|
||||||
AtomicBoolean acceptedFile = new AtomicBoolean(false);
|
|
||||||
List<FieldEntity> fieldEntities = definition != null ? definition.getFieldById(fieldId).stream().filter(x -> x != null && x.getData() != null && x.getData().getFieldType().equals(FieldType.UPLOAD)).toList() : new ArrayList<>();
|
|
||||||
|
|
||||||
fieldEntities.forEach(x-> {
|
|
||||||
UploadDataEntity uploadDataEntity = (UploadDataEntity)x.getData();
|
|
||||||
if (DataSize.ofBytes(file.getSize()).equals(DataSize.ofMegabytes(uploadDataEntity.getMaxFileSizeInMB()))) {
|
|
||||||
acceptedFile.set(true);
|
|
||||||
}
|
|
||||||
if(acceptedFile.get() && uploadDataEntity.getTypes() != null && !uploadDataEntity.getTypes().isEmpty()) {
|
|
||||||
acceptedFile.set(false);
|
|
||||||
for (UploadDataEntity.UploadDataOptionEntity option: uploadDataEntity.getTypes()) {
|
|
||||||
if(Objects.equals(file.getContentType(), option.getValue())) {
|
|
||||||
acceptedFile.set(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!acceptedFile.get()) {
|
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message("The uploaded file is too large or has an unaccepted type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
File convFile = new File(this.environment.getProperty("temp.temp") + uuid);
|
|
||||||
convFile.createNewFile();
|
|
||||||
FileOutputStream fos = new FileOutputStream(convFile);
|
|
||||||
fos.write(file.getBytes());
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().payload(uuid)
|
|
||||||
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/delete-temp"})
|
|
||||||
public ResponseEntity<ResponseItem<String>> upload(@RequestBody String filename) throws IllegalAccessException, IOException {
|
|
||||||
File convFile = new File(this.environment.getProperty("temp.temp") + filename);
|
|
||||||
// Boolean deleted = convFile.delete();
|
|
||||||
Boolean deleted = Files.deleteIfExists(convFile.toPath());
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().payload(deleted.toString())
|
|
||||||
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"{id}"}, produces = "application/json")
|
|
||||||
public @ResponseBody
|
|
||||||
ResponseEntity download(@PathVariable String id) throws IOException, InvalidApplicationException {
|
|
||||||
|
|
||||||
this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole);
|
|
||||||
|
|
||||||
FileUpload fileUpload = databaseRepository.getFileUploadDao().find(UUID.fromString(id));
|
|
||||||
if(fileUpload == null) {
|
|
||||||
throw new NoSuchElementException("File with id "+id+" not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fileUpload.getEntityType().name().equals(FileUpload.EntityType.DATASET.name())) {
|
|
||||||
DescriptionEntity descriptionEntityEntity = this.queryFactory.query(DescriptionQuery.class).ids(fileUpload.getEntityId()).first();
|
|
||||||
if (descriptionEntityEntity == null) {
|
|
||||||
throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()).first();
|
|
||||||
|
|
||||||
if (!dmp.getAccessType().equals(DmpAccessType.Public)
|
|
||||||
//TODO
|
|
||||||
// && dmp.getUsers()
|
|
||||||
// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
|
|
||||||
// .collect(Collectors.toList()).size() == 0
|
|
||||||
)
|
|
||||||
throw new UnauthorisedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileEnvelope fileEnvelope = new FileEnvelope();
|
|
||||||
fileEnvelope.setFilename(fileUpload.getName());
|
|
||||||
File exportFile = new File(this.environment.getProperty("file.storage") + id);
|
|
||||||
fileEnvelope.setFile(exportFile);
|
|
||||||
|
|
||||||
InputStream resource = new FileInputStream(fileEnvelope.getFile());
|
|
||||||
HttpHeaders responseHeaders = new HttpHeaders();
|
|
||||||
responseHeaders.setContentLength(fileEnvelope.getFile().length());
|
|
||||||
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
||||||
String fileName = fileEnvelope.getFilename().replace(" ", "_").replace(",", "_");
|
|
||||||
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
|
|
||||||
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
||||||
responseHeaders.set("Cache-Control", "no-store");
|
|
||||||
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
||||||
|
|
||||||
byte[] content = IOUtils.toByteArray(resource);
|
|
||||||
resource.close();
|
|
||||||
return new ResponseEntity<>(content,
|
|
||||||
responseHeaders,
|
|
||||||
HttpStatus.OK);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectReader;
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||||
import eu.eudat.criteria.entities.Criteria;
|
import eu.eudat.criteria.entities.Criteria;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
|
@ -6,8 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectReader;
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||||
import eu.eudat.criteria.entities.Criteria;
|
import eu.eudat.criteria.entities.Criteria;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
|
||||||
import eu.eudat.model.User;
|
|
||||||
import eu.eudat.query.UserQuery;
|
import eu.eudat.query.UserQuery;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -58,10 +56,4 @@ public class UserCriteria {
|
||||||
return new LinkedList<>(fields);
|
return new LinkedList<>(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserQuery buildQuery(DatabaseRepository dao) {
|
|
||||||
List<String> fields = this.buildFields("");
|
|
||||||
// UserQuery query = new UserQuery(dao.getUserInfoDao(), fields);
|
|
||||||
// if (this.id != null) query.setId(this.id.getValue());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.service.remotefetcher.config.entities.GeneralUrls;
|
import eu.eudat.service.remotefetcher.config.entities.GeneralUrls;
|
||||||
import eu.eudat.service.remotefetcher.RemoteFetcherService;
|
import eu.eudat.service.remotefetcher.RemoteFetcherService;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
|
||||||
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
|
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
|
||||||
import eu.eudat.service.remotefetcher.config.AuthenticationConfiguration;
|
import eu.eudat.service.remotefetcher.config.AuthenticationConfiguration;
|
||||||
import eu.eudat.service.remotefetcher.config.DataFieldsUrlConfiguration;
|
import eu.eudat.service.remotefetcher.config.DataFieldsUrlConfiguration;
|
||||||
|
@ -39,13 +38,11 @@ public class DatasetProfileManager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DatasetProfileManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(DatasetProfileManager.class);
|
||||||
private static final List<String> cache = new ArrayList<>();
|
private static final List<String> cache = new ArrayList<>();
|
||||||
|
|
||||||
private final DatabaseRepository databaseRepository;
|
|
||||||
private final ConfigLoader configLoader;
|
private final ConfigLoader configLoader;
|
||||||
private final RemoteFetcherService remoteFetcherService;
|
private final RemoteFetcherService remoteFetcherService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DatasetProfileManager(ApiContext apiContext, ConfigLoader configLoader, RemoteFetcherService remoteFetcherService) {
|
public DatasetProfileManager(ApiContext apiContext, ConfigLoader configLoader, RemoteFetcherService remoteFetcherService) {
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
|
||||||
this.configLoader = configLoader;
|
this.configLoader = configLoader;
|
||||||
this.remoteFetcherService = remoteFetcherService;
|
this.remoteFetcherService = remoteFetcherService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
package eu.eudat.logic.managers;
|
|
||||||
|
|
||||||
import eu.eudat.data.old.FileUpload;
|
|
||||||
import eu.eudat.data.UserEntity;
|
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class FileManager {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(FileManager.class);
|
|
||||||
|
|
||||||
private ApiContext apiContext;
|
|
||||||
private DatabaseRepository databaseRepository;
|
|
||||||
private Environment environment;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public FileManager(ApiContext apiContext, Environment environment) {
|
|
||||||
this.apiContext = apiContext;
|
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
|
||||||
this.environment = environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String moveFromTmpToStorage(String filename) {
|
|
||||||
File tempFile = new File(this.environment.getProperty("temp.temp") + filename);
|
|
||||||
File newFile = new File(this.environment.getProperty("file.storage") + filename);
|
|
||||||
try {
|
|
||||||
return Files.move(tempFile.toPath(), newFile.toPath()).toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteFromStorage(String filename) {
|
|
||||||
File toBeDeletedFile = new File(this.environment.getProperty("file.storage") + filename);
|
|
||||||
// toBeDeletedFile.delete();
|
|
||||||
try {
|
|
||||||
return Files.deleteIfExists(toBeDeletedFile.toPath());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markOldFileAsDeleted(FileUpload fileUpload) {
|
|
||||||
fileUpload.setIsDeleted(true);
|
|
||||||
databaseRepository.getFileUploadDao().createOrUpdate(fileUpload);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FileUpload> getFileUploadsForEntityId(String entityId) throws InvalidApplicationException {
|
|
||||||
return databaseRepository.getFileUploadDao().asQueryable()
|
|
||||||
.where((builder, root) -> builder.equal(root.get("entityId"), entityId)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FileUpload> getCurrentFileUploadsForEntityId(UUID entityId) throws InvalidApplicationException {
|
|
||||||
return databaseRepository.getFileUploadDao().asQueryable()
|
|
||||||
.where((builder, root) -> builder.and(
|
|
||||||
builder.equal(root.get("entityId"), entityId),
|
|
||||||
builder.equal(root.get("isDeleted"), false))).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markAllFilesOfEntityIdAsDeleted(UUID entityId) throws InvalidApplicationException {
|
|
||||||
List<FileUpload> fileUploads = this.getCurrentFileUploadsForEntityId(entityId);
|
|
||||||
fileUploads.forEach(fileUpload -> {
|
|
||||||
this.markOldFileAsDeleted(fileUpload);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createFile(String id, String fileName, String fileType, String entityId, FileUpload.EntityType entityType, UserEntity userInfo) {
|
|
||||||
FileUpload fileUpload = new FileUpload();
|
|
||||||
fileUpload.setId(UUID.fromString(id));
|
|
||||||
fileUpload.setName(fileName);
|
|
||||||
fileUpload.setFileType(fileType);
|
|
||||||
fileUpload.setEntityId(UUID.fromString(entityId));
|
|
||||||
fileUpload.setEntityType(entityType);
|
|
||||||
fileUpload.setCreatedAt(new Date());
|
|
||||||
fileUpload.setIsDeleted(false);
|
|
||||||
fileUpload.setCreator(userInfo);
|
|
||||||
databaseRepository.getFileUploadDao().createOrUpdate(fileUpload);
|
|
||||||
|
|
||||||
this.moveFromTmpToStorage(fileUpload.getId().toString());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package eu.eudat.logic.services.operations;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.entities.*;
|
|
||||||
|
|
||||||
public interface DatabaseRepository {
|
|
||||||
|
|
||||||
FileUploadDao getFileUploadDao();
|
|
||||||
|
|
||||||
<T> void detachEntity(T entity);
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package eu.eudat.logic.services.operations;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.entities.*;
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service("databaseRepository")
|
|
||||||
public class DatabaseRepositoryImpl implements DatabaseRepository {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private FileUploadDao fileUploadDao;
|
|
||||||
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setEntityManager(EntityManager entityManager) {
|
|
||||||
this.entityManager = entityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileUploadDao getFileUploadDao() {
|
|
||||||
return fileUploadDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setFileUploadDao(FileUploadDao fileUploadDao) {
|
|
||||||
this.fileUploadDao = fileUploadDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void detachEntity(T entity) {
|
|
||||||
this.entityManager.detach(entity);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,8 +9,6 @@ import org.springframework.context.ApplicationContext;
|
||||||
*/
|
*/
|
||||||
public interface OperationsContext {
|
public interface OperationsContext {
|
||||||
|
|
||||||
DatabaseRepository getDatabaseRepository();
|
|
||||||
|
|
||||||
ApplicationContext getApplicationContext();
|
ApplicationContext getApplicationContext();
|
||||||
|
|
||||||
BuilderFactory getBuilderFactory();
|
BuilderFactory getBuilderFactory();
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
|
||||||
@Service("operationsContext")
|
@Service("operationsContext")
|
||||||
public class OperationsContextImpl implements OperationsContext {
|
public class OperationsContextImpl implements OperationsContext {
|
||||||
|
|
||||||
private final DatabaseRepository databaseRepository;
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
private final RemoteFetcherService remoteFetcherService;
|
private final RemoteFetcherService remoteFetcherService;
|
||||||
private final BuilderFactory builderFactory;
|
private final BuilderFactory builderFactory;
|
||||||
|
@ -20,9 +19,8 @@ public class OperationsContextImpl implements OperationsContext {
|
||||||
// private final ElasticRepository elasticRepository;
|
// private final ElasticRepository elasticRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcherService remoteFetcherService
|
public OperationsContextImpl(ApplicationContext applicationContext, RemoteFetcherService remoteFetcherService
|
||||||
, BuilderFactory builderFactory/*FileStorageService fileStorageService, ElasticRepository elasticRepository*/) {
|
, BuilderFactory builderFactory/*FileStorageService fileStorageService, ElasticRepository elasticRepository*/) {
|
||||||
this.databaseRepository = databaseRepository;
|
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.remoteFetcherService = remoteFetcherService;
|
this.remoteFetcherService = remoteFetcherService;
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
|
@ -30,11 +28,6 @@ public class OperationsContextImpl implements OperationsContext {
|
||||||
// this.elasticRepository = elasticRepository;
|
// this.elasticRepository = elasticRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DatabaseRepository getDatabaseRepository() {
|
|
||||||
return databaseRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationContext getApplicationContext() {
|
public ApplicationContext getApplicationContext() {
|
||||||
return applicationContext;
|
return applicationContext;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.eudat.models.data;
|
package eu.eudat.models.data;
|
||||||
|
|
||||||
import eu.eudat.data.old.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue