agave-apps/clients/model/Profile.java
/**
	 * Parses and validates a JSON representation, updating the passed in
	 * Profile object. If null, a new Profile object is returned.
	 * 
	 * @param jsonProfile
	 * @return Profile object
	 * @throws ProfileException
	 */
Parses and validates a JSON representation, updating the passed in
Profile object. If null, a new Profile object is returned.

@param jsonProfile
@return Profile object
@throws ProfileException
Parses and validates a JSON representation updating the passed in Profile object . If null a new Profile object is returned . @param jsonProfile @return Profile object @throws ProfileException
public static Profile fromJSON(JsonNode jsonProfile, Profile profile) 
	throws ProfileException
	{
		if (profile == null) {
			profile = new Profile();
		}
		try 
		{
			if (ClientUtils.isNonEmptyString(jsonProfile.get("username"))) {
				profile.setUsername(jsonProfile.get("username").asText());
			} else {
				throw new ProfileException("Please specify a valid string value for the 'username' field.");
			}
			if (ClientUtils.isNonEmptyString(jsonProfile.get("email"))) {
				String email = jsonProfile.get("email").asText();
				if (ClientUtils.isValidEmailAddress(email)) {
					profile.setEmail(email);
				} else {
					throw new ProfileException("Invalid 'email' value given. " +
							"Please specify a valid 'email' value for this user.");
				}
				profile.setEmail(jsonProfile.get("email").asText());
			} else {
				throw new ProfileException("Please specify a valid 'email' value for this user.");
			}
			if (jsonProfile.has("firstName")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("firstName"))) {
					profile.setFirstName(jsonProfile.get("firstName").asText());
				} else {
					throw new ProfileException("Invalid 'firstName' value. " +
							"If specified, please specify a valid first name for this user.");
				}
			}
			if (jsonProfile.has("lastName")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("lastName"))) {
					profile.setLastName(jsonProfile.get("lastName").asText());
				} else {
					throw new ProfileException("Invalid 'lastName' value. " +
							"If specified, please specify a valid last name for this user.");
				}
			}
			if (jsonProfile.has("position")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("position"))) {
					profile.setPosition(jsonProfile.get("position").asText());
				} else {
					throw new ProfileException("Invalid 'position' value. " +
							"If specified, please specify a valid job position for this user.");
				}
			}
			if (jsonProfile.has("institution")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("institution"))) {
					profile.setInstitution(jsonProfile.get("institution").asText());
				} else {
					throw new ProfileException("Invalid 'institution' value. " +
							"If specified, please specify a valid institution for this user.");
				}
			}
			if (jsonProfile.has("phone")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("phone"))) {
					String phone = jsonProfile.get("phone").asText();
					if (ClientUtils.isValidPhoneNumber(phone))
						profile.setPhone(phone);
					else
						throw new ProfileException("Invalid 'phone' value. " +
								"If specified, please specify a valid phone number for this user " +
								"in ###-###-#### format.");
				} else {
					throw new ProfileException("Invalid 'phone' value. " +
							"If specified, please specify a valid phone number for this user" +
							"in ###-###-#### format.");
				}
			}
			if (jsonProfile.has("fax")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("fax"))) {
					String fax = jsonProfile.get("fax").asText();
					if (ClientUtils.isValidPhoneNumber(fax))
						profile.setFax(fax);
					else
						throw new ProfileException("Invalid 'fax' value. " +
								"If specified, please specify a valid fax number for this user " +
								"in ###-###-#### format.");
				} else {
					throw new ProfileException("Invalid 'fax' value. " +
							"If specified, please specify a valid fax number for this user" +
							"in ###-###-#### format.");
				}
			}
			if (jsonProfile.has("researchArea")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("researchArea"))) {
					profile.setResearchArea(jsonProfile.get("researchArea").asText());
				} else {
					throw new ProfileException("Invalid 'researchArea' value. " +
							"If specified, please specify a valid researchArea for this user.");
				}
			}
			if (jsonProfile.has("department")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("department"))) {
					profile.setDepartment(jsonProfile.get("department").asText());
				} else {
					throw new ProfileException("Invalid 'department' value. " +
							"If specified, please specify a valid department for this user.");
				}
			}
			if (jsonProfile.has("city")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("city"))) {
					profile.setCity(jsonProfile.get("city").asText());
				} else {
					throw new ProfileException("Invalid 'city' value. " +
							"If specified, please specify a valid city for this user.");
				}
			}
			if (jsonProfile.has("state")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("state"))) {
					profile.setState(jsonProfile.get("state").asText());
				} else {
					throw new ProfileException("Invalid 'state' value. " +
							"If specified, please specify a valid state or state abbreviation for this user.");
				}
			}
			if (jsonProfile.has("country")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("country"))) {
					profile.setCountry(jsonProfile.get("country").asText());
				} else {
					throw new ProfileException("Invalid 'country' value. " +
							"If specified, please specify a valid country or country code for this user.");
				}
			}
			if (jsonProfile.has("gender")) {
				if (ClientUtils.isNonEmptyString(jsonProfile.get("gender"))) {
					try {
						GenderType genderType = GenderType.valueOf(jsonProfile.get("gender").asText().toUpperCase());
						profile.setGender(genderType);
					} catch (Exception e) {
						throw new ProfileException("Invalid 'gender' provided. " +
								"If specified, 'gender' must be either MALE or FEMALE.");
					}
				} else {
					throw new ProfileException("Invalid 'gender' provided. " +
							"If specified, 'gender' must be either MALE or FEMALE.");
				}
			}
			return profile;
		} 
		catch (Exception e) {
			throw new ProfileException("Failed to parse profile. " + e.getMessage(), e);
		}
	}
