Example usage for com.fasterxml.jackson.databind JsonNode toString

List of usage examples for com.fasterxml.jackson.databind JsonNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode toString.

Prototype

public abstract String toString();

Source Link

Usage

From source file:com.digitalpebble.storm.crawler.filtering.basic.BasicURLNormalizer.java

@Override
public void configure(Map stormConf, JsonNode paramNode) {
    JsonNode node = paramNode.get("removeAnchorPart");
    if (node != null) {
        removeAnchorPart = node.booleanValue();
    }/*from ww  w .j  av  a 2 s . c o  m*/

    node = paramNode.get("unmangleQueryString");
    if (node != null) {
        unmangleQueryString = node.booleanValue();
    }

    node = paramNode.get("queryElementsToRemove");
    if (node != null) {
        if (!node.isArray()) {
            LOG.warn("Failed to configure queryElementsToRemove.  Not an array: {}", node.toString());
        } else {
            ArrayNode array = (ArrayNode) node;
            for (JsonNode element : array) {
                queryElementsToRemove.add(element.asText());
            }
        }
    }
}

From source file:org.wisdom.wamp.WampController.java

/**
 * Sends the given message on the websocket.
 *
 * @param message the message/*from  www.j  av a 2  s  .  co  m*/
 * @param to      the client receiving the message.
 */
private void sendOnWebSocket(JsonNode message, WampClient to) {
    publisher.send(Constants.WAMP_ROUTE, to.wisdomClientId(), message.toString());
}

From source file:controllers.EntryController.java

