Skip to content

Commit

Permalink
Merge pull request #68 from orppst/59-allow-tac-chair-to-withdraw-a-p…
Browse files Browse the repository at this point in the history
…reviously-allocated-proposal

59 allow tac chair to withdraw a previously allocated proposal
  • Loading branch information
DJWalker42 authored Dec 13, 2024
2 parents 49faacd + 2405421 commit ea02257
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,16 +47,23 @@ 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,
Long submittedId)
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);

Expand All @@ -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();
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -161,7 +157,7 @@ void allocateProposal() throws JsonProcessingException {



Integer resourceTypeId = given()
int resourceTypeId = given()
.when()
.get("proposalCycles/" + cycleId + "/availableResources/types" )
.then()
Expand All @@ -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))
Expand All @@ -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));

}

}

0 comments on commit ea02257

Please sign in to comment.