@Override
  public List<LaboratoryDto> getLaboratories(
      SectionDto sectionDto, YearDto yearDto, SemesterDto semesterDto) {
    Section section = modelMapper.map(sectionDto, Section.class);
    Year year = modelMapper.map(yearDto, Year.class);
    Semester semester = modelMapper.map(semesterDto, Semester.class);

    List<Laboratory> laboratories = laboratoryDao.getLaboratories(section, year, semester);

    return modelMapper.map(laboratories, new TypeToken<List<LaboratoryDto>>() {}.getType());
  }
コード例 #2
0
  @Override
  public void savePurchase(final Purchase purchase) {
    PurchaseEntity entity;
    ModelMapper mapper = new ModelMapper();
    entity = mapper.map(purchase, PurchaseEntity.class);

    // TODO: remove CustomerEntity Depenency
    CustomerEntity ce =
        mapper.map(cdl.getCustomerById(purchase.getCustomer().getId()), CustomerEntity.class);
    entity.setCustomerid(ce);

    List<PurchaseitemEntity> list = new LinkedList<PurchaseitemEntity>();
    for (PurchaseItem pi : purchase.getPurchaseItems()) {
      PurchaseitemEntity e = mapper.map(pi, PurchaseitemEntity.class);
      // ProductEntity pe = new ProductEntity(pi.getProductid());
      // e.setProductid(pe);
      e.setProductno(pi.getProductNo());
      e.setPurchaseid(entity);
      list.add(e);
    }

    entity.setPurchaseitemCollection(list);

    try {
      this.pfl.create(entity);
    } catch (Exception ex) {
      Logger.getGlobal().log(Level.WARNING, ex.toString());
    }
  }
コード例 #3
0
 @Override
 public User update(User entity) {
   log.info("Updating ... {}", entity);
   UserEntity usrEntity = modelMapper.map(entity, UserEntity.class);
   userRepo.save(usrEntity);
   return modelMapper.map(usrEntity, User.class);
 }
コード例 #4
0
 @Override
 public User create(User entity) {
   log.info("Saving... {}", entity);
   UserEntity usrEntity = modelMapper.map(entity, UserEntity.class);
   usrEntity.setCreateDate(LocalDateTime.now());
   userRepo.save(usrEntity);
   return modelMapper.map(usrEntity, User.class);
 }
コード例 #5
0
  @Bean
  public ModelMapper modelMapper() {
    ModelMapper modelMapper = new ModelMapper();

    modelMapper.getConfiguration().addValueReader(new RecordValueReader());
    modelMapper.getConfiguration().setSourceNameTokenizer(NameTokenizers.UNDERSCORE);
    addCustomConvertersToModelMapper(modelMapper);
    return modelMapper;
  }
コード例 #6
0
  public <S, T> List<T> convert(List<S> source, Class<T> tClass) {

    List<T> content = new ArrayList<>();

    ModelMapper modelMapper = entityConvertersPack.getPreparedModelMapper();

    for (S s : source) {
      content.add(modelMapper.map(s, tClass));
    }

    return content;
  }
コード例 #7
0
  public static <S, T> List<T> mapList(List<S> source, Class<T> targetClass) {
    List<T> list = new ArrayList<>();
    for (int i = 0; i < source.size(); i++) {
      T target = INSTANCE.map(source.get(i), targetClass);
      list.add(target);
    }

    return list;
  }
コード例 #8
0
 // TODO stream() vs parallelStream()
 // TODO 로깅
 // TODO HEATEOAS
 // TODO 뷰
 // TODO boot를 프로덕션에 배포할때 튜닝포인트(?) 궁금해요~ ^^ (강대권)
 // NSPA 1. Thymeleaf
 // SPA 2. 앨귤러 3. 리엑트
 @RequestMapping(value = "/accounts", method = GET)
 @ResponseStatus(HttpStatus.OK)
 public PageImpl<AccountDto.Response> getAccounts(Pageable pageable) {
   Page<Account> page = repository.findAll(pageable);
   List<AccountDto.Response> content =
       page.getContent()
           .parallelStream()
           .map(account -> modelMapper.map(account, AccountDto.Response.class))
           .collect(Collectors.toList());
   return new PageImpl<>(content, pageable, page.getTotalElements());
 }
  @Override
  public LaboratoryDto getLaboratoryById(int id) throws ServiceEntityNotFoundException {
    try {
      Laboratory laboratory = laboratoryDao.getLaboratoryById(id);

      return modelMapper.map(laboratory, LaboratoryDto.class);
    } catch (DaoEntityNotFoundException e) {
      LOGGER.debug("DaoEntityNotFoundException");
      throw new ServiceEntityNotFoundException(e);
    }
  }
