src/org/ohmage/request/clazz/ClassUpdateRequest.java
@Override
	public void service() {
		LOGGER.info("Servicing a class update request.");
		
		if(! authenticate(AllowNewAccount.NEW_ACCOUNT_DISALLOWED)) {
			return;
		}
		
		try {	
			LOGGER.info("Checking that the user is privileged in the class or is an admin.");
			UserClassServices
				.instance().
				userIsAdminOrPrivileged(classId, getUser().getUsername());
			
			LOGGER.info("Checking that the class exists.");
			ClassServices.instance().checkClassExistence(classId, true);
			
			// Validate the list of users to add.
			if(usersToAdd != null) {
				// Get the existing list of users in the class.
				List<String> existingUsers =
					UserClassServices.instance().getUsersInClass(classId);
				
				// Get the users that are being added to the class.
				Set<String> addingUsers =
					new HashSet<String>(usersToAdd.keySet());
				
				// Remove any users that already exist in the class.
				addingUsers.removeAll(existingUsers);
				
				// If the user is attempting to add new users to the class,
				// they must be an admin.
				if(! addingUsers.isEmpty()) {
					LOGGER
						.info(
							"The user is attempting to add users to the " +
								"class, so we must ensure that they are an " +
								"admin.");
					if(! 
						UserServices
							.instance()
							.isUserAnAdmin(getUser().getUsername())) {
						
						throw
							new ServiceException(
								ErrorCode.CLASS_INSUFFICIENT_PERMISSIONS,
								"The requesting user must be an admin to " +
									"add users to a class.");
					}
					
					LOGGER.info("Verifying that the new users exist.");
					UserServices
						.instance()
						.verifyUsersExist(usersToAdd.keySet(), true);
				}
			}
			
			LOGGER.info("Updating the class.");
			ClassServices.instance().updateClass(classId, className, classDescription, usersToAdd, usersToRemove);
		}
		catch(ServiceException e) {
			e.failRequest(this);
			e.logException(LOGGER);
		}
	}
/**
	 * Services the request. This includes authenticating the user, checking
	 * that the class exists, checking that the requester has permissions to
	 * modify the class, and updating the class.
	 */
Services the request. This includes authenticating the user, checking
that the class exists, checking that the requester has permissions to
modify the class, and updating the class.
Services the request . This includes authenticating the user checking that the class exists checking that the requester has permissions to modify the class and updating the class .
@Override
	public void service() {
		LOGGER.info("Servicing a class update request.");
		if(! authenticate(AllowNewAccount.NEW_ACCOUNT_DISALLOWED)) {
			return;
		}
		try {	
			LOGGER.info("Checking that the user is privileged in the class or is an admin.");
			UserClassServices
				.instance().
				userIsAdminOrPrivileged(classId, getUser().getUsername());
			LOGGER.info("Checking that the class exists.");
			ClassServices.instance().checkClassExistence(classId, true);
			if(usersToAdd != null) {
				List<String> existingUsers =
					UserClassServices.instance().getUsersInClass(classId);
				Set<String> addingUsers =
					new HashSet<String>(usersToAdd.keySet());
				addingUsers.removeAll(existingUsers);
				if(! addingUsers.isEmpty()) {
					LOGGER
						.info(
							"The user is attempting to add users to the " +
								"class, so we must ensure that they are an " +
								"admin.");
					if(! 
						UserServices
							.instance()
							.isUserAnAdmin(getUser().getUsername())) {
						throw
							new ServiceException(
								ErrorCode.CLASS_INSUFFICIENT_PERMISSIONS,
								"The requesting user must be an admin to " +
									"add users to a class.");
					}
					LOGGER.info("Verifying that the new users exist.");
					UserServices
						.instance()
						.verifyUsersExist(usersToAdd.keySet(), true);
				}
			}
			LOGGER.info("Updating the class.");
			ClassServices.instance().updateClass(classId, className, classDescription, usersToAdd, usersToRemove);
		}
		catch(ServiceException e) {
			e.failRequest(this);
			e.logException(LOGGER);
		}
	}
@ Override public void service ( ) { LOGGER . info ( "Servicing a class update request." ) ; if ( ! authenticate ( AllowNewAccount . NEW_ACCOUNT_DISALLOWED ) ) { return ; } try { LOGGER . info ( "Checking that the user is privileged in the class or is an admin." ) ; UserClassServices . instance ( ) . userIsAdminOrPrivileged ( classId , getUser ( ) . getUsername ( ) ) ; LOGGER . info ( "Checking that the class exists." ) ; ClassServices . instance ( ) . checkClassExistence ( classId , true ) ; if ( usersToAdd != null ) { List < String > existingUsers = UserClassServices . instance ( ) . getUsersInClass ( classId ) ; Set < String > addingUsers = new HashSet < String > ( usersToAdd . keySet ( ) ) ; addingUsers . removeAll ( existingUsers ) ; if ( ! addingUsers . isEmpty ( ) ) { LOGGER . info ( "The user is attempting to add users to the " + "class, so we must ensure that they are an " + "admin." ) ; if ( ! UserServices . instance ( ) . isUserAnAdmin ( getUser ( ) . getUsername ( ) ) ) { throw new ServiceException ( ErrorCode . CLASS_INSUFFICIENT_PERMISSIONS , "The requesting user must be an admin to " + "add users to a class." ) ; } LOGGER . info ( "Verifying that the new users exist." ) ; UserServices . instance ( ) . verifyUsersExist ( usersToAdd . keySet ( ) , true ) ; } } LOGGER . info ( "Updating the class." ) ; ClassServices . instance ( ) . updateClass ( classId , className , classDescription , usersToAdd , usersToRemove ) ; } catch ( ServiceException e ) { e . failRequest ( this ) ; e . logException ( LOGGER ) ; } }
Services the request.
Services the request .
// Validate the list of users to add. // Get the existing list of users in the class. // Get the users that are being added to the class. // Remove any users that already exist in the class. // If the user is attempting to add new users to the class, // they must be an admin.