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 dcb99e942..5b375c49b 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 @@ -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().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } + @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/recentActivity"}, produces = "application/json") + @Transactional + public ResponseEntity>> getNewRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, + @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) { + List statistics = dashBoardManager.getNewRecentActivity(principal, numberOfActivities); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); + } + @RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json") public ResponseEntity> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) { RecentActivity statistics = dashBoardManager.getRecentActivity(principal, numberOfActivities); 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 50e45f103..eba7e1a58 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 @@ -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 getNewRecentActivity(Principal principal, Integer numberofactivities) { + List 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 dmpList; + QueryableList datasetList; + + if (principal.getId() != null) { + List 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> 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> 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 searchUserData(String like, Principal principal) { UserInfo user = new UserInfo(); user.setId(principal.getId()); 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 new file mode 100644 index 000000000..015c76af3 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentActivityModel.java @@ -0,0 +1,125 @@ +package eu.eudat.models.data.dashboard.recent.model; + +import java.util.Date; + +public abstract class RecentActivityModel { + 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); +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java new file mode 100644 index 000000000..58156453c --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java @@ -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 { + 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; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java new file mode 100644 index 000000000..9c28bdec2 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java @@ -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 { + private String doi; + private Map extraProperties; + private List datasets; + private List associatedProfiles; + private String organisations; + private UUID groupId; + private List users; + private Boolean isPublic; + + + public String getDoi() { + return doi; + } + + public void setDoi(String doi) { + this.doi = doi; + } + + public Map getExtraProperties() { + return extraProperties; + } + + public void setExtraProperties(Map extraProperties) { + this.extraProperties = extraProperties; + } + + public List getDatasets() { + return datasets; + } + + public void setDatasets(List datasets) { + 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; + } + + public void setGroupId(UUID groupId) { + this.groupId = groupId; + } + + public List getUsers() { + return users; + } + + public void setUsers(List 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; + } +} diff --git a/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts b/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts index 2046a1b20..b715942de 100644 --- a/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts +++ b/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts @@ -24,4 +24,8 @@ export class DashboardService { getUserStatistics(): Observable { return this.http.get(this.actionUrl + 'me/getStatistics', { headers: this.headers }); } + + getRecentAcitvity(): Observable { + return this.http.get(this.actionUrl + 'recentActivity', {headers: this.headers}); + } }