コード例 #10
0
 @Override
 public List<Purchase> getPurchaseByCustomer(final Customer customer) {
   List<Purchase> purchases = new LinkedList<Purchase>();
   List<PurchaseEntity> entities = pfl.findAll();
   ModelMapper mapper = new ModelMapper();
   for (PurchaseEntity e : entities) {
     if (e.getCustomerid().getId() == customer.getId()) {
       Purchase p = mapper.map(e, Purchase.class);
       for (PurchaseitemEntity pie : e.getPurchaseitemCollection()) {
         PurchaseItem pi = new PurchaseItem();
         pi.setDescription(pie.getDescription());
         pi.setId(pie.getId());
         pi.setQuantity(pie.getQuantity());
         pi.setProductNo(pie.getProductno());
         p.getPurchaseItems().add(pi);
       }
       purchases.add(p);
     }
   }
   return purchases;
 }
コード例 #11
0
 @Override
 @Transactional(readOnly = true)
 public List<User> getAllUsers() {
   List<User> lstUsers = new ArrayList<>();
   userRepo
       .findAll()
       .forEach(
           usr -> {
             lstUsers.add(modelMapper.map(usr, User.class));
           });
   return lstUsers;
 }
  @Test
  public void shouldMapUserEntity() {

    // given
    final User user = new User("John Doe");

    // when
    final UserDto result = modelMapper.map(user, UserDto.class);

    // then
    Assert.assertEquals("John", result.getFirstName());
    Assert.assertEquals("Doe", result.getLastName());
  }
コード例 #13
0
  // 부분 업데이트 : PATCH
  // - (username:"******")
  // - (passowrd:"pass")
  // - (fullName:"seokgon lee")
  @RequestMapping(value = "/accounts/{id}", method = PUT)
  public ResponseEntity updateAccount(
      @PathVariable Long id,
      @RequestBody @Valid AccountDto.Update updateDto,
      BindingResult result) {
    if (result.hasErrors()) {
      return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    Account updateAccount = service.updateAccount(id, updateDto);
    return new ResponseEntity<>(
        modelMapper.map(updateAccount, AccountDto.Response.class), HttpStatus.OK);
  }
コード例 #14
0
  public static <S, T> Page<T> mapPage(Page<S> source, Class<T> targetClass) {
    List<S> sourceList = source.getContent();

    List<T> list = new ArrayList<>();
    for (int i = 0; i < sourceList.size(); i++) {
      T target = INSTANCE.map(sourceList.get(i), targetClass);
      list.add(target);
    }

    return new PageImpl<>(
        list,
        new PageRequest(source.getNumber(), source.getSize(), source.getSort()),
        source.getTotalElements());
  }
コード例 #15
0
  @Override
  public GameRoom create(final GameRoomDto.Create createDto) throws JsonProcessingException {
    final GameRoom gameRoom = modelMapper.map(createDto, GameRoom.class);

    if (gameRoomRepository.findOneByOwnerAndEnabled(createDto.getOwner(), Enabled.TRUE) != null) {
      log.error(
          "owner duplicated exception. {} : {}",
          createDto.getOwner().getId(),
          createDto.getOwner().getNickname());
      throw new OwnerDuplicatedException("[" + createDto.getOwner().getEmail() + "] 중복된 방장 입니다.");
    }

    fillInitData(gameRoom);

    return gameRoomRepository.save(gameRoom);
  }
コード例 #16
0
  @RequestMapping(value = "/accounts", method = POST)
  public ResponseEntity createAccount(
      @RequestBody @Valid AccountDto.Create create, BindingResult result) {
    if (result.hasErrors()) {
      ErrorResponse errorResponse = new ErrorResponse();
      errorResponse.setMessage("잘못된 요청입니다.");
      errorResponse.setCode("bad.request");
      // TODO bindingResult 안에 들어있는 에러 정보 사용하기.
      return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
    }

    // 1.리턴 타임으로 판단.
    // 2.파라미터 이용.
    Account newAccount = service.createAccount(create);
    return new ResponseEntity<>(
        modelMapper.map(newAccount, AccountDto.Response.class), HttpStatus.CREATED);
  }
  @Override
  public void saveLaboratory(LaboratoryDto laboratoryDto)
      throws ServiceEntityNotFoundException, ServiceEntityAlreadyExistsException {
    Laboratory laboratory = modelMapper.map(laboratoryDto, Laboratory.class);

    try {
      populateLaboratoryFields(laboratory);

      laboratoryDao.saveLaboratory(laboratory);
    } catch (DaoEntityNotFoundException e) {
      LOGGER.debug("DaoEntityNotFoundException");
      throw new ServiceEntityNotFoundException(e);
    } catch (DaoEntityAlreadyExistsException e) {
      LOGGER.debug("DaoEntityAlreadyExistsException");
      throw new ServiceEntityAlreadyExistsException(e);
    }
  }
コード例 #18
0
 @Override
 public Job to(UriInfo uriInfo, JobModel representation) {
   return Job.Builder.build(
       j -> {
         j.setJobName(representation.getName());
         j.setExternalIds(representation.getExternalIds());
         j.setJobType(JobType.valueOf(representation.getType()));
         Optional.ofNullable(representation.getStatus())
             .map(ResourceStatusModel::getCurrent)
             .map(JobStatus::valueOf)
             .ifPresent(j::setStatus);
         j.setJobConfiguration(
             modelMapper.map(
                 representation.getConfiguration(),
                 getJobConfigurationClass(representation.getType())));
         Optional.ofNullable(representation.getPriority()).ifPresent(j::setPriority);
       });
 }
コード例 #19
0
  @Override
  public List<NoteDto> getNotesByLaboratory(int laboratoryId) {
    List<Note> notes = noteDao.getNotesByLaboratory(laboratoryId);

    return modelMapper.map(notes, new TypeToken<List<NoteDto>>() {}.getType());
  }
 /** Constructor. */
 public DetallePlanillaHasEmpleadosServiceMapper() {
   modelMapper = new ModelMapper();
   modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
 }
 @BeforeClass
 public static void setUp() {
   modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
 }
コード例 #22
0
 /** Constructor. */
 public PeriodServiceMapper() {
   modelMapper = new ModelMapper();
   modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
 }
コード例 #23
0
 @RequestMapping(value = "accounts/{id}", method = GET)
 @ResponseStatus(HttpStatus.OK)
 public AccountDto.Response getAccount(@PathVariable Long id) {
   Account account = service.getAccount(id);
   return modelMapper.map(account, AccountDto.Response.class);
 }
コード例 #24
0
 @Override
 public Job update(UriInfo uriInfo, JobModel jobModel, Job target) {
   modelMapper.map(jobModel, target);
   return target;
 }
コード例 #25
0
 static {
   modelMapper = new ModelMapper();
   modelMapper.addMappings(new JobPropertyMap());
 }
コード例 #26
0
 @Override
 @Transactional(readOnly = true)
 public User getById(Long id) {
   return modelMapper.map(userRepo.findOne(id), User.class);
 }
コード例 #27
0
 /** Constructor. */
 public EmployeeGroupServiceMapper() {
   modelMapper = new ModelMapper();
   modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
 }
コード例 #28
0
 /**
  * Map input bean to a new output bean.
  *
  * @param input Input bean
  * @param outputClass Output bean class
  * @return New output bean
  */
 protected <I, O> O map(I input, Class<O> outputClass) {
   return modelMapper.map(input, outputClass);
 }
コード例 #29
0
 /**
  * Map input bean to an existing output bean.
  *
  * @param input Input bean
  * @param output Output bean
  */
 protected <I, O> void map(I input, O output) {
   modelMapper.map(input, output);
 }
コード例 #30
0
 private UserCredentials userCredentialsEntityToUserCredentials(
     UserCredentialsEntity userCredentialsEntity) {
   return modelMapper.map(userCredentialsEntity, UserCredentials.class);
 }