Example usage for org.json.simple JSONArray isEmpty

List of usage examples for org.json.simple JSONArray isEmpty

Introduction

In this page you can find the example usage for org.json.simple JSONArray isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:org.codinjutsu.tools.jenkins.logic.JenkinsJsonParser.java

@Override
public List<Job> createCloudbeesViewJobs(String jsonData) {
    checkJsonDataAndThrowExceptionIfNecessary(jsonData);

    JSONParser parser = new JSONParser();

    try {/*from  w  w  w  .  j av  a  2s .c o  m*/
        List<Job> jobs = new LinkedList<Job>();
        JSONObject jsonObject = (JSONObject) parser.parse(jsonData);
        JSONArray viewObjs = (JSONArray) jsonObject.get(VIEWS);
        if (viewObjs == null && viewObjs.isEmpty()) {
            return jobs;
        }

        JSONObject viewJobObj = (JSONObject) viewObjs.get(0);
        if (viewJobObj == null) {
            return jobs;
        }

        JSONArray jobObjs = (JSONArray) viewJobObj.get(JOBS);
        for (Object obj : jobObjs) {
            JSONObject jobObj = (JSONObject) obj;
            jobs.add(getJob(jobObj));
        }

        return jobs;
    } catch (ParseException e) {
        String message = String.format("Error during parsing JSON data : %s", jsonData);
        LOG.error(message, e);
        throw new RuntimeException(e);
    }
}

From source file:org.dia.kafka.isatools.producer.ISAToolsKafkaProducer.java

private static JSONObject adjustUnifiedSchema(JSONObject parse) {
    JSONObject jsonObject = new JSONObject();
    List invNames = new ArrayList<String>();
    List invMid = new ArrayList<String>();
    List invLastNames = new ArrayList<String>();

    Set<Map.Entry> set = parse.entrySet();
    for (Map.Entry entry : set) {
        String jsonKey = SolrKafkaConsumer.updateCommentPreffix(entry.getKey().toString());
        String solrKey = ISA_SOLR.get(jsonKey);

        //            System.out.println("solrKey " + solrKey);
        if (solrKey != null) {
            //                System.out.println("jsonKey: " + jsonKey + " -> solrKey: " + solrKey);
            if (jsonKey.equals("Study_Person_First_Name")) {
                invNames.addAll(((JSONArray) JSONValue.parse(entry.getValue().toString())));
            } else if (jsonKey.equals("Study_Person_Mid_Initials")) {
                invMid.addAll(((JSONArray) JSONValue.parse(entry.getValue().toString())));
            } else if (jsonKey.equals("Study_Person_Last_Name")) {
                invLastNames.addAll(((JSONArray) JSONValue.parse(entry.getValue().toString())));
            }//from  w  ww  .ja  v  a  2  s  .c  o  m
            jsonKey = solrKey;
        } else {
            jsonKey = jsonKey.replace(" ", "_");
        }
        jsonObject.put(jsonKey, entry.getValue());
    }

    JSONArray jsonArray = new JSONArray();

    for (int cnt = 0; cnt < invLastNames.size(); cnt++) {
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isEmpty(invNames.get(cnt).toString()))
            sb.append(invNames.get(cnt)).append(" ");
        if (!StringUtils.isEmpty(invMid.get(cnt).toString()))
            sb.append(invMid.get(cnt)).append(" ");
        if (!StringUtils.isEmpty(invLastNames.get(cnt).toString()))
            sb.append(invLastNames.get(cnt));
        jsonArray.add(sb.toString());
    }
    if (!jsonArray.isEmpty()) {
        jsonObject.put("Investigator", jsonArray.toJSONString());
    }
    return jsonObject;
}

From source file:org.dia.kafka.solr.consumer.SolrKafkaConsumer.java

/**
 * Converts ISATools messages into Solr documents
 *
 * @param jsonObject// www .ja va  2  s .  com
 * @return
 */
