List of usage examples for com.fasterxml.jackson.databind.node BooleanNode FALSE
BooleanNode FALSE
To view the source code for com.fasterxml.jackson.databind.node BooleanNode FALSE.
Click Source Link
From source file:org.jsonbuilder.implementations.jackson.JacksonBooleanNode.java
public JacksonBooleanNode(Boolean value) { if (value) {/*ww w.ja va2 s.c o m*/ this.value = BooleanNode.TRUE; } else { this.value = BooleanNode.FALSE; } }
From source file:com.squarespace.template.JsonUtilsTest.java
@Test public void testJsonCompare() { assertEquals(JsonUtils.compare(json(1), json(1)), 0); assertEquals(JsonUtils.compare(json(1), json(2)), -1); assertEquals(JsonUtils.compare(json(2), json(1)), 1); assertEquals(JsonUtils.compare(json(1.0), json(1.0)), 0); assertEquals(JsonUtils.compare(json(1.0), json(2.0)), -1); assertEquals(JsonUtils.compare(json(2.0), json(1.0)), 1); assertEquals(JsonUtils.compare(json("a"), json("a")), 0); assertEquals(JsonUtils.compare(json("a"), json("b")), -1); assertEquals(JsonUtils.compare(json("b"), json("a")), 1); assertEquals(JsonUtils.compare(BooleanNode.TRUE, BooleanNode.TRUE), 0); assertEquals(JsonUtils.compare(BooleanNode.FALSE, BooleanNode.FALSE), 0); assertEquals(JsonUtils.compare(BooleanNode.TRUE, json("true")), 0); assertEquals(JsonUtils.compare(BooleanNode.FALSE, json("false")), 0); assertEquals(JsonUtils.compare(BooleanNode.TRUE, BooleanNode.FALSE), 1); assertEquals(JsonUtils.compare(BooleanNode.FALSE, BooleanNode.TRUE), -1); }
From source file:com.sri.save.FloraJsonServer.java
/** * Loads the given file into the main module, overriding any previously loaded file. * Sets the given file as the active file. */*from w w w . j a v a 2s . com*/ * Note: The file should import any other files that it depends on. Import paths are * relative to the contentdir that FloraJsonServer was created with. * * @param filename JSON node containing the filename to be loaded, relative to the content * dir that this FloraJsonServer was created with. * */ public BooleanNode loadFile(String filename) throws FloraJsonServerException { logger.debug("loadFile: " + filename); // Load a flora file (to the "main" module - always use this) try { boolean success = engine.loadFile(filename, "main"); if (!success) return BooleanNode.FALSE; activeFile = new File(contentDir + File.separator + filename); logger.debug("Set active file to: " + activeFile.getAbsolutePath()); docService.setActiveFile(activeFile); return BooleanNode.TRUE; } catch (FlrException ex) { throw new FloraJsonServerException(ex.getMessage()); } }
From source file:com.sri.save.florahttp.FloraJsonServer.java
public BooleanNode command(String cmd) throws FloraJsonServerException { try {/*from ww w .ja v a2 s . c o m*/ boolean result = engine.floraCommand(cmd); if (result) return BooleanNode.TRUE; else return BooleanNode.FALSE; } catch (Exception ex) { ex.printStackTrace(); throw new FloraJsonServerException(ex.getMessage()); } }
From source file:com.ikanow.aleph2.management_db.mongodb.services.TestIkanowV1SyncService_Buckets.java
@Test public void test_compareSourcesToBuckets_get() throws JsonProcessingException, IOException, ParseException, InterruptedException, ExecutionException { _logger.info("Starting test_compareSourcesToBuckets_get"); @SuppressWarnings("unchecked") ICrudService<JsonNode> v1_source_db = this._service_context.getCoreManagementDbService() .getUnderlyingPlatformDriver(ICrudService.class, Optional.of("ingest.source")).get(); v1_source_db.deleteDatastore().get(); IManagementCrudService<DataBucketBean> bucket_db = this._service_context.getCoreManagementDbService() .getDataBucketStore();/*from w w w.ja va2 s . co m*/ bucket_db.deleteDatastore().get(); // Create 2 V1 sources final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); final JsonNode v1_source_1 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); final JsonNode v1_source_2 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); final JsonNode v1_source_3 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); ((ObjectNode) v1_source_2).set("_id", null); ((ObjectNode) v1_source_2).set("key", new TextNode("aleph...bucket.Template_V2_data_bucket.2")); ((ObjectNode) v1_source_3).set("_id", null); ((ObjectNode) v1_source_3).set("key", new TextNode("aleph...bucket.Template_V2_data_bucket.3")); ((ObjectNode) v1_source_3).set("isApproved", BooleanNode.FALSE); assertEquals(0L, (long) v1_source_db.countObjects().get()); v1_source_db.storeObjects(Arrays.asList(v1_source_1, v1_source_2, v1_source_3)).get(); assertEquals(3L, (long) v1_source_db.countObjects().get()); // Create 2 buckets final DataBucketBean bucket1 = IkanowV1SyncService_Buckets.getBucketFromV1Source(v1_source_1); final DataBucketBean bucket2 = IkanowV1SyncService_Buckets.getBucketFromV1Source(v1_source_2); assertEquals(0L, (long) bucket_db.countObjects().get()); bucket_db.storeObjects(Arrays.asList(bucket1, bucket2)).get(); assertEquals(2L, (long) bucket_db.countObjects().get()); // Run the function under test final Tuple2<Map<String, String>, Map<String, Date>> f_res = IkanowV1SyncService_Buckets .compareSourcesToBuckets_get(bucket_db, v1_source_db).get(); assertEquals( "{aleph...bucket.Template_V2_data_bucket.=May 25, 2015 01:52:01 PM UTC, aleph...bucket.Template_V2_data_bucket.3=, aleph...bucket.Template_V2_data_bucket.2=May 25, 2015 01:52:01 PM UTC}", f_res._1().toString()); assertEquals(2, f_res._2().size()); //(times are sys dependent here so just check the keys) assertEquals(true, f_res._2().containsKey("aleph...bucket.Template_V2_data_bucket.")); assertEquals(true, f_res._2().containsKey("aleph...bucket.Template_V2_data_bucket.2")); }
From source file:com.ikanow.aleph2.management_db.mongodb.services.TestIkanowV1SyncService_Buckets.java
@SuppressWarnings("deprecation") @Test//from w ww . jav a 2 s.c o m public void test_puttingItAllTogether() throws JsonProcessingException, IOException, ParseException, InterruptedException, ExecutionException { _logger.info("Starting test_puttingItAllTogether"); // Set up 3 different scenarios: // 1 - doc to be deleted // 1 - doc to be updated (+1 that would be updated if it was non-approveD) // 1 - doc to be created (+1 that would be created if it was non-approveD) @SuppressWarnings("unchecked") ICrudService<JsonNode> v1_source_db = this._service_context.getCoreManagementDbService() .getUnderlyingPlatformDriver(ICrudService.class, Optional.of("ingest.source")).get(); v1_source_db.deleteDatastore().get(); IManagementCrudService<DataBucketBean> bucket_db = this._service_context.getCoreManagementDbService() .getDataBucketStore(); bucket_db.deleteDatastore().get(); IManagementCrudService<DataBucketStatusBean> bucket_status_db = this._service_context .getCoreManagementDbService().getDataBucketStatusStore(); bucket_status_db.deleteDatastore().get(); // Create 3 V1 sources (only going to save 1 of them) final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); final JsonNode v1_source_1 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); final JsonNode v1_source_2 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); final JsonNode v1_source_3 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); final JsonNode v1_source_4 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); final JsonNode v1_source_5 = mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_source.json")); ((ObjectNode) v1_source_2).set("_id", null); ((ObjectNode) v1_source_2).set("key", new TextNode("aleph...bucket.Template_V2_data_bucket.2")); // (not saving this one it's just a template) ((ObjectNode) v1_source_3).set("_id", null); ((ObjectNode) v1_source_3).set("key", new TextNode("aleph...bucket.Template_V2_data_bucket.3")); // (disabled one) ((ObjectNode) v1_source_4).set("_id", null); ((ObjectNode) v1_source_4).set("key", new TextNode("aleph...bucket.Template_V2_data_bucket.4")); ((ObjectNode) v1_source_4).set("isApproved", BooleanNode.FALSE); // (disabled one with matching bucket) ((ObjectNode) v1_source_5).set("_id", null); ((ObjectNode) v1_source_5).set("key", new TextNode("aleph...bucket.Template_V2_data_bucket.5")); ((ObjectNode) v1_source_5).set("isApproved", BooleanNode.FALSE); // Create 3 buckets final DataBucketBean bucket1 = IkanowV1SyncService_Buckets.getBucketFromV1Source(v1_source_1); final DataBucketBean bucket3 = IkanowV1SyncService_Buckets.getBucketFromV1Source(v1_source_3); final DataBucketBean bucket5 = IkanowV1SyncService_Buckets.getBucketFromV1Source(v1_source_5); assertEquals(0L, (long) bucket_db.countObjects().get()); bucket_db.storeObjects(Arrays.asList(bucket1, bucket3, bucket5)).get(); assertEquals(3L, (long) bucket_db.countObjects().get()); //(store status) final DataBucketStatusBean bucket_status1 = BeanTemplateUtils.build(DataBucketStatusBean.class) .with(DataBucketStatusBean::_id, bucket1._id()).with(DataBucketStatusBean::suspended, false) .with(DataBucketStatusBean::bucket_path, bucket1.full_name()).done().get(); final DataBucketStatusBean bucket_status3 = BeanTemplateUtils.build(DataBucketStatusBean.class) .with(DataBucketStatusBean::_id, bucket3._id()).with(DataBucketStatusBean::suspended, true) .with(DataBucketStatusBean::bucket_path, bucket3.full_name()).done().get(); final DataBucketStatusBean bucket_status5 = BeanTemplateUtils.build(DataBucketStatusBean.class) .with(DataBucketStatusBean::_id, bucket5._id()).with(DataBucketStatusBean::suspended, true) .with(DataBucketStatusBean::bucket_path, bucket5.full_name()).done().get(); assertEquals(0L, (long) bucket_status_db.countObjects().get()); bucket_status_db.storeObjects(Arrays.asList(bucket_status1, bucket_status3, bucket_status5)).get(); assertEquals(3L, (long) bucket_status_db.countObjects().get()); // Mod + save sources ((ObjectNode) v1_source_1).set("modified", new TextNode(new Date().toGMTString())); ((ObjectNode) v1_source_1).set("searchCycle_secs", new IntNode(-1)); ((ObjectNode) v1_source_1).set("description", new TextNode("NEW DESCRIPTION")); ((ObjectNode) v1_source_5).set("modified", new TextNode(new Date().toGMTString())); assertEquals(0L, (long) v1_source_db.countObjects().get()); v1_source_db.storeObjects(Arrays.asList(v1_source_1, v1_source_2, v1_source_4, v1_source_5)).get(); assertEquals(4L, (long) v1_source_db.countObjects().get()); // OK now fire off an instance of the runner IkanowV1SyncService_Buckets s1 = new IkanowV1SyncService_Buckets( BeanTemplateUtils.clone(_service_config).with("v1_enabled", true).done(), _service_context); int old = IkanowV1SyncService_Buckets._num_leader_changes; s1.start(); for (int i = 0; i < 20; ++i) { try { Thread.sleep(1000); } catch (Exception e) { } if ((old + 1) == IkanowV1SyncService_Buckets._num_leader_changes) break; } s1.stop(); assertEquals(old + 1, IkanowV1SyncService_Buckets._num_leader_changes); // Now sleep a bit more to let the monitor have time to finish: Thread.sleep(3000L); // Check a few things have happened: // 1) bucket3 has been deleted assertEquals(false, bucket_db .getObjectById(IkanowV1SyncService_Buckets .getBucketIdFromV1SourceKey("aleph...bucket.Template_V2_data_bucket.3")) .get().isPresent()); // 2) bucket2 has been created assertEquals(true, bucket_db .getObjectById(IkanowV1SyncService_Buckets .getBucketIdFromV1SourceKey("aleph...bucket.Template_V2_data_bucket.2")) .get().isPresent()); // 3) bucket1 has been updated final Optional<DataBucketStatusBean> status = bucket_status_db.getObjectById(bucket1._id()).get(); assertEquals(true, status.get().suspended()); final Optional<DataBucketBean> updated_bucket = bucket_db.getObjectById(bucket1._id()).get(); assertEquals("NEW DESCRIPTION", updated_bucket.get().description()); assertEquals(bucket1.display_name(), updated_bucket.get().display_name()); assertEquals(bucket1.tags(), updated_bucket.get().tags()); assertEquals(bucket1.full_name(), updated_bucket.get().full_name()); // 4) Check counts quickly assertEquals(4L, (long) bucket_status_db.countObjects().get()); //(this should be 3 but we're using the wrong db for maven reasons so the proxy doesn't occur) assertEquals(3L, (long) bucket_db.countObjects().get()); assertEquals(4L, (long) v1_source_db.countObjects().get()); // 5) Check v1 statuses have been updated... final Optional<JsonNode> res1 = v1_source_db .getObjectBySpec(CrudUtils.anyOf().when("key", "aleph...bucket.Template_V2_data_bucket.")).get(); assertEquals( "{'harvest_status':'success','harvest_message':'[DATE] Bucket synchronization:\\n(no messages)'}", res1.get().get("harvest").toString().replace("\"", "'").replaceAll("\\[.*?\\]", "[DATE]")); final Optional<JsonNode> res2 = v1_source_db .getObjectBySpec(CrudUtils.anyOf().when("key", "aleph...bucket.Template_V2_data_bucket.2")).get(); assertEquals( "{'harvest_status':'success','harvest_message':'[DATE] Bucket synchronization:\\n(no messages)'}", res2.get().get("harvest").toString().replace("\"", "'").replaceAll("\\[.*?\\]", "[DATE]")); }