From 51285f722b1c240b430ac9a1d5aa565dc651517a Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 6 Feb 2024 16:20:37 +0200 Subject: [PATCH] remove old logic --- .../java/eu/eudat/data/old/FileUpload.java | 128 ------------ .../data/dao/entities/FileUploadDao.java | 12 -- .../data/dao/entities/FileUploadDaoImpl.java | 57 ------ .../query/definition/TableCriteriaQuery.java | 1 - .../eu/eudat/controllers/FileController.java | 183 ------------------ .../eu/eudat/criteria/DatasetCriteria.java | 1 - .../java/eu/eudat/criteria/UserCriteria.java | 8 - .../logic/managers/DatasetProfileManager.java | 3 - .../eu/eudat/logic/managers/FileManager.java | 96 --------- .../operations/DatabaseRepository.java | 10 - .../operations/DatabaseRepositoryImpl.java | 38 ---- .../operations/OperationsContext.java | 2 - .../operations/OperationsContextImpl.java | 9 +- .../eudat/models/data/FetcherReference.java | 1 - 14 files changed, 1 insertion(+), 548 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/FileUpload.java delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDao.java delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDaoImpl.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/FileUpload.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/FileUpload.java deleted file mode 100644 index 977855fcb..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/FileUpload.java +++ /dev/null @@ -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 { - 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, List 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; - } -} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDao.java deleted file mode 100644 index 3fdc74cb0..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDao.java +++ /dev/null @@ -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 { - List getFileUploads(UUID entityId) throws InvalidApplicationException; -} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDaoImpl.java deleted file mode 100644 index 59fb93b76..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/FileUploadDaoImpl.java +++ /dev/null @@ -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 implements FileUploadDao { - - @Autowired - public FileUploadDaoImpl(DatabaseService databaseService) { - super(databaseService); - } - - @Override - public FileUpload createOrUpdate(FileUpload item) { - return getDatabaseService().createOrUpdate(item, FileUpload.class); - } -// - @Override - public CompletableFuture 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 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 asQueryable() { - return this.getDatabaseService().getQueryable(FileUpload.class); - } -} \ No newline at end of file diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/definition/TableCriteriaQuery.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/definition/TableCriteriaQuery.java index eb3baa75b..6ae6400c6 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/definition/TableCriteriaQuery.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/definition/TableCriteriaQuery.java @@ -2,7 +2,6 @@ package eu.eudat.data.query.definition; import eu.eudat.data.dao.criteria.Criteria; import eu.eudat.queryable.QueryableList; -import eu.eudat.data.old.queryableentity.DataEntity; /** * Created by ikalyvas on 3/21/2018. diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java deleted file mode 100644 index f70912743..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java +++ /dev/null @@ -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> 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 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().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().payload(uuid) - .status(ApiMessageCode.SUCCESS_MESSAGE).message("")); - } - - @RequestMapping(method = RequestMethod.POST, value = {"/delete-temp"}) - public ResponseEntity> 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().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); - - } - -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/criteria/DatasetCriteria.java b/dmp-backend/web/src/main/java/eu/eudat/criteria/DatasetCriteria.java index ec591be19..73bff6cc8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/criteria/DatasetCriteria.java +++ b/dmp-backend/web/src/main/java/eu/eudat/criteria/DatasetCriteria.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.node.JsonNodeType; import eu.eudat.criteria.entities.Criteria; -import eu.eudat.logic.services.operations.DatabaseRepository; import java.io.IOException; import java.util.*; diff --git a/dmp-backend/web/src/main/java/eu/eudat/criteria/UserCriteria.java b/dmp-backend/web/src/main/java/eu/eudat/criteria/UserCriteria.java index a6874888c..08bf9e3ed 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/criteria/UserCriteria.java +++ b/dmp-backend/web/src/main/java/eu/eudat/criteria/UserCriteria.java @@ -6,8 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.node.JsonNodeType; import eu.eudat.criteria.entities.Criteria; -import eu.eudat.logic.services.operations.DatabaseRepository; -import eu.eudat.model.User; import eu.eudat.query.UserQuery; import java.io.IOException; @@ -58,10 +56,4 @@ public class UserCriteria { return new LinkedList<>(fields); } - public UserQuery buildQuery(DatabaseRepository dao) { - List fields = this.buildFields(""); -// UserQuery query = new UserQuery(dao.getUserInfoDao(), fields); -// if (this.id != null) query.setId(this.id.getValue()); - return null; - } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java index ab9f33da7..f82b7f721 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java @@ -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.RemoteFetcherService; 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.config.AuthenticationConfiguration; 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 List cache = new ArrayList<>(); - private final DatabaseRepository databaseRepository; private final ConfigLoader configLoader; private final RemoteFetcherService remoteFetcherService; @Autowired public DatasetProfileManager(ApiContext apiContext, ConfigLoader configLoader, RemoteFetcherService remoteFetcherService) { - this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.configLoader = configLoader; this.remoteFetcherService = remoteFetcherService; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java deleted file mode 100644 index 04f0aa333..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java +++ /dev/null @@ -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 getFileUploadsForEntityId(String entityId) throws InvalidApplicationException { - return databaseRepository.getFileUploadDao().asQueryable() - .where((builder, root) -> builder.equal(root.get("entityId"), entityId)).toList(); - } - - public List 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 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()); - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java deleted file mode 100644 index 44fd59e82..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package eu.eudat.logic.services.operations; - -import eu.eudat.data.dao.entities.*; - -public interface DatabaseRepository { - - FileUploadDao getFileUploadDao(); - - void detachEntity(T entity); -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java deleted file mode 100644 index 5db7935c4..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java +++ /dev/null @@ -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 void detachEntity(T entity) { - this.entityManager.detach(entity); - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContext.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContext.java index f0ee1cbba..154a1d1ca 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContext.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContext.java @@ -9,8 +9,6 @@ import org.springframework.context.ApplicationContext; */ public interface OperationsContext { - DatabaseRepository getDatabaseRepository(); - ApplicationContext getApplicationContext(); BuilderFactory getBuilderFactory(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContextImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContextImpl.java index 4a0631ed2..31eec326d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContextImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/OperationsContextImpl.java @@ -12,7 +12,6 @@ import org.springframework.stereotype.Service; @Service("operationsContext") public class OperationsContextImpl implements OperationsContext { - private final DatabaseRepository databaseRepository; private final ApplicationContext applicationContext; private final RemoteFetcherService remoteFetcherService; private final BuilderFactory builderFactory; @@ -20,9 +19,8 @@ public class OperationsContextImpl implements OperationsContext { // private final ElasticRepository elasticRepository; @Autowired - public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcherService remoteFetcherService + public OperationsContextImpl(ApplicationContext applicationContext, RemoteFetcherService remoteFetcherService , BuilderFactory builderFactory/*FileStorageService fileStorageService, ElasticRepository elasticRepository*/) { - this.databaseRepository = databaseRepository; this.applicationContext = applicationContext; this.remoteFetcherService = remoteFetcherService; this.builderFactory = builderFactory; @@ -30,11 +28,6 @@ public class OperationsContextImpl implements OperationsContext { // this.elasticRepository = elasticRepository; } - @Override - public DatabaseRepository getDatabaseRepository() { - return databaseRepository; - } - @Override public ApplicationContext getApplicationContext() { return applicationContext; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/FetcherReference.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/FetcherReference.java index ccef82936..21265b85e 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/FetcherReference.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/FetcherReference.java @@ -1,6 +1,5 @@ package eu.eudat.models.data; -import eu.eudat.data.old.*; import java.util.Map;