Created a new Recent Activity model and backend end-point that contains more details about it's objects

This commit is contained in:
George Kalampokis 2020-06-30 16:59:06 +03:00
parent 1cec40a4da
commit f821938542
6 changed files with 411 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.logic.managers.DashBoardManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.dashboard.recent.RecentActivity;
import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel;
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
import eu.eudat.models.data.helpers.responses.ResponseItem;
@ -15,6 +16,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.List;
@ -42,6 +44,14 @@ public class DashBoardController extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
}
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/recentActivity"}, produces = "application/json")
@Transactional
public ResponseEntity<ResponseItem<List<RecentActivityModel>>> getNewRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
List<RecentActivityModel> statistics = dashBoardManager.getNewRecentActivity(principal, numberOfActivities);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RecentActivityModel>>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
}
@RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json")
public ResponseEntity<ResponseItem<RecentActivity>> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) {
RecentActivity statistics = dashBoardManager.getRecentActivity(principal, numberOfActivities);

View File

@ -11,21 +11,27 @@ import eu.eudat.elastic.entities.Dmp;
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
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;
import eu.eudat.models.data.dashboard.recent.model.RecentDatasetModel;
import eu.eudat.models.data.dashboard.recent.model.RecentDmpModel;
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@ -175,6 +181,55 @@ public class DashBoardManager {
return activity;
}
@Transactional
public List<RecentActivityModel> getNewRecentActivity(Principal principal, Integer numberofactivities) {
List<RecentActivityModel> recentActivityModels = new ArrayList<>();
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
UserInfo user = new UserInfo();
user.setId(principal.getId());
DatasetCriteria datasetCriteria = new DatasetCriteria();
datasetCriteria.setAllVersions(false);
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
dataManagementPlanCriteria.setAllVersions(false);
QueryableList<DMP> dmpList;
QueryableList<Dataset> datasetList;
if (principal.getId() != null) {
List<Integer> roles = new LinkedList<>();
dmpList = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles);
datasetList = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles);
} else {
dataManagementPlanCriteria.setIsPublic(true);
dataManagementPlanCriteria.setOnlyPublic(true);
datasetCriteria.setIsPublic(true);
dmpList = dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria);
datasetList = datasetRepository.getWithCriteria(datasetCriteria);
}
CompletableFuture<List<RecentActivityModel>> dmps = dmpList
.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.take(numberofactivities)
.selectAsync(item -> {
return new RecentDmpModel().fromEntity(item);
})
.whenComplete((dmpActivities, throwable) -> recentActivityModels.addAll(dmpActivities));
CompletableFuture<List<RecentActivityModel>> datasets = datasetList
.withHint(HintedModelFactory.getHint(DatasetListingModel.class))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.take(numberofactivities)
.selectAsync(item -> {
return new RecentDatasetModel().fromEntity(item);
})
.whenComplete((datasetActivities, throwable) -> recentActivityModels.addAll(datasetActivities));
CompletableFuture.allOf(dmps, datasets).join();
return recentActivityModels.stream().sorted(Comparator.comparing(RecentActivityModel::getModified)).collect(Collectors.toList());
}
public List<SearchBarItem> searchUserData(String like, Principal principal) {
UserInfo user = new UserInfo();
user.setId(principal.getId());

View File

@ -0,0 +1,125 @@
package eu.eudat.models.data.dashboard.recent.model;
import java.util.Date;
public abstract class RecentActivityModel<T> {
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 String profile;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getGrant() {
return grant;
}
public void setGrant(String grant) {
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;
}
public void setFinalizedAt(Date finalizedAt) {
this.finalizedAt = finalizedAt;
}
public Date getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Date publishedAt) {
this.publishedAt = publishedAt;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public abstract RecentActivityModel fromEntity(T entity);
}

View File

@ -0,0 +1,100 @@
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.listingmodels.DatasetListingModel;
import java.util.Date;
import java.util.stream.Collectors;
public class RecentDatasetModel extends RecentActivityModel<Dataset> {
private String dmp;
private String dmpId;
private String dataRepositories;
private String registries;
private String services;
public String getDmp() {
return dmp;
}
public void setDmp(String dmp) {
this.dmp = dmp;
}
public String getDmpId() {
return dmpId;
}
public void setDmpId(String dmpId) {
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.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 ? entity.getProfile().getLabel() : "");
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())));
return this;
}
public RecentDatasetModel fromDmpEntity(Dataset entity) {
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 ? entity.getProfile().getLabel() : "");
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() : "");
return this;
}
}

View File

@ -0,0 +1,114 @@
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 javax.transaction.Transactional;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
public class RecentDmpModel extends RecentActivityModel<DMP> {
private String doi;
private Map<String, Object> extraProperties;
private List<RecentDatasetModel> datasets;
private List<AssociatedProfile> associatedProfiles;
private String organisations;
private UUID groupId;
private List<UserInfoListingModel> users;
private Boolean isPublic;
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public Map<String, Object> getExtraProperties() {
return extraProperties;
}
public void setExtraProperties(Map<String, Object> extraProperties) {
this.extraProperties = extraProperties;
}
public List<RecentDatasetModel> getDatasets() {
return datasets;
}
public void setDatasets(List<RecentDatasetModel> datasets) {
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;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public List<UserInfoListingModel> getUsers() {
return users;
}
public void setUsers(List<UserInfoListingModel> users) {
this.users = users;
}
public Boolean getPublic() {
return isPublic;
}
public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}
@Override
@Transactional
public RecentActivityModel fromEntity(DMP entity) {
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.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.isPublic = entity.isPublic();
this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()));
if (entity.getProfile() != null) this.setProfile(entity.getProfile().getLabel());
this.setPublishedAt(entity.getPublishedAt());
this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
return this;
}
}

View File

@ -24,4 +24,8 @@ export class DashboardService {
getUserStatistics(): Observable<DashboardStatisticsModel> {
return this.http.get<DashboardStatisticsModel>(this.actionUrl + 'me/getStatistics', { headers: this.headers });
}
getRecentAcitvity(): Observable<any[]> {
return this.http.get<any[]>(this.actionUrl + 'recentActivity', {headers: this.headers});
}
}