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

org.labkey.remoteapi.experiment.LineageResponse 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
/*
 * Copyright (c) 2017-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.experiment;

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


public class LineageResponse extends CommandResponse
{
    List _seeds;
    Map _nodes;

    public LineageResponse(String text, int statusCode, String contentType, JSONObject json, LineageCommand sourceCommand)
    {
        super(text, statusCode, contentType, json, sourceCommand);

        List seedLsids = getProperty("seeds");
        List seeds = new ArrayList<>(seedLsids.size());

        Map nodeMap = getProperty("nodes");

        Map nodes = new HashMap<>();

        for (Map.Entry entry : nodeMap.entrySet())
        {
            String lsid = entry.getKey();
            LineageNode node = new LineageNode(lsid, (Map)entry.getValue());
            nodes.put(lsid, node);

            if (seeds.size() != seedLsids.size() && seedLsids.contains(lsid))
                seeds.add(node);
        }

        for (LineageNode node : nodes.values())
            node.fixup(nodes);

        _seeds = Collections.unmodifiableList(seeds);
        _nodes = Collections.unmodifiableMap(nodes);
    }

    public LineageNode getSeed()
    {
        if (_seeds.size() > 0)
            return _seeds.get(0);
        return null;
    }

    public List getSeeds()
    {
        return _seeds;
    }

    public Map getNodes()
    {
        return _nodes;
    }

    public String dump()
    {
        StringBuilder sb = new StringBuilder();
        dump(sb);
        return sb.toString();
    }

    private void dump(StringBuilder sb)
    {
        if (_seeds == null)
        {
            sb.append("No seeds found");
            return;
        }

        Set seen = new HashSet<>();
        for (LineageNode seed : _seeds)
        {
            seed.dump(0, sb, seen);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy