All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.labkey.remoteapi.storage.StorageCommandResponse Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 6.2.0
Show newest version
package org.labkey.remoteapi.storage;

import org.json.JSONObject;
import org.labkey.remoteapi.Command;
import org.labkey.remoteapi.CommandResponse;

import java.util.Collections;
import java.util.Map;

/**
 * Response object used for the storage {@link CreateCommand}, {@link UpdateCommand}, and {@link DeleteCommand}.
 * The response object will include a string message and a data object with the
 * properties from the relevant storage item from the command.
 */
public class StorageCommandResponse extends CommandResponse
{
    private final String _message;
    private final Map _data;

    /**
     * Constructs a new StorageCommandResponse, initialized with the provided
     * response text and status code.
     *
     * @param text          The response text
     * @param statusCode    The HTTP status code
     * @param contentType   The response content type
     * @param json          The parsed JSONObject (or null if JSON was not returned).
     * @param sourceCommand A copy of the command that created this response
     */
    public StorageCommandResponse(String text, int statusCode, String contentType, JSONObject json, Command sourceCommand)
    {
        super(text, statusCode, contentType, json, sourceCommand);
        _message = json.get("message").toString();
        _data = Collections.unmodifiableMap(json.getJSONObject("data").toMap());
    }

    /**
     * Returns the success message for the command.
     * @return The success message string.
     */
    public String getMessage()
    {
        return _message;
    }

    /**
     * Returns the data object with properties from the newly created storage item.
     * @return A map of the key value pairs for the storage item.
     */
    public Map getData()
    {
        return _data;
    }

    public Integer getRowId()
    {
        if (getData().containsKey("rowId"))
            return Integer.parseInt(getData().get("rowId").toString());

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy