Skip to content

Commit a873ae5

Browse files
committed
feat(core): delete applications method
Added bulk method for deleting multiple applications at once.
1 parent f0d9024 commit a873ae5

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

perun-openapi/openapi.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16385,6 +16385,23 @@ paths:
1638516385
default:
1638616386
$ref: '#/components/responses/ExceptionResponse'
1638716387

16388+
16389+
/urlinjsonout/registrarManager/deleteApplications:
16390+
post:
16391+
tags:
16392+
- RegistrarManager
16393+
operationId: deleteApplications
16394+
summary: Manually deletes multiple applications at once.
16395+
description: |
16396+
Expected to be called as a result of direct VO administrator action in the web UI.
16397+
parameters:
16398+
- $ref: '#/components/parameters/ids'
16399+
responses:
16400+
'200':
16401+
$ref: '#/components/responses/VoidResponse'
16402+
default:
16403+
$ref: '#/components/responses/ExceptionResponse'
16404+
1638816405
/json/registrarManager/sendMessage:
1638916406
post:
1639016407
tags:

perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/RegistrarManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ public interface RegistrarManager {
267267
*/
268268
void deleteApplication(PerunSession session, Application application) throws PerunException;
269269

270+
/**
271+
* Manually deletes multiple applications at once. Expected to be called as a result of direct VO administrator action in the web UI.
272+
*
273+
* @param sess perun session
274+
* @param applications list of applications
275+
* @throws PerunException
276+
*/
277+
void deleteApplications(PerunSession sess, List<Application> applications) throws PerunException;
270278

271279
/**
272280
* Get page of applications for the given vo, with the given parameters

perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/impl/RegistrarManagerImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ public void deleteApplication(PerunSession sess, Application app) throws PerunEx
15721572
// lock to prevent concurrent runs
15731573
synchronized(runningDeleteApplication) {
15741574
if (runningDeleteApplication.contains(app.getId())) {
1575-
throw new AlreadyProcessingException("Application deletion is already processing.");
1575+
throw new AlreadyProcessingException("Application " + app.getId() + " deletion is already processing.");
15761576
} else {
15771577
runningDeleteApplication.add(app.getId());
15781578
}
@@ -1589,9 +1589,9 @@ public void deleteApplication(PerunSession sess, Application app) throws PerunEx
15891589

15901590
} else {
15911591
if (AppState.VERIFIED.equals(app.getState()))
1592-
throw new RegistrarException("Submitted application can't be deleted. Please reject the application first.");
1592+
throw new RegistrarException("Submitted application " + app.getId() + " can't be deleted. Please reject the application first.");
15931593
if (AppState.APPROVED.equals(app.getState()))
1594-
throw new RegistrarException("Approved application can't be deleted. Try to refresh the view to see changes.");
1594+
throw new RegistrarException("Approved application " + app.getId() + " can't be deleted. Try to refresh the view to see changes.");
15951595
}
15961596
perun.getAuditer().log(sess, new ApplicationDeleted(app));
15971597
log.info("Application {} deleted.", app.getId());
@@ -1604,6 +1604,13 @@ public void deleteApplication(PerunSession sess, Application app) throws PerunEx
16041604

16051605
}
16061606

1607+
@Override
1608+
public void deleteApplications(PerunSession sess, List<Application> applications) throws PerunException {
1609+
for (Application app : applications) {
1610+
deleteApplication(sess, app);
1611+
}
1612+
}
1613+
16071614
@Override
16081615
public Application verifyApplication(PerunSession sess, int appId) throws PerunException {
16091616

perun-registrar-lib/src/test/java/cz/metacentrum/perun/registrar/RegistrarBaseIntegrationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,35 @@ public void testHandleGroupApplications() throws PerunException {
12321232
assertEquals(user, group1Apps.get(0).getUser());
12331233
}
12341234

1235+
@Test
1236+
public void testDeleteApplications() throws PerunException {
1237+
User user1 = new User(-1, "User1", "Test1", "", "", "");
1238+
User user2 = new User(-2, "User2", "Test2", "", "", "");
1239+
User user3 = new User(-3, "User3", "Test3", "", "", "");
1240+
user1 = perun.getUsersManagerBl().createUser(session, user1);
1241+
user2 = perun.getUsersManagerBl().createUser(session, user2);
1242+
user3 = perun.getUsersManagerBl().createUser(session, user3);
1243+
1244+
Application application1 = prepareApplicationToVo(user1);
1245+
Application application2 = prepareApplicationToVo(user2);
1246+
Application application3 = prepareApplicationToVo(user3);
1247+
registrarManager.submitApplication(session, application1, new ArrayList<>());
1248+
registrarManager.submitApplication(session, application2, new ArrayList<>());
1249+
registrarManager.submitApplication(session, application3, new ArrayList<>());
1250+
1251+
1252+
application1.setState(Application.AppState.REJECTED);
1253+
application2.setState(Application.AppState.REJECTED);
1254+
application3.setState(Application.AppState.REJECTED);
1255+
1256+
1257+
registrarManager.deleteApplications(session, List.of(application1, application2));
1258+
1259+
List<Integer> applicationIds = registrarManager.getApplicationsForVo(session, vo, List.of("APPROVED", "NEW", "VERIFIED", "REJECTED"), false).stream().map(Application::getId).toList();
1260+
assertEquals(1, applicationIds.size());
1261+
assertThat(applicationIds).containsOnly(application3.getId());
1262+
}
1263+
12351264
@Test
12361265
public void testRejectApplicationsAfterMemberRemoval() throws PerunException {
12371266
GroupsManagerBl groupsManager = perun.getGroupsManagerBl();

perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/RegistrarManagerMethod.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,30 @@ public Object call(ApiCaller ac, Deserializer parms) throws PerunException {
840840

841841
},
842842

843+
844+
/*#
845+
* Manually delete multiple applications at once.
846+
* Expected to be called as a result of direct VO administrator action in the web UI.
847+
*
848+
* @param ids int[] List of Application IDs
849+
*/
850+
deleteApplications {
851+
852+
@Override
853+
public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
854+
parms.stateChangingCheck();
855+
856+
List<Application> applications = new ArrayList<>();
857+
List<Integer> appIds = parms.readList("ids", Integer.class);
858+
for (Integer id : appIds) {
859+
applications.add(ac.getRegistrarManager().getApplicationById(ac.getSession(), id));
860+
}
861+
ac.getRegistrarManager().deleteApplications(ac.getSession(), applications);
862+
return null;
863+
}
864+
865+
},
866+
843867
/*#
844868
* Manually approves an application.
845869
* Expected to be called as a result of direct VO administrator action in the web UI.

0 commit comments

Comments
 (0)