Optimize Dashboard's recent activity logic, removed various unused fields from Listing Models and implement toDataModel conversion logic in some models

This commit is contained in:
George Kalampokis 2022-02-21 17:16:32 +02:00
parent 71b1010ea1
commit b6c28be3b3
10 changed files with 106 additions and 435 deletions

View File

@ -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<ResponseItem<List<RecentActivityModel>>> 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<RecentActivityModel> statistics = dashBoardManager.getNewRecentActivity(tableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RecentActivityModel>>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
}

View File

@ -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<RecentActivityModel> getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) {
public List<RecentActivityModel> getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) throws Exception {
boolean isAuthenticated = principal.getId() != null;
List<RecentActivityModel> recentActivityModels = new ArrayList<>();
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
List<RecentActivityModel> 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<DMP> dmpList;
QueryableList<Dataset> datasetList;
List<eu.eudat.elastic.entities.Dataset> datasets = null;
List<eu.eudat.elastic.entities.Dmp> 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<Dmp> 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<eu.eudat.elastic.entities.Dataset> 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<Integer> 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<DMP> 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<RecentActivityModel> 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<DataManagementPlanListingModel> 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<DatasetListingModel> 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<Dataset> retrieveRelevantDatasets(DatasetCriteria datasetCriteria) {
return retrieveRelevantDatasets(datasetCriteria, null);
}
private Set<Dataset> retrieveRelevantDatasets (DatasetCriteria datasetCriteria, UUID principal) {
QueryableList<Dataset> datasetItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria);
if (principal != null) {
UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal);
List<Integer> 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<Dataset> datasetsSet = new LinkedHashSet<>();
try {
datasetItems = PaginationManager.applyPaging(datasetItems, datasetTableRequest);
List<Dataset> 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;
}
}

View File

@ -11,17 +11,13 @@ import java.util.List;
public abstract class RecentActivityModel<T extends DataEntity, S extends DataModel> implements DataModel<T, S> {
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<UserInfoListingModel> users;
private Boolean isPublic;
@ -42,14 +38,6 @@ public abstract class RecentActivityModel<T extends DataEntity, S extends DataMo
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreated() {
return created;
}
@ -90,22 +78,6 @@ public abstract class RecentActivityModel<T extends DataEntity, S extends DataMo
this.grant = grant;
}
public String getGrantAbbreviation() {
return grantAbbreviation;
}
public void setGrantAbbreviation(String grantAbbreviation) {
this.grantAbbreviation = grantAbbreviation;
}
public String getGrantId() {
return grantId;
}
public void setGrantId(String grantId) {
this.grantId = grantId;
}
public Date getFinalizedAt() {
return finalizedAt;
}
@ -122,14 +94,6 @@ public abstract class RecentActivityModel<T extends DataEntity, S extends DataMo
this.publishedAt = publishedAt;
}
public DatasetProfileOverviewModel getProfile() {
return profile;
}
public void setProfile(DatasetProfileOverviewModel profile) {
this.profile = profile;
}
public int getType() {
return type;
}

View File

@ -1,10 +1,6 @@
package eu.eudat.models.data.dashboard.recent.model;
import eu.eudat.data.entities.Dataset;
import eu.eudat.logic.utilities.helpers.LabelBuilder;
import eu.eudat.models.data.dataset.DataRepository;
import eu.eudat.models.data.dataset.Service;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import java.util.Date;
@ -13,9 +9,6 @@ import java.util.stream.Collectors;
public class RecentDatasetModel extends RecentActivityModel<Dataset, RecentDatasetModel> {
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<Dataset, RecentDatas
this.dmpId = dmpId;
}
public String getDataRepositories() {
return dataRepositories;
}
public void setDataRepositories(String dataRepositories) {
this.dataRepositories = dataRepositories;
}
public String getRegistries() {
return registries;
}
public void setRegistries(String registries) {
this.registries = registries;
}
public String getServices() {
return services;
}
public void setServices(String services) {
this.services = services;
}
@Override
public RecentActivityModel fromEntity(Dataset entity) {
this.setType(RecentActivityType.DATASET.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.getDmp() != null ? entity.getDmp().getVersion(): 0);
this.setFinalizedAt(entity.getFinalizedAt());
this.setGrantAbbreviation(entity.getDmp() != null ? entity.getDmp().getGrant().getAbbreviation() : "");
this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date());
this.setGrantId(entity.getDmp() != null ? entity.getDmp().getGrant().getId().toString() : "");
this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()): null);
this.setGrant(entity.getDmp() != null ? entity.getDmp().getGrant().getLabel() : "");
this.setDataRepositories(entity.getDatasetDataRepositories() != null && !entity.getDatasetDataRepositories().isEmpty()? LabelBuilder.getLabel(entity.getDatasetDataRepositories().stream().map(item -> 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<Dataset, RecentDatas
this.setType(RecentActivityType.DATASET.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.getDmp() != null ? entity.getDmp().getVersion(): 0);
this.setFinalizedAt(entity.getFinalizedAt());
this.setGrantAbbreviation(entity.getDmp() != null ? entity.getDmp().getGrant().getAbbreviation() : "");
this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date());
this.setGrantId(entity.getDmp() != null ? entity.getDmp().getGrant().getId().toString() : "");
this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null);
this.setGrant(entity.getDmp() != null ? entity.getDmp().getGrant().getLabel() : "");
this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : "");
this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : "");

