agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/JobResubmissionRequestInputProcessor.java
/**
	 * Validates the {@link SoftwareInput} values passed into a job request.
	 * 
	 * @param jobRequestMap 
	 * @throws JobProcessingException
	 */
Validates the  SoftwareInput values passed into a job request.


Validates the SoftwareInput values passed into a job request .
public void process(Map<String, Object> jobRequestMap)
	throws JobProcessingException 
	{
		setJobInputs(getMapper().createObjectNode());
		for (SoftwareInput softwareInput : getSoftware().getInputs()) {
			ArrayNode jobRequestInputValue = null;
			try {
				if (!softwareInput.isVisible()) {
					if (isIgnoreInputConflicts()) { 
						jobRequestInputValue = doProcessSoftwareInputValue(softwareInput, softwareInput.getDefaultValueAsJsonArray());
					}
					else if (!jobRequestMap.containsKey(softwareInput.getKey())) {
						throw new JobProcessingException(400,
								"Invalid value for " + softwareInput.getKey()
								+ ". No value for the hidden input " + softwareInput.getKey()
								+ " was present in the original job. This usually indicates that "
								+ "the app definition has changed since the job was last run. "
								+ "To override hidden input on job resubmissions, set the ignoreInputConflicts "
								+ "field to true in the request. ");
					} 
					else {
						jobRequestInputValue = doProcessSoftwareInputValue(softwareInput, softwareInput.getDefaultValueAsJsonArray());
						ArrayNode previousJobInputValue = doProcessSoftwareInputValue(softwareInput, jobRequestMap.get(softwareInput.getKey()));
						if (jobRequestInputValue.size() != previousJobInputValue.size()) {
							throw new JobProcessingException(400,
									"Invalid value for " + softwareInput.getKey()
									+ ". The value of the hidden input " + softwareInput.getKey()
									+ " has changed since the job was last run. To override hidden "
									+ "inputs on job resubmissions, set the ignoreInputConflicts "
									+ "field to true in the request. ");
						}
						else {
							List<String> newValues = new ArrayList<String>();
							for (int i=0; i<jobRequestInputValue.size(); i++) {
								newValues.add(jobRequestInputValue.get(i).asText());
							}
							List<String> oldValues = new ArrayList<String>();
							for (int i=0; i<previousJobInputValue.size(); i++) {
								oldValues.add(previousJobInputValue.get(i).asText());
							}
							if (!CollectionUtils.subtract(newValues, oldValues).isEmpty() && 
									!CollectionUtils.subtract(oldValues, newValues).isEmpty()) {
								throw new JobProcessingException(400,
										"Invalid value for " + softwareInput.getKey()
										+ ". The value of the hidden input " + softwareInput.getKey()
										+ " has changed since the job was last run. To ignore hidden "
										+ "input conflicts on job resubmissions, set the ignoreInputConflicts "
										+ "field to true in the request. ");
							}
						}
					}
				} 
				else if (!jobRequestMap.containsKey(softwareInput.getKey())) {
					if (softwareInput.isRequired()) {
						throw new JobProcessingException(400,
								"Missing required input " + softwareInput.getKey()
								+ ". The  input field " + softwareInput.getKey()
								+ " has changed since the job was last run and is now required. "
								+ "Resubmission of this job will not be possible due to this "
								+ "change in the app definition. ");
					}
					else {
						continue;
					}
				} 
				else {
					jobRequestInputValue = doProcessSoftwareInputValue(softwareInput, jobRequestMap.get(softwareInput.getKey()));
				}
				getJobInputs().set(softwareInput.getKey(), jobRequestInputValue);
			} 
			catch (PermissionException e) {
				throw new JobProcessingException(400, e.getMessage(), e);
			} 
			catch (JobProcessingException e) {
				throw e;
			} 
			catch (Exception e) {
				throw new JobProcessingException(400,
						"Failed to parse input for " + softwareInput.getKey(), e);
			}
		}
	}
