From b6c28be3b32ab26d944f8b9ba55fbb1286b3eb67 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Mon, 21 Feb 2022 17:16:32 +0200 Subject: [PATCH] Optimize Dashboard's recent activity logic, removed various unused fields from Listing Models and implement toDataModel conversion logic in some models --- .../controllers/DashBoardController.java | 3 +- .../logic/managers/DashBoardManager.java | 209 ++++-------------- .../recent/model/RecentActivityModel.java | 36 --- .../recent/model/RecentDatasetModel.java | 42 ---- .../recent/model/RecentDmpModel.java | 38 ---- .../DatasetProfileOverviewModel.java | 7 +- .../DataManagementPlanListingModel.java | 93 ++------ .../listingmodels/DatasetListingModel.java | 93 ++------ .../listingmodels/UserInfoListingModel.java | 11 +- .../models/data/urls/DatasetUrlListing.java | 9 +- 10 files changed, 106 insertions(+), 435 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java index 6041f865c..12a75d5be 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java @@ -1,6 +1,5 @@ package eu.eudat.controllers; -import eu.eudat.criteria.RecentActivityCriteria; import eu.eudat.logic.managers.DashBoardManager; import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.services.ApiContext; @@ -49,7 +48,7 @@ public class DashBoardController extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/dashboard/recentActivity"}, produces = "application/json") @Transactional public ResponseEntity>> getNewRecentActivity(@RequestBody RecentActivityTableRequest tableRequest, - @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) { + @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { List statistics = dashBoardManager.getNewRecentActivity(tableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java index 5b5bf2d0f..aded6d599 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java @@ -8,16 +8,15 @@ import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DatasetDao; import eu.eudat.data.dao.entities.GrantDao; import eu.eudat.data.dao.entities.OrganisationDao; -import eu.eudat.data.entities.*; -import eu.eudat.data.query.PaginationService; +import eu.eudat.data.entities.DMP; +import eu.eudat.data.entities.Dataset; +import eu.eudat.data.entities.Grant; +import eu.eudat.data.entities.UserInfo; import eu.eudat.data.query.items.table.dataset.DatasetTableRequest; -import eu.eudat.elastic.criteria.SortCriteria; -import eu.eudat.elastic.entities.Dmp; +import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder; -import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.operations.DatabaseRepository; -import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.dashboard.recent.RecentActivity; import eu.eudat.models.data.dashboard.recent.RecentActivityData; import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel; @@ -26,10 +25,10 @@ import eu.eudat.models.data.dashboard.recent.model.RecentDmpModel; import eu.eudat.models.data.dashboard.recent.tablerequest.RecentActivityTableRequest; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics; +import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.data.listingmodels.DatasetListingModel; import eu.eudat.models.data.security.Principal; -import eu.eudat.queryable.QueryableList; import eu.eudat.types.searchbar.SearchBarItemType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +41,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; @Component @@ -60,11 +58,15 @@ public class DashBoardManager { private ApiContext apiContext; private DatabaseRepository databaseRepository; + private final DataManagementPlanManager dataManagementPlanManager; + private final DatasetManager datasetManager; @Autowired - public DashBoardManager(ApiContext apiContext) { + public DashBoardManager(ApiContext apiContext, DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) { this.apiContext = apiContext; this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + this.dataManagementPlanManager = dataManagementPlanManager; + this.datasetManager = datasetManager; } public DashBoardStatistics getStatistics() { @@ -210,11 +212,9 @@ public class DashBoardManager { } @Transactional - public List getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) { + public List getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) throws Exception { boolean isAuthenticated = principal.getId() != null; - List recentActivityModels = new ArrayList<>(); - DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); - DatasetDao datasetRepository = databaseRepository.getDatasetDao(); + List recentActivityModels = new ArrayList<>(); UserInfo user = new UserInfo(); if (isAuthenticated) { user.setId(principal.getId()); @@ -229,117 +229,24 @@ public class DashBoardManager { dataManagementPlanCriteria.setIsPublic(!isAuthenticated); dataManagementPlanCriteria.setOnlyPublic(!isAuthenticated); - QueryableList dmpList; - QueryableList datasetList; - - List datasets = null; - List dmps = null; - - if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository() != null) { - try { - eu.eudat.elastic.criteria.DatasetCriteria datasetElasticCriteria = new eu.eudat.elastic.criteria.DatasetCriteria(); - datasetElasticCriteria.setLike(tableRequest.getCriteria().getLike()); - datasetElasticCriteria.setAllowAllVersions(false); - datasetElasticCriteria.setPublic(!isAuthenticated); - datasetElasticCriteria.setOffset(tableRequest.getDatasetOffset()); - datasetElasticCriteria.setSize(tableRequest.getLength()); - if (isAuthenticated) { - datasetElasticCriteria.setCollaborators(Collections.singletonList(principal.getId())); - } - datasetElasticCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(tableRequest.getOrderings())); - datasetElasticCriteria.getSortCriteria().stream().filter(sortCriteria -> sortCriteria.getFieldName().equals("publishedAt")).forEach(sortCriteria -> { - sortCriteria.setFieldName("dmp:" + sortCriteria.getFieldName()); - sortCriteria.setColumnType(SortCriteria.ColumnType.JOIN_COLUMN); - }); - datasets = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().queryIds(datasetElasticCriteria); - }catch (Exception e) { - logger.warn(e.getMessage(), e); - datasets = null; - } - } - - if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) { - try { - eu.eudat.elastic.criteria.DmpCriteria dmpElasticCriteria = new eu.eudat.elastic.criteria.DmpCriteria(); - dmpElasticCriteria.setLike(tableRequest.getCriteria().getLike()); - dmpElasticCriteria.setAllowAllVersions(false); - dmpElasticCriteria.setPublic(!isAuthenticated); - dmpElasticCriteria.setOffset(tableRequest.getDmpOffset()); - dmpElasticCriteria.setSize(tableRequest.getLength()); - if (isAuthenticated) { - dmpElasticCriteria.setCollaborators(Collections.singletonList(principal.getId())); - } - dmpElasticCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(tableRequest.getOrderings())); - dmps = apiContext.getOperationsContext().getElasticRepository().getDmpRepository().query(dmpElasticCriteria); - }catch (Exception e) { - logger.warn(e.getMessage(), e); - dmps = null; - } - } - - if (dmps != null && !dmps.isEmpty()) { - List finalDmps = dmps; - dmpList = dataManagementPlanRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDmps.stream().map(Dmp::getId).collect(Collectors.toList()))).distinct(); - } else { - dmpList = dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria).distinct(); - PaginationService.applyOrder(dmpList, tableRequest.getOrderings()); - dmpList.skip(tableRequest.getDmpOffset()).take(tableRequest.getLength()); - } - - if (datasets != null && !datasets.isEmpty()) { - List finalDatasets = datasets; - datasetList = datasetRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList()))); - } else { - datasetList = datasetRepository.getWithCriteria(datasetCriteria); - } - IntStream.range(0, tableRequest.getOrderings().getFields().size()).filter(i -> tableRequest.getOrderings().getFields().get(i).contains("publishedAt")) - .forEach(i -> tableRequest.getOrderings().getFields().set(i, tableRequest.getOrderings().getFields().get(i).toCharArray()[0] + "dmp:publishedAt|join|")); - // tableRequest.getOrderings().getFields().stream().filter(s -> s.contains("publishedAt")).forEach(s -> s = s.toCharArray()[0] + "dmp:publishedAt|join|" ); - /*for (int i = 0; i< tableRequest.getOrderings().getFields().size(); i++) { - if (tableRequest.getOrderings().getFields().get(i).contains("publishedAt")) { - String newField = tableRequest.getOrderings().getFields().get(i).toCharArray()[0] + "dmp:publishedAt|join|"; - tableRequest.getOrderings().getFields().set(i, newField); - } - }*/ - /*if (tableRequest.getOrderings().getFields().get(0).contains("publishedAt")) { - tableRequest.getOrderings().getFields().set(0, tableRequest.getOrderings().getFields().get(0).charAt(0) + "dmp:" + tableRequest.getOrderings().getFields().get(0).substring(1) + "|join|"); - }*/ - PaginationService.applyOrder(datasetList, tableRequest.getOrderings()); - datasetList.skip(tableRequest.getDatasetOffset()).take(tableRequest.getLength()); - - if (isAuthenticated) { - - List roles = new LinkedList<>(); - roles.add(UserDMP.UserDMPRoles.USER.getValue()); - roles.add(UserDMP.UserDMPRoles.OWNER.getValue()); - dmpList = dataManagementPlanRepository.getAuthenticated(dmpList, principal.getId(), roles); - datasetList = datasetRepository.getAuthenticated(datasetList, user, roles).distinct(); - - } - - - - /*CompletableFuture future = CompletableFuture.runAsync(() -> */{ - List dmps1 = dmpList.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) - .distinct().toList(); - recentActivityModels.addAll(dmps1.stream().map(dmp -> { - DatasetCriteria datasetCriteria1 = new DatasetCriteria(); - datasetCriteria1.setDmpIds(Collections.singletonList(dmp.getId())); - datasetCriteria1.setAllVersions(false); - if (isAuthenticated) { - dmp.setDataset(retrieveRelevantDatasets(datasetCriteria1, principal.getId())); - } else { - datasetCriteria1.setIsPublic(true); - dmp.setDataset(retrieveRelevantDatasets(datasetCriteria1)); - } - return new RecentDmpModel().fromDataModel(dmp); - }).collect(Collectors.toList())); - - List recentDatasetModels = datasetList - .withHint(HintedModelFactory.getHint(DatasetListingModel.class)) - .select(item -> new RecentDatasetModel().fromEntity(item)); - recentActivityModels.addAll(recentDatasetModels); - }/*);*/ + //GK: Use the managers to get the data in order to be better synced with other lists + DataManagementPlanTableRequest dataManagementPlanTableRequest = new DataManagementPlanTableRequest(); + dataManagementPlanTableRequest.setCriteria(dataManagementPlanCriteria); + dataManagementPlanTableRequest.setOrderings(tableRequest.getOrderings()); + dataManagementPlanTableRequest.setLength(tableRequest.getLength()); + dataManagementPlanTableRequest.setOffset(tableRequest.getDmpOffset()); + DataTableData dmps = this.dataManagementPlanManager.getPaged(dataManagementPlanTableRequest, principal, "listing"); + recentActivityModels.addAll(dmps.getData().stream().map(dataManagementPlanListingModel -> new RecentDmpModel().fromDataModel(dataManagementPlanListingModel.toDataModel())).collect(Collectors.toList())); + DatasetTableRequest datasetTableRequest = new DatasetTableRequest(); + datasetCriteria.setCollaborators(new ArrayList<>()); + datasetTableRequest.setCriteria(datasetCriteria); + datasetTableRequest.setOrderings(tableRequest.getOrderings()); + datasetTableRequest.getOrderings().getFields().addAll(datasetTableRequest.getOrderings().getFields().stream().filter(s -> s.contains("publishedAt")).map(s -> s.charAt(0) + "dmp:" + s.substring(1) + "|join|").collect(Collectors.toList())); + datasetTableRequest.getOrderings().getFields().removeIf(s -> s.contains("publishedAt") && !s.endsWith("|join|")); + datasetTableRequest.setLength(tableRequest.getLength()); + datasetTableRequest.setOffset(tableRequest.getDatasetOffset()); + DataTableData datasets = this.datasetManager.getPaged(datasetTableRequest, principal); + recentActivityModels.addAll(datasets.getData().stream().map(datasetListingModel -> new RecentDatasetModel().fromDataModel(datasetListingModel.toDataModel())).collect(Collectors.toList())); //GK: Shuffle the deck otherwise we will summon the DMPodia when sorting with status /*int pos = -1; @@ -355,25 +262,23 @@ public class DashBoardManager { }*/ //GK: No one likes to play shuffle with the recent activities. So just re-sort them based on how they have been sorted already + String order = tableRequest.getOrderings().getFields().get(0).toCharArray()[0] + ""; + String field = tableRequest.getOrderings().getFields().get(0).substring(1); + if (field.contains(":") && field.contains("|")) { + field = field.substring(field.lastIndexOf(":") + 1, field.indexOf("|")); + } + field = field.equals("label") ? "title" : field; + field = field.substring(0, 1).toUpperCase() + field.substring(1); + String finalField = field; recentActivityModels = recentActivityModels.stream().sorted((o1, o2) -> { try { - String order = tableRequest.getOrderings().getFields().get(0).toCharArray()[0] + ""; - String field = tableRequest.getOrderings().getFields().get(0).substring(1); - if (field.contains(":") && field.contains("|")) { - field = field.substring(field.lastIndexOf(":") + 1, field.indexOf("|")); - } - field = field.equals("label") ? "title" : field; - field = field.substring(0, 1).toUpperCase() + field.substring(1); - return (order.equals("+") ? 1 : -1 ) * ((Comparable)o1.getClass().getMethod("get" + field).invoke(o1)).compareTo(o2.getClass().getMethod("get" + field).invoke(o2)); + return (order.equals("+") ? 1 : -1 ) * ((Comparable)o1.getClass().getMethod("get" + finalField).invoke(o1)).compareTo(o2.getClass().getMethod("get" + finalField).invoke(o2)); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { logger.error(e.getLocalizedMessage(), e); } return 0; }).collect(Collectors.toList()); - //CompletableFuture.allOf(future).join(); - // CompletableFuture.allOf(dmps, datasets).join(); - return recentActivityModels; } @@ -435,38 +340,4 @@ public class DashBoardManager { return searchBarItems; } - - private Set retrieveRelevantDatasets(DatasetCriteria datasetCriteria) { - return retrieveRelevantDatasets(datasetCriteria, null); - } - - private Set retrieveRelevantDatasets (DatasetCriteria datasetCriteria, UUID principal) { - QueryableList datasetItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria); - if (principal != null) { - UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal); - List roles = new ArrayList<>(); - roles.add(0); - roles.add(1); - datasetItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getAuthenticated(datasetItems, userInfo, roles); - } - Long maxDatasets = datasetItems.distinct().count(); - DatasetTableRequest datasetTableRequest = new DatasetTableRequest(); - datasetTableRequest.setOffset(0); - datasetTableRequest.setLength(3); - Set datasetsSet = new LinkedHashSet<>(); - try { - datasetItems = PaginationManager.applyPaging(datasetItems, datasetTableRequest); - List datasets = datasetItems.distinct().toList(); - datasetsSet.addAll(datasets); - for (int i = 0; i < maxDatasets - datasets.size(); i++) { - Dataset fakedataset = new Dataset(); - fakedataset.setId(UUID.randomUUID()); - datasetsSet.add(fakedataset); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - - return datasetsSet; - } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentActivityModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentActivityModel.java index 3c168b4a4..10b30b87b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentActivityModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentActivityModel.java @@ -11,17 +11,13 @@ import java.util.List; public abstract class RecentActivityModel implements DataModel { private String id; private String title; - private String description; private Date created; private Date modified; private int status; private int version; private String grant; - private String grantAbbreviation; - private String grantId; private Date finalizedAt; private Date publishedAt; - private DatasetProfileOverviewModel profile; private int type; private List users; private Boolean isPublic; @@ -42,14 +38,6 @@ public abstract class RecentActivityModel { private String dmp; private String dmpId; - private String dataRepositories; - private String registries; - private String services; public String getDmp() { return dmp; @@ -33,51 +26,20 @@ public class RecentDatasetModel extends RecentActivityModel new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList())) : ""); this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : ""); this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : ""); - this.setRegistries(LabelBuilder.getLabel(entity.getRegistries().stream().map(item -> new eu.eudat.models.data.dataset.Registry().fromDataModel(item)).collect(Collectors.toList()))); - this.setServices(LabelBuilder.getLabel(entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()))); this.setPublic(entity.getDmp().isPublic()); this.setUsers(entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); return this; @@ -87,16 +49,12 @@ public class RecentDatasetModel extends RecentActivityModel { - private String doi; private Map extraProperties; private List datasets; - private List associatedProfiles; - private String organisations; private UUID groupId; - - public String getDoi() { - return doi; - } - - public void setDoi(String doi) { - this.doi = doi; - } - public Map getExtraProperties() { return extraProperties; } @@ -46,22 +31,6 @@ public class RecentDmpModel extends RecentActivityModel { this.datasets = datasets; } - public List getAssociatedProfiles() { - return associatedProfiles; - } - - public void setAssociatedProfiles(List associatedProfiles) { - this.associatedProfiles = associatedProfiles; - } - - public String getOrganisations() { - return organisations; - } - - public void setOrganisations(String organisations) { - this.organisations = organisations; - } - public UUID getGroupId() { return groupId; } @@ -76,22 +45,15 @@ public class RecentDmpModel extends RecentActivityModel { this.setType(RecentActivityType.DMP.getIndex()); this.setId(entity.getId().toString()); this.setTitle(entity.getLabel()); - this.setDescription(entity.getDescription()); this.setCreated(entity.getCreated()); this.setModified(entity.getModified()); this.setStatus(entity.getStatus()); this.setVersion(entity.getVersion()); - //this.datasets = entity.getDataset().stream().map(dataset -> new RecentDatasetModel().fromDmpEntity(dataset)).collect(Collectors.toList()); this.datasets = entity.getDataset().stream().map(dataset -> new DatasetUrlListing().fromDataModel(dataset)).collect(Collectors.toList()); - this.associatedProfiles = entity.getAssociatedDmps().stream().map(item -> new AssociatedProfile().fromData(item)).collect(Collectors.toList()); this.setFinalizedAt(entity.getFinalizedAt()); this.setGrant(entity.getGrant().getLabel()); - this.setGrantAbbreviation(entity.getGrant().getAbbreviation()); - this.setGrantId(entity.getGrant().getId().toString()); this.groupId = entity.getGroupId(); this.setPublic(entity.isPublic()); - this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList())); - //if (entity.getProfile() != null) this.setProfile(new DatasetProfileOverviewModel().fromDataModel(entity.getProfile())); this.setPublishedAt(entity.getPublishedAt()); this.setUsers(entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); return this; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetprofile/DatasetProfileOverviewModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetprofile/DatasetProfileOverviewModel.java index 8e84655c6..58d837f77 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetprofile/DatasetProfileOverviewModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetprofile/DatasetProfileOverviewModel.java @@ -31,8 +31,11 @@ public class DatasetProfileOverviewModel implements DataModel datasets; -// private List associatedProfiles; private List users; - private String description; - // private String grantAbbreviation; - // private String grantId; private Date finalizedAt; private Boolean isPublic; private Date publishedAt; @@ -63,13 +49,6 @@ public class DataManagementPlanListingModel implements DataModel getAssociatedProfiles() { - return associatedProfiles; - } - public void setAssociatedProfiles(List associatedProfiles) { - this.associatedProfiles = associatedProfiles; - }*/ - public List getUsers() { return users; } @@ -133,27 +98,6 @@ public class DataManagementPlanListingModel implements DataModel new AssociatedProfile().fromData(item)).collect(Collectors.toList()); return this; } @@ -205,33 +148,37 @@ public class DataManagementPlanListingModel implements DataModel new Organisation().fromDataModel(item)).collect(Collectors.toList())); this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); - this.description = entity.getDescription(); -// this.grantAbbreviation = entity.getGrant().getAbbreviation(); -// this.grantId = entity.getGrant().getId().toString(); this.finalizedAt = entity.getFinalizedAt(); this.isPublic = entity.isPublic(); this.publishedAt = entity.getPublishedAt(); - /*if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.associatedProfiles = new LinkedList<>(); - for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); - this.associatedProfiles.add(associatedProfile); - } - }*/ - return this; } @Override public DMP toDataModel() { - return null; + DMP entity = new DMP(); + entity.setId(UUID.fromString(this.getId())); + entity.setLabel(this.getLabel()); + entity.setGroupId(this.getGroupId()); + entity.setStatus(Integer.valueOf(this.getStatus()).shortValue()); + entity.setCreated(this.getCreationTime()); + entity.setFinalizedAt(this.getFinalizedAt()); + entity.setModified(this.getModifiedTime()); + entity.setPublic(this.getPublic()); + entity.setPublishedAt(this.getPublishedAt()); + entity.setVersion(this.getVersion()); + + entity.setDataset(this.getDatasets().stream().map(DatasetUrlListing::toDataModel).collect(Collectors.toCollection(LinkedHashSet::new))); + Grant grant = new Grant(); + grant.setLabel(this.getGrant()); + entity.setGrant(grant); + entity.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet())); + return entity; } @Override diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java index 45e751963..1932b96ea 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java @@ -1,15 +1,14 @@ package eu.eudat.models.data.listingmodels; +import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.Dataset; +import eu.eudat.data.entities.Grant; import eu.eudat.models.DataModel; -import eu.eudat.models.data.dataset.DataRepository; -import eu.eudat.models.data.dataset.Service; -import eu.eudat.logic.utilities.helpers.LabelBuilder; -import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; @@ -19,22 +18,15 @@ public class DatasetListingModel implements DataModel users; private Boolean isPublic; - private Boolean isProfileLatestVersion; public String getId() { return id; @@ -71,35 +63,6 @@ public class DatasetListingModel implements DataModel new eu.eudat.models.data.dataset.Registry().fromDataModel(item)).collect(Collectors.toList())); - // this.dataRepositories = LabelBuilder.getLabel(entity.getDatasetDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList())); - //this.services = LabelBuilder.getLabel(entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList())); if (entity.getFinalizedAt() == null && entity.getStatus() == Dataset.Status.FINALISED.getValue()) { this.finalizedAt = entity.getDmp().getFinalizedAt(); } else { @@ -218,7 +153,27 @@ public class DatasetListingModel implements DataModel { } @Override - public Dataset toDataModel() throws Exception { - return null; + public Dataset toDataModel() { + Dataset entity = new Dataset(); + entity.setId(UUID.fromString(this.getUrl())); + entity.setLabel(this.getLabel()); + return entity; } @Override