src/org/ohmage/service/AccessRequestServices.java
public void sendNotification(String requester, String requestId, Boolean notifiedAdmin) {

		AccessRequest request = null;
		String recipient = null;
		
		try {	
			request = userSetupRequestQueries.getAccessRequest(requester, requestId); 
		} catch (DataAccessException e) {
			LOGGER.warn(requester + " can't access the request: " + requestId, e);
			return;
		}
		
		try {		
			// Get the session.
			Session smtpSession = MailUtils.getMailSession();
			// Create the message.
			MimeMessage message = new MimeMessage(smtpSession);

			try {
				if (notifiedAdmin) 
					recipient = PreferenceCache.instance().lookup(PreferenceCache.KEY_MAIL_ADMIN_ADDRESS);
				else 
					recipient = request.getEmailAddress();
			} catch(CacheMissException e) {
				LOGGER.warn("Missing an entry in the preference table : " + PreferenceCache.KEY_MAIL_ADMIN_ADDRESS +
						". Will use " + LOCAL_ADMIN_ADDRESS + "instead.", e);	
				recipient = LOCAL_ADMIN_ADDRESS;
			}	
			
			// set up properties
			MailUtils.setMailMessageFrom(message, PreferenceCache.KEY_MAIL_ACCESS_REQUEST_SENDER);
			MailUtils.setMailMessageTo(message, recipient);
			MailUtils.setMailMessageSubject(message, PreferenceCache.KEY_MAIL_ACCESS_REQUEST_SUBJECT);
			
			StringBuilder content = new StringBuilder();

			if (notifiedAdmin) {
				content.append("<p>Dear admin,</p>\n");
				content.append("<p>The following request has been submitted: </p>\n");
			} else {
				content.append("<p>Dear user,</p>\n");
				content.append("<p>Below please find the status and information of your request: </p>\n");
			}
			
			try {
				content.append(request.toHTML());
			} catch (DomainException e) {
				throw new ServiceException(
						"Can't generate the html content of the request",
						e);				
			}
			try {
				// Set the content of the message.
				message.setContent(content.toString(), "text/html");
			}
			catch(MessagingException e) {
				throw new ServiceException(
						"There was an error constructing the message.",
						e);
			}
			
			// send message
			MailUtils.sendMailMessage(smtpSession, message);
			
		} catch (ServiceException e) {
			LOGGER.warn("Unable to send notification to " + recipient, e);		
		}
	}
/**
	 * Send email notification to user or admin depending on the parameter.
	 * If something is wrong during the notification process, will not throw
	 * an exception, but will generate a warning message. 
	 *  
	 * @param requester The username of the requester.
	 * 
	 * @param requestId The request UUID. 
	 *  
	 * @param notifiedAdmin A flag indicating whether to notify the admin or user
	 * 					on the request. If true, will send the notification to admin. 
	 * 					If false, will send the notification to the owner of the request. 
	 * 
	 * 
	 */
Send email notification to user or admin depending on the parameter.
If something is wrong during the notification process, will not throw
an exception, but will generate a warning message.

@param requester The username of the requester.

@param requestId The request UUID.

