use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.
the class UserImportAPI method updateUserPreference.
private Future<RequestPreference> updateUserPreference(User user, UserImportData userImportData, Map<String, String> okapiHeaders) {
return prefService.get(okapiHeaders, user.getId()).compose(result -> {
if (Objects.nonNull(result)) {
RequestPreference requestPreference = userImportData.getRequestPreferences().get(user.getUsername());
if (Objects.nonNull(requestPreference)) {
requestPreference.setId(result.getId());
requestPreference.setUserId(result.getUserId());
return prefService.validate(requestPreference, userImportData, user).compose(o -> {
udpService.updateUserPreference(requestPreference, userImportData);
return prefService.update(okapiHeaders, requestPreference).mapEmpty();
});
} else if (!userImportData.isUpdateOnlyPresentFields()) {
return prefService.delete(okapiHeaders, result.getId()).mapEmpty();
} else {
return Future.succeededFuture();
}
} else {
return createUserPreference(user, userImportData, okapiHeaders);
}
});
}
use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithNewPreferenceCreation.
@Test
public void testImportWithNewPreferenceCreation() throws IOException {
mock.setMockJsonContent("mock_user_creation_with_new_preference.json");
List<User> users = new ArrayList<>();
User user = generateUser("1234567", "Amy", "Cabble", null);
Address address = new Address().withAddressLine1("Test first line").withCity("Test city").withRegion("Test region").withPostalCode("12345").withAddressTypeId("Returns").withPrimaryAddress(Boolean.FALSE);
List<Address> addresses = new ArrayList<>();
addresses.add(address);
user.getPersonal().setAddresses(addresses);
user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(true).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da").withDefaultDeliveryAddressTypeId("Returns").withFulfillment(RequestPreference.Fulfillment.DELIVERY));
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(1)).body(UPDATED_RECORDS, equalTo(0)).body(FAILED_RECORDS, equalTo(0)).body(FAILED_USERS, hasSize(0)).statusCode(200);
}
use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithUserPreferenceDeliveryIsTrueAndAddressTypeNotFound.
@Test
public void testImportWithUserPreferenceDeliveryIsTrueAndAddressTypeNotFound() throws IOException {
mock.setMockJsonContent("mock_user_creation_with_new_preference.json");
List<User> users = new ArrayList<>();
User user = generateUser("1234567", "Amy", "Cabble", null);
user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(true).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da").withDefaultDeliveryAddressTypeId("11111111-1111-1111-b111-111111111111").withFulfillment(RequestPreference.Fulfillment.DELIVERY));
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(FAILED_USERS + "[0]." + EXTERNAL_SYSTEM_ID, equalTo(users.get(0).getExternalSystemId())).body(FAILED_USERS + "[0]." + USERNAME, equalTo(users.get(0).getUsername())).body(FAILED_USERS + "[0]." + USER_ERROR_MESSAGE, containsString(UserImportAPIConstants.FAILED_USER_PREFERENCE_VALIDATION + "Provided defaultDeliveryAddressTypeId value does not exist")).statusCode(200);
}
use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithUserUpdateAndNewPreferenceCreation.
@Test
public void testImportWithUserUpdateAndNewPreferenceCreation() throws IOException {
mock.setMockJsonContent("mock_user_update_with_new_preference_creation.json");
List<User> users = new ArrayList<>();
User user = generateUser("89101112", "User", "Update", "58512926-9a29-483b-b801-d36aced855d3");
user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(false).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da"));
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(0)).body(UPDATED_RECORDS, equalTo(1)).body(FAILED_RECORDS, equalTo(0)).body(FAILED_USERS, hasSize(0)).statusCode(200);
}
use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithUserPreferenceDeliveryIsTrueAndFulfillmentIsNull.
@Test
public void testImportWithUserPreferenceDeliveryIsTrueAndFulfillmentIsNull() throws IOException {
mock.setMockJsonContent("mock_user_creation_with_new_preference.json");
List<User> users = new ArrayList<>();
User user = generateUser("1234567", "Amy", "Cabble", null);
user.setRequestPreference(new RequestPreference().withHoldShelf(RequestPreference.HoldShelf.TRUE).withDelivery(true).withDefaultServicePointId("59646a99-4074-4ee5-bfd4-86f3fc7717da").withDefaultDeliveryAddressTypeId("71628bf4-1962-4dff-a8f2-11108ab532cc").withFulfillment(null));
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(FAILED_USERS + "[0]." + EXTERNAL_SYSTEM_ID, equalTo(users.get(0).getExternalSystemId())).body(FAILED_USERS + "[0]." + USERNAME, equalTo(users.get(0).getUsername())).body(FAILED_USERS + "[0]." + USER_ERROR_MESSAGE, containsString(UserImportAPIConstants.FAILED_USER_PREFERENCE_VALIDATION + "fulfillment must not be null")).statusCode(200);
}
Aggregations