@Test @Sql(scripts = { "/sql/clearUserRoles.sql", "/sql/clearUsers.sql", "/sql/clearRoles.sql", "/sql/createRoles.sql", "/sql/clearAddresses.sql" }) public void test_should_save_permanent_address_on_creating_new_user() { Address permanentAddress = Address.builder().address("address").type(AddressType.PERMANENT) .addressType("PERMANENT").city("city").pinCode("123").build(); final Set<Role> roles = new HashSet<>(); final String roleCode = "EMP"; roles.add(Role.builder().code(roleCode).tenantId("ap.public").build()); User domainUser = User.builder().roles(roles) .username("TestUserName").password("password").tenantId("ap.public").permanentAddress(permanentAddress) .build(); User actualUser = userRepository.create(domainUser); assertThat(actualUser != null); assertThat(actualUser.getId().equals(1l)); assertThat(actualUser.getRoles().size() == 1l); assertThat(actualUser.getUsername().equals("TestUserName")); assertThat(actualUser.getTenantId().equals("ap.public")); assertThat(actualUser.getPermanentAddress() != null); assertThat(actualUser.getPermanentAddress().getAddressType().toString().equals("PERMANENT")); assertThat(actualUser.getPermanentAddress().getCity().equals("city")); assertThat(actualUser.getPermanentAddress().getAddress().equals("address")); assertThat(actualUser.getPermanentAddress().getPinCode().equals("123")); }
public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } @Autowired  UserRepository(RoleRepository roleRepository, UserTypeQueryBuilder userTypeQueryBuilder,
                   AddressRepository addressRepository, UserResultSetExtractor userResultSetExtractor,
                   JdbcTemplate jdbcTemplate,
                   NamedParameterJdbcTemplate namedParameterJdbcTemplate); }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } @Autowired  UserRepository(RoleRepository roleRepository, UserTypeQueryBuilder userTypeQueryBuilder,
                   AddressRepository addressRepository, UserResultSetExtractor userResultSetExtractor,
                   JdbcTemplate jdbcTemplate,
                   NamedParameterJdbcTemplate namedParameterJdbcTemplate); List<User> findAll(UserSearchCriteria userSearch); boolean isUserPresent(String userName, String tenantId, UserType userType); User create(User user); void update(final User user, User oldUser); void fetchFailedLoginAttemptsByUser(String uuid); List<FailedLoginAttempt> fetchFailedAttemptsByUserAndTime(String uuid, long attemptStartDate); FailedLoginAttempt insertFailedLoginAttempt(FailedLoginAttempt failedLoginAttempt); void resetFailedLoginAttemptsForUser(String uuid); }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } @Autowired  UserRepository(RoleRepository roleRepository, UserTypeQueryBuilder userTypeQueryBuilder,
                   AddressRepository addressRepository, UserResultSetExtractor userResultSetExtractor,
                   JdbcTemplate jdbcTemplate,
                   NamedParameterJdbcTemplate namedParameterJdbcTemplate); List<User> findAll(UserSearchCriteria userSearch); boolean isUserPresent(String userName, String tenantId, UserType userType); User create(User user); void update(final User user, User oldUser); void fetchFailedLoginAttemptsByUser(String uuid); List<FailedLoginAttempt> fetchFailedAttemptsByUserAndTime(String uuid, long attemptStartDate); FailedLoginAttempt insertFailedLoginAttempt(FailedLoginAttempt failedLoginAttempt); void resetFailedLoginAttemptsForUser(String uuid);  }