agave-apps/apps-core/src/main/java/org/iplantc/service/apps/managers/ApplicationManager.java
/**
	 * Validates a {@link JSONObject} representing a {@link Software} registration request. If an 
	 * {@code existingSoftware} exists, then the {@link JSONObject} is validated for correctness 
	 * and merged with the existing {@link Software} object as an update. Otherwise a new {@link Software}
	 * entry is created.
	 *
	 * @param existingSoftware the existing {@link Software) resource to be updated by the <code>json</code> object
	 * @param json the json definition of the system
	 * @param callingUser the username of the user callign the method
	 * @return
	 * @throws SoftwareResourceException
	 */
Validates a  JSONObject representing a  Software registration request. If an
existingSoftware exists, then the  JSONObject is validated for correctness
and merged with the existing  Software object as an update. Otherwise a new  Software
entry is created.


Validates a JSONObject representing a Software registration request . If an existingSoftware exists then the JSONObject is validated for correctness and merged with the existing Software object as an update . Otherwise a new Software entry is created .
public Software processSoftware(Software existingSoftware, JSONObject json, String callingUser)
	throws SoftwareResourceException
	{
		String owner = (existingSoftware == null ? callingUser : existingSoftware.getOwner());
		try 
		{
	        Software newSoftware = Software.fromJSON(json, owner);
	        newSoftware.setOwner(owner);
	        if (!newSoftware.getExecutionSystem().getUserRole(callingUser).canPublish()) {
	        	throw new SoftwareResourceException(CLIENT_ERROR_FORBIDDEN,
	        			"User does not have permission to publish applications on execution system \"" + 
	        					newSoftware.getExecutionSystem().getSystemId() + "\"");
	        }
	        if (existingSoftware != null && 
	        		!newSoftware.getUniqueName().equalsIgnoreCase(existingSoftware.getUniqueName())) 
	        {
	        	if (SoftwareDao.getSoftwareByUniqueName(newSoftware.getUniqueName()) != null) {
	        		throw new SoftwareResourceException(CLIENT_ERROR_BAD_REQUEST,
						"Uploaded application description does not match target uri. You uploaded an " +
						"application description for \"" + newSoftware.getUniqueName() + "\" to the uri " +
						"for \"" + existingSoftware.getUniqueName() + "\". Please either register a new " +
						"application or post your update to " + 
						Settings.IPLANT_JOB_SERVICE + "apps/" + newSoftware.getUniqueName() +
						" to update that app.");
	        	} else {
	        		throw new SoftwareResourceException(CLIENT_ERROR_BAD_REQUEST,
						"Uploaded application description does not match target uri. You uploaded an " +
						"application description for \"" + newSoftware.getUniqueName() + "\" to the uri " +
						"for \"" + existingSoftware.getUniqueName() + "\". Please post your application " +
						"description to " + Settings.IPLANT_JOB_SERVICE + "apps to create a new app.");
	        	}
	        }
	        if (ApplicationManager.userCanPublish(callingUser, newSoftware))
	        {	
	        	validateSoftwareDependencies(callingUser, newSoftware);
	        } else {
	        	throw new SoftwareResourceException(CLIENT_ERROR_FORBIDDEN,
						"Permission denied. You do not have permission to register applications");
	        }
	        if (existingSoftware != null) 
            {
	            newSoftware.setUuid(existingSoftware.getUuid());
	            newSoftware.setCreated(existingSoftware.getCreated());
	            newSoftware.setLastUpdated(new Date());
				newSoftware.setRevisionCount(existingSoftware.getRevisionCount() + 1);
				for (SoftwarePermission pem: existingSoftware.getPermissions()) {
					SoftwarePermission newPem = pem.clone();
					newPem.setSoftware(newSoftware);
					newSoftware.getPermissions().add(newPem);
				}
            }
			return newSoftware;
		} 
		catch (JSONException e) 
		{
			throw new SoftwareResourceException(CLIENT_ERROR_BAD_REQUEST,
					"Invalid json description: " + e.getMessage(), e);
        } 
		catch (FileNotFoundException e) 
		{
        	throw new SoftwareResourceException(CLIENT_ERROR_NOT_FOUND, e.getMessage(), e);
        }
        catch (SoftwareException | SoftwareResourceException e) 
        {
			throw e;
		} 
		catch (RemoteDataException e) 
		{
			throw new SoftwareResourceException(SERVER_ERROR_INTERNAL, 
					"Failed to verify application dependencies: " + e.getMessage(), e);
		} 
		catch (Throwable e) 
		{
			throw new SoftwareResourceException(SERVER_ERROR_INTERNAL,
					"Failed to update application: " + e.getMessage(), e);
		}
	}
