Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.8.12 first name fix (#81) #82

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,13 @@ public final class JsonKey {
public static final String LAST_LOGIN = "last_login";
public static final String FIRST_LOGIN = "first_login";
public static final String EDATA = "edata";

public static final String SELF_REGISTRATION = "self_registration";
public static final String CREATEDBY = "createdby";
public static final String CONTEXT_TYPE = "contextType";
public static final String CONTEXT_ATTRIBUTES = "contextAttributes";
public static final String CONTEXT_TOKEN = "contextToken";
public static final String OTP_VALIDATION_SECRET_KEY = "otpValidationSecretKey";
public static final String OTP_EXPIRATION_TIME_TOKEN = "otpExpirationTimeToken";
public static final String PERSONAL_DETAILS = "personalDetails";
private JsonKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void validateCreateUserRequest(Request userRequest) {
validateUserType(userRequest.getRequest(), null, userRequest.getRequestContext());
phoneValidation(userRequest);
validatePassword((String) userRequest.getRequest().get(JsonKey.PASSWORD));
formatFirstName(userRequest);
}

public static boolean isGoodPassword(String password) {
Expand All @@ -80,6 +81,20 @@ private void validatePassword(String password) {
}
}

private void formatFirstName(Request userRequest) {
String firstName = (String) userRequest.getRequest().get(JsonKey.FIRST_NAME);
String[] words = firstName.split("\\s+");
StringBuilder modifiedFirstName = new StringBuilder();
for (String word : words) {
if (word.length() > 0) {
modifiedFirstName.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase())
.append(" ");
}
}
userRequest.getRequest().put(JsonKey.FIRST_NAME,modifiedFirstName.toString());
}

/**
* This method will validate location type
*
Expand Down Expand Up @@ -437,6 +452,9 @@ private void updateUserBasicValidation(Request userRequest) {
ResponseCode.mandatoryParamsMissing,
MessageFormat.format(
ResponseCode.mandatoryParamsMissing.getErrorMessage(), JsonKey.FIRST_NAME));
} else if (userRequest.getRequest().containsKey(JsonKey.FIRST_NAME)
&& (StringUtils.isNotBlank((String) userRequest.getRequest().get(JsonKey.FIRST_NAME)))){
formatFirstName(userRequest);
}

if ((userRequest.getRequest().containsKey(JsonKey.EMAIL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public class ExtendedUserProfileServiceImpl implements ExtendedUserProfileServic
public void validateProfile(Request userRequest) {
if (userRequest!=null && userRequest.get(JsonKey.PROFILE_DETAILS)!=null) {
try{
Map<String, Object> profileDetails = (Map<String, Object>) userRequest.get(JsonKey.PROFILE_DETAILS);
if (profileDetails.get(JsonKey.PERSONAL_DETAILS) != null) {
Map<String, Object> personalDetails = (Map<String, Object>) profileDetails.get(JsonKey.PERSONAL_DETAILS);
if (personalDetails.get(JsonKey.FIRST_NAME) != null) {
personalDetails.put(JsonKey.FIRST_NAME, formatFirstName((String) profileDetails.get(JsonKey.FIRST_NAME)));
}
}
String userProfile = mapper.writeValueAsString(userRequest.getRequest().get(JsonKey.PROFILE_DETAILS));
JSONObject obj = new JSONObject(userProfile);
UserExtendedProfileSchemaValidator.validate(SCHEMA, obj);
Expand All @@ -33,4 +40,17 @@ public void validateProfile(Request userRequest) {
}
}
}

private String formatFirstName(String firstName) {
String[] words = firstName.split("\\s+");
StringBuilder modifiedFirstName = new StringBuilder();
for (String word : words) {
if (word.length() > 0) {
modifiedFirstName.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase())
.append(" ");
}
}
return modifiedFirstName.toString();
}
}
Loading