Commit b7bf4e1d authored by Matija Obreza's avatar Matija Obreza

AccessionRefs: Throw exception if validation of CSV fails

parent c9f36b38
......@@ -59,6 +59,7 @@ import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.DetailedConstraintViolationException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
......@@ -290,6 +291,8 @@ public class DatasetController extends ApiBaseController {
Set<ConstraintViolation<DatasetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
} else {
throw new DetailedConstraintViolationException("Failed to read CSV file in line " + reader.getLinesRead(), violations);
}
}
}
......
......@@ -39,6 +39,7 @@ import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.DetailedConstraintViolationException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
......@@ -329,6 +330,8 @@ public class DiversityTreeController extends ApiBaseController {
Set<ConstraintViolation<DiversityTreeAccessionRef>> violations = validator.validate(dtAcceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(dtAcceRef);
} else {
throw new DetailedConstraintViolationException("Failed to read CSV file in line " + reader.getLinesRead(), violations);
}
}
}
......
......@@ -42,6 +42,7 @@ import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.DetailedConstraintViolationException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
......@@ -340,6 +341,8 @@ public class SubsetController extends ApiBaseController {
Set<ConstraintViolation<SubsetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
} else {
throw new DetailedConstraintViolationException("Failed to read CSV file in line " + reader.getLinesRead(), violations);
}
}
}
......
......@@ -334,6 +334,8 @@ public class DatasetController extends ApiBaseController {
Set<ConstraintViolation<DatasetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
} else {
throw new DetailedConstraintViolationException("Failed to read CSV file in line " + reader.getLinesRead(), violations);
}
}
}
......
......@@ -377,6 +377,8 @@ public class DiversityTreeController extends ApiBaseController {
Set<ConstraintViolation<DiversityTreeAccessionRef>> violations = validator.validate(dtAcceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(dtAcceRef);
} else {
throw new DetailedConstraintViolationException("Failed to read CSV file in line " + reader.getLinesRead(), violations);
}
}
}
......
......@@ -385,6 +385,8 @@ public class SubsetController extends ApiBaseController {
Set<ConstraintViolation<SubsetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
} else {
throw new DetailedConstraintViolationException("Failed to read CSV file in line " + reader.getLinesRead(), violations);
}
}
}
......
......@@ -62,11 +62,11 @@ public class DetailedConstraintViolationException extends ConstraintViolationExc
*/
@Override
public String getMessage() {
final StringBuilder message = new StringBuilder();
if (super.getMessage() != null) {
return super.getMessage();
message.append(super.getMessage()).append(": ");
}
final StringBuilder message = new StringBuilder("Validation failed: ");
if (super.getConstraintViolations() != null) {
for (ConstraintViolation<?> cv : super.getConstraintViolations()) {
final PathImpl path = (PathImpl) cv.getPropertyPath();
......
......@@ -838,16 +838,12 @@ public class DatasetControllerTest extends AbstractDatasetControllerTest {
.perform(MockMvcRequestBuilders.multipart(DatasetController.CONTROLLER_URL.concat("/upload-accessions/{uuid},{version}"), dataset.getUuid(), dataset.getVersion())
.file(file))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(status().is4xxClientError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(dataset.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
;
/*@formatter:on*/
// only the one accessionRef must be persisted
assertThat(accessionRefRepository.count(), is(1L));
assertThat("AccessionRef must not be persisted", accessionRefRepository.count(), is(0L));
assertThat(csvFile.delete(), is(true));
}
......
......@@ -485,16 +485,12 @@ public class DiversityTreeControllerTest extends AbstractDiversityTreeController
.perform(MockMvcRequestBuilders.multipart(DiversityTreeController.CONTROLLER_URL.concat("/upload-accessions/{uuid},{version}"), tree.getUuid(), tree.getVersion())
.file(file))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(status().is4xxClientError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(tree.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
;
/*@formatter:on*/
// only the one accessionRef must be persisted
assertThat(accessionRefRepository.count(), is(1L));
assertThat("AccessionRef must not be persisted", accessionRefRepository.count(), is(0L));
assertThat(csvFile.delete(), is(true));
}
......
......@@ -355,16 +355,12 @@ public class SubsetRestControllerTest extends AbstractSubsetControllerTest {
.perform(MockMvcRequestBuilders.multipart(SubsetController.CONTROLLER_URL.concat("/upload-accessions/{uuid},{version}"), subset.getUuid(), subset.getVersion())
.file(file))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(status().is4xxClientError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(subset.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
;
/*@formatter:on*/
// only the one accessionRef must be persisted
assertThat(accessionRefRepository.count(), is(1L));
assertThat("AccessionRef must not be persisted", accessionRefRepository.count(), is(0L));
assertThat(csvFile.delete(), is(true));
}
......
......@@ -573,16 +573,12 @@ public class DatasetControllerTest extends AbstractDatasetControllerTest {
.perform(MockMvcRequestBuilders.multipart(DatasetController.CONTROLLER_URL.concat("/upload-accessions/{uuid},{version}"), dataset.getUuid(), dataset.getVersion())
.file(file))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(status().is4xxClientError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(dataset.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
;
/*@formatter:on*/
// only the one accessionRef must be persisted
assertThat(accessionRefRepository.count(), is(1L));
assertThat("AccessionRef must not be persisted", accessionRefRepository.count(), is(0L));
assertThat(csvFile.delete(), is(true));
}
......
......@@ -439,16 +439,12 @@ public class DiversityTreeControllerTest extends AbstractDiversityTreeController
.perform(MockMvcRequestBuilders.multipart(DiversityTreeController.CONTROLLER_URL.concat("/upload-accessions/{uuid},{version}"), tree.getUuid(), tree.getVersion())
.file(file))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(status().is4xxClientError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(tree.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
;
/*@formatter:on*/
// only the one accessionRef must be persisted
assertThat(accessionRefRepository.count(), is(1L));
assertThat("AccessionRef must not be persisted", accessionRefRepository.count(), is(0L));
assertThat(csvFile.delete(), is(true));
}
......
......@@ -457,16 +457,12 @@ public class SubsetControllerTest extends AbstractSubsetControllerTest {
.perform(MockMvcRequestBuilders.multipart(SubsetController.CONTROLLER_URL.concat("/upload-accessions/{uuid},{version}"), subset.getUuid(), subset.getVersion())
.file(file))
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(status().is4xxClientError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.uuid", is(subset.getUuid().toString())))
.andExpect(jsonPath("$.accessionCount", is(1)))
;
/*@formatter:on*/
// only the one accessionRef must be persisted
assertThat(accessionRefRepository.count(), is(1L));
assertThat("AccessionRef must not be persisted", accessionRefRepository.count(), is(0L));
assertThat(csvFile.delete(), is(true));
}
......
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