Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-04-05 11:11:49 +03:00
commit f0ec8b5fae
6 changed files with 52 additions and 22 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.OwnedResource; import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.*; import eu.eudat.commons.enums.*;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.dashborad.RecentActivityItemEntity; import eu.eudat.commons.types.dashborad.RecentActivityItemEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
@ -41,6 +42,7 @@ public class DashboardServiceImpl implements DashboardService {
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final UserScope userScope; private final UserScope userScope;
private final TenantScope tenantScope;
private final DashboardServiceProperties config; private final DashboardServiceProperties config;
private final ElasticQueryHelperService elasticQueryHelperService; private final ElasticQueryHelperService elasticQueryHelperService;
private final DashboardStatisticsCacheService dashboardStatisticsCacheService; private final DashboardStatisticsCacheService dashboardStatisticsCacheService;
@ -49,13 +51,15 @@ public class DashboardServiceImpl implements DashboardService {
ConventionService conventionService, AuthorizationService authorizationService, ConventionService conventionService, AuthorizationService authorizationService,
BuilderFactory builderFactory, BuilderFactory builderFactory,
QueryFactory queryFactory, QueryFactory queryFactory,
UserScope userScope, UserScope userScope,
TenantScope tenantScope,
DashboardServiceProperties config, ElasticQueryHelperService elasticQueryHelperService, DashboardStatisticsCacheService dashboardStatisticsCacheService) { DashboardServiceProperties config, ElasticQueryHelperService elasticQueryHelperService, DashboardStatisticsCacheService dashboardStatisticsCacheService) {
this.conventionService = conventionService; this.conventionService = conventionService;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.userScope = userScope; this.userScope = userScope;
this.tenantScope = tenantScope;
this.config = config; this.config = config;
this.elasticQueryHelperService = elasticQueryHelperService; this.elasticQueryHelperService = elasticQueryHelperService;
this.dashboardStatisticsCacheService = dashboardStatisticsCacheService; this.dashboardStatisticsCacheService = dashboardStatisticsCacheService;
@ -138,7 +142,7 @@ public class DashboardServiceImpl implements DashboardService {
public DashboardStatistics getMyDashboardStatistics() throws InvalidApplicationException { public DashboardStatistics getMyDashboardStatistics() throws InvalidApplicationException {
this.authorizationService.authorizeAtLeastOneForce(this.userScope.getUserIdSafe() != null ? List.of(new OwnedResource(this.userScope.getUserIdSafe())) : null); this.authorizationService.authorizeAtLeastOneForce(this.userScope.getUserIdSafe() != null ? List.of(new OwnedResource(this.userScope.getUserIdSafe())) : null);
DashboardStatisticsCacheService.DashboardStatisticsCacheValue cacheValue = this.dashboardStatisticsCacheService.lookup(this.dashboardStatisticsCacheService.buildKey(this.userScope.getUserId().toString().toLowerCase(Locale.ROOT))); DashboardStatisticsCacheService.DashboardStatisticsCacheValue cacheValue = this.dashboardStatisticsCacheService.lookup(this.dashboardStatisticsCacheService.buildKey(this.dashboardStatisticsCacheService.generateUserTenantCacheKey(this.userScope.getUserId(), this.tenantScope.getTenantCode())));
if (cacheValue == null || cacheValue.getDashboardStatistics() == null) { if (cacheValue == null || cacheValue.getDashboardStatistics() == null) {
DmpUserQuery dmpUserLookup = this.queryFactory.query(DmpUserQuery.class); DmpUserQuery dmpUserLookup = this.queryFactory.query(DmpUserQuery.class);
dmpUserLookup.userIds(this.userScope.getUserId()); dmpUserLookup.userIds(this.userScope.getUserId());
@ -161,7 +165,7 @@ public class DashboardServiceImpl implements DashboardService {
statistics.getReferenceTypeStatistics().add(referenceTypeStatistics); statistics.getReferenceTypeStatistics().add(referenceTypeStatistics);
} }
} }
cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(this.userScope.getUserId()); cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(this.userScope.getUserId(), this.tenantScope.getTenantCode());
cacheValue.setPublic(false); cacheValue.setPublic(false);
cacheValue.setDashboardStatistics(statistics); cacheValue.setDashboardStatistics(statistics);
this.dashboardStatisticsCacheService.put(cacheValue); this.dashboardStatisticsCacheService.put(cacheValue);

View File

@ -1,5 +1,6 @@
package eu.eudat.service.dashborad; package eu.eudat.service.dashborad;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.model.DashboardStatistics; import eu.eudat.model.DashboardStatistics;
import gr.cite.tools.cache.CacheService; import gr.cite.tools.cache.CacheService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -19,12 +20,14 @@ public class DashboardStatisticsCacheService extends CacheService<DashboardStati
this.isPublic = true; this.isPublic = true;
} }
public DashboardStatisticsCacheValue(UUID userId) { public DashboardStatisticsCacheValue(UUID userId, String tenantCode) {
this.userId = userId; this.userId = userId;
this.tenantCode = tenantCode;
this.isPublic = false; this.isPublic = false;
} }
private UUID userId; private UUID userId;
private String tenantCode;
private boolean isPublic; private boolean isPublic;
private DashboardStatistics dashboardStatistics; private DashboardStatistics dashboardStatistics;
@ -37,6 +40,14 @@ public class DashboardStatisticsCacheService extends CacheService<DashboardStati
this.userId = userId; this.userId = userId;
} }
public String getTenantCode() {
return tenantCode;
}
public void setTenantCode(String tenantCode) {
this.tenantCode = tenantCode;
}
public DashboardStatistics getDashboardStatistics() { public DashboardStatistics getDashboardStatistics() {
return dashboardStatistics; return dashboardStatistics;
} }
@ -71,7 +82,7 @@ public class DashboardStatisticsCacheService extends CacheService<DashboardStati
if (value.isPublic) return this.buildKey(publicKey); if (value.isPublic) return this.buildKey(publicKey);
else throw new IllegalArgumentException("Key not set"); else throw new IllegalArgumentException("Key not set");
} else { } else {
return this.buildKey(value.userId.toString().toLowerCase(Locale.ROOT)); return this.buildKey(this.generateUserTenantCacheKey(value.userId, value.tenantCode));
} }
} }
@ -80,4 +91,14 @@ public class DashboardStatisticsCacheService extends CacheService<DashboardStati
keyParts.put("$key$", key); keyParts.put("$key$", key);
return this.generateKey(keyParts); return this.generateKey(keyParts);
} }
public String generateUserTenantCacheKey(UUID userId, String tenantCode) {
StringBuilder builder = new StringBuilder();
builder.append(userId.toString().toLowerCase(Locale.ROOT));
if (tenantCode != null) {
builder.append("_");
builder.append(tenantCode.toLowerCase(Locale.ROOT));
}
return builder.toString();
}
} }

