Example usage for org.json.simple JSONArray add

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

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:Contract.AbstractContract.java

@Override
public JSONObject getJSONObject() {
    JSONObject obj = new JSONObject();
    JSONArray list = new JSONArray();
    for (Iterator<AbstractPayment> it = this.payments.iterator(); it.hasNext();) {
        AbstractPayment ap = it.next();//ww  w .j  a va 2s  .c  o  m
        list.add(ap.getJSONObject());
    }
    obj.put("payments", list);
    obj.put("id", this.getContractUniqueId());
    obj.put("workPlace", this.workPlace);
    obj.put("post", this.post);
    obj.put("validDate", this.validDate);
    obj.put("forever", new Boolean(this.forever));

    return obj;

}

From source file:com.replaymod.sponge.recording.AbstractRecorder.java

/**
 * Converts the meta data supplied to a JSON string.
 * @param metaData The meta data//w ww .ja v a 2 s  .co  m
 * @return The JSON string
 */
@SuppressWarnings("unchecked")
private String toJson(ReplayMetaData metaData) {
    JSONObject data = new JSONObject();
    for (String key : metaData.keys()) {
        Object value = metaData.get(key).get();
        if (value instanceof Collection) {
            JSONArray array = new JSONArray();
            for (Object element : (Collection) value) {
                array.add(element == null ? null : element);
            }
            value = array;
        }
        data.put(key, value);
    }
    return data.toString();
}

From source file:org.kitodo.data.index.elasticsearch.type.TaskType.java

