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

org.opencds.cqf.cds.request.Prefetch Maven / Gradle / Ivy

package org.opencds.cqf.cds.request;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.util.HashMap;
import java.util.Map;

public class Prefetch {

    private JsonObject prefetchJson;
    private JsonObject discoveryPrefetchJson;
    private Map resourceMap;

    public Prefetch(JsonObject prefetchJson, JsonObject discoveryPrefetchJson) {
        this.prefetchJson = prefetchJson;
        this.discoveryPrefetchJson = discoveryPrefetchJson;
        resourceMap = new HashMap<>();

        if (prefetchJson != null) {
            for (Map.Entry entry : prefetchJson.entrySet()) {
                if (entry.getValue().isJsonObject()) {
                    JsonObject obj = entry.getValue().getAsJsonObject();
                    if (obj.has("response") && obj.get("response").isJsonObject()) {
                        String status = JsonHelper.getStringRequired(obj.get("response").getAsJsonObject(), "status");
                        if (status.startsWith("200") && obj.has("resource")) {
                            resourceMap.put(entry.getKey(), obj.get("resource"));
                        }
                    }
                    else {
                        resourceMap.put(entry.getKey(), obj);
                    }
                }
                else {
                    resourceMap.put(entry.getKey(), entry.getValue());
                }
            }
        }
    }

    public JsonObject getPrefetchJson() {
        return prefetchJson;
    }

    public JsonObject getDiscoveryPrefetchJson() {
        return discoveryPrefetchJson;
    }

    public Map getResourceMap() {
        return resourceMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy