src/org/ohmage/request/clazz/ClassCreationRequest.java
@Override
	public void service() {
		LOGGER.info("Servicing a class creation request.");
		
		if(! authenticate(AllowNewAccount.NEW_ACCOUNT_DISALLOWED)) {
			return;
		}
		
		try {
			// Check if the user is an administrator.
			LOGGER.info("Checking that the user can create classes.");
			UserServices
				.instance()
				.verifyUserCanCreateClasses(getUser().getUsername());
			
			// Check that the class doesn't already exist.
			LOGGER.info("Checking that a class with the same ID doesn't already exist.");
			ClassServices.instance().checkClassExistence(classId, false);
			
			// Create the class.
			LOGGER.info("Creating the class.");
			ClassServices.instance().createClass(classId, className, classDescription);
			
			// Add the user to the class.
			Map<String, Clazz.Role> usersToAdd =
				new HashMap<String, Clazz.Role>();
			usersToAdd.put(getUser().getUsername(), Clazz.Role.PRIVILEGED);
			LOGGER.info("Adding the user to the class.");
			ClassServices
				.instance()
				.updateClass(classId, null, null, usersToAdd, null);
		}
		catch(ServiceException e) {
			e.failRequest(this);
			e.logException(LOGGER);
		}
	}
/**
	 * Ensures that the class doesn't already exists and, if not, creates it.
	 */
Ensures that the class doesn't already exists and, if not, creates it.
Ensures that the class doesn ' t already exists and if not creates it .
@Override
	public void service() {
		LOGGER.info("Servicing a class creation request.");
		if(! authenticate(AllowNewAccount.NEW_ACCOUNT_DISALLOWED)) {
			return;
		}
		try {
			LOGGER.info("Checking that the user can create classes.");
			UserServices
				.instance()
				.verifyUserCanCreateClasses(getUser().getUsername());
			LOGGER.info("Checking that a class with the same ID doesn't already exist.");
			ClassServices.instance().checkClassExistence(classId, false);
			LOGGER.info("Creating the class.");
			ClassServices.instance().createClass(classId, className, classDescription);
			Map<String, Clazz.Role> usersToAdd =
				new HashMap<String, Clazz.Role>();
			usersToAdd.put(getUser().getUsername(), Clazz.Role.PRIVILEGED);
			LOGGER.info("Adding the user to the class.");
			ClassServices
				.instance()
				.updateClass(classId, null, null, usersToAdd, null);
		}
		catch(ServiceException e) {
			e.failRequest(this);
			e.logException(LOGGER);
		}
	}
@ Override public void service ( ) { LOGGER . info ( "Servicing a class creation request." ) ; if ( ! authenticate ( AllowNewAccount . NEW_ACCOUNT_DISALLOWED ) ) { return ; } try { LOGGER . info ( "Checking that the user can create classes." ) ; UserServices . instance ( ) . verifyUserCanCreateClasses ( getUser ( ) . getUsername ( ) ) ; LOGGER . info ( "Checking that a class with the same ID doesn't already exist." ) ; ClassServices . instance ( ) . checkClassExistence ( classId , false ) ; LOGGER . info ( "Creating the class." ) ; ClassServices . instance ( ) . createClass ( classId , className , classDescription ) ; Map < String , Clazz . Role > usersToAdd = new HashMap < String , Clazz . Role > ( ) ; usersToAdd . put ( getUser ( ) . getUsername ( ) , Clazz . Role . PRIVILEGED ) ; LOGGER . info ( "Adding the user to the class." ) ; ClassServices . instance ( ) . updateClass ( classId , null , null , usersToAdd , null ) ; } catch ( ServiceException e ) { e . failRequest ( this ) ; e . logException ( LOGGER ) ; } }
Ensures that the class doesn't already exists and, if not, creates it.
Ensures that the class doesn ' t already exists and if not creates it .
// Check if the user is an administrator. // Check that the class doesn't already exist. // Create the class. // Add the user to the class.