@SuppressWarnings("unchecked")
@Override/*  ww w .  j a  v a  2 s.  c  om*/
public HttpEntity createDocument(Task task) {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    LinkedHashMap<String, String> orderedTaskMap = new LinkedHashMap<>();
    orderedTaskMap.put("title", task.getTitle());
    String priority = task.getPriority() != null ? task.getPriority().toString() : "null";
    orderedTaskMap.put("priority", priority);
    String ordering = task.getOrdering() != null ? task.getOrdering().toString() : "null";
    orderedTaskMap.put("ordering", ordering);
    String processingStatus = task.getProcessingStatusEnum() != null ? task.getProcessingStatusEnum().toString()
            : "null";
    orderedTaskMap.put("processingStatus", processingStatus);
    String processingTime = task.getProcessingTime() != null ? dateFormat.format(task.getProcessingTime())
            : null;
    orderedTaskMap.put("processingTime", processingTime);
    String processingBegin = task.getProcessingBegin() != null ? dateFormat.format(task.getProcessingBegin())
            : null;
    orderedTaskMap.put("processingBegin", processingBegin);
    String processingEnd = task.getProcessingEnd() != null ? dateFormat.format(task.getProcessingEnd()) : null;
    orderedTaskMap.put("processingEnd", processingEnd);
    orderedTaskMap.put("homeDirectory", String.valueOf(task.getHomeDirectory()));
    orderedTaskMap.put("typeMetadata", String.valueOf(task.isTypeMetadata()));
    orderedTaskMap.put("typeAutomatic", String.valueOf(task.isTypeAutomatic()));
    orderedTaskMap.put("typeImportFileUpload", String.valueOf(task.isTypeImportFileUpload()));
    orderedTaskMap.put("typeExportRussian", String.valueOf(task.isTypeExportRussian()));
    orderedTaskMap.put("typeImagesRead", String.valueOf(task.isTypeImagesRead()));
    orderedTaskMap.put("typeImagesWrite", String.valueOf(task.isTypeImagesWrite()));
    orderedTaskMap.put("batchStep", String.valueOf(task.isBatchStep()));
    String processingUser = task.getProcessingUser() != null ? task.getProcessingUser().getId().toString()
            : "null";
    orderedTaskMap.put("processingUser", processingUser);
    String process = task.getProcess() != null ? task.getProcess().getId().toString() : "null";
    orderedTaskMap.put("process", process);

    JSONObject taskObject = new JSONObject(orderedTaskMap);

    JSONArray users = new JSONArray();
    List<User> taskUsers = task.getUsers();
    for (User user : taskUsers) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("id", user.getId());
        users.add(propertyObject);
    }
    taskObject.put("users", users);

    JSONArray userGroups = new JSONArray();
    List<UserGroup> taskUserGroups = task.getUserGroups();
    for (UserGroup userGroup : taskUserGroups) {
        JSONObject userGroupObject = new JSONObject();
        userGroupObject.put("id", userGroup.getId().toString());
        userGroups.add(userGroupObject);
    }
    taskObject.put("userGroups", userGroups);

    return new NStringEntity(taskObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:chat.com.server.ChatServer.java

private void updateUserOnline() {
    int s = map.size();
    JSONArray arr = new JSONArray();
    for (String key : map.keySet()) {
        // add user online
        arr.add(key);
    }//  w w w  .  j  a va 2 s .  com
    JSONObject jsonUpdateUser = new JSONObject();
    jsonUpdateUser.put("type", "userOnline");
    jsonUpdateUser.put("listUser", arr);

    String json = jsonUpdateUser.toString();

    for (String key : map.keySet()) {
        // send message to all
        PrintWriter writer = map.get(key);
        writer.println(json);
        writer.flush();
    }

}

From source file:be.iminds.aiolos.ui.NodeServlet.java

@SuppressWarnings("unchecked")
protected void writeJSON(final Writer w, final Locale locale) throws IOException {
    final Collection<NodeInfo> allNodes = this.getNodes();
    final Object[] status = getStatus(allNodes);

    JSONObject obj = new JSONObject();

    JSONArray stat = new JSONArray();
    for (int i = 0; i < status.length; i++)
        stat.add(status[i]);
    obj.put("status", stat);

    JSONArray nodes = new JSONArray();
    for (NodeInfo node : allNodes) {
        JSONObject nodeObj = new JSONObject();
        JSONArray components = new JSONArray();

        // TODO extend functionality
        nodeObj.put("id", node.getNodeId());
        nodeObj.put("state", "Unknown"); // TODO hardcoded in javascript
        components.addAll(getComponents(node.getNodeId()));
        nodeObj.put("components", components);
        nodeObj.put("ip", node.getIP());
        //         nodeObj.put("proxy", node.getProxyInfoMap());
        //         nodeObj.put("hostname", node.getHostname());
        if (node.getHttpPort() != -1)
            nodeObj.put("console", "http://" + node.getIP() + ":" + node.getHttpPort() + "/system/console");
        //         nodeObj.put("stoppable", (node.getVMInstance()!=null));
        nodes.add(nodeObj);/*from   w w w.  j  a v  a  2  s .c o  m*/
    }
    obj.put("nodes", nodes);

    JSONArray components = new JSONArray();
    components.addAll(getComponents());
    obj.put("components", components);

    try {
        JSONArray bndruns = new JSONArray();
        bndruns.addAll(cloudTracker.getService().getBndrunFiles());
        obj.put("bndruns", bndruns);
    } catch (NullPointerException e) {
    }

    w.write(obj.toJSONString());
}

From source file:org.kitodo.data.index.elasticsearch.type.UserType.java

@SuppressWarnings("unchecked")
@Override//from w w  w  .  jav  a  2 s. c om
public HttpEntity createDocument(User user) {

    LinkedHashMap<String, String> orderedUserMap = new LinkedHashMap<>();
    orderedUserMap.put("name", user.getName());
    orderedUserMap.put("surname", user.getSurname());
    orderedUserMap.put("login", user.getLogin());
    orderedUserMap.put("ldapLogin", user.getLdapLogin());
    orderedUserMap.put("active", String.valueOf(user.isActive()));
    orderedUserMap.put("location", user.getLocation());
    orderedUserMap.put("metadataLanguage", user.getMetadataLanguage());
    String ldapGroup = user.getLdapGroup() != null ? user.getLdapGroup().getId().toString() : "null";
    orderedUserMap.put("ldapGroup", ldapGroup);

    JSONObject userObject = new JSONObject(orderedUserMap);

    JSONArray userGroups = new JSONArray();
    List<UserGroup> userUserGroups = user.getUserGroups();
    for (UserGroup userGroup : userUserGroups) {
        JSONObject userGroupObject = new JSONObject();
        userGroupObject.put("id", userGroup.getId().toString());
        userGroups.add(userGroupObject);
    }
    userObject.put("userGroups", userGroups);

    JSONArray properties = new JSONArray();
    List<UserProperty> userProperties = user.getProperties();
    for (UserProperty property : userProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    userObject.put("properties", properties);

    return new NStringEntity(userObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:azkaban.web.pages.FlowExecutionServlet.java

@SuppressWarnings("unchecked")
private String createJsonJobList(Flow flow) {
    JSONArray jsonArray = new JSONArray();
    for (FlowNode node : flow.getFlowNodes()) {
        jsonArray.add(node.getAlias());
    }/*from w w w  .  j a  v a 2  s.  c  o m*/

    return jsonArray.toJSONString();
}

From source file:cpd4414.assign2.Order.java

public JSONObject tojsonconvert() {
    JSONObject json = new JSONObject();
    json.put("customerId", getCustomerId());
    json.put("customerName", getCustomerName());

    json.put("timeReceived", (getTimeReceived() != null) ? getTimeReceived().toString() : null);
    json.put("timeProcessed", (getTimeProcessed() != null) ? getTimeProcessed().toString() : null);
    json.put("timeFulfilled", (getTimeFulfilled() != null) ? getTimeFulfilled().toString() : null);

    JSONArray pList = new JSONArray();
    for (Purchase p

    : getListOfPurchases()) {/* w ww .j  a v a2s .c  o m*/
        JSONObject pObj = new JSONObject();
        pObj.put("ProductId", p.getProductId());
        pObj.put("quantity", p.getQuantity());
        pList.add(pObj);

    }

    json.put(

            "purchases", pList);
    json.put("notes", getNotes());
    return json;

}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java

public static String getGeneAliases(String gene) {
    JSONArray aliases = new JSONArray();
    try {//w  w w. j ava  2s. com
        if (!DataValidator.isGeneSymbolFound(gene)) {
            AllGeneAliasLookup[] allGeneAlias = DataValidator.searchGeneKeyWord(gene);
            // if there are aliases , set the array to be displayed in the form and return the showAlias warning
            if (allGeneAlias != null) {
                for (int i = 0; i < allGeneAlias.length; i++) {
                    JSONObject a = new JSONObject();

                    AllGeneAliasLookup alias = allGeneAlias[i];
                    a.put("alias", (alias.getAlias() != null) ? alias.getAlias() : "N/A");
                    a.put("symbol", (alias.getApprovedSymbol() != null) ? alias.getApprovedSymbol() : "N/A");
                    a.put("name", (alias.getApprovedName() != null) ? alias.getApprovedName() : "N/A");
                    //alias.getAlias()+"\t"+alias.getApprovedSymbol()+"\t"+alias.getApprovedName()
                    aliases.add(a);
                }
            } else {
                aliases.add("invalid");
            }
        } else {
            aliases.add("valid");
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return aliases.toString();
}

From source file:com.gunjan.businessLayer.dictServlet.java

protected String getJSONObjectForWord(String word) throws IOException {
    DBConnection conn = DBConnection.getConnection();
    ArrayList defs = conn.getDefinition(word);
    if (defs == null) {
        defs = new ArrayList();
    }//w ww . j a v a  2  s . co  m
    Iterator<Definition> it = defs.iterator();
    JSONArray defList = new JSONArray();
    while (it.hasNext()) {
        Definition d = (Definition) it.next();
        JSONObject obj = new JSONObject();
        obj.put("type", d.getType());
        obj.put("definition", d.getDefinition());
        defList.add(obj);
    }
    JSONObject mainObj = new JSONObject();
    mainObj.put("word", word);
    mainObj.put("definitions", defList);

    StringWriter out = new StringWriter();
    mainObj.writeJSONString(out);

    String jsonText = out.toString();
    return jsonText;
}