View File

@ -594,7 +594,7 @@ export class DescriptionEditorComponent extends BaseEditor<DescriptionEditorMode
const commonDescriptions = descriptions.filter(x => x.dmpDescriptionTemplate.descriptionTemplateGroupId == sectionDescriptionTemplate.descriptionTemplateGroupId); const commonDescriptions = descriptions.filter(x => x.dmpDescriptionTemplate.descriptionTemplateGroupId == sectionDescriptionTemplate.descriptionTemplateGroupId);
if (commonDescriptions && commonDescriptions.length >= sectionDescriptionTemplate.maxMultiplicity) { if (commonDescriptions && commonDescriptions.length >= sectionDescriptionTemplate.maxMultiplicity) {
rejectedDmpDescriptionTemplates = commonDescriptions.map(x => x.dmpDescriptionTemplate); rejectedDmpDescriptionTemplates.push.apply(rejectedDmpDescriptionTemplates, commonDescriptions.map(x => x.dmpDescriptionTemplate));
} }
} }
}) })

View File

@ -96,17 +96,11 @@
</li> </li>
</ol> </ol>
<ul *ngIf="item.id && section.hasTemplates && canEditSection(section.id) && !formGroup.disabled" class="add-description-option"> <ul *ngIf="item.id && section.hasTemplates && canEditSection(section.id) && !formGroup.disabled" class="add-description-option">
<li *ngIf="canAddDescription(section)"> <li>
<a class="add-description-action" [routerLink]="['/descriptions/edit/' + item.id + '/' + section.id]"> <a class="add-description-action" [ngClass]="{'drag-handle-disabled': !canAddDescription(section)}" [routerLink]="canAddDescription(section) ? ['/descriptions/edit/' + item.id + '/' + section.id] : null">
<mat-icon>add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}} <mat-icon [matTooltipDisabled]="canAddDescription(section)" [matTooltip]="'DMP-EDITOR.DESCRIPTION-TEMPLATES-MAX-MULTIPLICITY' | translate">add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
</a> </a>
</li> </li>
<li *ngIf="!canAddDescription(section)">
<a [ngClass]="{'drag-handle-disabled': true}" class="add-description-action">
<mat-icon>add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
</a>
<small class="text-danger">{{'DMP-EDITOR.DESCRIPTION-TEMPLATES-MAX-MULTIPLICITY'| translate}}</small>
</li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -172,12 +172,18 @@ export class DmpEditorComponent extends BaseEditor<DmpEditorModel, Dmp> implemen
prepareForm(data: Dmp) { prepareForm(data: Dmp) {
try { try {
this.editorModel = data ? new DmpEditorModel().fromModel(data) : new DmpEditorModel(); this.editorModel = data ? new DmpEditorModel().fromModel(data) : new DmpEditorModel();
if (data && data.descriptions) { if (data) {
if (data.status == DmpStatus.Finalized) { if(data.descriptions){
data.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized); if (data.status == DmpStatus.Finalized) {
} else { data.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized);
data.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status !== DescriptionStatus.Canceled); } else {
data.descriptions = data.descriptions.filter(x => x.isActive === IsActive.Active && x.status !== DescriptionStatus.Canceled);
}
} }
if(data.dmpDescriptionTemplates){
data.dmpDescriptionTemplates = data.dmpDescriptionTemplates.filter(x => x.isActive === IsActive.Active);
}
} }
this.item = data; this.item = data;
@ -413,7 +419,7 @@ export class DmpEditorComponent extends BaseEditor<DmpEditorModel, Dmp> implemen
// //
// //
public descriptionsInSection(sectionId: Guid) { public descriptionsInSection(sectionId: Guid) {
return this.item?.descriptions?.filter(x => x?.dmpDescriptionTemplate?.sectionId === sectionId) || []; return this.item?.descriptions?.filter(x => x.isActive == IsActive.Active && x?.dmpDescriptionTemplate?.sectionId === sectionId && x.dmpDescriptionTemplate.isActive == IsActive.Active) || [];
} }
editDescription(id: string, isNew: boolean) { editDescription(id: string, isNew: boolean) {
@ -456,6 +462,10 @@ export class DmpEditorComponent extends BaseEditor<DmpEditorModel, Dmp> implemen
if (section.descriptionTemplates?.length > 0){ if (section.descriptionTemplates?.length > 0){
const descriptions = this.descriptionsInSection(section.id) const descriptions = this.descriptionsInSection(section.id)
if (this.item.dmpDescriptionTemplates.filter(x => x.sectionId == section.id).length > descriptions.map(x => x.dmpDescriptionTemplate).length){
return true;
}
let multiplicityValidResults :boolean[] = []; let multiplicityValidResults :boolean[] = [];
section.descriptionTemplates.forEach(sectionDescriptionTemplate => { section.descriptionTemplates.forEach(sectionDescriptionTemplate => {
if (sectionDescriptionTemplate.maxMultiplicity != null){ if (sectionDescriptionTemplate.maxMultiplicity != null){

View File

@ -62,6 +62,7 @@ export class DmpEditorResolver extends BaseEditorResolver {
[nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.id)].join('.'), [nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.id)].join('.'),
[nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.sectionId)].join('.'), [nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.sectionId)].join('.'),
[nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.descriptionTemplateGroupId)].join('.'), [nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.descriptionTemplateGroupId)].join('.'),
[nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.dmpDescriptionTemplate), nameof<DmpDescriptionTemplate>(x => x.isActive)].join('.'),
[nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'), [nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'),
[nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'), [nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'),