use of net.cryptonomica.returns.UserSearchAndViewReturn in project cryptonomica by Cryptonomica.
the class UserSearchAndViewAPI method generalSearchUserProfiles.
@ApiMethod(name = "generalSearchUserProfiles", path = "generalSearchUserProfiles", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // returns list of user profiles
UserSearchAndViewReturn generalSearchUserProfiles(final HttpServletRequest httpServletRequest, final User googleUser, final GeneralSearchUserProfilesForm generalSearchUserProfilesForm) throws Exception {
LOG.info("serch request: " + new Gson().toJson(generalSearchUserProfilesForm));
// authorization
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
// initialize object for search result:
List<CryptonomicaUser> cryptonomicaUsersList;
// set "" value to be null
if (generalSearchUserProfilesForm.getFirstName() != null && generalSearchUserProfilesForm.getFirstName().equals("")) {
generalSearchUserProfilesForm.setFirstName(null);
}
if (generalSearchUserProfilesForm.getLastName() != null && generalSearchUserProfilesForm.getLastName().equals("")) {
generalSearchUserProfilesForm.setLastName(null);
}
if (generalSearchUserProfilesForm.getEmail() != null && generalSearchUserProfilesForm.getEmail().equals("")) {
generalSearchUserProfilesForm.setEmail(null);
}
// search: first name + last name
if (generalSearchUserProfilesForm.getFirstName() != null && generalSearchUserProfilesForm.getLastName() != null && generalSearchUserProfilesForm.getEmail() == null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("firstName", generalSearchUserProfilesForm.getFirstName().toLowerCase()).filter("lastName", generalSearchUserProfilesForm.getLastName().toLowerCase()).list();
} else // first name + last name + email
if (generalSearchUserProfilesForm.getFirstName() != null && generalSearchUserProfilesForm.getLastName() != null && generalSearchUserProfilesForm.getEmail() != null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("firstName", generalSearchUserProfilesForm.getFirstName().toLowerCase()).filter("lastName", generalSearchUserProfilesForm.getLastName().toLowerCase()).filter("email", new Email(generalSearchUserProfilesForm.getEmail().toLowerCase())).list();
} else // first name + email
if (generalSearchUserProfilesForm.getFirstName() != null && generalSearchUserProfilesForm.getLastName() == null && generalSearchUserProfilesForm.getEmail() != null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("firstName", generalSearchUserProfilesForm.getFirstName().toLowerCase()).filter("email", new Email(generalSearchUserProfilesForm.getEmail().toLowerCase())).list();
} else // last name + email
if (generalSearchUserProfilesForm.getFirstName() == null && generalSearchUserProfilesForm.getLastName() != null && generalSearchUserProfilesForm.getEmail() != null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("lastName", generalSearchUserProfilesForm.getLastName().toLowerCase()).filter("email", new Email(generalSearchUserProfilesForm.getEmail().toLowerCase())).list();
} else // email only
if (generalSearchUserProfilesForm.getFirstName() == null && generalSearchUserProfilesForm.getLastName() == null && generalSearchUserProfilesForm.getEmail() != null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("email", new Email(generalSearchUserProfilesForm.getEmail().toLowerCase())).list();
} else // first name only
if (generalSearchUserProfilesForm.getFirstName() != null && generalSearchUserProfilesForm.getLastName() == null && generalSearchUserProfilesForm.getEmail() == null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("firstName", generalSearchUserProfilesForm.getFirstName().toLowerCase()).list();
} else // last name
if (generalSearchUserProfilesForm.getFirstName() == null && generalSearchUserProfilesForm.getLastName() != null && generalSearchUserProfilesForm.getEmail() == null) {
cryptonomicaUsersList = ofy().load().type(CryptonomicaUser.class).filter("lastName", generalSearchUserProfilesForm.getLastName().toLowerCase()).list();
} else {
throw new Exception("Search query is incorrect or empty");
}
//
UserSearchAndViewReturn userSearchAndViewReturn;
if (cryptonomicaUsersList != null && !cryptonomicaUsersList.isEmpty()) {
userSearchAndViewReturn = new UserSearchAndViewReturn("results found", new ArrayList<>(cryptonomicaUsersList));
} else {
userSearchAndViewReturn = new UserSearchAndViewReturn("no results found");
}
LOG.info("search result: " + new Gson().toJson(userSearchAndViewReturn));
return userSearchAndViewReturn;
}
Aggregations