public Software processSoftware ( Software existingSoftware , JSONObject json , String callingUser ) throws SoftwareResourceException { String owner = ( existingSoftware == null ? callingUser : existingSoftware . getOwner ( ) ) ; try { Software newSoftware = Software . fromJSON ( json , owner ) ; newSoftware . setOwner ( owner ) ; if ( ! newSoftware . getExecutionSystem ( ) . getUserRole ( callingUser ) . canPublish ( ) ) { throw new SoftwareResourceException ( CLIENT_ERROR_FORBIDDEN , "User does not have permission to publish applications on execution system \"" + newSoftware . getExecutionSystem ( ) . getSystemId ( ) + "\"" ) ; } if ( existingSoftware != null && ! newSoftware . getUniqueName ( ) . equalsIgnoreCase ( existingSoftware . getUniqueName ( ) ) ) { if ( SoftwareDao . getSoftwareByUniqueName ( newSoftware . getUniqueName ( ) ) != null ) { throw new SoftwareResourceException ( CLIENT_ERROR_BAD_REQUEST , "Uploaded application description does not match target uri. You uploaded an " + "application description for \"" + newSoftware . getUniqueName ( ) + "\" to the uri " + "for \"" + existingSoftware . getUniqueName ( ) + "\". Please either register a new " + "application or post your update to " + Settings . IPLANT_JOB_SERVICE + "apps/" + newSoftware . getUniqueName ( ) + " to update that app." ) ; } else { throw new SoftwareResourceException ( CLIENT_ERROR_BAD_REQUEST , "Uploaded application description does not match target uri. You uploaded an " + "application description for \"" + newSoftware . getUniqueName ( ) + "\" to the uri " + "for \"" + existingSoftware . getUniqueName ( ) + "\". Please post your application " + "description to " + Settings . IPLANT_JOB_SERVICE + "apps to create a new app." ) ; } } if ( ApplicationManager . userCanPublish ( callingUser , newSoftware ) ) { validateSoftwareDependencies ( callingUser , newSoftware ) ; } else { throw new SoftwareResourceException ( CLIENT_ERROR_FORBIDDEN , "Permission denied. You do not have permission to register applications" ) ; } if ( existingSoftware != null ) { newSoftware . setUuid ( existingSoftware . getUuid ( ) ) ; newSoftware . setCreated ( existingSoftware . getCreated ( ) ) ; newSoftware . setLastUpdated ( new Date ( ) ) ; newSoftware . setRevisionCount ( existingSoftware . getRevisionCount ( ) + 1 ) ; for ( SoftwarePermission pem : existingSoftware . getPermissions ( ) ) { SoftwarePermission newPem = pem . clone ( ) ; newPem . setSoftware ( newSoftware ) ; newSoftware . getPermissions ( ) . add ( newPem ) ; } } return newSoftware ; } catch ( JSONException e ) { throw new SoftwareResourceException ( CLIENT_ERROR_BAD_REQUEST , "Invalid json description: " + e . getMessage ( ) , e ) ; } catch ( FileNotFoundException e ) { throw new SoftwareResourceException ( CLIENT_ERROR_NOT_FOUND , e . getMessage ( ) , e ) ; } catch ( SoftwareException | SoftwareResourceException e ) { throw e ; } catch ( RemoteDataException e ) { throw new SoftwareResourceException ( SERVER_ERROR_INTERNAL , "Failed to verify application dependencies: " + e . getMessage ( ) , e ) ; } catch ( Throwable e ) { throw new SoftwareResourceException ( SERVER_ERROR_INTERNAL , "Failed to update application: " + e . getMessage ( ) , e ) ; } }
Validates a {@link JSONObject} representing a {@link Software} registration request.
Validates a { @link JSONObject } representing a { @link Software } registration request .
// parse and validate the json // why update? we should just blow them away and add the new ones.  // they can't upload a partial description...