View File

@ -1,9 +1,6 @@
package eu.eudat.models.data.dashboard.recent.model;
import eu.eudat.data.entities.DMP;
import eu.eudat.logic.utilities.helpers.LabelBuilder;
import eu.eudat.models.data.dmp.AssociatedProfile;
import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.urls.DatasetUrlListing;
@ -14,22 +11,10 @@ import java.util.UUID;
import java.util.stream.Collectors;
public class RecentDmpModel extends RecentActivityModel<DMP, RecentDmpModel> {
private String doi;
private Map<String, Object> extraProperties;
private List<DatasetUrlListing> datasets;
private List<AssociatedProfile> associatedProfiles;
private String organisations;
private UUID groupId;
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public Map<String, Object> getExtraProperties() {
return extraProperties;
}
@ -46,22 +31,6 @@ public class RecentDmpModel extends RecentActivityModel<DMP, RecentDmpModel> {
this.datasets = datasets;
}
public List<AssociatedProfile> getAssociatedProfiles() {
return associatedProfiles;
}
public void setAssociatedProfiles(List<AssociatedProfile> 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<DMP, RecentDmpModel> {
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;

View File

@ -31,8 +31,11 @@ public class DatasetProfileOverviewModel implements DataModel<DatasetProfile, Da
}
@Override
public DatasetProfile toDataModel() throws Exception {
return null;
public DatasetProfile toDataModel() {
DatasetProfile entity = new DatasetProfile();
entity.setId(this.getId());
entity.setLabel(this.getLabel());
return entity;
}
@Override

View File

@ -1,20 +1,12 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.data.entities.Grant;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.dmp.AssociatedProfile;
import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.logic.utilities.helpers.LabelBuilder;
import eu.eudat.models.data.urls.DatasetUrlListing;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Date;
import java.util.LinkedList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -24,19 +16,13 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
private String id;
private String label;
private String grant;
// private String profile;
private Date creationTime;
private Date modifiedTime;
//private String organisations;
private int version;
private int status;
private UUID groupId;
private List<DatasetUrlListing> datasets;
// private List<AssociatedProfile> associatedProfiles;
private List<UserInfoListingModel> 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<DMP, DataManage
this.grant = grant;
}
/* public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}*/
public Date getCreationTime() {
return creationTime;
}
@ -84,13 +63,6 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
this.modifiedTime = modifiedTime;
}
/*public String getOrganisations() {
return organisations;
}
public void setOrganisations(String organisations) {
this.organisations = organisations;
}*/
public int getVersion() {
return version;
}
@ -119,13 +91,6 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
this.status = status;
}
/*public List<AssociatedProfile> getAssociatedProfiles() {
return associatedProfiles;
}
public void setAssociatedProfiles(List<AssociatedProfile> associatedProfiles) {
this.associatedProfiles = associatedProfiles;
}*/
public List<UserInfoListingModel> getUsers() {
return users;
}
@ -133,27 +98,6 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
this.users = users;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
/*public String getGrantAbbreviation() {
return grantAbbreviation;
}
public void setGrantAbbreviation(String grantAbbreviation) {
this.grantAbbreviation = grantAbbreviation;
}*/
/*public String getGrantId() {
return grantId;
}
public void setGrantId(String grantId) {
this.grantId = grantId;
}*/
public Date getFinalizedAt() {
return finalizedAt;
}
@ -188,7 +132,6 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.creationTime = entity.getCreated();
// this.associatedProfiles = entity.getAssociatedDmps().stream().map(item -> new AssociatedProfile().fromData(item)).collect(Collectors.toList());
return this;
}
@ -205,33 +148,37 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
this.status = entity.getStatus();
this.version = entity.getVersion();
this.grant = entity.getGrant().getLabel();
/*if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel(); */
this.creationTime = entity.getCreated();
this.modifiedTime = entity.getModified();
// this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> 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

View File

