// Determine project list's URI
String projectsListURI = "http://${hostname}/api/v2/projects"
def builder = new StreamingMarkupBuilder()
builder.encoding = "UTF-8"
openDate = "2017-08-24"
// Build a new project using Markup Builder
def projectDoc = builder.bind {
mkp.xmlDeclaration()
mkp.declareNamespace(prj: 'http://genologics.com/ri/project')
mkp.declareNamespace(udf: 'http://genologics.com/ri/userdefined')
'prj:project'{
'name'(projectName)
'open-date'(openDate)
'researcher'(uri:"http://${hostname}/api/v2/researchers/1")
'udf:field'(name:"Objective","To test httpPOST")
}
}
// Post the new project
def projectNode = GLSRestApiUtils.xmlStringToNode(projectDoc.toString())
projectNode = GLSRestApiUtils.httpPOST(projectNode, projectsListURI, username, password)
println GLSRestApiUtils.nodeToXmlString(projectNode)<prj:project xmlns:prj="http://genologics.com/ri/project" uri="http://yourIPaddress/api/v2/projects/WOR512" limsid="WOR512">
<name>httpPOST Project then remove nodes</name>
<open-date>2017-08-24</open-date>
<researcher uri="http://yourIPaddress/api/v2/researchers/1"/>
<udf:field xmlns:udf="http://genologics.com/ri/userdefined" type="String" name="Objective">To test httpPOST</udf:field>
<permissions uri="http://yourIPaddress/api/v2/permissions/projects/WOR512"/>
</prj:project>// If projectNode is parentNode, remove the child udf:field
projectNode?.children()?.remove(projectNode.'udf:field'[0])
// Print the node that will be updated
println GLSRestApiUtils.nodeToXmlString(projectNode)// Determine project list's URI
String projectsListURI = "http://${hostname}/api/v2/projects"
def builder = new StreamingMarkupBuilder()
builder.encoding = "UTF-8"
openDate = "2017-08-22"
// Build a new project using Markup Builder
def projectDoc = builder.bind {
mkp.xmlDeclaration()
mkp.declareNamespace(prj: 'http://genologics.com/ri/project')
mkp.declareNamespace(udf: 'http://genologics.com/ri/userdefined')
'prj:project'{
'name'(projectName)
'open-date'(openDate)
'researcher'(uri:"http://${hostname}/api/v2/researchers/1")
'udf:field'(name:"Objective", "To test httpPOST")
}
}// Turn the markup into a node and post it to the API
def projectNode = GLSRestApiUtils.xmlStringToNode(projectDoc.toString())
projectNode = GLSRestApiUtils.httpPOST(projectNode, projectsListURI, username, password)
println GLSRestApiUtils.nodeToXmlString(projectNode)<prj:project uri="http://yourIPaddress/api/v2/projects/ADM1101" limsid="ADM1101">
<name>httpPOST Project</name>
<open-date>2017-08-22</open-date>
<researcher uri="http://yourIPaddress/api/v2/researchers/1"/>
<udf:field xmlns:udf="http://genologics.com/ri/userdefined" type="String" name="Objective">To test httpPOST</udf:field>
<permissions uri="http://yourIPaddress/api/v2/permissions/projects/ADM1101"/>
</prj:project>// Determine the project's URI
URI projectURI = new URI("http://${hostname}/api/v2/projects/${projectID}")// Get a single Project by limsid
projectNode = GLSRestApiUtils.httpGET(projectURI.toString(), username, password)
println GLSRestApiUtils.nodeToXmlString(projectNode) // Obtain the name
println("Project ID : ${projectNode.name.text()}")<prj:project xmlns:prj="http://genologics.com/ri/project" uri="http://yourIpAddress/api/v2/projects/LUN3" limsid="LUN3">
<name>HTTP Get Project Name with GLS Utils</name>
<open-date>2017-05-31</open-date>
<researcher uri="http://yourIpAddress/api/v2/researchers/1"/>
<permissions uri="http://yourIpAddress/api/v2/permissions/projects/LUN3"/>
</prj:project>// Retrieve and format a date
c = Calendar.getInstance()
c.add(Calendar.MONTH, -1)
df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
time = df.format(c.getTime()).replace('+', '%2B')
// Filter labs by last-modified on specified date
labsURI = "http://${hostname}/api/v2/labs?last-modified=" + time
labs = GLSRestApiUtils.httpGET(labsURI, username, password)
// For each lab, retrieve it
labs.'lab'.each {
labResource = GLSRestApiUtils.httpGET(it.@uri, username, password)
println "Welcome to the team, ${labResource.name.text()}"
labState = labResource.'shipping-address'.state.text()
// If lab is in Washington, print message
if (labState == "WA") {
println "Go Huskies!"
}
}<lab:labs>
<lab uri="http://yourIPaddress/api/v2/labs/2">
<name>Administrative Lab</name>
</lab>
<lab uri="http://yourIPaddress/api/v2/labs/52">
<name>Giant Facility</name>
</lab>
<lab uri="http://yourIPaddress/api/v2/labs/102">
<name>University West</name>
</lab>
</lab:labs>Welcome to the team, Administrative Lab
Welcome to the team, Giant Facility
Welcome to the team, University West
Go Huskies!// Retrieve the researcher
Node researcher = GLSRestApiUtils.httpGET(researcherURI, username, password)<res:researcher uri="http://yourIPaddress/api/v2/researchers/103">
<first-name>Sue</first-name>
<last-name>Eriksond</last-name>
<phone>212-212-2130</phone>
<fax>212-212-2131</fax>
<email>[email protected]</email>
<lab uri="http://yourIPaddress/api/v2/labs/102"/>
<credentials>
<username>serikson</username>
<account-locked>false</account-locked>
<role roleName="webclient"/>
<role roleName="administrator"/>
<role roleName="labtech"/>
</credentials>
<initials>SEK</initials>
</res:researcher>newPhoneNumber = '212-212-2133' // Set the new phone number researcher.'phone'[0].setValue(newPhoneNumber) Node returnNode = GLSRestApiUtils.httpPUT(researcher, researcher.@uri, username, password) println GLSRestApiUtils.nodeToXmlString(returnNode)<res:researcher uri="http://yourIPaddress/api/v2/researchers/103">
<first-name>Sue</first-name>
<last-name>Eriksond</last-name>
<phone>212-212-2133</phone>
<fax>212-212-2131</fax>
<email>[email protected]</email>
<lab uri="http://yourIPaddress/api/v2/labs/102"/>
<credentials>
<username>serikson</username>
<account-locked>false</account-locked>
<role roleName="webclient"/>
<role roleName="administrator"/>
<role roleName="labtech"/>
</credentials>
<initials>SEK</initials>
</res:researcher>