diff --git a/src/main/java/org/orph2020/pst/apiimpl/rest/AllocatedProposalResource.java b/src/main/java/org/orph2020/pst/apiimpl/rest/AllocatedProposalResource.java index c03f088..c7fb1d9 100644 --- a/src/main/java/org/orph2020/pst/apiimpl/rest/AllocatedProposalResource.java +++ b/src/main/java/org/orph2020/pst/apiimpl/rest/AllocatedProposalResource.java @@ -3,6 +3,7 @@ import jakarta.transaction.Transactional; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.ivoa.dm.proposal.management.AllocatedProposal; @@ -46,7 +47,7 @@ public AllocatedProposal getAllocatedProposal(@PathParam("cycleCode") Long cycle @PUT - @Operation(summary = "upgrade a proposal under review to an allocated proposal") + @Operation(summary = "upgrade a submitted proposal to an allocated proposal") @Consumes(MediaType.TEXT_PLAIN) @Transactional(rollbackOn = {WebApplicationException.class}) public ProposalSynopsis allocateProposalToCycle(@PathParam("cycleCode") Long cycleCode, @@ -54,8 +55,15 @@ public ProposalSynopsis allocateProposalToCycle(@PathParam("cycleCode") Long cyc throws WebApplicationException { AllocatedProposal allocatedProposal = new AllocatedProposal( - findChildByQuery(ProposalCycle.class, SubmittedProposal.class, - "submittedProposals", cycleCode, submittedId),new ArrayList<>()); + findChildByQuery( + ProposalCycle.class, + SubmittedProposal.class, + "submittedProposals", + cycleCode, + submittedId + ), + new ArrayList<>() //empty allocations list to be added to later + ); ProposalCycle cycle = findObject(ProposalCycle.class, cycleCode); @@ -66,6 +74,32 @@ public ProposalSynopsis allocateProposalToCycle(@PathParam("cycleCode") Long cyc return new ProposalSynopsis(allocatedProposal.getSubmitted()); } + //TODO: make this callable by a 'TAC Chair' user only + @DELETE + @Path("{allocatedId}") + @Operation(summary = "withdraw a previously allocated proposal from the cycle") + @Transactional(rollbackOn = {WebApplicationException.class}) + public Response withdrawAllocatedProposal(@PathParam("cycleCode") Long cycleCode, + @PathParam("allocatedId") Long allocatedId) + throws WebApplicationException { + + ProposalCycle cycle = findObject(ProposalCycle.class, cycleCode); + + AllocatedProposal allocatedProposal = findChildByQuery( + ProposalCycle.class, + AllocatedProposal.class, + "allocatedProposals", + cycleCode, + allocatedId + ); + + cycle.removeFromAllocatedProposals(allocatedProposal); + + em.merge(cycle); + + return Response.noContent().build(); + } + diff --git a/src/test/java/org/orph2020/pst/apiimpl/rest/UseCaseTacChairTest.java b/src/test/java/org/orph2020/pst/apiimpl/rest/UseCaseTacChairTest.java index 2084ae8..da19c84 100644 --- a/src/test/java/org/orph2020/pst/apiimpl/rest/UseCaseTacChairTest.java +++ b/src/test/java/org/orph2020/pst/apiimpl/rest/UseCaseTacChairTest.java @@ -13,9 +13,7 @@ import org.junit.jupiter.api.Test; import jakarta.inject.Inject; - -import java.util.Calendar; -import java.util.Date; +import java.util.List; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; @@ -46,9 +44,7 @@ void setup(){ "$.size()", greaterThanOrEqualTo(1) ) .extract().jsonPath().getLong("[0].dbid"); - raObjectMapper = new Jackson2Mapper(((type, charset) -> { - return mapper; - })); + raObjectMapper = new Jackson2Mapper(((type, charset) -> mapper)); TAC tac = given() @@ -87,7 +83,7 @@ void reviewProposal() throws JsonProcessingException { .extract().jsonPath().getLong("[0].dbid"); // the TAC member gets a proposal for review - SubmittedProposal revprop = given() + given() .when() .get("proposalCycles/" + cycleId + "/submittedProposals/" + revId) .then() @@ -142,7 +138,7 @@ void allocateProposal() throws JsonProcessingException { //Create a new AllocatedBlock //IMPL have chosen the first of everything here - in GUI each will be a list. - Integer gradeId = given() + int gradeId = given() .when() .get("proposalCycles/" + cycleId + "/grades") .then() @@ -161,7 +157,7 @@ void allocateProposal() throws JsonProcessingException { - Integer resourceTypeId = given() + int resourceTypeId = given() .when() .get("proposalCycles/" + cycleId + "/availableResources/types" ) .then() @@ -186,13 +182,20 @@ void allocateProposal() throws JsonProcessingException { } ); - Integer allocatedId = given() + int allocatedId = given() .when() .get("proposalCycles/" + cycleId + "/allocatedProposals") .then() .body("$.size()", greaterThan(0)) .extract().jsonPath().getInt("[0].dbid"); + int allocationsSize = given() + .when() + .get("proposalCycles/" + cycleId + "/allocatedProposals") + .then() + .body("$.size()", greaterThan(0)) + .extract().as(List.class).size(); + given() .when() .body(mapper.writeValueAsString(allocatedBlock)) @@ -201,6 +204,20 @@ void allocateProposal() throws JsonProcessingException { .then() .statusCode(200); + //test remove the allocated proposal + given() + .when() + .delete("proposalCycles/" + cycleId + "/allocatedProposals/" + allocatedId) + .then() + .statusCode(204); + + //check the list of allocated proposals; should now one fewer than before + given() + .when() + .get("proposalCycles/" + cycleId + "/allocatedProposals") + .then() + .body("$.size()", equalTo(allocationsSize - 1)); + } }