@Transactional
@BodyParser.Of(BodyParser.Json.class)
public Result enter() {
    Entry entry = new Entry();
    ArrayList<String> missing = new ArrayList<String>();
    JsonNode json = request().body().asJson();
    Logger.debug("GOT: " + json.toString());
    boolean retServerId = false;
    JsonNode value;//from   w w  w .  j  a v  a2  s.  c  o  m
    value = json.findValue("tech_id");
    if (value == null) {
        missing.add("tech_id");
    } else {
        entry.tech_id = value.intValue();
    }
    value = json.findValue("date");
    if (value == null) {
        missing.add("date");
    } else {
        entry.entry_time = new Date(value.longValue());
    }
    value = json.findValue("server_id");
    if (value != null) {
        entry.id = value.longValue();
        retServerId = true;
        Entry existing;
        if (entry.id > 0) {
            existing = Entry.find.byId(entry.id);
            existing.entry_time = entry.entry_time;
            existing.tech_id = entry.tech_id;
        } else {
            existing = Entry.findByDate(entry.tech_id, entry.entry_time);
        }
        if (existing != null) {
            entry = existing;
        }
    }
    int truck_number;
    String license_plate;
    value = json.findValue("truck_number");
    if (value != null) {
        truck_number = value.intValue();
    } else {
        truck_number = 0;
    }
    value = json.findValue("license_plate");
    if (value != null) {
        license_plate = value.textValue();
    } else {
        license_plate = null;
    }
    if (truck_number == 0 && license_plate == null) {
        missing.add("truck_number");
        missing.add("license_plate");
    } else {
        // Note: I don't call Version.inc(Version.VERSION_TRUCK) intentionally.
        // The reason is that other techs don't need to know about a local techs truck updates.
        Truck truck = Truck.add(truck_number, license_plate, entry.tech_id);
        entry.truck_id = truck.id;
    }
    value = json.findValue("project_id");
    if (value == null) {
        missing.add("project_id");
    } else {
        entry.project_id = value.longValue();
    }
    value = json.findValue("status");
    if (value != null) {
        entry.status = Entry.Status.from(value.textValue());
    }
    value = json.findValue("address_id");
    if (value == null) {
        value = json.findValue("address");
        if (value == null) {
            missing.add("address_id");
        } else {
            String address = value.textValue().trim();
            if (address.length() > 0) {
                try {
                    Company company = Company.parse(address);
                    Company existing = Company.has(company);
                    if (existing != null) {
                        company = existing;
                    } else {
                        company.created_by = entry.tech_id;
                        company.save();
                        Version.inc(Version.VERSION_COMPANY);
                    }
                    entry.company_id = company.id;
                } catch (Exception ex) {
                    return badRequest2("address: " + ex.getMessage());
                }
            } else {
                return badRequest2("address");
            }
        }
    } else {
        entry.company_id = value.longValue();
    }
    value = json.findValue("equipment");
    if (value != null) {
        if (value.getNodeType() != JsonNodeType.ARRAY) {
            Logger.error("Expected array for element 'equipment'");
        } else {
            int collection_id;
            if (entry.equipment_collection_id > 0) {
                collection_id = (int) entry.equipment_collection_id;
                EntryEquipmentCollection.deleteByCollectionId(entry.equipment_collection_id);
            } else {
                collection_id = Version.inc(Version.NEXT_EQUIPMENT_COLLECTION_ID);
            }
            boolean newEquipmentCreated = false;
            Iterator<JsonNode> iterator = value.elements();
            while (iterator.hasNext()) {
                JsonNode ele = iterator.next();
                EntryEquipmentCollection collection = new EntryEquipmentCollection();
                collection.collection_id = (long) collection_id;
                JsonNode subvalue = ele.findValue("equipment_id");
                if (subvalue == null) {
                    subvalue = ele.findValue("equipment_name");
                    if (subvalue == null) {
                        missing.add("equipment_id");
                        missing.add("equipment_name");
                    } else {
                        String name = subvalue.textValue();
                        List<Equipment> equipments = Equipment.findByName(name);
                        Equipment equipment;
                        if (equipments.size() == 0) {
                            equipment = new Equipment();
                            equipment.name = name;
                            equipment.created_by = entry.tech_id;
                            equipment.save();
                        } else {
                            if (equipments.size() > 1) {
                                Logger.error("Too many equipments found with name: " + name);
                            }
                            equipment = equipments.get(0);
                        }
                        collection.equipment_id = equipment.id;
                        newEquipmentCreated = true;
                    }
                } else {
                    collection.equipment_id = subvalue.longValue();
                }
                collection.save();
            }
            entry.equipment_collection_id = collection_id;
            if (newEquipmentCreated) {
                Version.inc(Version.VERSION_EQUIPMENT);
            }
        }
    }
    value = json.findValue("picture");
    if (value != null) {
        if (value.getNodeType() != JsonNodeType.ARRAY) {
            Logger.error("Expected array for element 'picture'");
        } else {
            int collection_id;
            if (entry.picture_collection_id > 0) {
                collection_id = (int) entry.picture_collection_id;
                PictureCollection.deleteByCollectionId(entry.picture_collection_id, null);
            } else {
                collection_id = Version.inc(Version.NEXT_PICTURE_COLLECTION_ID);
            }
            Iterator<JsonNode> iterator = value.elements();
            while (iterator.hasNext()) {
                JsonNode ele = iterator.next();
                PictureCollection collection = new PictureCollection();
                collection.collection_id = (long) collection_id;
                JsonNode subvalue = ele.findValue("note");
                if (subvalue != null) {
                    collection.note = subvalue.textValue();
                }
                subvalue = ele.findValue("filename");
                if (subvalue == null) {
                    missing.add("filename");
                } else {
                    collection.picture = subvalue.textValue();
                    collection.save();
                }
            }
            entry.picture_collection_id = collection_id;
        }
    }
    value = json.findValue("notes");
    if (value != null) {
        if (value.getNodeType() != JsonNodeType.ARRAY) {
            Logger.error("Expected array for element 'notes'");
        } else {
            int collection_id;
            if (entry.note_collection_id > 0) {
                collection_id = (int) entry.note_collection_id;
                EntryNoteCollection.deleteByCollectionId(entry.note_collection_id);
            } else {
                collection_id = Version.inc(Version.NEXT_NOTE_COLLECTION_ID);
            }
            Iterator<JsonNode> iterator = value.elements();
            while (iterator.hasNext()) {
                JsonNode ele = iterator.next();
                EntryNoteCollection collection = new EntryNoteCollection();
                collection.collection_id = (long) collection_id;
                JsonNode subvalue = ele.findValue("id");
                if (subvalue == null) {
                    subvalue = ele.findValue("name");
                    if (subvalue == null) {
                        missing.add("note:id, note:name");
                    } else {
                        String name = subvalue.textValue();
                        List<Note> notes = Note.findByName(name);
                        if (notes == null || notes.size() == 0) {
                            missing.add("note:" + name);
                        } else if (notes.size() > 1) {
                            Logger.error("Too many notes with name: " + name);
                            missing.add("note:" + name);
                        } else {
                            collection.note_id = notes.get(0).id;
                        }
                    }
                } else {
                    collection.note_id = subvalue.longValue();
                }
                subvalue = ele.findValue("value");
                if (value == null) {
                    missing.add("note:value");
                } else {
                    collection.note_value = subvalue.textValue();
                }
                collection.save();
            }
            entry.note_collection_id = collection_id;
        }
    }
    if (missing.size() > 0) {
        return missingRequest(missing);
    }
    if (entry.id != null && entry.id > 0) {
        entry.update();
        Logger.debug("Updated entry " + entry.id);
    } else {
        entry.save();
        Logger.debug("Created new entry " + entry.id);
    }
    long ret_id;
    if (retServerId) {
        ret_id = entry.id;
    } else {
        ret_id = 0;
    }
    return ok(Long.toString(ret_id));
}

From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDControllerTest.java

@Test
public void series1_phase2_Person_FindMany() throws Exception {
    Response response = getLightblueFactory().getMediator()
            .find(createRequest_FromResource(FindRequest.class, "./crud/find/person-find-many.json"));

    assertNotNull(response);//from  w ww  . j ava 2  s  . c  om
    assertNoErrors(response);
    assertNoDataErrors(response);
    assertEquals(3, response.getMatchCount());

    JsonNode entityData = response.getEntityData();
    assertNotNull(entityData);

    //Search requests results in desc order, strict mode is enforced to assure this.
    JSONAssert
            .assertEquals(
                    "[{\"dn\":\"uid=junior.doe," + BASEDB_USERS + "\"},{\"dn\":\"uid=john.doe," + BASEDB_USERS
                            + "\"},{\"dn\":\"uid=jane.doe," + BASEDB_USERS + "\"}]",
                    entityData.toString(), true);
}