public static Profile fromJSON ( JsonNode jsonProfile , Profile profile ) throws ProfileException { if ( profile == null ) { profile = new Profile ( ) ; } try { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "username" ) ) ) { profile . setUsername ( jsonProfile . get ( "username" ) . asText ( ) ) ; } else { throw new ProfileException ( "Please specify a valid string value for the 'username' field." ) ; } if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "email" ) ) ) { String email = jsonProfile . get ( "email" ) . asText ( ) ; if ( ClientUtils . isValidEmailAddress ( email ) ) { profile . setEmail ( email ) ; } else { throw new ProfileException ( "Invalid 'email' value given. " + "Please specify a valid 'email' value for this user." ) ; } profile . setEmail ( jsonProfile . get ( "email" ) . asText ( ) ) ; } else { throw new ProfileException ( "Please specify a valid 'email' value for this user." ) ; } if ( jsonProfile . has ( "firstName" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "firstName" ) ) ) { profile . setFirstName ( jsonProfile . get ( "firstName" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'firstName' value. " + "If specified, please specify a valid first name for this user." ) ; } } if ( jsonProfile . has ( "lastName" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "lastName" ) ) ) { profile . setLastName ( jsonProfile . get ( "lastName" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'lastName' value. " + "If specified, please specify a valid last name for this user." ) ; } } if ( jsonProfile . has ( "position" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "position" ) ) ) { profile . setPosition ( jsonProfile . get ( "position" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'position' value. " + "If specified, please specify a valid job position for this user." ) ; } } if ( jsonProfile . has ( "institution" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "institution" ) ) ) { profile . setInstitution ( jsonProfile . get ( "institution" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'institution' value. " + "If specified, please specify a valid institution for this user." ) ; } } if ( jsonProfile . has ( "phone" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "phone" ) ) ) { String phone = jsonProfile . get ( "phone" ) . asText ( ) ; if ( ClientUtils . isValidPhoneNumber ( phone ) ) profile . setPhone ( phone ) ; else throw new ProfileException ( "Invalid 'phone' value. " + "If specified, please specify a valid phone number for this user " + "in ###-###-#### format." ) ; } else { throw new ProfileException ( "Invalid 'phone' value. " + "If specified, please specify a valid phone number for this user" + "in ###-###-#### format." ) ; } } if ( jsonProfile . has ( "fax" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "fax" ) ) ) { String fax = jsonProfile . get ( "fax" ) . asText ( ) ; if ( ClientUtils . isValidPhoneNumber ( fax ) ) profile . setFax ( fax ) ; else throw new ProfileException ( "Invalid 'fax' value. " + "If specified, please specify a valid fax number for this user " + "in ###-###-#### format." ) ; } else { throw new ProfileException ( "Invalid 'fax' value. " + "If specified, please specify a valid fax number for this user" + "in ###-###-#### format." ) ; } } if ( jsonProfile . has ( "researchArea" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "researchArea" ) ) ) { profile . setResearchArea ( jsonProfile . get ( "researchArea" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'researchArea' value. " + "If specified, please specify a valid researchArea for this user." ) ; } } if ( jsonProfile . has ( "department" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "department" ) ) ) { profile . setDepartment ( jsonProfile . get ( "department" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'department' value. " + "If specified, please specify a valid department for this user." ) ; } } if ( jsonProfile . has ( "city" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "city" ) ) ) { profile . setCity ( jsonProfile . get ( "city" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'city' value. " + "If specified, please specify a valid city for this user." ) ; } } if ( jsonProfile . has ( "state" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "state" ) ) ) { profile . setState ( jsonProfile . get ( "state" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'state' value. " + "If specified, please specify a valid state or state abbreviation for this user." ) ; } } if ( jsonProfile . has ( "country" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "country" ) ) ) { profile . setCountry ( jsonProfile . get ( "country" ) . asText ( ) ) ; } else { throw new ProfileException ( "Invalid 'country' value. " + "If specified, please specify a valid country or country code for this user." ) ; } } if ( jsonProfile . has ( "gender" ) ) { if ( ClientUtils . isNonEmptyString ( jsonProfile . get ( "gender" ) ) ) { try { GenderType genderType = GenderType . valueOf ( jsonProfile . get ( "gender" ) . asText ( ) . toUpperCase ( ) ) ; profile . setGender ( genderType ) ; } catch ( Exception e ) { throw new ProfileException ( "Invalid 'gender' provided. " + "If specified, 'gender' must be either MALE or FEMALE." ) ; } } else { throw new ProfileException ( "Invalid 'gender' provided. " + "If specified, 'gender' must be either MALE or FEMALE." ) ; } } return profile ; } catch ( Exception e ) { throw new ProfileException ( "Failed to parse profile. " + e . getMessage ( ) , e ) ; } }
Parses and validates a JSON representation, updating the passed in
 Profile object.
Parses and validates a JSON representation updating the passed in Profile object .