statistics changes

This commit is contained in:
Efstratios Giannopoulos 2023-12-06 14:18:19 +02:00
parent bee0e9f152
commit 85bd0de2d5
4 changed files with 43 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.ReferenceType; import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.PublicReference; import eu.eudat.model.PublicReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
@ -36,6 +37,9 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
private Collection<UUID> excludedIds; private Collection<UUID> excludedIds;
private DmpReferenceQuery dmpReferenceQuery;
private Collection<UUID> referenceTypeIds; private Collection<UUID> referenceTypeIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@ -135,6 +139,11 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
return this; return this;
} }
public ReferenceQuery dmpReferenceSubQuery(DmpReferenceQuery value) {
this.dmpReferenceQuery = value;
return this;
}
public ReferenceQuery authorize(EnumSet<AuthorizationFlags> values) { public ReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
@ -151,7 +160,7 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.referenceTypes) || this.isEmpty(this.referenceSourceTypes); return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.referenceTypes) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery);
} }
@Override @Override
@ -193,6 +202,10 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
notInClause.value(item); notInClause.value(item);
predicates.add(notInClause.not()); predicates.add(notInClause.not());
} }
if (this.dmpReferenceQuery != null) {
QueryContext<DmpReferenceEntity, UUID> subQuery = this.applySubQuery(this.dmpReferenceQuery, queryContext, UUID.class, root -> root.get(DmpReferenceEntity._referenceId));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._id)).value(subQuery.Query));
}
if (!predicates.isEmpty()) { if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray); return queryContext.CriteriaBuilder.and(predicatesArray);

View File

@ -146,8 +146,12 @@ public class DashboardServiceImpl implements DashboardService {
DashboardStatistics statistics = new DashboardStatistics(); DashboardStatistics statistics = new DashboardStatistics();
statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(Public)).count()); statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(Public)).count());
statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(Public)).count()); statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(Public)).count());
statistics.setOrganizationCount(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).dmpSubQuery(dmpQuery).referenceSubQuery(this.queryFactory.query(ReferenceQuery.class).types(ReferenceType.Organizations).isActive(IsActive.Active)).authorize(EnumSet.of(Public)).count()); statistics.setOrganizationCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Organizations).authorize(EnumSet.of(Public))
statistics.setDmpCount(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).dmpSubQuery(dmpQuery).referenceSubQuery(this.queryFactory.query(ReferenceQuery.class).types(ReferenceType.Grants).isActive(IsActive.Active)).authorize(EnumSet.of(Public)).count()); .dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
statistics.setGrantCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Grants).authorize(EnumSet.of(Public))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(); cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue();
cacheValue.setPublic(true); cacheValue.setPublic(true);
cacheValue.setDashboardStatistics(statistics); cacheValue.setDashboardStatistics(statistics);
@ -166,13 +170,17 @@ public class DashboardServiceImpl implements DashboardService {
dmpUserLookup.userIds(this.userScope.getUserId()); dmpUserLookup.userIds(this.userScope.getUserId());
dmpUserLookup.isActives(IsActive.Active); dmpUserLookup.isActives(IsActive.Active);
DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active).dmpUserSubQuery(dmpUserLookup).versionStatuses(DmpVersionStatus.Current).statuses(DmpStatus.Finalized); DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active).dmpUserSubQuery(dmpUserLookup).versionStatuses(DmpVersionStatus.Current);
DashboardStatistics statistics = new DashboardStatistics(); DashboardStatistics statistics = new DashboardStatistics();
statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(Owner)).count()); statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(AuthorizationFlags.DmpAssociated)).count());
statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(Owner)).count()); statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(AuthorizationFlags.DmpAssociated)).count());
statistics.setOrganizationCount(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).dmpSubQuery(dmpQuery).referenceSubQuery(this.queryFactory.query(ReferenceQuery.class).types(ReferenceType.Organizations).isActive(IsActive.Active)).authorize(EnumSet.of(Owner)).count()); statistics.setOrganizationCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Organizations).authorize(EnumSet.of(Owner))
statistics.setDmpCount(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).dmpSubQuery(dmpQuery).referenceSubQuery(this.queryFactory.query(ReferenceQuery.class).types(ReferenceType.Grants).isActive(IsActive.Active)).authorize(EnumSet.of(Owner)).count()); .dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
statistics.setGrantCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Grants).authorize(EnumSet.of(Owner))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(this.userScope.getUserId()); cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(this.userScope.getUserId());
cacheValue.setPublic(false); cacheValue.setPublic(false);