@ -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<Dataset, DatasetListingMod
private String grant;
private String dmp;
private String dmpId;
private DatasetProfileOverviewModel profile;
private String dataRepositories;
private String registries;
private String services;
private int status;
private Date created;
private Date modified;
private String description;
private String grantAbbreviation;
private String grantId;
private Date finalizedAt;
private Date dmpPublishedAt;
private int version;
private List<UserInfoListingModel> users;
private Boolean isPublic;
private Boolean isProfileLatestVersion;
public String getId() {
return id;
@ -71,35 +63,6 @@ public class DatasetListingModel implements DataModel<Dataset, DatasetListingMod
this.dmpId = dmpId;
}
public DatasetProfileOverviewModel getProfile() {
return profile;
}
public void setProfile(DatasetProfileOverviewModel profile) {
this.profile = profile;
}
public String getDataRepositories() {
return dataRepositories;
}
public void setDataRepositories(String dataRepositories) {
this.dataRepositories = dataRepositories;
}
public String getRegistries() {
return registries;
}
public void setRegistries(String registries) {
this.registries = registries;
}
public String getServices() {
return services;
}
public void setServices(String services) {
this.services = services;
}
public int getStatus() {
return status;
}
@ -128,20 +91,6 @@ public class DatasetListingModel implements DataModel<Dataset, DatasetListingMod
this.description = description;
}
public String getGrantAbbreviation() {
return grantAbbreviation;
}
public void setGrantAbbreviation(String grantAbbreviation) {
this.grantAbbreviation = grantAbbreviation;
}
public String getGrantId() {
return grantId;
}
public void setGrantId(String grantId) {
this.grantId = grantId;
}
public Date getFinalizedAt() {
return finalizedAt;
}
@ -179,14 +128,6 @@ public class DatasetListingModel implements DataModel<Dataset, DatasetListingMod
isPublic = aPublic;
}
public Boolean getProfileLatestVersion() {
return isProfileLatestVersion;
}
public void setProfileLatestVersion(Boolean profileLatestVersion) {
isProfileLatestVersion = profileLatestVersion;
}
@Override
public DatasetListingModel fromDataModel(Dataset entity) {
this.id = entity.getId() != null ? entity.getId().toString() : "";
@ -196,14 +137,8 @@ public class DatasetListingModel implements DataModel<Dataset, DatasetListingMod
this.grant = entity.getDmp() != null ? entity.getDmp().getGrant().getLabel() : "";
this.dmp = entity.getDmp() != null ? entity.getDmp().getLabel() : "";
this.dmpId = entity.getDmp() != null ? entity.getDmp().getId().toString() : "";
this.profile = entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null;
this.description = entity.getDescription();
this.status = entity.getStatus();
//this.grantAbbreviation = entity.getDmp() != null ? entity.getDmp().getGrant().getAbbreviation() : "";
// this.grantId = entity.getDmp() != null ? entity.getDmp().getGrant().getId().toString() : "";
//this.registries = LabelBuilder.getLabel(entity.getRegistries().stream().map(item -> 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<Dataset, DatasetListingMod
@Override
public Dataset toDataModel() {
return null;
Dataset entity = new Dataset();
entity.setId(UUID.fromString(this.getId()));
entity.setLabel(this.getLabel());
entity.setCreated(this.getCreated());
entity.setModified(this.getModified());
entity.setDescription(this.getDescription());
entity.setFinalizedAt(this.getFinalizedAt());
entity.setStatus(Integer.valueOf(this.getStatus()).shortValue());
DMP dmp = new DMP();
Grant grant = new Grant();
grant.setLabel(this.getGrant());
dmp.setGrant(grant);
dmp.setLabel(this.getDmp());
dmp.setId(UUID.fromString(this.getDmpId()));
dmp.setPublishedAt(this.getDmpPublishedAt());
dmp.setVersion(this.getVersion());
dmp.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet()));
dmp.setPublic(this.getPublic());
dmp.setFinalizedAt(this.getFinalizedAt());
entity.setDmp(dmp);
return entity;
}
@Override

View File

@ -51,8 +51,15 @@ public class UserInfoListingModel implements DataModel<UserDMP, UserInfoListingM
}
@Override
public UserDMP toDataModel() throws Exception {
return null;
public UserDMP toDataModel() {
UserDMP entity = new UserDMP();
entity.setId(this.getId());
entity.setRole(this.getRole());
UserInfo userInfo = new UserInfo();
userInfo.setName(this.getName());
userInfo.setEmail(this.getEmail());
entity.setUser(userInfo);
return entity;
}
@Override

View File

@ -2,6 +2,8 @@ package eu.eudat.models.data.urls;
import eu.eudat.data.entities.Dataset;
import java.util.UUID;
/**
* Created by ikalyvas on 7/23/2018.
*/
@ -14,8 +16,11 @@ public class DatasetUrlListing extends UrlListing<Dataset, DatasetUrlListing> {
}
@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