public void process ( Map < String , Object > jobRequestMap ) throws JobProcessingException { setJobInputs ( getMapper ( ) . createObjectNode ( ) ) ; for ( SoftwareInput softwareInput : getSoftware ( ) . getInputs ( ) ) { ArrayNode jobRequestInputValue = null ; try { if ( ! softwareInput . isVisible ( ) ) { if ( isIgnoreInputConflicts ( ) ) { jobRequestInputValue = doProcessSoftwareInputValue ( softwareInput , softwareInput . getDefaultValueAsJsonArray ( ) ) ; } else if ( ! jobRequestMap . containsKey ( softwareInput . getKey ( ) ) ) { throw new JobProcessingException ( 400 , "Invalid value for " + softwareInput . getKey ( ) + ". No value for the hidden input " + softwareInput . getKey ( ) + " was present in the original job. This usually indicates that " + "the app definition has changed since the job was last run. " + "To override hidden input on job resubmissions, set the ignoreInputConflicts " + "field to true in the request. " ) ; } else { jobRequestInputValue = doProcessSoftwareInputValue ( softwareInput , softwareInput . getDefaultValueAsJsonArray ( ) ) ; ArrayNode previousJobInputValue = doProcessSoftwareInputValue ( softwareInput , jobRequestMap . get ( softwareInput . getKey ( ) ) ) ; if ( jobRequestInputValue . size ( ) != previousJobInputValue . size ( ) ) { throw new JobProcessingException ( 400 , "Invalid value for " + softwareInput . getKey ( ) + ". The value of the hidden input " + softwareInput . getKey ( ) + " has changed since the job was last run. To override hidden " + "inputs on job resubmissions, set the ignoreInputConflicts " + "field to true in the request. " ) ; } else { List < String > newValues = new ArrayList < String > ( ) ; for ( int i = 0 ; i < jobRequestInputValue . size ( ) ; i ++ ) { newValues . add ( jobRequestInputValue . get ( i ) . asText ( ) ) ; } List < String > oldValues = new ArrayList < String > ( ) ; for ( int i = 0 ; i < previousJobInputValue . size ( ) ; i ++ ) { oldValues . add ( previousJobInputValue . get ( i ) . asText ( ) ) ; } if ( ! CollectionUtils . subtract ( newValues , oldValues ) . isEmpty ( ) && ! CollectionUtils . subtract ( oldValues , newValues ) . isEmpty ( ) ) { throw new JobProcessingException ( 400 , "Invalid value for " + softwareInput . getKey ( ) + ". The value of the hidden input " + softwareInput . getKey ( ) + " has changed since the job was last run. To ignore hidden " + "input conflicts on job resubmissions, set the ignoreInputConflicts " + "field to true in the request. " ) ; } } } } else if ( ! jobRequestMap . containsKey ( softwareInput . getKey ( ) ) ) { if ( softwareInput . isRequired ( ) ) { throw new JobProcessingException ( 400 , "Missing required input " + softwareInput . getKey ( ) + ". The  input field " + softwareInput . getKey ( ) + " has changed since the job was last run and is now required. " + "Resubmission of this job will not be possible due to this " + "change in the app definition. " ) ; } else { continue ; } } else { jobRequestInputValue = doProcessSoftwareInputValue ( softwareInput , jobRequestMap . get ( softwareInput . getKey ( ) ) ) ; } getJobInputs ( ) . set ( softwareInput . getKey ( ) , jobRequestInputValue ) ; } catch ( PermissionException e ) { throw new JobProcessingException ( 400 , e . getMessage ( ) , e ) ; } catch ( JobProcessingException e ) { throw e ; } catch ( Exception e ) { throw new JobProcessingException ( 400 , "Failed to parse input for " + softwareInput . getKey ( ) , e ) ; } } }
Validates the {@link SoftwareInput} values passed into a job request.
Validates the { @link SoftwareInput } values passed into a job request .
// add hidden inputs into the input array so we have a full // record of all inputs for this job in the history. // if overriding is present, then force it here. this will  // replace whatever was there before. // if the hidden input wasn't there before. The app has changed. Alert them.  // the hidden field was there before and now. Verify the value is identical since it's  // it's possible it was not hidden when they ran the job originally.  // resolve the current default value for this input // resolve the previous value from the job  // if the sizes are off, that's a red flag // make sure the composition of the two arrays is identical. We don't // care about ordering per se, just composition. // this will make sure that the cardinality of repeated values  // is identical as well // missing fields could be completely optional // if it's requried, that's a problem // if not, carry on // the field is present and availble to receive input. validate it