@Test public void testIdGen() { RequestInfo requestInfo = new RequestInfo("", "", 0L, "", "", "", "", "", "8e88988e-d342-45c2-81d0-487a2a20350e", null); IdGenerationResponse response = idGenRepository.getId(requestInfo, "pb", "pg.txnid", "" + "PB-PG-[cy:yyyy/MM/dd]-[SEQ_EG_PG_TXN]-[d{2}]", 1); System.out.println(response.getIdResponses()); }
public IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count) { List<IdRequest> reqList = new ArrayList<>(); for (int i = 0; i < count; i++) { reqList.add(new IdRequest(name, tenantId, format)); } IdGenerationRequest req = new IdGenerationRequest(requestInfo, reqList); String uri = UriComponentsBuilder .fromHttpUrl(appProperties.getIdGenHost()) .path(appProperties.getIdGenPath()) .build() .toUriString(); try { return restTemplate.postForObject(uri, req, IdGenerationResponse.class); } catch (HttpClientErrorException e) { log.error("ID Gen Service failure ", e); throw new ServiceCallException(e.getResponseBodyAsString()); } catch (Exception e) { log.error("ID Gen Service failure", e); throw new CustomException("IDGEN_SERVICE_ERROR", "Failed to generate ID, unknown error occurred"); } }
IdGenRepository { public IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count) { List<IdRequest> reqList = new ArrayList<>(); for (int i = 0; i < count; i++) { reqList.add(new IdRequest(name, tenantId, format)); } IdGenerationRequest req = new IdGenerationRequest(requestInfo, reqList); String uri = UriComponentsBuilder .fromHttpUrl(appProperties.getIdGenHost()) .path(appProperties.getIdGenPath()) .build() .toUriString(); try { return restTemplate.postForObject(uri, req, IdGenerationResponse.class); } catch (HttpClientErrorException e) { log.error("ID Gen Service failure ", e); throw new ServiceCallException(e.getResponseBodyAsString()); } catch (Exception e) { log.error("ID Gen Service failure", e); throw new CustomException("IDGEN_SERVICE_ERROR", "Failed to generate ID, unknown error occurred"); } } }
IdGenRepository { public IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count) { List<IdRequest> reqList = new ArrayList<>(); for (int i = 0; i < count; i++) { reqList.add(new IdRequest(name, tenantId, format)); } IdGenerationRequest req = new IdGenerationRequest(requestInfo, reqList); String uri = UriComponentsBuilder .fromHttpUrl(appProperties.getIdGenHost()) .path(appProperties.getIdGenPath()) .build() .toUriString(); try { return restTemplate.postForObject(uri, req, IdGenerationResponse.class); } catch (HttpClientErrorException e) { log.error("ID Gen Service failure ", e); throw new ServiceCallException(e.getResponseBodyAsString()); } catch (Exception e) { log.error("ID Gen Service failure", e); throw new CustomException("IDGEN_SERVICE_ERROR", "Failed to generate ID, unknown error occurred"); } } @Autowired  IdGenRepository(RestTemplate restTemplate, AppProperties appProperties); }
IdGenRepository { public IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count) { List<IdRequest> reqList = new ArrayList<>(); for (int i = 0; i < count; i++) { reqList.add(new IdRequest(name, tenantId, format)); } IdGenerationRequest req = new IdGenerationRequest(requestInfo, reqList); String uri = UriComponentsBuilder .fromHttpUrl(appProperties.getIdGenHost()) .path(appProperties.getIdGenPath()) .build() .toUriString(); try { return restTemplate.postForObject(uri, req, IdGenerationResponse.class); } catch (HttpClientErrorException e) { log.error("ID Gen Service failure ", e); throw new ServiceCallException(e.getResponseBodyAsString()); } catch (Exception e) { log.error("ID Gen Service failure", e); throw new CustomException("IDGEN_SERVICE_ERROR", "Failed to generate ID, unknown error occurred"); } } @Autowired  IdGenRepository(RestTemplate restTemplate, AppProperties appProperties); IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count); }
IdGenRepository { public IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count) { List<IdRequest> reqList = new ArrayList<>(); for (int i = 0; i < count; i++) { reqList.add(new IdRequest(name, tenantId, format)); } IdGenerationRequest req = new IdGenerationRequest(requestInfo, reqList); String uri = UriComponentsBuilder .fromHttpUrl(appProperties.getIdGenHost()) .path(appProperties.getIdGenPath()) .build() .toUriString(); try { return restTemplate.postForObject(uri, req, IdGenerationResponse.class); } catch (HttpClientErrorException e) { log.error("ID Gen Service failure ", e); throw new ServiceCallException(e.getResponseBodyAsString()); } catch (Exception e) { log.error("ID Gen Service failure", e); throw new CustomException("IDGEN_SERVICE_ERROR", "Failed to generate ID, unknown error occurred"); } } @Autowired  IdGenRepository(RestTemplate restTemplate, AppProperties appProperties); IdGenerationResponse getId(RequestInfo requestInfo, String tenantId, String name, String format, int count);  }