// Retrieve a date and format it to a string
c = Calendar.getInstance()
c.add(Calendar.WEEK_OF_YEAR, -1)
df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
time = df.format(c.getTime())
time = URLEncoder.encode(time, "UTF-8")
// Retrieve the processes that were last-modified in the given date range
processesURI = "http://${hostname}/api/v2/processes?type=Denature%20and%20Anneal%20RNA%20%28TruSight%20Tumor%20170%20v1.0%29&last-modified=" + time
processes = GLSRestApiUtils.httpGET(processesURI, username, password)?type=Denature%20and%20Anneal%20RNA%20%28TruSight%20Tumor%20170%20v1.0%29&last-modified= + time

// Retrieve the sample
sampleURI = "http://${hostname}/api/v2/samples/${sampleLIMSID}"
sample = GLSRestApiUtils.httpGET(sampleURI, username, password)
// Initialize storage variables
targetAnalyteLIMSID = sample.artifact.@limsid[0]
artifactMap = [:]
artifactMap[targetAnalyteLIMSID] = null
lastProcMap = [:]
processesURI = "http://${hostname}/api/v2/processes?inputartifactlimsid="Â // While there are still output artifacts to process
outputArtifactsExist = true
while (outputArtifactsExist) {
outputArtifactMap = [:]
artifactMap.each { key, value ->
// Retrieve a list of processes that have the given artifact as an input
processes = GLSRestApiUtils.httpGET(processesURI + key, username, password)
processes.'process'.each {
process = GLSRestApiUtils.httpGET(it.@uri, username, password)
// For each input-output-map, add the process limsid to the storage map
process.'input-output-map'.each { iomap ->
if(key == iomap.input.@limsid[0]) {
outputArtifactMap[iomap.output.@limsid[0]] = process.@limsid
}
}
}
// If there were no processes
if(!processes.'process') {
lastProcMap[key] = value
}
}
// If there are no more artifacts to process, set variable to exit
if(outputArtifactMap.isEmpty()) {
outputArtifactsExist = false
} else {
artifactMap = outputArtifactMap
}
}// Print the artifact associated with the given process limsid
lastProcMap.each { key, value ->
println value + ',' + key
}UVQ-MSA-100326-24-854,92-910
BIA-MSA-100326-24-857,92-912
A23-BMJ-100903-24-1495,ANN753A1AP11
A23-BMJ-100903-24-1495,ANN753A1AP10
A23-BMJ-100903-24-1495,ANN753A1AP9
A14-BMJ-100903-24-1496,ANN753A1AP12
BGX-MSA-100326-24-860,92-921

