Search in sources :

Example 1 with InstrumentDto

use of uk.ac.bbsrc.tgac.miso.dto.InstrumentDto in project miso-lims by miso-lims.

the class EditInstrumentController method setupForm.

private ModelAndView setupForm(Instrument instrument, ModelMap model) throws IOException {
    InstrumentDto instrumentDto = Dtos.asDto(instrument);
    if (instrument.isSaved()) {
        Instrument preUpgrade = instrumentService.getByUpgradedInstrumentId(instrument.getId());
        if (preUpgrade != null) {
            instrumentDto.setPreUpgradeInstrumentId(preUpgrade.getId());
            instrumentDto.setPreUpgradeInstrumentName(preUpgrade.getName());
        }
    }
    ObjectMapper mapper = new ObjectMapper();
    model.put("instrument", instrument);
    model.put("instrumentDto", mapper.writeValueAsString(instrumentDto));
    List<InstrumentDto> otherInstruments = instrumentService.list().stream().filter(other -> other.getId() != instrument.getId()).map(Dtos::asDto).collect(Collectors.toList());
    model.put("otherInstruments", mapper.writeValueAsString(otherInstruments));
    ArrayNode instrumentTypes = mapper.createArrayNode();
    for (InstrumentType type : InstrumentType.values()) {
        ObjectNode dto = instrumentTypes.addObject();
        dto.put("label", type.getLabel());
        dto.put("value", type.name());
    }
    model.put("instrumentTypes", mapper.writeValueAsString(instrumentTypes));
    List<WorkstationDto> workstationDtos = workstationService.list().stream().map(Dtos::asDto).collect(Collectors.toList());
    model.put("workstations", mapper.writeValueAsString(workstationDtos));
    return new ModelAndView("/WEB-INF/pages/editInstrument.jsp", model);
}
Also used : InstrumentDto(uk.ac.bbsrc.tgac.miso.dto.InstrumentDto) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Instrument(uk.ac.bbsrc.tgac.miso.core.data.Instrument) InstrumentType(uk.ac.bbsrc.tgac.miso.core.data.type.InstrumentType) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkstationDto(uk.ac.bbsrc.tgac.miso.dto.WorkstationDto)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 Instrument (uk.ac.bbsrc.tgac.miso.core.data.Instrument)1 InstrumentType (uk.ac.bbsrc.tgac.miso.core.data.type.InstrumentType)1 InstrumentDto (uk.ac.bbsrc.tgac.miso.dto.InstrumentDto)1 WorkstationDto (uk.ac.bbsrc.tgac.miso.dto.WorkstationDto)1