Search in sources :

Example 1 with DiseaseTraitDto

use of uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto in project goci by EBISPOT.

the class DiseaseTraitDtoAssembler method toResource.

public Resource<DiseaseTraitDto> toResource(DiseaseTrait diseaseTrait) {
    DiseaseTraitDto diseaseTraitDTO = DiseaseTraitDto.builder().id(diseaseTrait.getId()).trait(diseaseTrait.getTrait()).studies(diseaseTrait.getStudies().size()).build();
    final ControllerLinkBuilder controllerLinkBuilder = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(DiseaseTraitController.class).getOneDiseaseTrait(diseaseTrait.getId()));
    Resource<DiseaseTraitDto> resource = new Resource<>(diseaseTraitDTO);
    resource.add(controllerLinkBuilder.withSelfRel());
    return resource;
}
Also used : Resource(org.springframework.hateoas.Resource) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto) ControllerLinkBuilder(org.springframework.hateoas.mvc.ControllerLinkBuilder)

Example 2 with DiseaseTraitDto

use of uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto in project goci by EBISPOT.

the class DiseaseTraitDtoAssembler method assemble.

public static List<DiseaseTraitDto> assemble(List<DiseaseTrait> diseaseTraits) {
    List<DiseaseTraitDto> diseaseTraitDTOS = new ArrayList<>();
    diseaseTraits.forEach(diseaseTrait -> {
        DiseaseTraitDto diseaseTraitDTO = DiseaseTraitDto.builder().id(diseaseTrait.getId()).trait(diseaseTrait.getTrait()).build();
        diseaseTraitDTOS.add(diseaseTraitDTO);
    });
    return diseaseTraitDTOS;
}
Also used : ArrayList(java.util.ArrayList) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto)

Example 3 with DiseaseTraitDto

use of uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto in project goci by EBISPOT.

the class DiseaseTraitDtoAssembler method disassemble.

public static List<DiseaseTrait> disassemble(MultipartFile multipartFile) {
    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = FileHandler.getSchemaFromMultiPartFile(multipartFile);
    List<DiseaseTraitDto> diseaseTraitDtos;
    try {
        InputStream inputStream = multipartFile.getInputStream();
        MappingIterator<DiseaseTraitDto> iterator = mapper.readerFor(DiseaseTraitDto.class).with(schema).readValues(inputStream);
        diseaseTraitDtos = iterator.readAll();
    } catch (IOException ex) {
        throw new FileUploadException("Could not read the file");
    }
    List<DiseaseTrait> diseaseTraits = new ArrayList<>();
    diseaseTraitDtos.forEach(diseaseTraitDTO -> {
        DiseaseTrait diseaseTrait = new DiseaseTrait();
        diseaseTrait.setTrait(diseaseTraitDTO.getTrait());
        diseaseTraits.add(diseaseTrait);
    });
    return diseaseTraits;
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) InputStream(java.io.InputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ArrayList(java.util.ArrayList) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto) IOException(java.io.IOException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException)

Aggregations

DiseaseTraitDto (uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto)3 ArrayList (java.util.ArrayList)2 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Resource (org.springframework.hateoas.Resource)1 ControllerLinkBuilder (org.springframework.hateoas.mvc.ControllerLinkBuilder)1 FileUploadException (uk.ac.ebi.spot.goci.curation.exception.FileUploadException)1 DiseaseTrait (uk.ac.ebi.spot.goci.model.DiseaseTrait)1