Example usage for org.json.simple JSONObject put

List of usage examples for org.json.simple JSONObject put

Introduction

In this page you can find the example usage for org.json.simple JSONObject put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.oic.event.map.GetMapInfo.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "getmapinfo");
    if (!validation(json)) {
        responseJSON.put("status", "1");
        webSocket.sendJson(responseJSON);
        return;//www.j av  a2s .co  m
    }

    MapFactory factory = MapFactory.getInstance();
    int mapid = Integer.parseInt(json.get("mapid").toString());
    OicMap map = factory.getMap(mapid);

    responseJSON.put("mapid", map.getMapId());
    responseJSON.put("imgpath", map.getPath());
    JSONObject posJSON = new JSONObject();
    Position pos = map.getPos();
    posJSON.put("x", pos.getX());
    posJSON.put("y", pos.getX());
    posJSON.put("width", pos.getWidth());
    posJSON.put("height", pos.getHeight());
    responseJSON.put("pos", posJSON);
    webSocket.sendJson(responseJSON);
}

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

@SuppressWarnings("unchecked")
@Override/*from  w  w  w .  ja  v a2 s. com*/
public HttpEntity createDocument(Process process) {

    JSONObject processObject = new JSONObject();
    processObject.put("title", process.getTitle());
    processObject.put("outputName", process.getOutputName());
    String creationDate = process.getCreationDate() != null ? formatDate(process.getCreationDate()) : null;
    processObject.put("creationDate", creationDate);
    processObject.put("wikiField", process.getWikiField());
    processObject.put("sortHelperStatus", process.getSortHelperStatus());
    processObject.put("sortHelperImages", process.getSortHelperImages());
    processObject.put("processBaseUri", process.getProcessBaseUri());
    processObject.put("template", process.isTemplate());
    Integer project = process.getProject() != null ? process.getProject().getId() : null;
    processObject.put("project", project);
    Integer ruleset = process.getRuleset() != null ? process.getRuleset().getId() : null;
    processObject.put("ruleset", ruleset);
    Integer docket = process.getDocket() != null ? process.getDocket().getId() : null;
    processObject.put("docket", docket);
    processObject.put("batches", addObjectRelation(process.getBatches()));
    processObject.put("workpieces", addObjectRelation(process.getWorkpieces()));
    processObject.put("tasks", addObjectRelation(process.getTasks()));
    processObject.put("properties", addObjectRelation(process.getProperties()));

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

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.json.MapperStatusQuery.java

@SuppressWarnings("unchecked")
public String execute(IServletConfig config, String[] parameters) {

    if (mapper == null) {
        return "";
    }/*from   w  w w .  j a va  2  s .c  o m*/

    Map<String, IRegistrationData> registrationData = mapper.getRegistrationData();
    //      Map<String, IStatusProxy> statusProxyMap = mapper.getStatusProxyMap();
    //      List<IVirtualVehicleInfo> virtualVehicleList = mapper.getVirtualVehicleList();

    JSONArray a = new JSONArray();
    for (Entry<String, IRegistrationData> rdEntry : registrationData.entrySet()) {
        IRegistrationData rd = rdEntry.getValue();

        JSONObject o = new JSONObject();
        o.put("regDat", rd);
        a.add(o);
    }

    return JSONValue.toJSONString(a);
}

From source file:com.conwet.xjsp.features.DefaultXJSPHandlerTest.java

@Test
@SuppressWarnings("unchecked")
public void shouldParseErrorMessages() throws Exception {
    System.out.println("should parse error messages");

    // Given//w ww.  j  a va2s .  c o  m
    JSONObject payload = new JSONObject();
    payload.put("id", "1234");
    payload.put("message", "msg");
    payload.put("code", 301l);
    Message message = new ImmutableMessage("xjsp", "error", payload, "1");
    Session session = mock(Session.class);

    // Do
    DefaultXJSPHandler instance = spy(new DefaultXJSPHandler());
    instance.handleMessage(message, session);

    // Assert
    ArgumentCaptor<ErrorMessage> error = ArgumentCaptor.forClass(ErrorMessage.class);
    verify(instance).doHandleError(error.capture(), eq(session));

    assertThat(error.getValue().getCode()).isEqualTo(301L);
    assertThat(error.getValue().getSourceId()).isEqualTo("1234");
    assertThat(error.getValue().getMessage()).isEqualTo("msg");
}

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

@SuppressWarnings("unchecked")
@Override/*from   w  w  w.j a va2  s  . c  om*/
public HttpEntity createDocument(Batch batch) {

    LinkedHashMap<String, String> orderedBatchMap = new LinkedHashMap<>();
    orderedBatchMap.put("title", batch.getTitle());
    String type = batch.getType() != null ? batch.getType().toString() : "null";
    orderedBatchMap.put("type", type);

    JSONArray processes = new JSONArray();
    List<Process> batchProcesses = batch.getProcesses();
    for (Process process : batchProcesses) {
        JSONObject processObject = new JSONObject();
        processObject.put("id", process.getId().toString());
        processes.add(processObject);
    }

    JSONObject batchObject = new JSONObject(orderedBatchMap);
    batchObject.put("processes", processes);

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

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

@SuppressWarnings("unchecked")
@Override/*from  w  ww .  jav a  2 s  . com*/
public HttpEntity createDocument(Template template) {

    LinkedHashMap<String, String> orderedTemplateMap = new LinkedHashMap<>();
    String process = template.getProcess() != null ? template.getProcess().getId().toString() : "null";
    orderedTemplateMap.put("process", process);

    JSONObject processObject = new JSONObject(orderedTemplateMap);

    JSONArray properties = new JSONArray();
    List<TemplateProperty> templateProperties = template.getProperties();
    for (TemplateProperty property : templateProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    processObject.put("properties", properties);

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

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

@SuppressWarnings("unchecked")
@Override/*w  ww.  ja v  a  2s.  c o  m*/
public HttpEntity createDocument(Workpiece workpiece) {

    LinkedHashMap<String, String> orderedWorkpieceMap = new LinkedHashMap<>();
    String process = workpiece.getProcess() != null ? workpiece.getProcess().getId().toString() : "null";
    orderedWorkpieceMap.put("process", process);

    JSONObject processObject = new JSONObject(orderedWorkpieceMap);

    JSONArray properties = new JSONArray();
    List<WorkpieceProperty> workpieceProperties = workpiece.getProperties();
    for (WorkpieceProperty property : workpieceProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    processObject.put("properties", properties);

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

From source file:co.mcme.animations.actions.ExplosionAction.java

@Override
public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    JSONObject data = new JSONObject();
    data.put("frame", frame);
    result.put("explosion", data);
    return result;
}

From source file:com.johncroth.histo.logging.LogHistogramWriter.java

@SuppressWarnings("unchecked")
JSONObject convert(RecordedInterval<LogHistogramRecorder> interval) {
    JSONObject jo = new JSONObject();
    jo.put(START, interval.getStartMillis());
    jo.put(END, interval.getEndMillis());
    jo.put(RECORDER, convert((LogHistogramRecorder) interval.getRecorder()));
    return jo;//from  ww w.  ja v  a  2 s .  c  o m
}

From source file:com.modeln.batam.connector.wrapper.Pair.java

@SuppressWarnings("unchecked")
public String toJSONString() {
    JSONObject obj = new JSONObject();
    obj.put("name", name);
    obj.put("value", value);

    return obj.toJSONString();
}