List of usage examples for com.fasterxml.jackson.databind ObjectMapper createObjectNode
@Override
public ObjectNode createObjectNode()
Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addRangeElementAttributeIndex(String dbName, String type, String parentnamespace, String parentlocalname, String namespace, String localname, String collation) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", type); childNodeObject.put("collation", collation); childNodeObject.put("parent-namespace-uri", parentnamespace); childNodeObject.put("parent-localname", parentlocalname); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", "reject"); childArray.add(childNodeObject);/*from w ww . j a v a 2 s .c o m*/ childNode.putArray("range-element-attribute-index").addAll(childArray); // mainNode.put("range-element-attribute-indexes", childNode); // System.out.println(type + mainNode.path("range-element-attribute-indexes").path("range-element-attribute-index").toString()); setDatabaseProperties(dbName, "range-element-attribute-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addFieldExcludeRoot(String dbName, String fieldName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("field-name", fieldName); childNodeObject.put("include-root", false); childNodeObject.putNull("included-elements"); childNodeObject.putNull("excluded-elements"); childNodeObject.putNull("tokenizer-overrides"); arrNode.add(childNodeObject);//from ww w . j a va 2 s .co m childNode.putArray("field").addAll(arrNode); // mainNode.put("fields", childNode); // System.out.println( childNode.toString()); setDatabaseProperties(dbName, "field", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addGeoSpatialElementChildIndexes(String dbName, String parentNamespaceUri, String parentLocalName, String namespace, String localname, String coordinateSystem, String pointFormat, boolean rangeValuePositions, String invalidValues) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("parent-namespace-uri", parentNamespaceUri); childNodeObject.put("parent-localname", parentLocalName); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", localname); childNodeObject.put("coordinate-system", coordinateSystem); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childNodeObject.put("point-format", pointFormat); childArray.add(childNodeObject);// ww w.j a v a 2 s.co m childNode.putArray("geospatial-element-child-index").addAll(childArray); // mainNode.put("geospatial-element-child-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "geospatial-element-child-index", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addGeospatialElementPairIndexes(String dbName, String parentNamespaceUri, String parentLocalName, String latNamespace, String latLocalname, String longNamespace, String longLocalname, String coordinateSystem, boolean rangeValuePositions, String invalidValues) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("parent-namespace-uri", parentNamespaceUri); childNodeObject.put("parent-localname", parentLocalName); childNodeObject.put("latitude-namespace-uri", latNamespace); childNodeObject.put("latitude-localname", latLocalname); childNodeObject.put("longitude-namespace-uri", latNamespace); childNodeObject.put("longitude-localname", longLocalname); childNodeObject.put("coordinate-system", coordinateSystem); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childArray.add(childNodeObject);// w ww . jav a 2 s .c om childNode.putArray("geospatial-element-pair-index").addAll(childArray); // mainNode.put("geospatial-element-pair-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "geospatial-element-pair-index", childNode); }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java
/** Creates a mapping for the bucket - search service elements .. up to but not including the mapping + type * NOTE: creates an embedded object that is {{, ie must be closed twice subsequently in order to be a well formed JSON object * @param bucket/*from ww w.j a v a 2s . c om*/ * @return * @throws IOException */ public static XContentBuilder getSearchServiceMapping(final DataBucketBean bucket, final Optional<String> secondary_buffer, final boolean is_primary, final ElasticsearchIndexServiceConfigBean schema_config, final Optional<XContentBuilder> to_embed, final ObjectMapper mapper) { try { final XContentBuilder start = to_embed.orElse(XContentFactory.jsonBuilder().startObject()); // (Nullable) final ElasticsearchIndexServiceConfigBean.SearchIndexSchemaDefaultBean search_schema = schema_config .search_technology_override(); //(very briefly Nullable) final JsonNode settings = Optional.ofNullable(search_schema).map(s -> s.settings()) .map(o -> mapper.convertValue(o, JsonNode.class)).orElse(null); //(very briefly Nullable) final ObjectNode aliases = (ObjectNode) Optional.ofNullable(search_schema).map(s -> s.aliases()) .map(o -> mapper.convertValue(o, JsonNode.class)).orElse(mapper.createObjectNode()); if (is_primary) { // add the "read only" prefix alias aliases.set( ElasticsearchContext.READ_PREFIX + ElasticsearchIndexUtils.getBaseIndexName(bucket, Optional.empty()), mapper.createObjectNode()); } // Settings final String type_key = getTypeKey(bucket, mapper); return Lambdas.wrap_u(__ -> { if (null == settings) { // nothing to do return start; } else { return start.rawField("settings", settings.toString().getBytes()); } }) // Aliases .andThen(Lambdas.wrap_u(json -> { if (!aliases.elements().hasNext()) { // nothing to do return json; } else { return start.rawField("aliases", aliases.toString().getBytes()); } })) // Mappings and overrides .andThen(Lambdas.wrap_u(json -> json.startObject("mappings").startObject(type_key))) // Add the secondary buffer name to the metadata: .andThen(Lambdas.wrap_u(json -> { return json.rawField(CUSTOM_META, createMergedMeta(Either.right(mapper), bucket, is_primary, secondary_buffer) .toString().getBytes()); })) // More mapping overrides .andThen(Lambdas.wrap_u(json -> { return Optional.ofNullable(search_schema).map(ss -> ss.mapping_overrides()) .map(m -> m.getOrDefault(type_key, m.get("*"))).orElse(Collections.emptyMap()) .entrySet().stream().reduce(json, Lambdas.wrap_u((acc, kv) -> { if (CUSTOM_META.equals(kv.getKey())) { // meta is a special case, merge my results in regardless return acc.rawField(kv.getKey(), createMergedMeta( Either.left( mapper.convertValue(kv.getValue(), JsonNode.class)), bucket, is_primary, secondary_buffer).toString() .getBytes()); } else { return acc.rawField(kv.getKey(), mapper .convertValue(kv.getValue(), JsonNode.class).toString().getBytes()); } }), (acc1, acc2) -> acc1 // (can't actually ever happen) ); })).apply(null); } catch (IOException e) { //Handle fake "IOException" return null; } }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void includeElementFieldWithWeight(String dbName, String field_name, String namespace, String elementName, double weight, String attrNS_URI, String attr_localname, String attr_value) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", elementName); childNodeObject.put("weight", weight); // These 3 are new fields that have been added as of 8.0.2 from 03/20/2015 in the Management API. childNodeObject.put("attribute-namespace-uri", attrNS_URI); childNodeObject.put("attribute-localname", attr_localname); childNodeObject.put("attribute-value", attr_value); arrNode.add(childNodeObject);/*ww w .jav a 2 s . co m*/ childNode.putArray("included-element").addAll(arrNode); //System.out.println( childNode.toString()); setDatabaseFieldProperties(dbName, field_name, "included-element", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addGeospatialElementAttributePairIndexes(String dbName, String parentNamespaceUri, String parentLocalName, String latNamespace, String latLocalname, String longNamespace, String longLocalname, String coordinateSystem, boolean rangeValuePositions, String invalidValues) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("parent-namespace-uri", parentNamespaceUri); childNodeObject.put("parent-localname", parentLocalName); childNodeObject.put("latitude-namespace-uri", latNamespace); childNodeObject.put("latitude-localname", latLocalname); childNodeObject.put("longitude-namespace-uri", latNamespace); childNodeObject.put("longitude-localname", longLocalname); childNodeObject.put("coordinate-system", coordinateSystem); childNodeObject.put("range-value-positions", false); childNodeObject.put("invalid-values", invalidValues); childArray.add(childNodeObject);//from ww w .j ava2s .c om childNode.putArray("geospatial-element-attribute-pair-index").addAll(childArray); // mainNode.put("geospatial-element-attribute-pair-indexes", childNode); // System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString()); setDatabaseProperties(dbName, "geospatial-element-attribute-pair-index", childNode); }
From source file:com.marklogic.client.functionaltest.TestBulkSearchWithStrucQueryDef.java
@Test public void testBulkSearchRawJSONStrucQD() throws Exception { // setAutomaticDirectoryCreation(dbName,"automatic"); setMaintainLastModified(dbName, true); this.loadJSONDocuments(); this.loadXMLDocuments(); GenericDocumentManager docMgr = client.newDocumentManager(); QueryManager queryMgr = client.newQueryManager(); JacksonHandle jh = new JacksonHandle(); ObjectMapper mapper = new ObjectMapper(); // constructing JSON representation of Raw JSON Structured Query ObjectNode txtNode = mapper.createObjectNode(); txtNode.putArray("text").add("woof"); ObjectNode termQNode = mapper.createObjectNode(); termQNode.set("term-query", txtNode); ObjectNode queriesArrayNode = mapper.createObjectNode(); queriesArrayNode.putArray("queries").add(termQNode); ObjectNode txtNode2 = mapper.createObjectNode(); txtNode2.putArray("text").add("bar"); ObjectNode termQNode2 = mapper.createObjectNode(); termQNode2.set("term-query", txtNode2); queriesArrayNode.withArray("queries").add(termQNode2); ObjectNode orQueryNode = mapper.createObjectNode(); orQueryNode.set("or-query", queriesArrayNode); ObjectNode queryArrayNode = mapper.createObjectNode(); queryArrayNode.putArray("queries").add(orQueryNode); ObjectNode mainNode = mapper.createObjectNode(); mainNode.set("query", queryArrayNode); jh.set(mainNode);/*from w w w.j av a2 s . c om*/ RawStructuredQueryDefinition qd = queryMgr.newRawStructuredQueryDefinition(jh); System.out.println(jh.get().toString()); docMgr.setNonDocumentFormat(Format.JSON); JacksonHandle results = new JacksonHandle(); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); int count = 1; while (count < 4) { page = docMgr.search(qd, count, results); while (page.hasNext()) { DocumentRecord rec = page.next(); if (rec.getMimetype().contains("xml")) { validateRecord(rec, Format.XML); } else { validateRecord(rec, Format.JSON); } docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertFalse("Record has collections ?", mh.getCollections().isEmpty()); } count++; } System.out.println(results.get().toString()); assertEquals("Total search results before transaction rollback are ", "204", results.get().get("total").asText()); }
From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java
public static void addRangeElementIndex(String dbName, String[][] rangeElements) throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode mainNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); int nRowsLen = rangeElements.length; int j = 0;/* w w w .j av a 2 s .c o m*/ for (int i = 0; i < nRowsLen; i++) { ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("scalar-type", rangeElements[i][j++]); childNodeObject.put("namespace-uri", rangeElements[i][j++]); childNodeObject.put("localname", rangeElements[i][j++]); childNodeObject.put("collation", rangeElements[i][j++]); if (rangeElements[i][j].equalsIgnoreCase("false")) childNodeObject.put("range-value-positions", false); else childNodeObject.put("range-value-positions", true); j++; childNodeObject.put("invalid-values", rangeElements[i][j++]); /* if new field elements are to be added, then: * 1) Increment value of j * 2) add them below here using childNodeObject.put("FIELD-NAME", rangeElements[i][j++]); */ childArray.add(childNodeObject); j = 0; } mainNode.putArray("range-element-index").addAll(childArray); setDatabaseProperties(dbName, "range-element-index", mainNode); }
From source file:com.hrm.controller.RegisterController.java
/** * author qwc// www . j a v a 2 s .c o m * 201741?12:49:43 * @param request * @param response * @throws IOException * ??? */ @RequestMapping("checkComName") public void checkComName(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter out = response.getWriter(); ObjectMapper mapper = new ObjectMapper(); ObjectNode checkStatus = mapper.createObjectNode(); int checkAmount = 0; String account = null; String enterpriseName = request.getParameter("enterpriseName"); if (enterpriseName != null) { account = enterpriseName; checkAmount = RTestDao.checkConName(account); } if (checkAmount > 0) { checkStatus.put("valid", false); out.write(checkStatus.toString());/*?*/ } else { checkStatus.put("valid", true); out.write(checkStatus.toString());/*?*/ } }