From a45dec7a5fa38fe9dfdf2f70a2bfcb82c70484ee Mon Sep 17 00:00:00 2001 From: amentis Date: Tue, 12 Mar 2024 18:47:57 +0200 Subject: [PATCH] fix backend dmp user and dashboard ui fixes --- .../eu/eudat/service/dmp/DmpServiceImpl.java | 49 ++++++++++++------- .../prefilling-source-editor.component.ts | 3 ++ .../app/ui/dashboard/dashboard.component.html | 6 +-- .../ui/dashboard/drafts/drafts.component.html | 4 +- .../ui/dashboard/drafts/drafts.component.ts | 15 +++++- .../recent-edited-activity.component.ts | 10 +++- ...edited-description-activity.component.html | 4 +- ...t-edited-description-activity.component.ts | 24 ++++----- .../recent-edited-dmp-activity.component.html | 10 ++-- .../recent-edited-dmp-activity.component.ts | 17 +++++-- 10 files changed, 95 insertions(+), 47 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index 2a752368d..a092d4604 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -192,16 +192,32 @@ public class DmpServiceImpl implements DmpService { this.annotationEntityTouchedIntegrationEventHandler.handle(AnnotationEntityTouchedIntegrationEventHandler.buildEventFromPersistModel(model)); this.sendNotification(data); - - this.elasticService.persistDmp(data); if (!this.conventionService.isListNullOrEmpty(model.getUsers())){ this.inviteUsers(data.getId(), model.getUsers()); + }else{ + this.assignUsers(data.getId(), new ArrayList<>(), null); + this.addOwner(data); } + + this.elasticService.persistDmp(data); return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data); } + private void addOwner(DmpEntity dmpEntity) throws InvalidApplicationException { + DmpUserEntity data = new DmpUserEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setUpdatedAt(Instant.now()); + data.setRole(DmpUserRole.Owner); + data.setUserId(userScope.getUserId()); + data.setDmpId(dmpEntity.getId()); + + this.entityManager.persist(data); + } + private void sendNotification(DmpEntity dmp) throws InvalidApplicationException { List existingUsers = this.queryFactory.query(DmpUserQuery.class) .dmpIds(dmp.getId()) @@ -539,7 +555,6 @@ public class DmpServiceImpl implements DmpService { Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); DmpEntity data; - DmpUserEntity dmpUserEntity = new DmpUserEntity(); if (isUpdate) { data = this.entityManager.find(DmpEntity.class, model.getId()); if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -560,14 +575,6 @@ public class DmpServiceImpl implements DmpService { data.setBlueprintId(model.getBlueprint()); data.setIsActive(IsActive.Active); data.setCreatedAt(Instant.now()); - - dmpUserEntity.setId(UUID.randomUUID()); - dmpUserEntity.setDmpId(data.getId()); - dmpUserEntity.setUserId(userScope.getUserId()); - dmpUserEntity.setRole(DmpUserRole.Owner); - dmpUserEntity.setCreatedAt(Instant.now()); - dmpUserEntity.setUpdatedAt(Instant.now()); - dmpUserEntity.setIsActive(IsActive.Active); } data.setLabel(model.getLabel()); @@ -580,7 +587,6 @@ public class DmpServiceImpl implements DmpService { this.entityManager.merge(data); else { this.entityManager.persist(data); - this.entityManager.persist(dmpUserEntity); } this.entityManager.flush(); @@ -804,6 +810,7 @@ public class DmpServiceImpl implements DmpService { throw new InvalidApplicationException("Dmp does not exist!"); } + List usersToAssign = new ArrayList<>(); for (DmpUserPersist user :users) { UUID userId = null; if (user.getUser() != null){ @@ -816,7 +823,7 @@ public class DmpServiceImpl implements DmpService { } if (userId != null){ user.setUser(userId); - this.assignUsers(id, List.of(user), null); + usersToAssign.add(user); if (this.userScope.getUserId() != userId){ this.sendDmpInvitationExistingUser(user.getUser(), dmp, user.getRole()); } @@ -825,6 +832,7 @@ public class DmpServiceImpl implements DmpService { } } + if(!usersToAssign.isEmpty()) this.assignUsers(id, usersToAssign, null); } private void sendDmpInvitationExistingUser(UUID userId, DmpEntity dmp, DmpUserRole role) throws InvalidApplicationException { @@ -908,10 +916,17 @@ public class DmpServiceImpl implements DmpService { } DmpInvitationEntity dmpInvitation = this.xmlHandlingService.fromXmlSafe(DmpInvitationEntity.class, action.getData()); - DmpUserPersist model = new DmpUserPersist(); - model.setUser(this.userScope.getUserIdSafe()); - model.setRole(dmpInvitation.getRole()); - this.assignUsers(dmpInvitation.getDmpId(), List.of(model), null); + + DmpUserEntity data = new DmpUserEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setUpdatedAt(Instant.now()); + data.setRole(dmpInvitation.getRole()); + data.setUserId(this.userScope.getUserIdSafe()); + data.setDmpId(dmpInvitation.getDmpId()); + this.entityManager.persist(data); + action.setStatus(ActionConfirmationStatus.Accepted); this.entityManager.merge(action); } diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts index 2549da858..11cc9cb54 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts @@ -184,6 +184,9 @@ export class PrefillingSourceEditorComponent extends BaseEditor
{{'DASHBOARD.EMPTY-LIST' | translate}}
- - + +
{{'DASHBOARD.EMPTY-LIST' | translate}}
- +
{{'GENERAL.ACTIONS.NO-MORE-AVAILABLE' | translate}} diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-description-activity/recent-edited-description-activity.component.ts b/dmp-frontend/src/app/ui/dashboard/recent-edited-description-activity/recent-edited-description-activity.component.ts index a9f39ee5a..c0d755343 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-description-activity/recent-edited-description-activity.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-description-activity/recent-edited-description-activity.component.ts @@ -7,10 +7,11 @@ import { DescriptionTemplate } from '@app/core/model/description-template/descri import { Description } from '@app/core/model/description/description'; import { Dmp, DmpUser } from '@app/core/model/dmp/dmp'; import { DmpReference } from '@app/core/model/dmp/dmp-reference'; +import { ReferenceType } from '@app/core/model/reference-type/reference-type'; import { Reference } from '@app/core/model/reference/reference'; -import { DescriptionLookup } from '@app/core/query/description.lookup'; +import { RecentActivityItemLookup } from '@app/core/query/recent-activity-item-lookup.lookup'; import { AuthService } from '@app/core/services/auth/auth.service'; -import { DescriptionService } from '@app/core/services/description/description.service'; +import { DashboardService } from '@app/core/services/dashboard/dashboard.service'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; import { BaseComponent } from '@common/base/base.component'; @@ -24,7 +25,7 @@ import { nameof } from 'ts-simple-nameof'; }) export class RecentEditedDescriptionActivityComponent extends BaseComponent implements OnInit { - lookup: DescriptionLookup = new DescriptionLookup(); + lookup: RecentActivityItemLookup = new RecentActivityItemLookup(); pageSize: number = 5; listingItems: Description[]; @@ -48,7 +49,7 @@ export class RecentEditedDescriptionActivityComponent extends BaseComponent impl private router: Router, public enumUtils: EnumUtils, private authentication: AuthService, - private descriptionService: DescriptionService, + private dashboardService: DashboardService, private location: Location, private matomoService: MatomoService ) { @@ -98,7 +99,7 @@ export class RecentEditedDescriptionActivityComponent extends BaseComponent impl } updateUrl() { - let parameters = "?type=dmps" + + let parameters = "?type=descriptions" + (this.page != 1 ? "&page=" + this.page : "") + //TODO refactor //(((this.formGroup.get("order").value != this.order.MODIFIED && !this.publicMode) || (this.formGroup.get("order").value != this.order.PUBLISHED && this.publicMode)) ? "&order=" + this.formGroup.get("order").value : "") + @@ -115,7 +116,7 @@ export class RecentEditedDescriptionActivityComponent extends BaseComponent impl this.formGroup.get('order').setValue(this.order.UpdatedAt); } this.lookup.page = { size: this.pageSize, offset: 0 }; - this.lookup.order = { items: ['-' + this.formGroup.get('order').value] }; + this.lookup.orderField = this.formGroup.get('order').value; this.lookup.like = this.formGroup.get('like').value; this.lookup.project = { @@ -136,17 +137,18 @@ export class RecentEditedDescriptionActivityComponent extends BaseComponent impl [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.id)].join('.'), [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.id)].join('.'), [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.label)].join('.'), - [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.type)].join('.'), + [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.type), nameof(x => x.id)].join('.'), [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.reference)].join('.'), + [nameof(x => x.dmp), nameof(x => x.dmpReferences), nameof(x => x.reference), nameof(x => x.isActive)].join('.'), ] }; - this.descriptionService - .query(this.lookup) + this.dashboardService + .getMyRecentActivityItems(this.lookup) .pipe(takeUntil(this._destroyed)) .subscribe(response => { - this.listingItems = response.items; - this.totalCount = response.count; + this.listingItems = response.map(x => x.description); + // this.totalCount = response.count; //this.totalCountDmps.emit(this.dmpActivities.length); diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.html b/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.html index dc5d56ba9..519620897 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.html +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.html @@ -4,10 +4,10 @@ {{'DMP-LISTING.SORT-BY' | translate}}: - {{enumUtils.toRecentActivityOrderString(order.MODIFIED)}} - {{enumUtils.toRecentActivityOrderString(order.PUBLISHED)}} - {{enumUtils.toRecentActivityOrderString(order.LABEL)}} - {{enumUtils.toRecentActivityOrderString(order.STATUS)}} + {{enumUtils.toRecentActivityOrderString(order.UpdatedAt)}} + + {{enumUtils.toRecentActivityOrderString(order.Label)}} + {{enumUtils.toRecentActivityOrderString(order.Status)}} @@ -24,7 +24,7 @@
- +