From cee24424c1c0f6c215cbb33742eb65d7e66df761 Mon Sep 17 00:00:00 2001 From: GeoffreyKarnbach <36735387+GeoffreyKarnbach@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:01:31 +0100 Subject: [PATCH] Global: Add sorting to DMPs, Storage, Datasets and other entities by ID to preserve order --- .../damap/base/rest/dmp/mapper/DmpDOMapper.java | 14 +++++++------- .../damap/base/rest/dmp/service/DmpService.java | 12 +++++++----- .../base/rest/storage/InternalStorageService.java | 3 +++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/damap/base/rest/dmp/mapper/DmpDOMapper.java b/src/main/java/org/damap/base/rest/dmp/mapper/DmpDOMapper.java index 69716b28..ab20033d 100644 --- a/src/main/java/org/damap/base/rest/dmp/mapper/DmpDOMapper.java +++ b/src/main/java/org/damap/base/rest/dmp/mapper/DmpDOMapper.java @@ -1,9 +1,6 @@ package org.damap.base.rest.dmp.mapper; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import lombok.experimental.UtilityClass; import lombok.extern.jbosslog.JBossLog; import org.damap.base.domain.*; @@ -74,7 +71,8 @@ public DmpDO mapEntityToDO(Dmp dmp, DmpDO dmpDO) { dmpDO.setDocumentation(dmp.getDocumentation()); List contributorDOList = new ArrayList<>(); - dmp.getContributorList() + dmp.getContributorList().stream() + .sorted(Comparator.comparing(contributor -> contributor.id)) .forEach( contributor -> { ContributorDO contributorDO = new ContributorDO(); @@ -99,7 +97,8 @@ public DmpDO mapEntityToDO(Dmp dmp, DmpDO dmpDO) { dmpDO.setLegalRestrictionsDocuments(legalRestrictionsDocumentsDOList); List datasetDOList = new ArrayList<>(); - dmp.getDatasetList() + dmp.getDatasetList().stream() + .sorted(Comparator.comparing(Dataset::getId)) .forEach( dataset -> { DatasetDO datasetDO = new DatasetDO(); @@ -154,7 +153,8 @@ public DmpDO mapEntityToDO(Dmp dmp, DmpDO dmpDO) { dmpDO.setExternalStorage(externalStorageDOList); List costDOList = new ArrayList<>(); - dmp.getCosts() + dmp.getCosts().stream() + .sorted(Comparator.comparing(cost -> cost.id)) .forEach( cost -> { CostDO costDO = new CostDO(); diff --git a/src/main/java/org/damap/base/rest/dmp/service/DmpService.java b/src/main/java/org/damap/base/rest/dmp/service/DmpService.java index b3fa6415..ff179531 100644 --- a/src/main/java/org/damap/base/rest/dmp/service/DmpService.java +++ b/src/main/java/org/damap/base/rest/dmp/service/DmpService.java @@ -5,11 +5,7 @@ import jakarta.transaction.Transactional; import jakarta.validation.Valid; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import lombok.extern.jbosslog.JBossLog; import org.damap.base.domain.Access; import org.damap.base.domain.Contributor; @@ -67,6 +63,9 @@ public List getAll() { dmpListItemDOList.add( DmpListItemDOMapper.mapEntityToDO( null, dmp, new DmpListItemDO(), versionService.getDmpVersions(dmp.id)))); + + dmpListItemDOList.sort(Comparator.comparing(DmpListItemDO::getId)); + return dmpListItemDOList; } @@ -90,6 +89,9 @@ public List getDmpListByPersonId(String personId) { access.getDmp(), new DmpListItemDO(), versionService.getDmpVersions(access.getDmp().id)))); + + dmpListItemDOS.sort(Comparator.comparing(DmpListItemDO::getId)); + return dmpListItemDOS; } diff --git a/src/main/java/org/damap/base/rest/storage/InternalStorageService.java b/src/main/java/org/damap/base/rest/storage/InternalStorageService.java index f700adba..c06a2a7b 100644 --- a/src/main/java/org/damap/base/rest/storage/InternalStorageService.java +++ b/src/main/java/org/damap/base/rest/storage/InternalStorageService.java @@ -9,6 +9,7 @@ import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.Response; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import lombok.extern.jbosslog.JBossLog; @@ -179,6 +180,8 @@ public ResultList search(MultivaluedMap query internalStorage, new InternalStorageDO(), translations)); } + internalStorageDOList.sort(Comparator.comparingLong(InternalStorageDO::getId)); + Search search = Search.fromMap(queryParams); return ResultList.fromItemsAndSearch(internalStorageDOList, search);