private SolrInputDocument convertIsaMsgSolr(JSONObject jsonObject) {
    System.out.format("[%s] Processing msg from %s\n", this.getClass().getSimpleName(), DataSource.ISATOOLS);
    final SolrInputDocument inputDoc = new SolrInputDocument();
    jsonObject.remove(SOURCE_TAG);
    Iterator<?> keys = jsonObject.keySet().iterator();
    List<String> invNames = new ArrayList<String>();
    List<String> invMid = new ArrayList<String>();
    List<String> invLastNames = new ArrayList<String>();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String cleanKey = updateCommentPreffix(key);
        if (!ISA_IGNORED_SET.contains(cleanKey)) {
            if (cleanKey.equals("DA_Number")) {
                inputDoc.addField("id", jsonObject.get(key));
            } else if (cleanKey.equals("Study_Person_First_Name")) { // dealing with investigators' names
                invNames.add(jsonObject.get(key).toString());
            } else if (cleanKey.equals("Study_Person_Mid_Initials")) {
                invMid.add(jsonObject.get(key).toString());
            } else if (cleanKey.equals("Description")) {
                invLastNames.add(jsonObject.get(key).toString());
            } else if (cleanKey.equals("Tags")) {
                inputDoc.addField("Study_Tags", jsonObject.get(key));
            } else if (cleanKey.equals("Created_with_configuration")) {
                inputDoc.addField("Created_With_Configuration", jsonObject.get(key));
            } else {//if (!key.startsWith("_")){
                inputDoc.addField(cleanKey, jsonObject.get(key));
            }
        }
    }
    JSONArray jsonArray = new JSONArray();
    for (int cnt = 0; cnt < invLastNames.size(); cnt++) {
        StringBuilder sb = new StringBuilder();
        sb.append(invNames.get(cnt) != null ? invNames.get(cnt) : "").append(" ");
        sb.append(invMid.get(cnt) != null ? invMid.get(cnt) : "").append(" ");
        sb.append(invLastNames.get(cnt) != null ? invLastNames.get(cnt) : "");
        jsonArray.add(sb.toString());
    }
    if (!jsonArray.isEmpty())
        inputDoc.addField("Investigator", jsonArray.toJSONString());
    return inputDoc;
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializeCandidates(JSONArray candidates, IceUdpTransportPacketExtension transportIQ) {
    if ((candidates != null) && !candidates.isEmpty()) {
        for (Object candidate : candidates) {
            deserializeCandidate((JSONObject) candidate, CandidatePacketExtension.class, transportIQ);
        }/*  w  w w .  j av  a2  s .c o m*/
    }
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializeChannelBundles(JSONArray channelBundles, ColibriConferenceIQ conferenceIQ) {
    if ((channelBundles != null) && !channelBundles.isEmpty()) {
        for (Object channelBundle : channelBundles) {
            deserializeChannelBundle((JSONObject) channelBundle, conferenceIQ);
        }/*from   w  w w  .  j a  v  a2  s.  c o m*/
    }
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializeChannels(JSONArray channels, ColibriConferenceIQ.Content contentIQ) {
    if ((channels != null) && !channels.isEmpty()) {
        for (Object channel : channels)
            deserializeChannel((JSONObject) channel, contentIQ);
    }//from   w w  w .  j  av a2 s . c om
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializeContents(JSONArray contents, ColibriConferenceIQ conferenceIQ) {
    if ((contents != null) && !contents.isEmpty()) {
        for (Object content : contents)
            deserializeContent((JSONObject) content, conferenceIQ);
    }//  w  w  w  .  ja  v  a2 s.  c  o  m
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializeFingerprints(JSONArray fingerprints, IceUdpTransportPacketExtension transportIQ) {
    if ((fingerprints != null) && !fingerprints.isEmpty()) {
        for (Object fingerprint : fingerprints)
            deserializeFingerprint((JSONObject) fingerprint, transportIQ);
    }/*  www  .  ja  v  a 2  s.c o m*/
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializeHeaderExtensions(JSONArray headerExtensions,
        ColibriConferenceIQ.Channel channelIQ) {
    if ((headerExtensions != null) && !headerExtensions.isEmpty()) {
        for (Object headerExtension : headerExtensions) {
            deserializeHeaderExtension((JSONObject) headerExtension, channelIQ);
        }//from   w w  w.  j  a  va2s  .  c  om
    }
}

From source file:org.jitsi.videobridge.rest.JSONDeserializer.java

public static void deserializePayloadTypes(JSONArray payloadTypes, ColibriConferenceIQ.Channel channelIQ) {
    if ((payloadTypes != null) && !payloadTypes.isEmpty()) {
        for (Object payloadType : payloadTypes)
            deserializePayloadType((JSONObject) payloadType, channelIQ);
    }//ww  w.  ja v a2 s . com
}