src/org/ohmage/service/UploadValidationServices.java
public static void validateLocation(final JSONObject location, 
			final String locationStatus) throws ServiceException {
		
		if(locationStatus.equals(JsonInputKeys.METADATA_LOCATION_STATUS_UNAVAILABLE) && location != null) {
			throw new ServiceException(
					ErrorCode.SERVER_INVALID_LOCATION, 
					"location object in upload message exists, but location status is unavailable");
		}
		
		if(! locationStatus.equals(JsonInputKeys.METADATA_LOCATION_STATUS_UNAVAILABLE) && location == null) {
			throw new ServiceException(
					ErrorCode.SERVER_INVALID_LOCATION, 
					"missing location object in upload message");
		}
		
		if(location != null) {
			UploadValidationServices.validateLatitude(JsonUtils.getDoubleFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_LATITUDE));
			UploadValidationServices.validateLongitude(JsonUtils.getDoubleFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_LONGITUDE));
			UploadValidationServices.validateAccuracy(JsonUtils.getStringFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_ACCURACY));
			UploadValidationServices.validateProvider(JsonUtils.getStringFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_PROVIDER));
			
			UploadValidationServices.validateIso8601Timestamp(
				JsonUtils.getStringFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_TIMESTAMP),
				LOCATION_TIMESTAMP_ERROR_MESSAGE_NULL,
				LOCATION_TIMESTAMP_ERROR_MESSAGE_INVALID
			);
		}
	}
/**
	 * Validates the provided location object. If the location status is 
	 * unavailable, it is an error to send a location object. Otherwise,
	 * the location object must contain values for longitude, latitude,
	 * accuracy, provider, and timestamp.
	 *  
	 * @param location  A JSON object containing location properties to be
	 * validated.
	 * @throws ServiceException  If the location is null and the location 
	 * status is unavailable or if the location status is not unavailable
	 * and the location is invalid in structure.
	 */
Validates the provided location object. If the location status is
unavailable, it is an error to send a location object. Otherwise,
the location object must contain values for longitude, latitude,
accuracy, provider, and timestamp.

@param location  A JSON object containing location properties to be
validated.
@throws ServiceException  If the location is null and the location
status is unavailable or if the location status is not unavailable
and the location is invalid in structure.
Validates the provided location object . If the location status is unavailable it is an error to send a location object . Otherwise the location object must contain values for longitude latitude accuracy provider and timestamp . @param location A JSON object containing location properties to be validated . @throws ServiceException If the location is null and the location status is unavailable or if the location status is not unavailable and the location is invalid in structure .
public static void validateLocation(final JSONObject location, 
			final String locationStatus) throws ServiceException {
		if(locationStatus.equals(JsonInputKeys.METADATA_LOCATION_STATUS_UNAVAILABLE) && location != null) {
			throw new ServiceException(
					ErrorCode.SERVER_INVALID_LOCATION, 
					"location object in upload message exists, but location status is unavailable");
		}
		if(! locationStatus.equals(JsonInputKeys.METADATA_LOCATION_STATUS_UNAVAILABLE) && location == null) {
			throw new ServiceException(
					ErrorCode.SERVER_INVALID_LOCATION, 
					"missing location object in upload message");
		}
		if(location != null) {
			UploadValidationServices.validateLatitude(JsonUtils.getDoubleFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_LATITUDE));
			UploadValidationServices.validateLongitude(JsonUtils.getDoubleFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_LONGITUDE));
			UploadValidationServices.validateAccuracy(JsonUtils.getStringFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_ACCURACY));
			UploadValidationServices.validateProvider(JsonUtils.getStringFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_PROVIDER));
			UploadValidationServices.validateIso8601Timestamp(
				JsonUtils.getStringFromJsonObject(location, JsonInputKeys.METADATA_LOCATION_TIMESTAMP),
				LOCATION_TIMESTAMP_ERROR_MESSAGE_NULL,
				LOCATION_TIMESTAMP_ERROR_MESSAGE_INVALID
			);
		}
	}
public static void validateLocation ( final JSONObject location , final String locationStatus ) throws ServiceException { if ( locationStatus . equals ( JsonInputKeys . METADATA_LOCATION_STATUS_UNAVAILABLE ) && location != null ) { throw new ServiceException ( ErrorCode . SERVER_INVALID_LOCATION , "location object in upload message exists, but location status is unavailable" ) ; } if ( ! locationStatus . equals ( JsonInputKeys . METADATA_LOCATION_STATUS_UNAVAILABLE ) && location == null ) { throw new ServiceException ( ErrorCode . SERVER_INVALID_LOCATION , "missing location object in upload message" ) ; } if ( location != null ) { UploadValidationServices . validateLatitude ( JsonUtils . getDoubleFromJsonObject ( location , JsonInputKeys . METADATA_LOCATION_LATITUDE ) ) ; UploadValidationServices . validateLongitude ( JsonUtils . getDoubleFromJsonObject ( location , JsonInputKeys . METADATA_LOCATION_LONGITUDE ) ) ; UploadValidationServices . validateAccuracy ( JsonUtils . getStringFromJsonObject ( location , JsonInputKeys . METADATA_LOCATION_ACCURACY ) ) ; UploadValidationServices . validateProvider ( JsonUtils . getStringFromJsonObject ( location , JsonInputKeys . METADATA_LOCATION_PROVIDER ) ) ; UploadValidationServices . validateIso8601Timestamp ( JsonUtils . getStringFromJsonObject ( location , JsonInputKeys . METADATA_LOCATION_TIMESTAMP ) , LOCATION_TIMESTAMP_ERROR_MESSAGE_NULL , LOCATION_TIMESTAMP_ERROR_MESSAGE_INVALID ) ; } }
Validates the provided location object.
Validates the provided location object .