/** * Creates new instance of BoilerplateNameResolver * @param apiClient ApiClient to use to create BoilerplateApi which will be contacted to resolve unknown names. */ public BoilerplateNameResolver(ApiClient apiClient){ if(apiClient!=null) { this.boilerplateApi = new BoilerplateApi(apiClient); } else { this.boilerplateApi = null; } }
@Override public BoilerplateExpression load(Pair<String, Long> projectIdExpressionIdPair) throws Exception { ApiClient apiClient = new ApiClient(); apiClient.setApiKey(projectIdExpressionIdPair.getLeft()); apiClient.setBasePath(getConfiguration().getBaseUrl()); BoilerplateApi boilerplateApi = new BoilerplateApi(apiClient); return boilerplateApi.getExpression(projectIdExpressionIdPair.getRight()); } };
@Override public Tag load(Pair<String, Long> projectIdTagIdPair) throws ApiException { ApiClient apiClient = new ApiClient(); apiClient.setApiKey(projectIdTagIdPair.getLeft()); apiClient.setBasePath(getConfiguration().getBaseUrl()); BoilerplateApi boilerplateApi = new BoilerplateApi(apiClient); return boilerplateApi.getTag(projectIdTagIdPair.getRight()); } };
@Override public List<BoilerplateExpression> load(Pair<String, Long> projectIdTagIdPair) throws Exception { ApiClient apiClient = new ApiClient(); apiClient.setApiKey(projectIdTagIdPair.getLeft()); apiClient.setBasePath(getConfiguration().getBaseUrl()); BoilerplateApi boilerplateApi = new BoilerplateApi(apiClient); return boilerplateApi.getExpressionsByTagPaged(projectIdTagIdPair.getRight(), null, null); } };
private static boolean waitUntilBoilerplateApiReady(String boilerplateApiUrl, Integer boilerplateApiReadyRetryAttempts){ ApiClient boilerplateApiClient = new ApiClient(); boilerplateApiClient.setApiKey("Ignored"); boilerplateApiClient.setBasePath(boilerplateApiUrl); BoilerplateApi boilerplateApi = new BoilerplateApi(boilerplateApiClient); int retryCount = 0; boolean apiReady = false; while(boilerplateApiReadyRetryAttempts == -1 || retryCount < boilerplateApiReadyRetryAttempts) { try { LOGGER.info("Sending example request to boilerplate API to verify it responds as expected."); boilerplateApi.getTags(1, 1); //if exception was not thrown then indicates successful communication and ready to proceed LOGGER.info("The boilerplate API replied with a valid response. Boilerplate API ready to receive requests."); apiReady = true; break; } catch (ApiException | ClientHandlerException e) { LOGGER.warn("The boilerplate API request failed while testing ability to communicate with API. Will retry after a delay.", e); } delayCall("Thread interrupted while waiting before retrying boilerplate API health check."); retryCount++; } return apiReady; } }