public JobManagerImpl(DatabaseClient jobClient) { this.jobClient = jobClient; this.docMgr = jobClient.newJSONDocumentManager(); this.jobDeleteRunner = new JobDeleteResource(jobClient); }
PojoRepositoryImpl(DatabaseClient client, Class<T> entityClass) { this.client = client; this.entityClass = entityClass; this.idClass = null; this.docMgr = client.newJSONDocumentManager(); this.qb = new PojoQueryBuilderImpl<>(entityClass); }
@Override public void write(List<? extends ObjectNode> items) throws Exception { JSONDocumentManager jsonDocumentManager = databaseClient.newJSONDocumentManager(); items.forEach(item -> { jsonDocumentManager.write(uriGenerator.generate(), new JacksonHandle(item)); }); } }
private static void uploadData() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(collection); JSONDocumentManager docMgr = evalClient.newJSONDocumentManager(); File folder = new File("src/test/resources/legal_holds/data"); for ( Path path: Files.newDirectoryStream(folder.toPath(), "*.json") ) { File file = path.toFile(); docMgr.write(directory + file.getName(), meta, new FileHandle(file)); } }
@Test public void testNewJSONDocument() { JSONDocumentManager doc = Common.client.newJSONDocumentManager(); assertNotNull("Client could not create JSON document", doc); }
@Test public void test_issue_623() { String uniqueDir = "BulkReadWriteTest_" + new Random().nextInt(10000) + "/"; List<String> uris = new ArrayList<>(); uris.add(uniqueDir + "test_with_ampersand.txt?a=b&c=d"); uris.add(uniqueDir + "test+with+plus.txt"); uris.add(uniqueDir + "test/with/forwardslash.txt"); uris.add(uniqueDir + "test.with.dot.txt"); uris.add(uniqueDir + "test_with!every@thing#else$*()-_[]:',~.txt"); uris.add(uniqueDir + "test_with;.txt"); test_issue_623_body( Common.client.newTextDocumentManager(), uris, "$0" ); test_issue_623_body( Common.client.newBinaryDocumentManager(), uris, "$0" ); test_issue_623_body( Common.client.newXMLDocumentManager(), uris, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xml>$0</xml>" ); test_issue_623_body( Common.client.newJSONDocumentManager(), uris, "[\"$0\"]" ); }
private void initializeDocManager() { if (connectionClient == null) { return; } switch (properties.docType.getValue()) { case MIXED: docMgr = connectionClient.newDocumentManager(); docIdSuffix = ""; break; case XML: docMgr = connectionClient.newXMLDocumentManager(); docIdSuffix = "xml"; break; case JSON: docMgr = connectionClient.newJSONDocumentManager(); docIdSuffix = "json"; break; case PLAIN_TEXT: docMgr = connectionClient.newTextDocumentManager(); docIdSuffix = "txt"; break; case BINARY: docMgr = connectionClient.newBinaryDocumentManager(); docIdSuffix = "bin"; break; } }
private void initializeDocManager() { if (connectionClient == null) { return; } switch (properties.docType.getValue()) { case MIXED: docMgr = connectionClient.newDocumentManager(); docIdSuffix = ""; break; case XML: docMgr = connectionClient.newXMLDocumentManager(); docIdSuffix = "xml"; break; case JSON: docMgr = connectionClient.newJSONDocumentManager(); docIdSuffix = "json"; break; case PLAIN_TEXT: docMgr = connectionClient.newTextDocumentManager(); docIdSuffix = "txt"; break; case BINARY: docMgr = connectionClient.newBinaryDocumentManager(); docIdSuffix = "bin"; break; } }
@BeforeClass public static void beforeClass() { Common.connect(); docMgr = Common.client.newJSONDocumentManager(); setup(); } @AfterClass
@Test /* * Test bitemporal protections - NOWIPE With transaction. */ public void testProtectWipeWithoutPermission() throws Exception { System.out.println("Inside testProtectWipeWithoutPermission"); DatabaseClient adminClient = getDatabaseClientOnDatabase(appServerHostname, restPort, dbName, "eval-readeruser", "x", getConnType()); ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName, temporalLsqtCollectionName, true); Calendar insertTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:01"); String docId = "javaSingleJSONDoc.json"; JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle("2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON", docId ); JSONDocumentManager docMgr = writerClient.newJSONDocumentManager(); JSONDocumentManager docMgrProtect = adminClient.newJSONDocumentManager(); docMgr.write(docId, null, handle, null, null, temporalLsqtCollectionName, insertTime); Thread.sleep(10000); StringBuilder str = new StringBuilder(); try { // Protect document for 30 sec. Use Duration. docMgrProtect.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOWIPE, DatatypeFactory.newInstance().newDuration("PT30S")); } catch (Exception ex) { str.append(ex.getMessage()); System.out.println("Exception not thrown when user does not have permissions" + str.toString()); } assertTrue("Exception not thrown when user does not have permissions ", str.toString().contains("User is not allowed to protect resource")); }
public void loadJSONDocuments() throws KeyManagementException, NoSuchAlgorithmException, JsonProcessingException, IOException { int count = 1; JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); Map<String, String> map = new HashMap<>(); for (int i = 0; i < 102; i++) { JsonNode jn = new ObjectMapper().readTree("{\"animal\":\"dog" + i + "\", \"says\":\"woof\"}"); JacksonHandle jh = new JacksonHandle(); jh.set(jn); 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); } }
public void loadJSONDocuments() throws KeyManagementException, NoSuchAlgorithmException, JsonProcessingException, IOException { int count = 1; JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); Map<String, String> map = new HashMap<>(); for (int i = 0; i < 102; i++) { JsonNode jn = new ObjectMapper().readTree("{\"animal\":\"dog " + i + "\", \"says\":\"woof\"}"); JacksonHandle jh = new JacksonHandle(); jh.set(jn); 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); } }
public void loadJSONDocuments() throws KeyManagementException, NoSuchAlgorithmException, JsonProcessingException, IOException { int count = 1; JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); Map<String, String> map = new HashMap<>(); for (int i = 0; i < 102; i++) { JsonNode jn = new ObjectMapper().readTree("{\"animal\":\"dog" + i + "\", \"says\":\"woof\"}"); JacksonHandle jh = new JacksonHandle(); jh.set(jn); 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); } }
public static DocumentManager documentMgrSelect(DatabaseClient client, DocumentManager docMgr, String type) { // create doc manager switch (type) { case "XML": docMgr = client.newXMLDocumentManager(); break; case "Text": docMgr = client.newTextDocumentManager(); break; case "JSON": docMgr = client.newJSONDocumentManager(); break; case "Binary": docMgr = client.newBinaryDocumentManager(); break; case "JAXB": docMgr = client.newXMLDocumentManager(); break; default: System.out.println("Invalid type"); break; } return docMgr; }
@Test public void testWriteMultipleJSONDocs() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "/a.json", "/b.json", "/c.json" }; String json1 = new String("{\"animal\":\"dog\", \"says\":\"woof\"}"); String json2 = new String("{\"animal\":\"cat\", \"says\":\"meow\"}"); String json3 = new String("{\"animal\":\"rat\", \"says\":\"keek\"}"); Reader strReader = new StringReader(json1); JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); writeset.add(docId[0], new ReaderHandle(strReader).withFormat(Format.JSON)); writeset.add(docId[1], new ReaderHandle(new StringReader(json2))); writeset.add(docId[2], new ReaderHandle(new StringReader(json3))); docMgr.write(writeset); ReaderHandle r1 = new ReaderHandle(); docMgr.read(docId[0], r1); BufferedReader bfr = new BufferedReader(r1.get()); assertEquals(json1, bfr.readLine()); docMgr.read(docId[1], r1); assertEquals("Json File Content" + docId[1], json2, new BufferedReader(r1.get()).readLine()); docMgr.read(docId[2], r1); assertEquals("Json File Content" + docId[2], json3, new BufferedReader(r1.get()).readLine()); bfr.close(); }
@BeforeClass public static void setupTestOptions() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { Common.connectAdmin(); QueryOptionsManager queryOptionsManager = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); File options = new File("src/test/resources/alerting-options.xml"); queryOptionsManager.writeOptions("alerts", new FileHandle(options)); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); JSONDocumentManager jsonDocMgr = Common.client.newJSONDocumentManager(); jsonDocMgr.write("/basic1.json", new FileHandle(new File("src/test/resources/basic1.json"))); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/alert/first.xml", new FileHandle(new File("src/test/resources/alertFirst.xml"))); docMgr.write("/alert/second.xml", new FileHandle(new File("src/test/resources/alertSecond.xml"))); docMgr.write("/alert/third.xml", new FileHandle(new File("src/test/resources/alertThird.xml"))); }
@BeforeClass public static void setupTestOptions() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { Common.connectAdmin(); QueryOptionsManager queryOptionsManager = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); File options = new File("src/test/resources/alerting-options.xml"); queryOptionsManager.writeOptions("alerts", new FileHandle(options)); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); JSONDocumentManager jsonDocMgr = Common.client.newJSONDocumentManager(); jsonDocMgr.write("/basic1.json", new FileHandle(new File("src/test/resources/basic1.json"))); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/alert/first.xml", new FileHandle(new File("src/test/resources/alertFirst.xml"))); docMgr.write("/alert/second.xml", new FileHandle(new File("src/test/resources/alertSecond.xml"))); docMgr.write("/alert/third.xml", new FileHandle(new File("src/test/resources/alertThird.xml"))); }
@Test public void testWriteMultipleJSONDocsWithDefaultMetadata() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "/a.json", "/b.json", "/c.json" }; String json1 = new String("{\"animal\":\"dog\", \"says\":\"woof\"}"); String json2 = new String("{\"animal\":\"cat\", \"says\":\"meow\"}"); String json3 = new String("{\"animal\":\"rat\", \"says\":\"keek\"}"); Reader strReader = new StringReader(json1); JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); // put metadata DocumentMetadataHandle mh = setMetadata(); writeset.addDefault(mh); writeset.add(docId[0], new ReaderHandle(strReader).withFormat(Format.JSON)); writeset.add(docId[1], new ReaderHandle(new StringReader(json2))); writeset.add(docId[2], new ReaderHandle(new StringReader(json3))); docMgr.write(writeset); DocumentPage page = docMgr.read(docId); while (page.hasNext()) { DocumentRecord rec = page.next(); docMgr.readMetadata(rec.getUri(), mh); System.out.println(rec.getUri()); validateMetadata(mh); } validateMetadata(mh); }
@Test public void jsonQbe() { JSONDocumentManager jdm = Common.client.newJSONDocumentManager(); QueryManager qm = Common.client.newQueryManager(); String queryAsString = "{ \"$query\": { \"kind\": \"bird\" } }"; StringHandle handle = new StringHandle(); handle.withFormat(Format.JSON).set(queryAsString); RawQueryByExampleDefinition query = qm.newRawQueryByExampleDefinition(handle); StringHandle report = qm.validate(query, new StringHandle()); System.out.println(report.toString()); SearchHandle results = qm.search(query, new SearchHandle()); assertEquals("6 json results should have matched", results.getTotalResults(), 6); DocumentPage documents = jdm.search(query, 1); assertEquals("6 json documents should have matched", documents.getTotalSize(), 6); documents = jdm.search(query, 1, new JacksonHandle()); assertEquals("6 json documents should have matched", documents.getTotalSize(), 6); documents = jdm.search(query, 1, new SearchHandle()); assertEquals("6 json documents should have matched", documents.getTotalSize(), 6); }
@Test public void testBulkSearchSQDwithResponseFormatandStringHandle() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadJSONDocuments(); JSONDocumentManager docMgr = client.newJSONDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qd = qb.and(qb.term("dog1", "dog11")); queryMgr.search(qd, new SearchHandle()); docMgr.setNonDocumentFormat(Format.JSON); docMgr.setSearchView(QueryView.METADATA); docMgr.setMetadataCategories(Metadata.PERMISSIONS); StringHandle results = new StringHandle().withFormat(Format.JSON); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); while (page.hasNext()) { DocumentRecord rec = page.next(); validateRecord(rec, Format.JSON); docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertTrue("Record has collections ?", mh.getCollections().isEmpty()); } assertFalse("Search handle contains", results.get().isEmpty()); }