org.labkey.remoteapi.query.RowsResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of labkey-client-api Show documentation
Show all versions of labkey-client-api Show documentation
The client-side library for Java developers is a separate JAR from the LabKey Server code base. It can be used by any Java program, including another Java web application.
/*
* Copyright (c) 2008-2016 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.remoteapi.query;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.labkey.remoteapi.Command;
import org.labkey.remoteapi.CommandResponse;
import org.labkey.remoteapi.collections.CaseInsensitiveHashMap;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Base class for command responses that contain an array of rows
* and meta-data about those rows. Primarily, this class converts
* date values in the rows array to real Java Date objects.
*/
abstract class RowsResponse extends CommandResponse
{
/**
* Constructs a new RowsResponse given the specified text and status code.
* @param text The response text.
* @param statusCode The HTTP status code.
* @param contentType the Content-Type header value.
* @param json The parsed JSONObject (or null if JSON was not returned.
* @param sourceCommand The source command object
*/
RowsResponse(String text, int statusCode, String contentType, JSONObject json, Command extends RowsResponse> sourceCommand)
{
super(text, statusCode, contentType, json, sourceCommand);
fixupParsedData();
caseInsensitizeRowMaps();
}
/**
* Returns the list of rows from the parsed response data. Note that numbers in the map values will be either of
* type Double or type Long depending on the presence of a decimal point. The most reliable way to work with them
* is to use the Number class. For example:
*
* for (Map<String, Object> row : response.getRows())
* {
* Number key = (Number)row.get("Key");
* // use Number.intValue(), doubleValue(), longValue(), etc to get various primitive types
* }
*
* @return The list of rows (each row is a Map), or null if the rows list was not included in the response.
*/
public List