Commit af0ea927 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-498-double-letters-to-genebank-fix' into 'master'

Don't validate already validated or dispatched request

See merge request genesys-pgr/genesys-server!449
parents 7b7ec2f4 61242368
......@@ -235,11 +235,15 @@ public class RequestServiceImpl implements RequestService {
// Rollback for any exception
@Override
@Transactional(rollbackFor= { NoPidException.class, EasySMTAException.class })
public MaterialRequest validateClientRequest(String tokenUuid, String key) throws NoSuchVerificationTokenException, NoPidException, EasySMTAException, TokenExpiredException {
public MaterialRequest validateClientRequest(String tokenUuid, String key) throws NoSuchVerificationTokenException, NoPidException, EasySMTAException, TokenExpiredException, RequestException {
final VerificationToken consumedToken = tokenVerificationService.consumeToken(REQUEST_TOKENTYPE, tokenUuid, key);
final MaterialRequest materialRequest = requestRepository.findByUuid(consumedToken.getData());
if (materialRequest.getState() != MaterialRequest.NOTVALIDATED) {
throw new RequestException("Request is already validated or dispatched.");
}
return validateRequest(materialRequest);
}
......
......@@ -17,6 +17,7 @@
package org.genesys.test.server.api.v1;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
......@@ -42,6 +43,7 @@ import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.EasySMTA;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.RequestService;
import org.genesys2.server.service.TokenVerificationService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
......@@ -80,6 +82,8 @@ public class RequestControllerTest extends AbstractApiTest {
private VerificationTokenRepository verificationTokenRepository;
@Autowired
private ArticleRepository articleRepository;
@Autowired
private TokenVerificationService tokenVerificationService;
@Before
@Override
......@@ -259,23 +263,38 @@ public class RequestControllerTest extends AbstractApiTest {
/*@formatter:on*/
}
@Test
public void validateAlreadyValidatedRequestTest() throws Exception {
final MaterialRequest materialRequest = initRequest();
materialRequest.setInternalRequest(true);
final MaterialRequest validated = requestService.validateRequest(materialRequest);
assertEquals(validated.getState(), MaterialRequest.DISPATCHED);
final VerificationToken verificationToken = tokenVerificationService.generateToken("confirm-request", validated.getUuid());
// expect an exception because Material Request is already dispatched
/*@formatter:off*/
mockMvc
.perform(post(RequestsController.CONTROLLER_URL + "/r/validate")
.param(RequestsController.PARAM_TOKENUUID, verificationToken.getUuid())
.param(RequestsController.PARAM_KEY, verificationToken.getKey()))
.andExpect(status().isBadRequest());
/*@formatter:on*/
}
private ObjectNode setUpAccession() {
ObjectNode accession = objectMapper.createObjectNode();
accession.put("instCode", institute.getCode());
accession.put("accessionNumber", "A1");
ObjectNode accession = upsertAccession(institute.getCode(), "A1", "Manihot", null);
accession.put("available", true);
ObjectNode taxa = accession.putObject("taxonomy");
taxa.put("genus", "Manihot");
return accession;
}
private void initRequest() throws Exception {
private MaterialRequest initRequest() throws Exception {
RequestService.RequestInfo requestInfo = new RequestService.RequestInfo();
requestInfo.setPreacceptSMTA(false);
requestInfo.setEmail("user@localhost");
UUID uuid = accessionRepository.findAll().get(0).getUuid();
requestService.initiateRequestByUuids(requestInfo, Collections.singleton(uuid));
return requestService.initiateRequestByUuids(requestInfo, Collections.singleton(uuid));
}
private MaterialSubRequest initSubrequest(MaterialRequest request) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment