Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. DTO na
  2. private String dealerMaster;
  3. private String dealerSub;
  4.  
  5. private DataStatus dealerStatus;
  6. private CreationalSpecificationDTO dealerCreationalDTO;
  7.  
  8.  
  9. REST na
  10.  
  11. @RequestMapping(value = "/update.dealer.group.mapping/{dealerMaster}",
  12. method = RequestMethod.POST,
  13. consumes = MediaType.APPLICATION_JSON_VALUE,
  14. produces = MediaType.APPLICATION_JSON_VALUE)
  15. public ResponseEntity<DealerGroupMappingDTO> updateDealerGroupMapping(@RequestBody DealerGroupMappingDTO dto, @PathVariable("dealerMaster") String dealerMaster) throws CustomException {
  16. DealerGroupMapping dealerGroup = (DealerGroupMapping) repo.findDealerGroupMappingByMaster(dealerMaster);
  17. if(dealerGroup == null){
  18. String message = env.getProperty("data.not.found.message");
  19. message = MessageFormat.format(message, dto.getDealerMaster());
  20. throw new CustomException(new DealerGroupMappingDTO(), message, HttpStatus.NOT_FOUND);
  21. }
  22. dealerGroup.setDealerMaster(dealerMaster);
  23. dealerGroup.setDealerSub(dto.getDealerSub());
  24. dealerGroup.setDataStatus(DataStatus.ACTIVE);
  25. try{
  26. repo.save(dealerGroup);
  27. }catch(ConstraintViolationException ex){
  28. throw new CustomConstraintViolationException(ex.getMessage(), ex.getConstraintViolations(), new DealerGroupMappingDTO());
  29. }catch(DataIntegrityViolationException ex){
  30. throw new CustomDataIntegrityException(ex, ex.getMessage(), new DealerGroupMappingDTO());
  31. }
  32. return ResponseEntity.status(HttpStatus.CREATED).body(new DealerGroupMappingAssembler().toDTO(dealerGroup));
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement