| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | ||||
| } | } | ||||
| if (tBCodeCreationDTO.getExpiredDate() == null) { | |||||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | |||||
| } | |||||
| Optional<TBCropDTO> tbCropDTO = tBCropService.findOne(tBCodeCreationDTO.gettBCropId()); | Optional<TBCropDTO> tbCropDTO = tBCropService.findOne(tBCodeCreationDTO.gettBCropId()); | ||||
| if (!tbCropDTO.isPresent()) { | if (!tbCropDTO.isPresent()) { | ||||
| throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | ||||
| tBCodeDTO.setCreatedDate(Instant.now()); | tBCodeDTO.setCreatedDate(Instant.now()); | ||||
| tBCodeDTO.setCreatedById(currentUser.getUserId()); | tBCodeDTO.setCreatedById(currentUser.getUserId()); | ||||
| tBCodeDTO.setStatus(TBCodeStatusEnum.NEW); | tBCodeDTO.setStatus(TBCodeStatusEnum.NEW); | ||||
| tBCodeDTO.setExpiredDate(tBCodeCreationDTO.getExpiredDate()); | |||||
| if (tBCodeCreationDTO.getTbExampleStampId() != null) { | if (tBCodeCreationDTO.getTbExampleStampId() != null) { | ||||
| tBCodeDTO.setTbExampleStampId(tBCodeCreationDTO.getTbExampleStampId()); | tBCodeDTO.setTbExampleStampId(tBCodeCreationDTO.getTbExampleStampId()); | ||||
| } | } | ||||
| Optional<TBCode> tbCode = tBCodeService.findByCode(activityCodeCreationDTO.getCode()); | Optional<TBCode> tbCode = tBCodeService.findByCode(activityCodeCreationDTO.getCode()); | ||||
| if(!tbCode.isPresent()) { | |||||
| if (!tbCode.isPresent()) { | |||||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | ||||
| } else { | } else { | ||||
| if(tbCode.get().getStatus().equals(TBCodeStatusEnum.EXPIRED) | |||||
| || tbCode.get().getStatus().equals(TBCodeStatusEnum.CANCELED)) { | |||||
| if (tbCode.get().getStatus().equals(TBCodeStatusEnum.EXPIRED) | |||||
| || tbCode.get().getStatus().equals(TBCodeStatusEnum.CANCELED)) { | |||||
| throw new BadRequestAlertException("1047", "TB Code is not active", "1047"); | throw new BadRequestAlertException("1047", "TB Code is not active", "1047"); | ||||
| } | } | ||||
| } | } |