Skip to content

Commit c593869

Browse files
authored
MODGOBI-216. Replace mod-configuration for retrieving configuration address (#278)
1 parent b2b77ec commit c593869

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/java/org/folio/gobi/LookupService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class LookupService {
4545
public static final String ACQ_METHODS_NAME = "acquisitionMethods";
4646
public static final String DEFAULT_ACQ_METHOD_VALUE = "Purchase At Vendor System";
4747
public static final String ACQ_METHODS_QUERY = "value==(%s OR "+ DEFAULT_ACQ_METHOD_VALUE +")";
48-
public static final String SETTINGS_ADDRESS_QUERY = "scope==ui-tenant-settings.addresses.manage AND value==*%s*";
48+
public static final String SETTINGS_ADDRESS_QUERY = "scope==ui-tenant-settings.addresses.manage";
4949
public static final String PO_LINE_NUMBER_QUERY = "poLineNumber==%s";
5050
public static final String UNSPECIFIED_MATERIAL_NAME = "unspecified";
5151
public static final String CHECK_ORGANIZATION_ISVENDOR = " and isVendor==true";
@@ -291,14 +291,19 @@ public CompletableFuture<Object> lookupAcquisitionUnitIdsByAccount(String data)
291291

292292
public CompletableFuture<String> lookupConfigAddress(String shipToName) {
293293
logger.debug("lookupConfigAddress:: Trying to look up config address by name: {}", shipToName);
294-
final String query = HelperUtils.encodeValue(String.format(SETTINGS_ADDRESS_QUERY, shipToName));
294+
final String query = HelperUtils.encodeValue(SETTINGS_ADDRESS_QUERY);
295295
String endpoint = String.format(SETTINGS_ENDPOINT + QUERY, query);
296296
return restClient.handleGetRequest(endpoint).toCompletionStage().toCompletableFuture()
297297
.thenApply(addressConfig -> {
298298
JsonArray addressJsonArray = addressConfig.getJsonArray(ITEMS);
299-
if(!addressJsonArray.isEmpty()) {
300-
JsonObject address = addressJsonArray.getJsonObject(FIRST_ELEM);
301-
return address.getString(ID);
299+
for (int i = 0; i < addressJsonArray.size(); i++) {
300+
JsonObject item = addressJsonArray.getJsonObject(i);
301+
JsonObject value = item.getJsonObject("value");
302+
if (value != null && shipToName.equals(value.getString(NAME))) {
303+
String addressId = item.getString(ID);
304+
logger.info("lookupConfigAddress:: found address id: {}", addressId);
305+
return addressId;
306+
}
302307
}
303308
logger.warn("lookupConfigAddress:: Config address with name '{}' not found", shipToName);
304309
return null;

src/test/java/org/folio/gobi/LookupServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void testSuccessMapLookupAddressId() throws IOException {
156156
doReturn(succeededFuture(new JsonObject(address)))
157157
.when(restClient).handleGetRequest(argThat(endpoint -> endpoint.startsWith("/settings/entries")));
158158

159-
var jsonAddress = lookupService.lookupConfigAddress("address").join();
159+
var jsonAddress = lookupService.lookupConfigAddress("Test Address").join();
160160

161161
assertNotNull(jsonAddress);
162162
}

0 commit comments

Comments
 (0)