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

org.labkey.remoteapi.assay.Run 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.

The newest version!
/*
 * Copyright (c) 2010-2018 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.assay;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Represents a single assay run
* User: jeckels
* Date: Apr 28, 2010
*/
public class Run extends ExpObject
{
    private String _comment;
    private List _dataInputs = new ArrayList();
    private List _dataOutputs = new ArrayList();
    private List _materialInputs = new ArrayList<>();
    private List _materialOutputs = new ArrayList<>();
    private String _lsid;

    // Used when inserting new data via SaveAssayBatchAction
    private List> _resultData;

    public Run()
    {
        super();
    }

    public Run(JSONObject json)
    {
        super(json);

        if (json.containsKey("dataInputs"))
        {
            JSONArray array = (JSONArray)json.get("dataInputs");
            for (Object o : array)
            {
                _dataInputs.add(new Data((JSONObject) o));
            }
        }

        if (json.containsKey("dataOutputs"))
        {
            JSONArray array = (JSONArray)json.get("dataOutputs");
            for (Object o : array)
            {
                _dataOutputs.add(new Data((JSONObject) o));
            }
        }

        if (json.containsKey("materialInputs"))
        {
            JSONArray array = (JSONArray)json.get("materialInputs");
            for (Object o : array)
            {
                _materialInputs.add(new Material((JSONObject) o));
            }
        }

        if (json.containsKey("materialOutputs"))
        {
            JSONArray array = (JSONArray)json.get("materialOutputs");
            for (Object o : array)
            {
                _materialOutputs.add(new Material((JSONObject) o));
            }
        }
        _comment = (String)json.get("comment");

        if (json.containsKey("lsid"))
        {
            _lsid = (String) json.get("lsid");
        }

    }

    @Override
    public JSONObject toJSONObject()
    {
        JSONObject result = super.toJSONObject();
        JSONArray dataInputs = new JSONArray();
        for (Data data : _dataInputs)
        {
            dataInputs.add(data.toJSONObject());
        }
        result.put("dataInputs", dataInputs);

        JSONArray dataOutputs = new JSONArray();
        for (Data data : _dataOutputs)
        {
            dataOutputs.add(data.toJSONObject());
        }
        result.put("dataOutputs", dataOutputs);
        result.put("comment", _comment);
        result.put("lsid", _lsid);

        JSONArray materialInputs = new JSONArray();
        JSONArray materialOutputs = new JSONArray();

        for (Material material : _materialInputs)
        {
            materialInputs.add(material.toJSONObject());
        }
        result.put("materialInputs", materialInputs);

        for (Material material : _materialOutputs)
        {
            materialOutputs.add(material.toJSONObject());
        }
        result.put("materialOutputs", materialOutputs);

        if (_resultData != null && !_resultData.isEmpty())
        {
            JSONArray dataRows = new JSONArray();
            for (Map row : _resultData)
            {
                JSONObject o = new JSONObject();
                for (Map.Entry entry : row.entrySet())
                {
                    o.put(entry.getKey(), entry.getValue());
                }
                dataRows.add(o);
            }
            result.put("dataRows", dataRows);
        }

        return result;
    }

    /** @return the list of data files that were consumed by this run */
    public List getDataInputs()
    {
        return _dataInputs;
    }

    /** @param dataInputs the list of data files that were consumed by this run */
    public void setDataInputs(List dataInputs)
    {
        _dataInputs = dataInputs;
    }

    /** @return the list of data files that were produced by this run */
    public List getDataOutputs()
    {
        return _dataOutputs;
    }

    /** @param dataOutputs the list of data files that were produced by this run */
    public void setDataOutputs(List dataOutputs)
    {
        _dataOutputs = dataOutputs;
    }

    public List getMaterialInputs()
    {
        return _materialInputs;
    }

    public void setMaterialInputs(List materialInputs)
    {
        _materialInputs = materialInputs;
    }

    public List getMaterialOutputs()
    {
        return _materialOutputs;
    }

    public void setMaterialOutputs(List materialOutputs)
    {
        _materialOutputs = materialOutputs;
    }

    /** @return the free-form comment attached to this run */
    public String getComment()
    {
        return _comment;
    }

    /** @param comment the free-form comment attached to this run */
    public void setComment(String comment)
    {
        _comment = comment;
    }

    /** @param resultData the list of data rows in this assay run */
    public void setResultData(List> resultData)
    {
        _resultData = resultData;
    }

    public String getLsid()
    {
        return _lsid;
    }

    public void setLsid(String lsid)
    {
        _lsid = lsid;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy