Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.labkey.remoteapi
Class CommandResponse

    java.lang.Object
      org.labkey.remoteapi.CommandResponse

Direct Known Subclasses:
  AssayListResponse, CreateGroupResponse, CreateUserResponse, FileNotificationResponse, GetContainersResponse, GetGroupPermsResponse, GetQueriesResponse, GetQueryDetailsResponse, GetSchemasResponse, GetUsersResponse, NAbRunsResponse, RenameGroupResponse, RowsResponse, SaveAssayBatchResponse, StartSearchResponse

    public class CommandResponse

extends java.lang.Object

Represents the details of a response returned from the LabKey Server.

Client code will typically use a class derived from this class that is returned from the particular command used (e.g. SelectRowsCommand returns SelectRowsResponse). However, if you are using the Command class directly to call an HTTP API that does not yet have a specialized command class, you would use this object to obtain the response details.

Version:
  1.0
Author:
  Dave Stearns, LabKey Corporation

Constructor Summary
`CommandResponse(java.lang.String text, int statusCode, java.lang.String contentType, org.json.simple.JSONObject json, Command sourceCommand)` Constructs a new CommandResponse, initialized with the provided response text and status code.

Method Summary
`protected java.util.Map<java.lang.String,java.lang.Object>` | `findObject(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> objects, java.lang.String propertyName, java.lang.String value)` Finds an Map in a List of Maps who's property identified by `propertyName` matches the `value` supplied.
`java.lang.String` | `getContentType()` Returns the Content-Type header value from the response.
`java.util.Map<java.lang.String,java.lang.Object>` | `getParsedData()` Attempts to parse the response text and return a property Map.
`
`<T> T`
` | `getProperty(java.lang.String path)` Returns the value of a specific property in the parsed data given a path to that property.
`protected
`<T> T`
` | `getProperty(java.lang.String[] path, int index, java.util.Map<java.lang.String,java.lang.Object> parent)` Called by `getProperty(String)` after splitting the path into a String[], and recursively by itself as it descends the property hierarchy.
`double` | `getRequiredVersion()` Returns the API version number required by the source command.
`Command` | `getSourceCommand()` Returns a reference to a copy of the command that created this response
`int` | `getStatusCode()` Returns the HTTP status code (typically 200).
`java.lang.String` | `getText()` Returns the raw response text.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CommandResponse

    public CommandResponse(java.lang.String text,
                           int statusCode,
                           java.lang.String contentType,
                           org.json.simple.JSONObject json,
                           Command sourceCommand)

  Constructs a new CommandResponse, initialized with the provided response text and status code.

  Parameters:
    `text` - The response text
    `statusCode` - The HTTP status code
    `contentType` - The response content type
    `json` - The parsed JSONObject (or null if JSON was not returned).
    `sourceCommand` - A copy of the command that created this response

Method Detail

### getText

    public java.lang.String getText()

  Returns the raw response text.

  Use this if your command returns something other than JSON, or if you want to use a different JSON parser.

  This may return null if no response body was sent by the server.

  Returns:
    The raw response text.

### getStatusCode

    public int getStatusCode()

  Returns the HTTP status code (typically 200).

  Returns:
    The HTTP status code

### getContentType

    public java.lang.String getContentType()

  Returns the Content-Type header value from the response. Note that this may return null if no content type header was supplied by the server (unlikely but possible).

  Returns:
    The content type of the response.

### getRequiredVersion

    public double getRequiredVersion()

  Returns the API version number required by the source command. Some APIs may return data in a different format depending on the required version

  Returns:
    the requried API version number

### getSourceCommand

    public Command getSourceCommand()

  Returns a reference to a copy of the command that created this response

  Returns:
    The command that created this response

### getParsedData

    public java.util.Map<java.lang.String,java.lang.Object> getParsedData()

  Attempts to parse the response text and return a property Map.

  If the response text cannot be parsed, a runtime error will be thrown.

  Note that the values in the Map may be simple values, Lists, or Maps.

  Returns:
    The parsed data as a property map.

### getProperty

    public <T> T getProperty(java.lang.String path)

  Returns the value of a specific property in the parsed data given a path to that property.

  The path is a period-delimited list of property names. For example, to obtain the 'bar' property from the Map associated with the 'foo' property, the path would be 'foo.bar'.

  Parameters:
    `path` - The property path.
  Returns:
    The property value, or null if the property was not found.

### getProperty

    protected <T> T getProperty(java.lang.String[] path,
                                int index,
                                java.util.Map<java.lang.String,java.lang.Object> parent)

  Called by `getProperty(String)` after splitting the path into a String[], and recursively by itself as it descends the property hierarchy.

  Parameters:
    `path` - The path split into a String[].
    `index` - The current index into the path array.
    `parent` - The current parent map.
  Returns:
    The property value, or null if not found.

### findObject

    protected java.util.Map<java.lang.String,java.lang.Object> findObject(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> objects,
                                                                          java.lang.String propertyName,
                                                                          java.lang.String value)

  Finds an Map in a List of Maps who's property identified by `propertyName` matches the `value` supplied. Returns null if not found.

  Parameters:
    `objects` - The list of Maps to search.
    `propertyName` - The property name to examine in each Map.
    `value` - The value to compare against.
  Returns:
    The Map where the value of propertyName equals value, or null if not found.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD