agave-notifications/notifications-core/src/main/java/org/iplantc/service/notification/events/NotificationMessageProcessor.java
/**
	 * Creates a {@link NotificationAttempt} instance from an {@link AbstractEventFilter}. This also 
	 * @param event
	 * @return
	 */
Creates a  NotificationAttempt instance from an  AbstractEventFilter. This also
@param event
@return
Creates a NotificationAttempt instance from an AbstractEventFilter . This also @param event @return
public static NotificationAttempt createNotificationAttemptFromEvent(EventFilter event) {
		NotificationAttempt attempt = new NotificationAttempt(event.getNotification().getUuid(), 
				event.resolveMacros(event.getNotification().getCallbackUrl(), true), 
				event.getOwner(), event.getAssociatedUuid().toString(), 
				event.getEvent(), "", Instant.now());
		try {
			NotificationCallbackProviderType provider = NotificationCallbackProviderType.getInstanceForUri(
					event.getNotification().getCallbackUrl(), event.getNotification().getTenantId());
			ObjectMapper mapper = new ObjectMapper();
			if (provider == EMAIL) {
				ObjectNode json = mapper.createObjectNode()
						.put("subject", event.getEmailSubject())
						.put("body", event.getEmailBody())
						.put("htmlBody", event.getHtmlEmailBody());
				attempt.setContent(json.toString());
			} 
			else if (provider == SLACK || provider == SMS) {
				ObjectNode json = mapper.createObjectNode()
						.put("subject", event.getEmailSubject());
				if (StringUtils.contains(event.getCustomNotificationMessageContextData(), "CUSTOM_USER_JOB_EVENT_NAME")) {
					try {
						json.put("body", mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(mapper.readTree(event.getCustomNotificationMessageContextData())));
					} catch (IOException e) {
						json.put("body", event.getCustomNotificationMessageContextData());
					}
					json.put("color", "good");
				}
				else {
					if (StringUtils.contains(event.getEvent(), "FAILED")) {
						json.put("color", "danger");
					}
					else if (StringUtils.contains(event.getEvent(), "RETRY")) {
						json.put("color", "warning");
					}
					else {
						json.put("color", "good");
					}
				}
				attempt.setContent(json.toString());
			}
			else if (provider == WEBHOOK || provider == AGAVE || provider == REALTIME) {
				attempt.setContent(event.getCustomNotificationMessageContextData());
				try {
					URL callbackUrl = new URL(event.getNotification().getCallbackUrl());
					URI encodedCallbackUrl = new URI(callbackUrl.getProtocol(), 
											callbackUrl.getUserInfo(), 
											callbackUrl.getHost(), 
											callbackUrl.getPort(), 
											event.resolveMacros(callbackUrl.getPath(), false), 
											event.resolveMacros(callbackUrl.getQuery(), true), 
											callbackUrl.getRef());
					attempt.setCallbackUrl(encodedCallbackUrl.toString());
				} catch (Exception e) {
				}
			} 
			else if (provider == NONE) {
				throw new BadCallbackException("No notification deliver provider found for for callbackUrl");
			}
			return attempt;
		}
		catch (BadCallbackException e) { 
			throw new NotImplementedException(e.getMessage(), e);
		}
	}
public static NotificationAttempt createNotificationAttemptFromEvent ( EventFilter event ) { NotificationAttempt attempt = new NotificationAttempt ( event . getNotification ( ) . getUuid ( ) , event . resolveMacros ( event . getNotification ( ) . getCallbackUrl ( ) , true ) , event . getOwner ( ) , event . getAssociatedUuid ( ) . toString ( ) , event . getEvent ( ) , "" , Instant . now ( ) ) ; try { NotificationCallbackProviderType provider = NotificationCallbackProviderType . getInstanceForUri ( event . getNotification ( ) . getCallbackUrl ( ) , event . getNotification ( ) . getTenantId ( ) ) ; ObjectMapper mapper = new ObjectMapper ( ) ; if ( provider == EMAIL ) { ObjectNode json = mapper . createObjectNode ( ) . put ( "subject" , event . getEmailSubject ( ) ) . put ( "body" , event . getEmailBody ( ) ) . put ( "htmlBody" , event . getHtmlEmailBody ( ) ) ; attempt . setContent ( json . toString ( ) ) ; } else if ( provider == SLACK || provider == SMS ) { ObjectNode json = mapper . createObjectNode ( ) . put ( "subject" , event . getEmailSubject ( ) ) ; if ( StringUtils . contains ( event . getCustomNotificationMessageContextData ( ) , "CUSTOM_USER_JOB_EVENT_NAME" ) ) { try { json . put ( "body" , mapper . writer ( new DefaultPrettyPrinter ( ) ) . writeValueAsString ( mapper . readTree ( event . getCustomNotificationMessageContextData ( ) ) ) ) ; } catch ( IOException e ) { json . put ( "body" , event . getCustomNotificationMessageContextData ( ) ) ; } json . put ( "color" , "good" ) ; } else { if ( StringUtils . contains ( event . getEvent ( ) , "FAILED" ) ) { json . put ( "color" , "danger" ) ; } else if ( StringUtils . contains ( event . getEvent ( ) , "RETRY" ) ) { json . put ( "color" , "warning" ) ; } else { json . put ( "color" , "good" ) ; } } attempt . setContent ( json . toString ( ) ) ; } else if ( provider == WEBHOOK || provider == AGAVE || provider == REALTIME ) { attempt . setContent ( event . getCustomNotificationMessageContextData ( ) ) ; try { URL callbackUrl = new URL ( event . getNotification ( ) . getCallbackUrl ( ) ) ; URI encodedCallbackUrl = new URI ( callbackUrl . getProtocol ( ) , callbackUrl . getUserInfo ( ) , callbackUrl . getHost ( ) , callbackUrl . getPort ( ) , event . resolveMacros ( callbackUrl . getPath ( ) , false ) , event . resolveMacros ( callbackUrl . getQuery ( ) , true ) , callbackUrl . getRef ( ) ) ; attempt . setCallbackUrl ( encodedCallbackUrl . toString ( ) ) ; } catch ( Exception e ) { } } else if ( provider == NONE ) { throw new BadCallbackException ( "No notification deliver provider found for for callbackUrl" ) ; } return attempt ; } catch ( BadCallbackException e ) { throw new NotImplementedException ( e . getMessage ( ) , e ) ; } }
Creates a {@link NotificationAttempt} instance from an {@link AbstractEventFilter}.
Creates a { @link NotificationAttempt } instance from an { @link AbstractEventFilter } .
// build a json object with the subject, body, and html body for the content // we'll create a formatted attachment if there is custom data to post to slack // add content as a json object so we don't double escape // if the notification got here, it's all good. // otherwise we'll just post a standard message //			else if (provider == RABBITMQ || provider == BEANSTALK || providprovider == JMS) { //				 //			} // bad url, move on