View File

@ -44,7 +44,7 @@ public class DashboardController {
@PostMapping("/mine/recent-activity") @PostMapping("mine/recent-activity")
public List<RecentActivityItem> getMyRecentActivityItems(@RequestBody RecentActivityItemLookup lookup) throws InvalidApplicationException { public List<RecentActivityItem> getMyRecentActivityItems(@RequestBody RecentActivityItemLookup lookup) throws InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + User.class.getSimpleName()).And("lookup", lookup)); logger.debug(new MapLogEntry("retrieving" + User.class.getSimpleName()).And("lookup", lookup));

View File

@ -49,6 +49,14 @@ public class DmpMigrationService {
List<DMP> items; List<DMP> items;
do { do {
items = dmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); items = dmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
List<DMP> finalItems = items;
List<DMP> groupDmps = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(finalItems.stream().map(DMP::getGroupId).distinct())).toList();
Map<UUID, List<DMP>> groupDmpMap = new HashMap<>();
for (DMP dmp: groupDmps) {
if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>());
groupDmpMap.get(dmp.getGroupId()).add(dmp);
}
if (items != null && !items.isEmpty()) { if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dmp " + page * PageSize + " of " + total); logger.debug("Migrate Dmp " + page * PageSize + " of " + total);
@ -57,6 +65,8 @@ public class DmpMigrationService {
DataManagementPlan model = new DataManagementPlan(); DataManagementPlan model = new DataManagementPlan();
model.fromDataModel(item); model.fromDataModel(item);
List<DMP> itemGroupDmps = groupDmpMap.get(item.getGroupId());
DMP currentVersionDmp = itemGroupDmps.stream().max(Comparator.comparing(DMP::getVersion)).orElseThrow();
DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity(); DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity();
dmpProperties.setDmpBlueprintValues(new ArrayList<>()); dmpProperties.setDmpBlueprintValues(new ArrayList<>());
@ -69,8 +79,7 @@ public class DmpMigrationService {
if (model.getCreator() != null && model.getCreator().getId() != null) { if (model.getCreator() != null && model.getCreator().getId() != null) {
data.setCreatorId(model.getCreator().getId()); data.setCreatorId(model.getCreator().getId());
} else { } else {
List<DMP> groupDmps = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(List.of(item.getGroupId()))).toList(); for (DMP groupDmp: itemGroupDmps) {
for (DMP groupDmp: groupDmps) {
DataManagementPlan groupDmpModel = new DataManagementPlan(); DataManagementPlan groupDmpModel = new DataManagementPlan();
groupDmpModel.fromDataModel(groupDmp); groupDmpModel.fromDataModel(groupDmp);
if (groupDmpModel.getCreator() != null) { if (groupDmpModel.getCreator() != null) {
@ -81,7 +90,7 @@ public class DmpMigrationService {
} }
data.setGroupId(model.getGroupId()); data.setGroupId(model.getGroupId());
data.setVersion((short) model.getVersion()); data.setVersion((short) model.getVersion());
data.setVersionStatus(DmpVersionStatus.of((short) model.getVersionStatus())); data.setVersionStatus(currentVersionDmp.getId().equals(item.getId()) ? DmpVersionStatus.Current: DmpVersionStatus.Previous);
if (model.getCreated() != null) if (model.getCreated() != null)
data.setCreatedAt(model.getCreated().toInstant()); data.setCreatedAt(model.getCreated().toInstant());
if (model.getModified() != null) if (model.getModified() != null)