diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaServiceImpl.java index 22600ae59c4e276d877fe3383d96968109f757a6..745f88673557b046bd9afe9182738393d343994c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaServiceImpl.java @@ -56,21 +56,17 @@ public class SchemaServiceImpl implements SchemaService { @Override public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { - String schemaFromStorageService = storageService.getStorageSchema(kind); + String schemaFromStorageService = getFromStorageService(kind); if (schemaFromStorageService != null) { return schemaFromStorageService; } - log.warning("Schema is not found on the Storage Service:" + kind); + return getFromSchemaService(kind); + } - String url = String.format("%s/%s", SCHEMA_HOST, URLEncoder.encode(kind, StandardCharsets.UTF_8.toString())); - FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() - .httpMethod(HttpMethods.GET) - .headers(this.requestInfo.getHeadersMap()) - .url(url) - .build(); - HttpResponse response = this.urlFetchService.sendRequest(request); + private String getFromSchemaService(String kind) throws UnsupportedEncodingException, URISyntaxException { + HttpResponse response = getSchemaServiceResponse(kind); if (response.getResponseCode() == HttpStatus.SC_NOT_FOUND) { log.warning("Schema is not found on the Schema Service:" + kind); @@ -80,4 +76,28 @@ public class SchemaServiceImpl implements SchemaService { return response.getResponseCode() != HttpStatus.SC_OK ? null : schemaToStorageFormat.convertToString(response.getBody(), kind); } + + private String getFromStorageService(String kind) throws URISyntaxException, UnsupportedEncodingException { + String schemaFromStorageService = storageService.getStorageSchema(kind); + + if (schemaFromStorageService != null) { + return schemaFromStorageService; + } + + log.warning("Schema is not found on the Storage Service:" + kind); + + return null; + } + + private HttpResponse getSchemaServiceResponse(String kind) throws UnsupportedEncodingException, URISyntaxException { + String url = String.format("%s/%s", SCHEMA_HOST, URLEncoder.encode(kind, StandardCharsets.UTF_8.toString())); + FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() + .httpMethod(HttpMethods.GET) + .headers(this.requestInfo.getHeadersMap()) + .url(url) + .build(); + + return this.urlFetchService.sendRequest(request); + } + }