Skip to content

Commit 3175b1a

Browse files
authored
Merge pull request #4067 from kofzera/delete_applications_bulk
feat(core): delete applications method
2 parents ee82635 + a873ae5 commit 3175b1a

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
@@ -16401,6 +16401,23 @@ paths:
1640116401
default:
1640216402
$ref: '#/components/responses/ExceptionResponse'
1640316403

16404+
16405+
/urlinjsonout/registrarManager/deleteApplications:
16406+
post:
16407+
tags:
16408+
- RegistrarManager
16409+
operationId: deleteApplications
16410+
summary: Manually deletes multiple applications at once.
16411+
description: |
16412+
Expected to be called as a result of direct VO administrator action in the web UI.
16413+
parameters:
16414+
- $ref: '#/components/parameters/ids'
16415+
responses:
16416+
'200':
16417+
$ref: '#/components/responses/VoidResponse'
16418+
default:
16419+
$ref: '#/components/responses/ExceptionResponse'
16420+
1640416421
/json/registrarManager/sendMessage:
1640516422
post:
1640616423
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
@@ -1250,6 +1250,35 @@ public void testHandleGroupApplications() throws PerunException {
12501250
assertEquals(user, group1Apps.get(0).getUser());
12511251
}
12521252

1253+
@Test
1254+
public void testDeleteApplications() throws PerunException {
1255+
User user1 = new User(-1, "User1", "Test1", "", "", "");
1256+
User user2 = new User(-2, "User2", "Test2", "", "", "");
1257+
User user3 = new User(-3, "User3", "Test3", "", "", "");
1258+
user1 = perun.getUsersManagerBl().createUser(session, user1);
1259+
user2 = perun.getUsersManagerBl().createUser(session, user2);
1260+
user3 = perun.getUsersManagerBl().createUser(session, user3);
1261+
1262+
Application application1 = prepareApplicationToVo(user1);
1263+
Application application2 = prepareApplicationToVo(user2);
1264+
Application application3 = prepareApplicationToVo(user3);
1265+
registrarManager.submitApplication(session, application1, new ArrayList<>());
1266+
registrarManager.submitApplication(session, application2, new ArrayList<>());
1267+
registrarManager.submitApplication(session, application3, new ArrayList<>());
1268+
1269+
1270+
application1.setState(Application.AppState.REJECTED);
1271+
application2.setState(Application.AppState.REJECTED);
1272+
application3.setState(Application.AppState.REJECTED);
1273+
1274+
1275+
registrarManager.deleteApplications(session, List.of(application1, application2));
1276+
1277+
List<Integer> applicationIds = registrarManager.getApplicationsForVo(session, vo, List.of("APPROVED", "NEW", "VERIFIED", "REJECTED"), false).stream().map(Application::getId).toList();
1278+
assertEquals(1, applicationIds.size());
1279+
assertThat(applicationIds).containsOnly(application3.getId());
1280+
}
1281+
12531282
@Test
12541283
public void testRejectApplicationsAfterMemberRemoval() throws PerunException {
12551284
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)