@param notifiedAdmin A flag indicating whether to notify the admin or user
on the request. If true, will send the notification to admin.
If false, will send the notification to the owner of the request.
Send email notification to user or admin depending on the parameter . If something is wrong during the notification process will not throw an exception but will generate a warning message . @param requester The username of the requester . @param requestId The request UUID . @param notifiedAdmin A flag indicating whether to notify the admin or user on the request . If true will send the notification to admin . If false will send the notification to the owner of the request .
public void sendNotification(String requester, String requestId, Boolean notifiedAdmin) {
		AccessRequest request = null;
		String recipient = null;
		try {	
			request = userSetupRequestQueries.getAccessRequest(requester, requestId); 
		} catch (DataAccessException e) {
			LOGGER.warn(requester + " can't access the request: " + requestId, e);
			return;
		}
		try {		
			Session smtpSession = MailUtils.getMailSession();
			MimeMessage message = new MimeMessage(smtpSession);
			try {
				if (notifiedAdmin) 
					recipient = PreferenceCache.instance().lookup(PreferenceCache.KEY_MAIL_ADMIN_ADDRESS);
				else 
					recipient = request.getEmailAddress();
			} catch(CacheMissException e) {
				LOGGER.warn("Missing an entry in the preference table : " + PreferenceCache.KEY_MAIL_ADMIN_ADDRESS +
						". Will use " + LOCAL_ADMIN_ADDRESS + "instead.", e);	
				recipient = LOCAL_ADMIN_ADDRESS;
			}	
			MailUtils.setMailMessageFrom(message, PreferenceCache.KEY_MAIL_ACCESS_REQUEST_SENDER);
			MailUtils.setMailMessageTo(message, recipient);
			MailUtils.setMailMessageSubject(message, PreferenceCache.KEY_MAIL_ACCESS_REQUEST_SUBJECT);
			StringBuilder content = new StringBuilder();
			if (notifiedAdmin) {
				content.append("<p>Dear admin,</p>\n");
				content.append("<p>The following request has been submitted: </p>\n");
			} else {
				content.append("<p>Dear user,</p>\n");
				content.append("<p>Below please find the status and information of your request: </p>\n");
			}
			try {
				content.append(request.toHTML());
			} catch (DomainException e) {
				throw new ServiceException(
						"Can't generate the html content of the request",
						e);				
			}
			try {
				message.setContent(content.toString(), "text/html");
			}
			catch(MessagingException e) {
				throw new ServiceException(
						"There was an error constructing the message.",
						e);
			}
			MailUtils.sendMailMessage(smtpSession, message);
		} catch (ServiceException e) {
			LOGGER.warn("Unable to send notification to " + recipient, e);		
		}
	}
public void sendNotification ( String requester , String requestId , Boolean notifiedAdmin ) { AccessRequest request = null ; String recipient = null ; try { request = userSetupRequestQueries . getAccessRequest ( requester , requestId ) ; } catch ( DataAccessException e ) { LOGGER . warn ( requester + " can't access the request: " + requestId , e ) ; return ; } try { Session smtpSession = MailUtils . getMailSession ( ) ; MimeMessage message = new MimeMessage ( smtpSession ) ; try { if ( notifiedAdmin ) recipient = PreferenceCache . instance ( ) . lookup ( PreferenceCache . KEY_MAIL_ADMIN_ADDRESS ) ; else recipient = request . getEmailAddress ( ) ; } catch ( CacheMissException e ) { LOGGER . warn ( "Missing an entry in the preference table : " + PreferenceCache . KEY_MAIL_ADMIN_ADDRESS + ". Will use " + LOCAL_ADMIN_ADDRESS + "instead." , e ) ; recipient = LOCAL_ADMIN_ADDRESS ; } MailUtils . setMailMessageFrom ( message , PreferenceCache . KEY_MAIL_ACCESS_REQUEST_SENDER ) ; MailUtils . setMailMessageTo ( message , recipient ) ; MailUtils . setMailMessageSubject ( message , PreferenceCache . KEY_MAIL_ACCESS_REQUEST_SUBJECT ) ; StringBuilder content = new StringBuilder ( ) ; if ( notifiedAdmin ) { content . append ( "<p>Dear admin,</p>\n" ) ; content . append ( "<p>The following request has been submitted: </p>\n" ) ; } else { content . append ( "<p>Dear user,</p>\n" ) ; content . append ( "<p>Below please find the status and information of your request: </p>\n" ) ; } try { content . append ( request . toHTML ( ) ) ; } catch ( DomainException e ) { throw new ServiceException ( "Can't generate the html content of the request" , e ) ; } try { message . setContent ( content . toString ( ) , "text/html" ) ; } catch ( MessagingException e ) { throw new ServiceException ( "There was an error constructing the message." , e ) ; } MailUtils . sendMailMessage ( smtpSession , message ) ; } catch ( ServiceException e ) { LOGGER . warn ( "Unable to send notification to " + recipient , e ) ; } }
Send email notification to user or admin depending on the parameter.
Send email notification to user or admin depending on the parameter .
// Get the session. // Create the message. // set up properties // Set the content of the message. // send message