- All Known Implementing Classes:
ClarityAPIImpl
This interface provides the basic methods one would expect to interact
with the server via REST. It and the objects under the com.genologics.ri
packages hide much of the trickiness from users of this class.
All methods that make calls to the server throw some run time exceptions that client code should expect and handle as appropriate:
-
ClarityException
- thrown when the server sends back a response that indicates an exception being raised on the server. The reply is automatically unmarshalled and thrown as this equivalent Java exception. -
ClarityUpdateException
- indicates more an error in client code, where an update is attempted on an entity that does not allow such an update. This can apply to create, update and delete methods. Refer to the REST documentation for details of what is and is not allowed. -
IllegalStateException
- thrown when calls are made to the server before the server URL has been set. -
HttpClientErrorException
- thrown when a call to the server doesn't get as far as being processed. A typical example is when the credentials have not been set. -
IllegalArgumentException
- thrown when parameters that must clearly be given arenull
. entityClass parameters are a prime example.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Move the process step to its next stage.beginProcessStep
(StepCreation stepCreation) Start a protocol step as if running through Clarity.<E extends Locatable>
voidcreate
(E entity) Create an instance of the given entity on the server.<E extends Locatable>
voidcreateAll
(Collection<E> entities) Create a batch of entities on the server.void
currentStatus
(ProgramStatus status) Get an updated program status from Clarity.<E extends Locatable>
voiddelete
(E entity) Deletes an entity from the server.<E extends Locatable>
voiddeleteAll
(Collection<E> entities) Deletes a batch of entities from the server.void
Delete a file from the file store and remove its record from the LIMS.void
downloadFile
(Linkable<ClarityFile> file, OutputStream resultStream) Download the given file from its source.executeProcess
(ExecutableProcess toExecute) Execute a process within the LIMS.Search for entities of the given type based on name value pairs.Get the base URL of the Clarity server.Get the base address of the REST API.Get the user name of the researcher currently connecting to the server.limsIdToUri
(String limsid, Class<E> entityClass) Convert the given LIMS id to a full URI for that entity.limsIdToUri
(String outerLimsid, String innerLimsid, Class<E> entityClass) Convert the given LIMS ids to a full URI for that entity.List all the objects of the given entity class.listQueue
(Linkable<ProtocolStep> protocolStep) List the artifacts in the queue for the given protocol step.listQueue
(Linkable<ProtocolStep> protocolStep, Map<String, ?> searchTerms) List the artifacts in the queue for the given protocol step, additionally filtering using the parameters available for the "queues" end point.List an arbitrary number of objects of the given entity class.<E extends Locatable>
ELoad an entity using a link to that entity.<E extends Locatable>
ELoad an entity by its LIMS id.<E extends Locatable>
ELoad an entity by its two required LIMS ids.loadAll
(Collection<? extends LimsLink<E>> links) Fetch a collection of LIMS entities given in the collection.void
nextCallCacheOverride
(CacheStatefulBehaviour behaviour) Deprecated.void
overrideStateful
(StatefulOverride override) Forces the API to fetch stateful entities according to the rule given for the next API call only.<E extends LimsEntity<E>>
voidreload
(E entity) Reload an entity in-situ.<E extends Locatable>
ERetrieve an entity using a String form of its URI.<E extends Locatable>
ERetrieve an entity by its URI.void
routeArtifacts
(Routing routing) Issue a routing request for artifacts into workflows.void
setAutoRevertToSFTPUploads
(boolean autoRevertToSFTP) Set whether the SFTP mechanism can be used as a fall back for uploading files if a file exceeds the HTTP upload size limit.void
setBulkOperationBatchSize
(int batchSize) Set the number of objects that will be fetched, updated or created in each call the Clarity API for the bulk operations (those that use a collection of links or objects).void
setConfiguration
(Properties configuration) Set configuration from a properties file.void
setCredentials
(String username, String password) Set the credentials to use to connect to the REST API.void
setCredentials
(Credentials httpCredentials) Set the credentials to use to connect to the REST API.void
setDownloadDirectFromHttpStore
(boolean downloadDirect) For files stored in a HTTP file store, set whether to download these files directly from their HTTP server or whether to fetch them via the API'sfiles/id/download
end point (i.e. the same as files in the regular file store).void
setFilestoreCredentials
(String username, String password) Set the credentials used to connect to the file store.void
setFilestoreServer
(String host) Set the name of the file store host.void
setHttpUploadSizeLimit
(long limit) Set the maximum size of file that can be uploaded using HTTP.void
Set the base URL to the Clarity server.void
setUploadOverHttp
(boolean uploadOverHttp) Set whether uploads over HTTP are permitted using thefiles/id/upload
API end point, or whether only SFTP uploads are allowed.startProgram
(AvailableProgram program) Start execution of an EPP as part of a process step moving through Clarity.<E extends Locatable>
voidupdate
(E entity) Update the given entity on the server.<E extends Locatable>
voidupdateAll
(Collection<E> entities) Updates a batch of entities.<E extends LimsEntity<E>>
ClarityFileuploadFile
(LimsEntityLinkable<E> entity, URL fileURL, boolean publishInLablink) Attach a file to an entity and upload that file to the file store.
-
Method Details
-
getServer
URL getServer()Get the base URL of the Clarity server. This does not include the path to the API, just the protocol, host and port.- Returns:
- The server base URL.
- Throws:
IllegalStateException
- if the API has not been configured.
-
setServer
Set the base URL to the Clarity server.- Parameters:
serverAddress
- The base URL. Should just be the protocol, host and port with no path.- Throws:
IllegalArgumentException
- ifserverAddress
is null.
-
getServerApiAddress
String getServerApiAddress()Get the base address of the REST API. This is the server base address plus the API path (/api/v2
).- Returns:
- The API base address.
-
getUsername
String getUsername()Get the user name of the researcher currently connecting to the server.- Returns:
- The user name used for connections.
-
setCredentials
Set the credentials to use to connect to the REST API.- Parameters:
username
- The researcher's user name.password
- The researcher's password.- Throws:
IllegalArgumentException
- ifusername
is null.
-
setCredentials
Set the credentials to use to connect to the REST API.- Parameters:
httpCredentials
- A Credentials object for the HTTP client. Does nothing if this isnull
.
-
setFilestoreServer
Set the name of the file store host.- Parameters:
host
- The name of the file store server.- Throws:
IllegalArgumentException
- ifhost
is empty.
-
setFilestoreCredentials
Set the credentials used to connect to the file store.- Parameters:
username
- The file store user account.password
- The file store user password.- Throws:
IllegalArgumentException
- ifusername
is null.
-
setConfiguration
Set configuration from a properties file. The properties may contain any of the following:api.server
- The base URL of the Clarity REST API (seesetServer(URL)
).api.user
- The user to access the API as (seesetCredentials(String, String)
).api.pass
- The password forapi.user
.filestore.server
- The host name for the file store (seesetFilestoreServer(String)
).filestore.user
- The user to access the file store as (seesetFilestoreCredentials(String, String)
).filestore.pass
- The password forfilestore.user
.batch.size
- The maximum number of objects to fetch/create/update in one call to the API (seesetBulkOperationBatchSize(int)
).http.upload
- Whether to use the HTTP file upload mechanism introduced with Clarity 4.0 (seesetUploadOverHttp(boolean)
).http.upload.maximum
- The maximum size of file that can be uploaded over HTTP (seesetHttpUploadSizeLimit(long)
).revert.to.sftp.upload
- Whether it is permissible to revert to SFTP uploads if the file is too large to send over HTTP (seesetAutoRevertToSFTPUploads(boolean)
).http.direct.download
- Whether to download files in a HTTP file store directly from their server or whether to download through the Clarity API (seesetDownloadDirectFromHttpStore(boolean)
).
The properties file does not have to contain all of these values. Any that are missing are simply ignored and, where possible, left as their defaults.
- Parameters:
configuration
- The properties file to configure from.- Throws:
InvalidURIException
- if theapi.server
property is set to an invalid URL.
-
setBulkOperationBatchSize
void setBulkOperationBatchSize(int batchSize) Set the number of objects that will be fetched, updated or created in each call the Clarity API for the bulk operations (those that use a collection of links or objects).It seems that naively asking for or sending all the links or objects in the collections does not sit well with the back end server. Experimentation has shown that the fastest overall operation time (at least for fetching artifacts) occurs when between twenty and thirty links or artifacts are in the POST call to the Clarity API.
The default is Genologics' recommendation of a "sweet spot" of 500.
- Parameters:
batchSize
- The number of objects to fetch or send per call to the API. A maximum of 10000 objects per batch is imposed because performance noticeably drops off long before this number of objects is used. If this argument is less than or equal to zero, all object or links in the collection will be sent at once up to the 10000 per call hard limit.- See Also:
-
setUploadOverHttp
void setUploadOverHttp(boolean uploadOverHttp) Set whether uploads over HTTP are permitted using thefiles/id/upload
API end point, or whether only SFTP uploads are allowed.Note that as of release 2.23, downloads from the regular file store take place through the
files/id/download
end point. This solves any problems for SFTP access to the file store. Files in a HTTP file store may be handled differently (seesetDownloadDirectFromHttpStore(boolean)
).The default is to perform uploads of files no bigger than the limit through HTTP.
- Parameters:
uploadOverHttp
- true if files can be uploaded using HTTP, false if not.- Since:
- 2.23
-
setHttpUploadSizeLimit
void setHttpUploadSizeLimit(long limit) Set the maximum size of file that can be uploaded using HTTP. This must be no greater than the corresponding Clarity configuration propertyapi.artifacts.max.resultfile.upload.size
.The default file size limit is 10,485,760 bytes (10MB), which is the default setting for the Clarity configuration property.
- Parameters:
limit
- The maximum size of file allowed over HTTP.- Throws:
IllegalArgumentException
- iflimit
is less than one.- Since:
- 2.23
-
setAutoRevertToSFTPUploads
void setAutoRevertToSFTPUploads(boolean autoRevertToSFTP) Set whether the SFTP mechanism can be used as a fall back for uploading files if a file exceeds the HTTP upload size limit.The default is to allow the SFTP upload mechanism to be used if a file is too large for HTTP.
- Parameters:
autoRevertToSFTP
- true to use SFTP to transfer files that are too large for HTTP, false to fail if such a file is given.- Since:
- 2.23
- See Also:
-
setDownloadDirectFromHttpStore
void setDownloadDirectFromHttpStore(boolean downloadDirect) For files stored in a HTTP file store, set whether to download these files directly from their HTTP server or whether to fetch them via the API'sfiles/id/download
end point (i.e. the same as files in the regular file store).The default is to download directly from the HTTP store rather than going through the API. This will save traffic and load on the LIMS server.
- Parameters:
downloadDirect
- true to fetch HTTP accessible files directly from their HTTP URL, false to fetch them via the Clarity API.- Since:
- 2.23
-
limsIdToUri
Convert the given LIMS id to a full URI for that entity.This method is for the most common entities in the API where the URIs are simply of the form
<endpoint>/<limsid>
.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
limsid
- The LIMS id of the entity required.entityClass
- The class of the entity.- Returns:
- The full URI to the entity.
- Throws:
InvalidURIException
- if the creation of the URI gives a malformed URI.IllegalArgumentException
- if either argument is null, or ifentityClass
is annotated with a primary section attribute.- See Also:
-
limsIdToUri
Convert the given LIMS ids to a full URI for that entity.This method is for use on entities that have been annotated to indicate they are part of a larger entity, for example
ProtocolStep
withinProtocol
orStage
withinWorkflow
.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
outerLimsid
- The LIMS id of the outer endpoint of the URI.innerLimsid
- The LIMS id of the inner endpoint of the URI.entityClass
- The class of the entity.- Returns:
- The full URI to the entity.
- Throws:
InvalidURIException
- if the creation of the URI gives a malformed URI.IllegalArgumentException
- if any argument is null, or ifentityClass
is not annotated with a primary section attribute.- Since:
- 2.22
-
nextCallCacheOverride
Deprecated.Calls through tooverrideStateful(StatefulOverride)
with a conversion of thebehaviour
value toStatefulOverride
, so behaviour is maintained but one should update code to useoverrideStateful
.This method was used to overrides the cache behaviour for the next call on the same thread. It has been replaced byoverrideStateful(StatefulOverride)
which does the correct thing. Momentarily changing how the cache worked didn't solve the problem this was intended for (up to date QC flags on artifacts).The values map as:
CacheStatefulBehaviour.EXACT
becomesStatefulOverride.EXACT
.CacheStatefulBehaviour.LATEST
becomesStatefulOverride.LATEST
.CacheStatefulBehaviour.ANY
ornull
clears the override.
- Parameters:
behaviour
- The cache behaviour for the next call from the current thread.- Since:
- 2.24.3
-
overrideStateful
Forces the API to fetch stateful entities according to the rule given for the next API call only.Calling this method only applies the change to the next call to the API on the current thread. After the call, the API returns to normal behaviour (fetching the entity with the state indicated by the URI). If this method is invoked and entities that are not stateful are requested, the call here has no effect. It is not remembered for the next stateful entity request, so make sure the code calls this immediately before the call it is needed for.
In practice, this is useful only for the QC flags from artifacts. One would either need the flag as specified by the URI exactly, or would want the flag in its current state rather than the state given in the URI.
- Parameters:
override
- The behaviour to use in the next call. If null, it will cancel a previously set override.- Since:
- 2.24.8
-
listAll
List all the objects of the given entity class.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
entityClass
- The type of entity to list.- Returns:
- A list of links to the real entities in the LIMS.
- Throws:
IllegalArgumentException
- ifentityClass
is annotated to be a part of another entity (itsprimaryEntity
attribute is set).
-
listSome
List an arbitrary number of objects of the given entity class. This is not all that helpful for most real applications but can be very handy for test cases.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
entityClass
- The type of entity to list.startIndex
- The index of the first item to fetch. This start number is zero-based.number
- The number of items to fetch.- Returns:
- A list of links to the real entities in the LIMS. This may be fewer
in number than
number
if there are too few items to fetch. - Throws:
IllegalArgumentException
- ifentityClass
is annotated to be a part of another entity (itsprimaryEntity
attribute is set).
-
find
Search for entities of the given type based on name value pairs. The query string is built up from the search terms. Where the term value is an array or collection, the term is added multiple times which Clarity interprets as an OR. For example, if the map contains:"projectname" : [ "projectA", "projectB" ]
then the search will be for entities whose projectname attribute is "projectA
" or "projectB
".- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
searchTerms
- The terms to use for the search.entityClass
- The type of entity to list.- Returns:
- A list of links to the real entities in the LIMS.
- Throws:
IllegalSearchTermException
- if any term insearchTerms
is found to be illegal. SeeIllegalSearchTermException
for details of what is illegal.IllegalArgumentException
- ifentityClass
is annotated to be a part of another entity (itsprimaryEntity
attribute is set).
-
retrieve
Retrieve an entity using a String form of its URI.Note that when this method is used (as opposed to its equivalent taking a URI object) Spring's REST template performs escaping on the URI string so that special characters are sent to be literally that character. This is typically what is wanted for a first call, but using this method to navigate from the server's response can cause problems (especially with searches). Subsequent calls using links returned from the server should use the variant of this method that accepts a URI object.
- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
uri
- The URI to retrieve, in string form.entityClass
- The type of entity to list.- Returns:
- The LIMS entity.
- Throws:
InvalidURIException
- ifuri
is not a valid URI.- See Also:
-
retrieve
Retrieve an entity by its URI.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
uri
- The URI to retrieve.entityClass
- The type of entity to list.- Returns:
- The LIMS entity.
- See Also:
-
load
Load an entity by its LIMS id. The URI of the object is created based on this interface's currently set server address, the type of the object requested and the LIMS id given.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
limsid
- The LIMS id of the entity.entityClass
- The type of entity to list.- Returns:
- The LIMS entity.
-
load
Load an entity by its two required LIMS ids. The URI of the object is created based on this interface's currently set server address, the type of the object requested and the LIMS ids given.This method is for use on entities that have been annotated to indicate they are part of a larger entity, for example
ProtocolStep
withinProtocol
orStage
withinWorkflow
.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
outerLimsid
- The LIMS id of the outer endpoint of the URI.innerLimsid
- The LIMS id of the inner endpoint of the URI.entityClass
- The type of entity to list.- Returns:
- The LIMS entity.
- Since:
- 2.22
-
load
Load an entity using a link to that entity. Typically, the link object will come from a search or another object already fetched from the LIMS.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
link
- The link to the LIMS entity.- Returns:
- The LIMS entity.
-
loadAll
Fetch a collection of LIMS entities given in the collection. The order of the returned entities is the same as the iteration order of thelinks
collection.Using this method to fetch several entities at once can be beneficial where the Clarity API allows batch fetching of objects. Rather than making a call for each link, the links are collected into a single call whose response is all the entities for the links. For those entities where this is not possible, a call is made for each link. The end result is the same.
- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
links
- The collection of links to the entities.- Returns:
- A list of the LIMS entities.
-
reload
Reload an entity in-situ. The given object is refreshed from the server.- Type Parameters:
E
- The type of LIMS entity referred to.- Parameters:
entity
- The LimsEntity to refresh.
-
create
Create an instance of the given entity on the server.When successful, the entity's fields are all updated based on the values returned in the call's response, so the entity will accurately reflect the object on the server.
When used with
Sample
objects, those objects must have an initial location specified using theirSample.setCreationLocation(com.genologics.ri.Location)
method.- Type Parameters:
E
- The type of LIMS entity.- Parameters:
entity
- The entity object to create in the LIMS.
-
createAll
Create a batch of entities on the server.When successful, the entities' fields are all updated based on the values returned in the call's response, so each entity will accurately reflect the equivalent object on the server.
When used with
Sample
objects, those objects must have an initial location specified using theirSample.setCreationLocation(com.genologics.ri.Location)
method.Using this method to create several entities at once can be beneficial where the Clarity API allows batch creation of objects. Rather than making a call for each object, the objects are collected into a single call whose response is information on the entities now present in the server. For those entities where this is not possible, a call is made for each object. The end result is the same.
- Type Parameters:
E
- The type of LIMS entity.- Parameters:
entities
- The entity objects to create in the LIMS.
-
update
Update the given entity on the server. The fields that can be updated differ between entities: refer to the Clarity REST documentation for details.When successful, the entity's fields are all updated based on the values returned in the call's response, so the entity will accurately reflect the object on the server.
- Type Parameters:
E
- The type of LIMS entity.- Parameters:
entity
- The entity to update.
-
updateAll
Updates a batch of entities.When successful, the entities' fields are all updated based on the values returned in the call's response, so each entity will accurately reflect the equivalent object on the server.
Using this method to update several entities at once can be beneficial where the Clarity API allows batch update of objects. Rather than making a call for each object, the objects are collected into a single call whose response is information on the entities now present in the server. For those entities where this is not possible, a call is made for each object. The end result is the same.
- Type Parameters:
E
- The type of LIMS entity.- Parameters:
entities
- The entities to update.
-
delete
Deletes an entity from the server.When successful, the entity object should no longer be used.
- Type Parameters:
E
- The type of LIMS entity.- Parameters:
entity
- The entity to delete.
-
deleteAll
Deletes a batch of entities from the server.When successful, the entity objects should no longer be used.
- Type Parameters:
E
- The type of LIMS entity.- Parameters:
entities
- The entities to delete.
-
executeProcess
Execute a process within the LIMS. The given executable process object needs to be set up carefully for this to work. Refer to the Clarity documentation.- Parameters:
toExecute
- The executable process with all the information of what is to run.- Returns:
- The ClarityProcess object reflecting the process record in the LIMS.
- See Also:
-
beginProcessStep
Start a protocol step as if running through Clarity.- Parameters:
stepCreation
- The step creation object. See Genologics' API documentation.- Returns:
- The
ProcessStep
object for the step started. - Throws:
IllegalArgumentException
- ifstepCreation
is null.- See Also:
-
advanceProcessStep
Move the process step to its next stage.Note that how the step advances is very dependent on the state it is currently in. For example, one may have to set values on the
Actions
object and update that before a step can advance past "next steps". Again, refer to the API documentation.- Parameters:
step
- The step to advance. The state of this object is updated in place.- See Also:
-
startProgram
Start execution of an EPP as part of a process step moving through Clarity.- Parameters:
program
- The program, as listed in theProcessStep
object.- Returns:
- An updated program status structure.
- Since:
- 2.27.5
- See Also:
-
currentStatus
Get an updated program status from Clarity.- Parameters:
status
- The program status to update. The object is updated in place with the latest values.- Since:
- 2.27.5
-
uploadFile
<E extends LimsEntity<E>> ClarityFile uploadFile(LimsEntityLinkable<E> entity, URL fileURL, boolean publishInLablink) throws IOException Attach a file to an entity and upload that file to the file store.The client can be configured to use either the existing SFTP mechanism for the upload or the HTTP upload end point added in Clarity 4.0. Care should be taken with this choice, as the older mechanism is either safer or more problematic, depending on one's viewpoint.
Uploading over HTTP has the additional issue that adding a file to a completed process fails. This is not a restriction of the SFTP upload.
There is a maximum size that Clarity will accept for a file uploaded over HTTP (see
setHttpUploadSizeLimit(long)
). The client can be configured to drop back to SFTP if this size is exceeded. Alternatively it can be configured to never use the HTTP mechanism or to fail if the file is too big.- Type Parameters:
E
- The type of LIMS entity the file is being attached to.- Parameters:
entity
- The LIMS entity to attach the file to.fileURL
- The URL of the file (relative to the local file system where relevant). This forms the original location part of the file record.publishInLablink
- Whether the file should be displayed in the LabLink interface.- Returns:
- The file record in the Clarity LIMS.
- Throws:
IOException
- if the file read or write fails.- See Also:
-
downloadFile
Download the given file from its source. Its content is written out toresultStream
.- Parameters:
file
- The file to fetch.resultStream
- The OutputStream to write the file content to.- Throws:
IOException
- if there is a problem with the download.InvalidURIException
- if the download URI string internally created to fetch the file isn't a valid URI (shouldn't happen).
-
deleteAndRemoveFile
Delete a file from the file store and remove its record from the LIMS. If the file is not in the file store, only its record is removed.- Parameters:
file
- The file to delete.- Throws:
IOException
- if there is a problem removing the file from the file store.
-
routeArtifacts
Issue a routing request for artifacts into workflows.Routing
is a funny object that is post only and doesn't fit with "create".- Parameters:
routing
- The Routing object that has been assembled.
-
listQueue
List the artifacts in the queue for the given protocol step.- Parameters:
protocolStep
- The protocol step of the queue (or a link to it).- Returns:
- Links to the artifacts currently in the given queue.
- Since:
- 2.22
-
listQueue
List<LimsEntityLink<Artifact>> listQueue(Linkable<ProtocolStep> protocolStep, Map<String, ?> searchTerms) List the artifacts in the queue for the given protocol step, additionally filtering using the parameters available for the "queues" end point.Search terms work the same as for the
find(Map, Class)
method. Also see Genologics' documentation of this end point for the options available.- Parameters:
protocolStep
- The protocol step of the queue (or a link to it).searchTerms
- The terms to use for the search.- Returns:
- Links to the artifacts currently in the given queue that meet the criteria of the search terms.
- Since:
- 2.24.1
-
overrideStateful(StatefulOverride)
with a conversion of thebehaviour
value toStatefulOverride
, so behaviour is maintained but one should update code to useoverrideStateful
.