SHARE
TWEET

PaperConverter

cinnamonandrew Jun 2nd, 2020 813 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package converter;
  2.  
  3. import dto.PaperDTO;
  4. import model.util.Paper;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. import repository.ConferenceRepository;
  8. import repository.UserRepository;
  9.  
  10. @Component
  11. public class PaperConverter extends BaseConverter<Paper, PaperDTO> {
  12.  
  13.     @Autowired
  14.     UserRepository userRepository;
  15.  
  16.     @Autowired
  17.     ConferenceRepository conferenceRepository;
  18.  
  19.     @Autowired
  20.     ConferenceConverter conferenceConverter;
  21.     @Autowired
  22.     UserConverter userConverter;
  23.  
  24.  
  25.     @Override
  26.     public Paper convertDtoToModel(PaperDTO dto) {
  27.         Paper paper = Paper.builder()
  28.                 .title(dto.getTitle())
  29.                 .keywords(dto.getKeywords())
  30.                 .topics(dto.getTopics())
  31.                 .conference(conferenceConverter.convertDtoToModel(dto.getConferenceDTO()))
  32.                 .user(userConverter.convertDtoToModel(dto.getUser()))
  33.                 .build();
  34.         paper.setId(dto.getId());
  35.         return paper;
  36.     }
  37.  
  38.     @Override
  39.     public PaperDTO convertModelToDto(Paper paper) {
  40.         PaperDTO paperDTO = PaperDTO.builder()
  41.                 .title(paper.getTitle())
  42.                 .keywords(paper.getKeywords())
  43.                 .topics(paper.getTopics())
  44.                 .user(userConverter.convertModelToDto(paper.getUser()))
  45.                 .conferenceDTO(conferenceConverter.convertModelToDto(paper.getConference()))
  46.                 .build();
  47.         paperDTO.setId(paper.getId());
  48.  
  49.         return paperDTO;
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top