// Determine the specified process URI and retrieve it
processURI = "http://${hostname}/api/v2/processes/${processLIMSID}"
processNode = GLSRestApiUtils.httpGET(processURI, username, password)
// Retrieve the process's 'Actual Equipment Start Time' UDF
startTimeUDF = processNode.'udf:field'.find { it.@name == 'Actual Equipment Start Time' }
newStartTime = parseInstrumentStartTime()Â <prc:process uri="http://yourIPaddress/api/v2/processes/A22-BMJ-100927-24-2188" limsid="A22-BMJ-100927-24-2188">
<type>HiSEQ PE</type>
<date-run>2017-05-11</date-run>
<technician uri="http://yourIPaddress/api/v2/researchers/305">
<first-name>System</first-name>
<last-name>Administrator</last-name>
</technician>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A49PA1?state=21004" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A49PA1?state=21009" limsid="AFF853A49PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/AFF853A49AP3?state=21010" output-type="Analyte" limsid="AFF853A49AP3"/>
</input-output-map>
</prc:process>Â // If the process's UDF was set, replace it, otherwise create a new node and attach it to the process
if (startTimeUDF) {
startTimeUDF.setValue(newStartTime)
} else {
startTimeQName = new QName('http://genologics.com/ri/userdefined', 'field', 'udf')
processNode.appendNode(startTimeQName, [type:'Numeric',name:'Actual Equipment Start Time'], newStartTime)
}// Update the process in the API
returnNode = GLSRestApiUtils.httpPUT(processNode, processNode.@uri, username, password)
println GLSRestApiUtils.nodeToXmlString(returnNode)
<prc:process uri="http://yourIPaddress/api/v2/processes/A22-BMJ-100927-24-2188" limsid="A22-BMJ-100927-24-2188">
<type>HiSEQ PE</type>
<date-run>2017-05-11</date-run>
<technician uri="http://yourIPaddress/api/v2/researchers/305">
<first-name>System</first-name>
<last-name>Administrator</last-name>
</technician>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A49PA1?state=21004" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A49PA1?state=21009" limsid="AFF853A49PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/AFF853A49AP3?state=21010" output-type="Analyte" limsid="AFF853A49AP3"/>
</input-output-map>
<udf:field type="String" name="Actual Equipment Start Time">2017-05-13T3:14:15-0700</udf:field>
</prc:process><exc:exception xmlns:exc="http://genologics.com/ri/exception">
<message>Field Equipment Start Time does not exist</message>
</exc:exception>// Determine the list URIs and the specified analyte URIs
processListURI = "http://${hostname}/api/v2/processes"
researcherURI = "http://${hostname}/api/v2/researchers/1"
analyte1URI = "http://${hostname}/api/v2/artifacts/${analyteLIMSIDs[0]}"
analyte2URI = "http://${hostname}/api/v2/artifacts/${analyteLIMSIDs[1]}"
analyte3URI = "http://${hostname}/api/v2/artifacts/${analyteLIMSIDs[2]}"
// Retrieve the process type
processTypeNode = GLSRestApiUtils.httpGET(processTypeURI, username, password)
// Create a new process using the Markup Builder
def processDoc = new StreamingMarkupBuilder().bind {
mkp.xmlDeclaration()
mkp.declareNamespace(prx: 'http://genologics.com/ri/processexecution')
'prx:process'{
'type'(processTypeNode.'@name')
'technician'(uri:researcherURI)
'input-output-map' {
'input'(uri:analyte1URI)
'output'(type:'Analyte') {
'location' {
'container'(uri:container96WellsURI)
'value'("A:1")
}
}
}
'input-output-map' {
'input'(uri:analyte2URI)
'output'(type:'Analyte') {
'location' {
'container'(uri:container96WellsURI)
'value'("A:2")
}
}
}
'input-output-map' {
'input'(uri:analyte3URI)
'output'(type:'Analyte') {
'location' {
'container'(uri:container96WellsURI)
'value'("A:3")
}
}
}
'input-output-map'(shared:'true') {
'input'(uri:analyte1URI)
'input'(uri:analyte2URI)
'input'(uri:analyte3URI)
'output'(type:'ResultFile')
}
}
}
// Post the new process to the API
unresolvedProcessNode = GLSRestApiUtils.xmlStringToNode(processDoc.toString())
returnNode = GLSRestApiUtils.httpPOST(unresolvedProcessNode, "${processListURI}", username, password)<prc:process xmlns:prc="http://genologics.com/ri/process" uri="http://yourIPaddress/api/v2/processes/A22-BMJ-100930-24-2203" limsid="A22-BMJ-100930-24-2203">
<type>HiSEQ PE</type>
<date-run>2016-09-30</date-run>
<technician uri="http://yourIPaddress/api/v2/researchers/305">
<first-name>John-Luck</first-name>
<last-name>Pikkard</last-name>
</technician>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A55AP11?state=21128" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A55AP11?state=21135" limsid="AFF853A55AP11">
<parent-process uri="http://yourIPaddress/api/v2/processes/A33-BMJ-100930-24-2200" limsid="A33-BMJ-100930-24-2200"/>
</input>
<output uri="http://yourIPaddress/api/v2/artifacts/92-2538?state=21134" output-type="ResultFile" limsid="92-2538"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A55AP11?state=21128" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A55AP11?state=21135" limsid="AFF853A55AP11">
<parent-process uri="http://yourIPaddress/api/v2/processes/A33-BMJ-100930-24-2200" limsid="A33-BMJ-100930-24-2200"/>
</input>
<output uri="http://yourIPaddress/api/v2/artifacts/AFF853A55AP13?state=21136" output-type="Analyte" limsid="AFF853A55AP13"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A53AP11?state=21124" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A53AP11?state=21130" limsid="AFF853A53AP11">
<parent-process uri="http://yourIPaddress/api/v2/processes/A33-BMJ-100930-24-2200" limsid="A33-BMJ-100930-24-2200"/>
</input>
<output uri="http://yourIPaddress/api/v2/artifacts/92-2538?state=21134" output-type="ResultFile" limsid="92-2538"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A53AP11?state=21124" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A53AP11?state=21130" limsid="AFF853A53AP11">
<parent-process uri="http://yourIPaddress/api/v2/processes/A33-BMJ-100930-24-2200" limsid="A33-BMJ-100930-24-2200"/>
</input>
<output uri="http://yourIPaddress/api/v2/artifacts/AFF853A53AP13?state=21132" output-type="Analyte" limsid="AFF853A53AP13"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A54AP11?state=21125" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A54AP11?state=21133" limsid="AFF853A54AP11">
<parent-process uri="http://yourIPaddress/api/v2/processes/A33-BMJ-100930-24-2200" limsid="A33-BMJ-100930-24-2200"/>
</input>
<output uri="http://yourIPaddress/api/v2/artifacts/92-2538?state=21134" output-type="ResultFile" limsid="92-2538"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/AFF853A54AP11?state=21125" post-process-uri="http://yourIPaddress/api/v2/artifacts/AFF853A54AP11?state=21133" limsid="AFF853A54AP11">
<parent-process uri="http://yourIPaddress/api/v2/processes/A33-BMJ-100930-24-2200" limsid="A33-BMJ-100930-24-2200"/>
</input>
<output uri="http://yourIPaddress/api/v2/artifacts/AFF853A54AP13?state=21131" output-type="Analyte" limsid="AFF853A54AP13"/>
</input-output-map>
</prc:process><exc:exception xmlns:exc="http://genologics.com/ri/exception">
<message>The process type named 'HiSEQ PE' cannot produce the following types of shared outputs: 'ResultFile'.</message>
</exc:exception>// Get the pool for this step
poolNode = GLSRestApiUtils.httpGET(stepURI + '/pools', username, password)
poolNode.'available-inputs'.'input'.each{
   artifact_uris.add(it.@uri)
}// Get all input artifacts
artifacts = GLSRestApiUtils.batchGET(artifact_uris, username, password)
// Iterate through retrieved artifacts
artifacts.each {
   // If the artifact has a UDF pool ID, then pool the artifact and remove it from the available-inputs node
   poolID = it.find { artifact_field -> artifact_field.@name == POOL_ID_UDF}?.value()[0]
   if (poolID != null) {
       // If a new pool ID is encountered, then use that new pool ID as the name for a new pool node
       if (!poolNode.'pooled-inputs'.'pool'.find { pool -> pool.@name == poolID }) {
           newPool = NodeBuilder.newInstance().pool(name:poolID)
           poolNode.'pooled-inputs'[0].append(newPool)
       }
       inputNode = NodeBuilder.newInstance().input(uri:it.@uri)
       // Add the input artifact to the pool with the name equal to 'poolID'
       poolNode.'pooled-inputs'.'pool'.find { poolID == it.@name }.append(inputNode)
       // Remove the input artifact from the 'available-inputs' node contained in the pool node
       poolNode.'available-inputs'[0].remove(inputNode)
   }
}
//Update the pool for this step and examine the result data
resultNode = GLSRestApiUtils.httpPUT(poolNode, poolNode.@uri, username, password)











