src/org/ohmage/service/ObserverServices.java
public Map<String, Long> verifyNewObserverIsValid(
			final Observer observer)
			throws ServiceException {
		
		if(observer == null) {
			throw new ServiceException(
				"The observer is null.");
		}
		
		try {
			// Compare the observer versions. If the new version is less than
			// or equal to the existing version, then this is not a valid 
			// update attempt.
			String observerId = observer.getId();
			if(observer.getVersion() <= 
				observerQueries.getGreatestObserverVersion(observerId)) {
				
				throw new ServiceException(
					ErrorCode.OBSERVER_INVALID_VERSION,
					"The new observer's version must increase: " +
						observer.getVersion());
			}
			
			// The set of stream IDs whose version did not increase. 
			Map<String, Long> result = new HashMap<String, Long>();
			
			// Compare each of the streams.
			for(Stream stream : observer.getStreamsMap().values()) {
				// Get the stream's version.
				Long streamVersion =
					observerQueries.getGreatestStreamVersion(
						observer.getId(), 
						stream.getId());
				
				// Get the new stream's version.
				long newStreamVersion = stream.getVersion();
				
				// If the stream didn't exist before, it is fine.
				if(streamVersion == null) {
					continue;
				}
				// If the new stream's version is less than the existing 
				// stream's version, that is an error.
				else if(newStreamVersion < streamVersion) {
					throw new ServiceException(
						ErrorCode.OBSERVER_INVALID_STREAM_VERSION,
						"The version of this stream, '" +
							stream.getId() +
							"', is less than the existing stream's version, '" +
							streamVersion +
							"': " + stream.getVersion());
				}
				// If the version didn't change, we add it to the set of stream
				// IDs.
				else if(newStreamVersion == streamVersion) {
					result.put(stream.getId(), streamVersion);
				}
				// Otherwise, the stream ID increased, in which case a new 
				// stream entry will be created.
			}
			
			return result;
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
/**
	 * Verifies that a new observer conforms to the requirements of the 
	 * existing observer.
	 * 
	 * @param observer The observer that must, at the very least, have an
	 * 				   increased version number and may contain other fixes.
	 * 
	 * @throws ServiceException The observer is invalid as a new observer or
	 * 							there was an error.
	 */
Verifies that a new observer conforms to the requirements of the
existing observer.

@param observer The observer that must, at the very least, have an
increased version number and may contain other fixes.

@throws ServiceException The observer is invalid as a new observer or
there was an error.
Verifies that a new observer conforms to the requirements of the existing observer . @param observer The observer that must at the very least have an increased version number and may contain other fixes . @throws ServiceException The observer is invalid as a new observer or there was an error .
public Map<String, Long> verifyNewObserverIsValid(
			final Observer observer)
			throws ServiceException {
		if(observer == null) {
			throw new ServiceException(
				"The observer is null.");
		}
		try {
			String observerId = observer.getId();
			if(observer.getVersion() <= 
				observerQueries.getGreatestObserverVersion(observerId)) {
				throw new ServiceException(
					ErrorCode.OBSERVER_INVALID_VERSION,
					"The new observer's version must increase: " +
						observer.getVersion());
			}
			Map<String, Long> result = new HashMap<String, Long>();
			for(Stream stream : observer.getStreamsMap().values()) {
				Long streamVersion =
					observerQueries.getGreatestStreamVersion(
						observer.getId(), 
						stream.getId());
				long newStreamVersion = stream.getVersion();
				if(streamVersion == null) {
					continue;
				}
				else if(newStreamVersion < streamVersion) {
					throw new ServiceException(
						ErrorCode.OBSERVER_INVALID_STREAM_VERSION,
						"The version of this stream, '" +
							stream.getId() +
							"', is less than the existing stream's version, '" +
							streamVersion +
							"': " + stream.getVersion());
				}
				else if(newStreamVersion == streamVersion) {
					result.put(stream.getId(), streamVersion);
				}
			}
			return result;
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
public Map < String , Long > verifyNewObserverIsValid ( final Observer observer ) throws ServiceException { if ( observer == null ) { throw new ServiceException ( "The observer is null." ) ; } try { String observerId = observer . getId ( ) ; if ( observer . getVersion ( ) <= observerQueries . getGreatestObserverVersion ( observerId ) ) { throw new ServiceException ( ErrorCode . OBSERVER_INVALID_VERSION , "The new observer's version must increase: " + observer . getVersion ( ) ) ; } Map < String , Long > result = new HashMap < String , Long > ( ) ; for ( Stream stream : observer . getStreamsMap ( ) . values ( ) ) { Long streamVersion = observerQueries . getGreatestStreamVersion ( observer . getId ( ) , stream . getId ( ) ) ; long newStreamVersion = stream . getVersion ( ) ; if ( streamVersion == null ) { continue ; } else if ( newStreamVersion < streamVersion ) { throw new ServiceException ( ErrorCode . OBSERVER_INVALID_STREAM_VERSION , "The version of this stream, '" + stream . getId ( ) + "', is less than the existing stream's version, '" + streamVersion + "': " + stream . getVersion ( ) ) ; } else if ( newStreamVersion == streamVersion ) { result . put ( stream . getId ( ) , streamVersion ) ; } } return result ; } catch ( DataAccessException e ) { throw new ServiceException ( e ) ; } }
Verifies that a new observer conforms to the requirements of the
 existing observer.
Verifies that a new observer conforms to the requirements of the existing observer .
// Compare the observer versions. If the new version is less than // or equal to the existing version, then this is not a valid  // update attempt. // The set of stream IDs whose version did not increase.  // Compare each of the streams. // Get the stream's version. // Get the new stream's version. // If the stream didn't exist before, it is fine. // If the new stream's version is less than the existing  // stream's version, that is an error. // If the version didn't change, we add it to the set of stream // IDs. // Otherwise, the stream ID increased, in which case a new  // stream entry will be created.