Skip to content

Commit

Permalink
Global: Add sorting to DMPs, Storage, Datasets and other entities by …
Browse files Browse the repository at this point in the history
…ID to preserve order
  • Loading branch information
GeoffreyKarnbach committed Dec 2, 2024
1 parent 6fd4949 commit cee2442
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/damap/base/rest/dmp/mapper/DmpDOMapper.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -74,7 +71,8 @@ public DmpDO mapEntityToDO(Dmp dmp, DmpDO dmpDO) {
dmpDO.setDocumentation(dmp.getDocumentation());

List<ContributorDO> contributorDOList = new ArrayList<>();
dmp.getContributorList()
dmp.getContributorList().stream()
.sorted(Comparator.comparing(contributor -> contributor.id))
.forEach(
contributor -> {
ContributorDO contributorDO = new ContributorDO();
Expand All @@ -99,7 +97,8 @@ public DmpDO mapEntityToDO(Dmp dmp, DmpDO dmpDO) {
dmpDO.setLegalRestrictionsDocuments(legalRestrictionsDocumentsDOList);

List<DatasetDO> datasetDOList = new ArrayList<>();
dmp.getDatasetList()
dmp.getDatasetList().stream()
.sorted(Comparator.comparing(Dataset::getId))
.forEach(
dataset -> {
DatasetDO datasetDO = new DatasetDO();
Expand Down Expand Up @@ -154,7 +153,8 @@ public DmpDO mapEntityToDO(Dmp dmp, DmpDO dmpDO) {
dmpDO.setExternalStorage(externalStorageDOList);

List<CostDO> costDOList = new ArrayList<>();
dmp.getCosts()
dmp.getCosts().stream()
.sorted(Comparator.comparing(cost -> cost.id))
.forEach(
cost -> {
CostDO costDO = new CostDO();
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/damap/base/rest/dmp/service/DmpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +63,9 @@ public List<DmpListItemDO> getAll() {
dmpListItemDOList.add(
DmpListItemDOMapper.mapEntityToDO(
null, dmp, new DmpListItemDO(), versionService.getDmpVersions(dmp.id))));

dmpListItemDOList.sort(Comparator.comparing(DmpListItemDO::getId));

return dmpListItemDOList;
}

Expand All @@ -90,6 +89,9 @@ public List<DmpListItemDO> getDmpListByPersonId(String personId) {
access.getDmp(),
new DmpListItemDO(),
versionService.getDmpVersions(access.getDmp().id))));

dmpListItemDOS.sort(Comparator.comparing(DmpListItemDO::getId));

return dmpListItemDOS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,6 +180,8 @@ public ResultList<InternalStorageDO> search(MultivaluedMap<String, String> query
internalStorage, new InternalStorageDO(), translations));
}

internalStorageDOList.sort(Comparator.comparingLong(InternalStorageDO::getId));

Search search = Search.fromMap(queryParams);

return ResultList.fromItemsAndSearch(internalStorageDOList, search);
Expand Down

0 comments on commit cee2442

Please sign in to comment.