agave-apps/apps-core/src/main/java/org/iplantc/service/apps/managers/SoftwareEventProcessor.java
/**
	 * Generates notification events for permission-related changes to a 
	 * {@link Software}. Permission changes are not propagated to the associated
	 * resources.
	 * 
	 * @param software the software for which the event was created
	 * @param softwarePermission the permission that was set
	 * @param createdBy the principal to attribute the event
	 * @return the {@link SoftwareEvent} created
	 */
Generates notification events for permission-related changes to a
Software. Permission changes are not propagated to the associated
resources.

@param software the software for which the event was created
@param softwarePermission the permission that was set
@param createdBy the principal to attribute the event
@return the  SoftwareEvent created
Generates notification events for permission - related changes to a Software . Permission changes are not propagated to the associated resources . @param software the software for which the event was created @param softwarePermission the permission that was set @param createdBy the principal to attribute the event @return the SoftwareEvent created
public SoftwareEvent processPermissionEvent(Software software, SoftwarePermission softwarePermission, String createdBy) 
	{
		SoftwareEvent event = null;
		try {
			if (software == null) {
				throw new EntityEventProcessingException("Valid app must be provided to process event.");
			}
			if (StringUtils.isEmpty(createdBy)) {
				throw new EntityEventProcessingException("Valid username must be provided to process event.");
			}
			SoftwareEventType eventType = null;
			String eventMessage = null;
			if (softwarePermission == null) {
				eventType = SoftwareEventType.PERMISSION_REVOKE;
				eventMessage = "All permissions were cleared by "  + createdBy;
			}
			else if (softwarePermission.getPermission() == PermissionType.NONE) { 
				eventType = SoftwareEventType.PERMISSION_REVOKE;
				eventMessage = String.format("User %s had their permissions revoked by %s",
						softwarePermission.getUsername(),
						createdBy);
			} else {
				eventType = SoftwareEventType.PERMISSION_GRANT;
				eventMessage = String.format("User %s was granted the permission of %s by %s", 
						softwarePermission.getUsername(), 
						softwarePermission.getPermission().name(),
						createdBy);
			}
			ObjectNode json = null;
			try {
			    json = mapper.createObjectNode();
		    	json.set("app", mapper.readTree(software.toJSON()));
			    json.set("permission", mapper.readTree(softwarePermission.toJSON()));
			} catch (Throwable e) {
			    log.error(String.format("Failed to serialize app "
			            + "%s to json for %s event notification", 
			            software.getUuid(), eventType.name()), e);
			    json = null;
			}
			event = new SoftwareEvent(software, 
					  eventType, 
					  eventMessage,
					  createdBy);
			getEntityEventDao().persist(event);
			fireNotification(software.getUuid(), eventType.name(), createdBy, json);
			doUserJobEvents(software, eventType.name(), softwarePermission.getUsername(), createdBy, json);
		}
		catch (EntityEventProcessingException e) {
			log.error(e.getMessage());
		}
		catch (SoftwareEventPersistenceException e) {
			log.error("Failed to persist history event for app " + software.getUuid(), e);
		}
		return event;
	}
public SoftwareEvent processPermissionEvent ( Software software , SoftwarePermission softwarePermission , String createdBy ) { SoftwareEvent event = null ; try { if ( software == null ) { throw new EntityEventProcessingException ( "Valid app must be provided to process event." ) ; } if ( StringUtils . isEmpty ( createdBy ) ) { throw new EntityEventProcessingException ( "Valid username must be provided to process event." ) ; } SoftwareEventType eventType = null ; String eventMessage = null ; if ( softwarePermission == null ) { eventType = SoftwareEventType . PERMISSION_REVOKE ; eventMessage = "All permissions were cleared by " + createdBy ; } else if ( softwarePermission . getPermission ( ) == PermissionType . NONE ) { eventType = SoftwareEventType . PERMISSION_REVOKE ; eventMessage = String . format ( "User %s had their permissions revoked by %s" , softwarePermission . getUsername ( ) , createdBy ) ; } else { eventType = SoftwareEventType . PERMISSION_GRANT ; eventMessage = String . format ( "User %s was granted the permission of %s by %s" , softwarePermission . getUsername ( ) , softwarePermission . getPermission ( ) . name ( ) , createdBy ) ; } ObjectNode json = null ; try { json = mapper . createObjectNode ( ) ; json . set ( "app" , mapper . readTree ( software . toJSON ( ) ) ) ; json . set ( "permission" , mapper . readTree ( softwarePermission . toJSON ( ) ) ) ; } catch ( Throwable e ) { log . error ( String . format ( "Failed to serialize app " + "%s to json for %s event notification" , software . getUuid ( ) , eventType . name ( ) ) , e ) ; json = null ; } event = new SoftwareEvent ( software , eventType , eventMessage , createdBy ) ; getEntityEventDao ( ) . persist ( event ) ; fireNotification ( software . getUuid ( ) , eventType . name ( ) , createdBy , json ) ; doUserJobEvents ( software , eventType . name ( ) , softwarePermission . getUsername ( ) , createdBy , json ) ; } catch ( EntityEventProcessingException e ) { log . error ( e . getMessage ( ) ) ; } catch ( SoftwareEventPersistenceException e ) { log . error ( "Failed to persist history event for app " + software . getUuid ( ) , e ) ; } return event ; }
Generates notification events for permission-related changes to a
 {@link Software}.
Generates notification events for permission - related changes to a { @link Software } .
// alert the job in case the job owner just had their app permissions revoked // TODO: send event to the user // We do not fire delegated app permission events on associated uuids