agave-apps/apps-core/src/main/java/org/iplantc/service/apps/managers/SoftwareEventProcessor.java
/**
	 * Propagates change of public/private scope to associated objects and 
	 * writes an event to the relevant software histories. The events thrown here
	 * are rather broad since taking a app offline may impact active
	 * transfers, jobs, apps, monitors, scheduled tasks, files, etc. 
	 *
	 * @param privateSoftware
	 * @param publishedSoftware
	 * @param createdBy
	 * @return
	 */
Propagates change of public/private scope to associated objects and
writes an event to the relevant software histories. The events thrown here
are rather broad since taking a app offline may impact active
transfers, jobs, apps, monitors, scheduled tasks, files, etc.


Propagates change of public / private scope to associated objects and writes an event to the relevant software histories . The events thrown here are rather broad since taking a app offline may impact active transfers jobs apps monitors scheduled tasks files etc .
public SoftwareEvent processPublishEvent(Software privateSoftware, Software publishedSoftware, String createdBy) {
		SoftwareEvent event = null;
		try {
			if (privateSoftware == null) {
				throw new EntityEventProcessingException("Valid original app must be provided to process event.");
			}
			if (publishedSoftware == null) {
				throw new EntityEventProcessingException("Valid published app must be provided to process event.");
			}
			if (StringUtils.isEmpty(createdBy)) {
				throw new EntityEventProcessingException("Valid username must be provided to process event.");
			}
			String description = String.format("App was published by %s as %s. The published asset checksum is %s", 
					createdBy, publishedSoftware.getUniqueName(), publishedSoftware.getChecksum() == null ? "unavailable" : publishedSoftware.getChecksum());
    		processSoftwareContentEvent(privateSoftware, SoftwareEventType.PUBLISHED, description, createdBy);
    		description = String.format("App was created by %s as a result of publishing %s. The asset checksum is %s", 
    				createdBy, privateSoftware.getUniqueName(),  publishedSoftware.getChecksum() == null ? "unavailable" : publishedSoftware.getChecksum());
    		processSoftwareContentEvent(publishedSoftware, SoftwareEventType.CREATED, description, createdBy);
    		String sPublishedAppJson = null;
			ObjectNode publishedAppJson = null;
    		try {
				publishedAppJson = (ObjectNode)mapper.createObjectNode().set("app", mapper.readTree(publishedSoftware.toJSON()));
				sPublishedAppJson = publishedAppJson.toString();
			} catch (IOException | JSONException e) {
				log.error(String.format("Failed to serialize app "
			            + "%s to json for %s event notification", 
			            publishedSoftware.getUniqueName(), SoftwareEventType.REPUBLISHED.name()), e);
			}
    		doSystemEvents(publishedSoftware, SoftwareEventType.PUBLISHED.name(), createdBy, publishedAppJson);
    		List<String> appuuids = getDao().getPreviousVersionsOfPublshedSoftware(publishedSoftware);
    		for (String previousPublicSoftwareVersionsUuid: appuuids) {
    			description = String.format("A new version of this app, %s, was created by %s as a result of publishing %s. The published asset checksum is %s", 
        				publishedSoftware.getUniqueName(), createdBy, privateSoftware.getUniqueName(), publishedSoftware.getChecksum() == null ? "unavailable" : publishedSoftware.getChecksum());
    			try {
	    			event = new SoftwareEvent(SoftwareEventType.REPUBLISHED.name(), description, createdBy);
	    			event.setSoftwareUuid(previousPublicSoftwareVersionsUuid);
	    			getEntityEventDao().persist(event);
    			}
    			catch (SoftwareEventPersistenceException e) {
    				log.error("Failed to save republished history event to " + previousPublicSoftwareVersionsUuid);
    			}
    			fireNotification(previousPublicSoftwareVersionsUuid, event.getStatus(), event.getCreatedBy(), sPublishedAppJson);
    		}
		}
		catch (EntityEventProcessingException e) {
			log.error(e.getMessage());
		} 
		return event;
	}
public SoftwareEvent processPublishEvent ( Software privateSoftware , Software publishedSoftware , String createdBy ) { SoftwareEvent event = null ; try { if ( privateSoftware == null ) { throw new EntityEventProcessingException ( "Valid original app must be provided to process event." ) ; } if ( publishedSoftware == null ) { throw new EntityEventProcessingException ( "Valid published app must be provided to process event." ) ; } if ( StringUtils . isEmpty ( createdBy ) ) { throw new EntityEventProcessingException ( "Valid username must be provided to process event." ) ; } String description = String . format ( "App was published by %s as %s. The published asset checksum is %s" , createdBy , publishedSoftware . getUniqueName ( ) , publishedSoftware . getChecksum ( ) == null ? "unavailable" : publishedSoftware . getChecksum ( ) ) ; processSoftwareContentEvent ( privateSoftware , SoftwareEventType . PUBLISHED , description , createdBy ) ; description = String . format ( "App was created by %s as a result of publishing %s. The asset checksum is %s" , createdBy , privateSoftware . getUniqueName ( ) , publishedSoftware . getChecksum ( ) == null ? "unavailable" : publishedSoftware . getChecksum ( ) ) ; processSoftwareContentEvent ( publishedSoftware , SoftwareEventType . CREATED , description , createdBy ) ; String sPublishedAppJson = null ; ObjectNode publishedAppJson = null ; try { publishedAppJson = ( ObjectNode ) mapper . createObjectNode ( ) . set ( "app" , mapper . readTree ( publishedSoftware . toJSON ( ) ) ) ; sPublishedAppJson = publishedAppJson . toString ( ) ; } catch ( IOException | JSONException e ) { log . error ( String . format ( "Failed to serialize app " + "%s to json for %s event notification" , publishedSoftware . getUniqueName ( ) , SoftwareEventType . REPUBLISHED . name ( ) ) , e ) ; } doSystemEvents ( publishedSoftware , SoftwareEventType . PUBLISHED . name ( ) , createdBy , publishedAppJson ) ; List < String > appuuids = getDao ( ) . getPreviousVersionsOfPublshedSoftware ( publishedSoftware ) ; for ( String previousPublicSoftwareVersionsUuid : appuuids ) { description = String . format ( "A new version of this app, %s, was created by %s as a result of publishing %s. The published asset checksum is %s" , publishedSoftware . getUniqueName ( ) , createdBy , privateSoftware . getUniqueName ( ) , publishedSoftware . getChecksum ( ) == null ? "unavailable" : publishedSoftware . getChecksum ( ) ) ; try { event = new SoftwareEvent ( SoftwareEventType . REPUBLISHED . name ( ) , description , createdBy ) ; event . setSoftwareUuid ( previousPublicSoftwareVersionsUuid ) ; getEntityEventDao ( ) . persist ( event ) ; } catch ( SoftwareEventPersistenceException e ) { log . error ( "Failed to save republished history event to " + previousPublicSoftwareVersionsUuid ) ; } fireNotification ( previousPublicSoftwareVersionsUuid , event . getStatus ( ) , event . getCreatedBy ( ) , sPublishedAppJson ) ; } } catch ( EntityEventProcessingException e ) { log . error ( e . getMessage ( ) ) ; } return event ; }
Propagates change of public/private scope to associated objects and
 writes an event to the relevant software histories.
Propagates change of public / private scope to associated objects and writes an event to the relevant software histories .
// notify the old app // notify the newly created public app // TODO: Throw events on the source and destination folders. Create LogicalFile records if not already present // notify all old versions of public app // notify the target system of the published event as well as the created one