From source file:portal.api.osm.client.OSMClient.java

/**
 * @param aNSDid/*from   www.ja  v a  2s .co m*/
 * @return
 */
public Nsd getNSDbyID(String aNSDid) {

    String response = getOSMResponse(BASE_SERVICE_URL + "/nsd-catalog/nsd/" + aNSDid);

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    try {

        JsonNode tr = mapper.readTree(response).findValue("nsd:nsd"); // needs a massage
        if (tr == null) {
            tr = mapper.readTree(response).findValue("nsd");
        }
        tr = tr.get(0);
        String s = tr.toString();
        s = s.replaceAll("vnfd:", ""); // some yaml files contain nsd: prefix in every key which is not common in
        // json

        Nsd nsd = mapper.readValue(s, Nsd.class);

        return nsd;

    } catch (IllegalStateException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:portal.api.osm.client.OSMClient.java

public Vnfd getVNFDbyID(String aVNFDid) {

    String response = getOSMResponse(BASE_SERVICE_URL + "/vnfd-catalog/vnfd/" + aVNFDid);

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    try {/*w  ww.  j  av a2  s  . c  o m*/

        JsonNode tr = mapper.readTree(response).findValue("vnfd:vnfd"); // needs a massage
        if (tr == null) {
            tr = mapper.readTree(response).findValue("vnfd");
        }
        tr = tr.get(0);
        String s = tr.toString();
        s = s.replaceAll("vnfd:", ""); // some yaml files contain nsd: prefix in every key which is not common in
        // json

        Vnfd v = mapper.readValue(s, Vnfd.class);

        return v;

    } catch (IllegalStateException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:com.baasbox.dao.ScriptsDao.java

private ODocument makeScript(String name, String language, String code, boolean isLibrary, boolean active,
        JsonNode initialStore) {
    ODocument doc = new ODocument(MODEL_NAME);
    doc.field(NAME, name);/* www.  jav  a 2s . com*/
    doc.field(LANG, language);
    List<String> codes = Collections.singletonList(code);
    doc.field(CODE, codes);
    doc.field(DATE, new Date());
    doc.field(LIB, isLibrary);
    doc.field(ACTIVE, active);
    ODocument local = new ODocument();
    if (initialStore != null) {
        local.fromJSON(initialStore.toString());
    }
    doc.field(LOCAL_STORAGE, local);
    doc.field(INVALID, false);
    return doc;
}

From source file:com.marklogic.client.functionaltest.TestBulkSearchWithStringQueryDef.java

public void loadJSONDocuments() throws JsonProcessingException, IOException {
    int count = 1;
    JSONDocumentManager docMgr = client.newJSONDocumentManager();
    DocumentWriteSet writeset = docMgr.newWriteSet();

    HashMap<String, String> map = new HashMap<String, String>();

    for (int i = 0; i < 102; i++) {
        JsonNode jn = new ObjectMapper().readTree("{\"animal\":\"dog" + i + "\", \"says\":\"woof\"}");
        JacksonHandle jh = new JacksonHandle();
        jh.set(jn);//from w ww . j  a  v a  2  s . c o m
        writeset.add(DIRECTORY + "dog" + i + ".json", jh);
        map.put(DIRECTORY + "dog" + i + ".json", jn.toString());
        if (count % BATCH_SIZE == 0) {
            docMgr.write(writeset);
            writeset = docMgr.newWriteSet();
        }
        count++;
        //         System.out.println(jn.toString());
    }
    if (count % BATCH_SIZE > 0) {
        docMgr.write(writeset);
    }
}

From source file:com.meetingninja.csse.database.volley.JsonNodeRequest.java

public JsonNodeRequest(int timeout, int method, String url, JsonNode payload, JsonRequestListener listener) {
    super(method, url, null);

    setShouldCache(false);//from   ww  w.  java 2  s.  co m

    mListener = listener;

    mAcceptedStatusCodes = new ArrayList<Integer>();
    mAcceptedStatusCodes.add(HttpStatus.SC_OK);
    mAcceptedStatusCodes.add(HttpStatus.SC_NO_CONTENT);

    setRetryPolicy(new DefaultRetryPolicy(timeout, 1, 1));

    if (method == Method.POST || method == Method.PUT) {
        mParams = new HashMap<String, String>();
        mParams.put("payload", payload.toString());
    }
}

From source file:com.neovisionaries.security.JsonDigestUpdater.java

private void updateNumber(JsonNode node) {
    // Number start.
    mark("N");// w  w w.  j a v  a  2 s. com

    // Numbers contribute to the digest as String to make it
    // easy to implement JsonDigestUpdater equivalent for other
    // non-Java platforms.
    //
    // Note that BigDecimal.toString() is used for floating point
    // numbers because USE_BIG_DECIMAL_FOR_FLOATS is enabled.
    digest.update(node.toString());

    // Number end.
    mark("n");
}