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

This commit is contained in:
Sofia Papacharalampous 2024-03-15 13:01:56 +02:00
commit c479d86ee4
3 changed files with 30 additions and 14 deletions

View File

@ -76,6 +76,7 @@ public final class Permission {
public static String CreateNewVersionDmp = "CreateNewVersionDmp"; public static String CreateNewVersionDmp = "CreateNewVersionDmp";
public static String ExportDmp = "ExportDmp"; public static String ExportDmp = "ExportDmp";
public static String FinalizeDmp = "FinalizeDmp"; public static String FinalizeDmp = "FinalizeDmp";
public static String UndoFinalizeDmp = "UndoFinalizeDmp";
public static String AssignDmpUsers = "AssignDmpUsers"; public static String AssignDmpUsers = "AssignDmpUsers";
public static String InviteDmpUsers = "InviteDmpUsers"; public static String InviteDmpUsers = "InviteDmpUsers";

View File

@ -817,6 +817,7 @@ public class DmpServiceImpl implements DmpService {
} }
public void finalize(UUID id, List<UUID> descriptionIds) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException { public void finalize(UUID id, List<UUID> descriptionIds) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.FinalizeDmp);
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).first(); DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).first();
if (dmp == null){ if (dmp == null){
@ -827,27 +828,22 @@ public class DmpServiceImpl implements DmpService {
throw new MyApplicationException("DMP is already finalized"); throw new MyApplicationException("DMP is already finalized");
} }
if (!this.conventionService.isListNullOrEmpty(descriptionIds)){ List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(id).isActive(IsActive.Active).collect();
List<DescriptionEntity> descriptionsToBeFinalised = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(descriptionIds).dmpIds(id).isActive(IsActive.Active).collect();
for (DescriptionEntity description: descriptionsToBeFinalised) { for (DescriptionEntity description: descriptions) {
if (descriptionIds.contains(description.getId())){
// description to be finalized
if (description.getStatus().equals(DescriptionStatus.Finalized)){ if (description.getStatus().equals(DescriptionStatus.Finalized)){
throw new MyApplicationException("Description is already finalized"); throw new MyApplicationException("Description is already finalized");
} }
description.setStatus(DescriptionStatus.Finalized); description.setStatus(DescriptionStatus.Finalized);
description.setUpdatedAt(Instant.now()); description.setUpdatedAt(Instant.now());
description.setFinalizedAt(Instant.now()); description.setFinalizedAt(Instant.now());
this.entityManager.merge(description); this.entityManager.merge(description);
} } else if (description.getStatus().equals(DescriptionStatus.Draft)) {
// description to be canceled
List<DescriptionEntity> descriptionsToBeCanceled = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).excludedIds(descriptionIds).dmpIds(id).isActive(IsActive.Active).collect();
for (DescriptionEntity description: descriptionsToBeCanceled) {
description.setStatus(DescriptionStatus.Canceled); description.setStatus(DescriptionStatus.Canceled);
} this.deleterFactory.deleter(DescriptionDeleter.class).delete(List.of(description), true);
this.deleterFactory.deleter(DescriptionDeleter.class).delete(descriptionsToBeCanceled, true);
} else {
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(descriptionIds).dmpIds(id).statuses(DescriptionStatus.Finalized).isActive(IsActive.Active).collect();
if (descriptions == null){
throw new MyApplicationException("Dmp don't have Finalized Descriptions");
} }
} }
@ -862,6 +858,7 @@ public class DmpServiceImpl implements DmpService {
} }
public void undoFinalize(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException { public void undoFinalize(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException {
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.UndoFinalizeDmp);
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).firstAs(fields); DmpEntity dmp = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id).isActive(IsActive.Active).firstAs(fields);
if (dmp == null){ if (dmp == null){
@ -872,6 +869,11 @@ public class DmpServiceImpl implements DmpService {
throw new MyApplicationException("DMP is already drafted"); throw new MyApplicationException("DMP is already drafted");
} }
EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).types(EntityType.DMP).entityIds(dmp.getId());
if (entityDoiQuery != null && entityDoiQuery.count() > 0){
throw new MyApplicationException("DMP is deposited");
}
dmp.setStatus(DmpStatus.Draft); dmp.setStatus(DmpStatus.Draft);
dmp.setUpdatedAt(Instant.now()); dmp.setUpdatedAt(Instant.now());

View File

@ -404,6 +404,19 @@ permissions:
clients: [ ] clients: [ ]
allowAnonymous: false allowAnonymous: false
allowAuthenticated: false allowAuthenticated: false
UndoFinalizeDmp:
roles:
- Admin
dmp:
roles:
- Owner
- User
- DescriptionContributor
- Reviewer
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
AssignDmpUsers: AssignDmpUsers:
roles: roles:
- Admin - Admin