diff --git a/src/main/java/org/folio/dew/service/UserReferenceService.java b/src/main/java/org/folio/dew/service/UserReferenceService.java index f1069a976..4db7ecabc 100644 --- a/src/main/java/org/folio/dew/service/UserReferenceService.java +++ b/src/main/java/org/folio/dew/service/UserReferenceService.java @@ -110,25 +110,18 @@ public String getPatronGroupIdByName(String name) { @Cacheable(cacheNames = "customFields") public CustomField getCustomFieldByRefId(String refId) { - - var customFields = customFieldsClient.getCustomFieldsByQuery(getModuleId(MOD_USERS),String.format("refId==\"%s\"", refId)); - if (customFields.getCustomFields().isEmpty()) { - var msg = format("Custom field with refId=%s not found", refId); - log.error(msg); - throw new BulkEditException(msg); - } - return customFields.getCustomFields().get(0); + return customFieldsClient.getCustomFieldsByQuery(getModuleId(MOD_USERS),String.format("refId==\"%s\"", refId)) + .getCustomFields().stream().filter(customField -> customField.getRefId().equals(refId)) + .findFirst() + .orElseThrow(() -> new BulkEditException(format("Custom field with refId=%s not found", refId))); } @Cacheable(cacheNames = "customFields") public CustomField getCustomFieldByName(String name) { - var customFields = customFieldsClient.getCustomFieldsByQuery(getModuleId(MOD_USERS), String.format("name==\"%s\"", name)); - if (customFields.getCustomFields().isEmpty()) { - var msg = format("Custom field with name=%s not found", name); - log.error(msg); - throw new BulkEditException(msg); - } - return customFields.getCustomFields().get(0); + return customFieldsClient.getCustomFieldsByQuery(getModuleId(MOD_USERS), String.format("name==\"%s\"", name)) + .getCustomFields().stream().filter(customField -> customField.getName().equals(name)) + .findFirst() + .orElseThrow(() -> new BulkEditException(format("Custom field with name=%s not found", name))); } @Cacheable(cacheNames = "moduleIds")