dmp finalize changes
This commit is contained in:
parent
5d24a38472
commit
498ffca73d
|
@ -76,6 +76,7 @@ public final class Permission {
|
|||
public static String CreateNewVersionDmp = "CreateNewVersionDmp";
|
||||
public static String ExportDmp = "ExportDmp";
|
||||
public static String FinalizeDmp = "FinalizeDmp";
|
||||
public static String UndoFinalizeDmp = "UndoFinalizeDmp";
|
||||
public static String AssignDmpUsers = "AssignDmpUsers";
|
||||
public static String InviteDmpUsers = "InviteDmpUsers";
|
||||
|
||||
|
|
|
@ -817,6 +817,7 @@ public class DmpServiceImpl implements DmpService {
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
if (dmp == null){
|
||||
|
@ -827,27 +828,22 @@ public class DmpServiceImpl implements DmpService {
|
|||
throw new MyApplicationException("DMP is already finalized");
|
||||
}
|
||||
|
||||
if (!this.conventionService.isListNullOrEmpty(descriptionIds)){
|
||||
List<DescriptionEntity> descriptionsToBeFinalised = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(descriptionIds).dmpIds(id).isActive(IsActive.Active).collect();
|
||||
for (DescriptionEntity description: descriptionsToBeFinalised) {
|
||||
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).dmpIds(id).isActive(IsActive.Active).collect();
|
||||
|
||||
for (DescriptionEntity description: descriptions) {
|
||||
if (descriptionIds.contains(description.getId())){
|
||||
// description to be finalized
|
||||
if (description.getStatus().equals(DescriptionStatus.Finalized)){
|
||||
throw new MyApplicationException("Description is already finalized");
|
||||
}
|
||||
}
|
||||
description.setStatus(DescriptionStatus.Finalized);
|
||||
description.setUpdatedAt(Instant.now());
|
||||
description.setFinalizedAt(Instant.now());
|
||||
this.entityManager.merge(description);
|
||||
}
|
||||
|
||||
List<DescriptionEntity> descriptionsToBeCanceled = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).excludedIds(descriptionIds).dmpIds(id).isActive(IsActive.Active).collect();
|
||||
for (DescriptionEntity description: descriptionsToBeCanceled) {
|
||||
} else if (description.getStatus().equals(DescriptionStatus.Draft)) {
|
||||
// description to be canceled
|
||||
description.setStatus(DescriptionStatus.Canceled);
|
||||
}
|
||||
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");
|
||||
this.deleterFactory.deleter(DescriptionDeleter.class).delete(List.of(description), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -862,6 +858,7 @@ public class DmpServiceImpl implements DmpService {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
if (dmp == null){
|
||||
|
@ -872,6 +869,11 @@ public class DmpServiceImpl implements DmpService {
|
|||
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.setUpdatedAt(Instant.now());
|
||||
|
||||
|
|
|
@ -404,6 +404,19 @@ permissions:
|
|||
clients: [ ]
|
||||
allowAnonymous: false
|
||||
allowAuthenticated: false
|
||||
UndoFinalizeDmp:
|
||||
roles:
|
||||
- Admin
|
||||
dmp:
|
||||
roles:
|
||||
- Owner
|
||||
- User
|
||||
- DescriptionContributor
|
||||
- Reviewer
|
||||
claims: [ ]
|
||||
clients: [ ]
|
||||
allowAnonymous: false
|
||||
allowAuthenticated: false
|
||||
AssignDmpUsers:
|
||||
roles:
|
||||
- Admin
|
||||
|
|
Loading…
Reference in New Issue