@Override protected void processProperties(DocumentFile documentFile, Properties properties) { String name = documentFile.getFile().getName(); if (properties.containsKey(name)) { String value = properties.getProperty(name); documentFile.getDocumentMetadata().withCollections(value.split(",")); } } }
@Override public DocumentMetadataWriteHandle getMetadata() { DocumentMetadataHandle h = new DocumentMetadataHandle(); if (collections != null) { h.withCollections(collections); } if (permissions != null) { for (String role : permissions.keySet()) { h.withPermission(role, permissions.get(role)); } } return h; }
@Override public DocumentFile processDocumentFile(DocumentFile documentFile) { if (collections != null && documentFile.getDocumentMetadata() != null) { documentFile.getDocumentMetadata().withCollections(collections); } return documentFile; } }
@Override public DocumentFile processDocumentFile(DocumentFile documentFile) { String uri = documentFile.getUri(); String extension = documentFile.getFileExtension(); if (("tdej".equals(extension) || "tdex".equals(extension)) || (uri != null && uri.startsWith("/tde"))) { documentFile.getDocumentMetadata().withCollections("http://marklogic.com/xdmp/tde"); } if ("tdej".equals(extension)) { documentFile.setFormat(Format.JSON); } else if ("tdex".equals(extension)) { documentFile.setFormat(Format.XML); } return documentFile; } }
protected DocumentMetadataHandle buildMetadata() { DocumentMetadataHandle h = new DocumentMetadataHandle(); h = h.withCollections(collections); if (permissions != null) { String[] array = permissions.split(","); for (int i = 0; i < array.length; i += 2) { h.getPermissions().add(array[i], Capability.valueOf(array[i + 1].toUpperCase())); } } return h; }
@Override public void write(T entity, Transaction transaction, String... collections) { if ( entity == null ) return; JacksonDatabindHandle<T> contentHandle = new JacksonDatabindHandle<>(entity); contentHandle.setMapper(objectMapper); DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle(); metadataHandle = metadataHandle.withCollections(entityClass.getName()); if ( collections != null && collections.length > 0 ) { metadataHandle = metadataHandle.withCollections(collections); } DocumentWriteSet writeSet = docMgr.newWriteSet(); writeSet.add(getDocumentUri(entity), metadataHandle, contentHandle); try { docMgr.write(writeSet, transaction); } catch(MarkLogicIOException e) { checkForEmptyBeans(e); throw e; } }
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)); } }
@Override public void saveJob(Job job, Transaction transaction) { JacksonDatabindHandle<Job> contentHandle = new JacksonDatabindHandle<>(job); contentHandle.setMapper(objectMapper); DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle(); metadataHandle = metadataHandle.withCollections("job"); DocumentWriteSet writeSet = docMgr.newWriteSet(); writeSet.add("/jobs/" + job.getJobId() + ".json", metadataHandle, contentHandle); docMgr.write(writeSet, transaction); }
public static void setup() throws Exception { StringBuffer failures = new StringBuffer(); WriteBatcher writeBatcher = moveMgr.newWriteBatcher() .withBatchSize(10) .onBatchFailure((event, throwable) -> { throwable.printStackTrace(); failures.append("ERORR:[" + throwable.toString() + "]"); }); moveMgr.startJob(writeBatcher); // a collection so we're only looking at docs related to this test run DocumentMetadataHandle meta = new DocumentMetadataHandle().withCollections(collection); for ( int i=1; i <= numDocs; i++ ) { writeBatcher.addAs(collection + "/doc_" + i + ".txt", meta, "test contents"); } writeBatcher.flushAsync(); writeBatcher.awaitCompletion(); if ( failures.length() > 0 ) fail(failures.toString()); logger.info("Successfully wrote {} docs to collection {}", numDocs, collection); }
@Test public void testCloseHandles() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(whbTestCollection); final AtomicInteger failCount = new AtomicInteger(0); WriteBatcher batcher = moveMgr.newWriteBatcher() .onBatchFailure( (batch, throwable) -> { logger.error("Error in testCloseHandles", throwable); failCount.incrementAndGet(); } ); JobTicket ticket = moveMgr.startJob(batcher); AtomicBoolean closed = new AtomicBoolean(false); FileInputStream fileStream = new FileInputStream("src/test/resources/test.xml") { public void close() throws IOException { super.close(); closed.set(true); } }; batcher.add("test.xml", meta, new InputStreamHandle(fileStream)); // when we call flushAndWait, the WriteBatcher should write the batch the close all the handles batcher.flushAndWait(); assertEquals(true, closed.get()); moveMgr.stopJob(ticket); assertEquals(0, failCount.get()); }
.withCollections(collection, whbTestCollection); ihb1.add("/doc/jackson", meta, new JacksonHandle(new ObjectMapper().readTree("{\"test\":true}"))); .withCollections(collection, whbTestCollection); ihb1.add("/doc/string", meta, new StringHandle("test"));
@Test public void testOnSkipped() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle().withCollections(collection); client.newDocumentManager().writeAs(collection + "/test1.txt", meta, "test"); client.newDocumentManager().writeAs(collection + "/test2.txt", meta, "test");
public DocumentMetadataHandle setUpdatedMetadataCollections() { // create and initialize a handle on the metadata DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle().withCollections("my-collection3", "my-collection4"); // metadataHandle.getCollections().addAll("my-collection1","my-collection2"); metadataHandle.getPermissions().add("app-user", Capability.UPDATE, Capability.READ); metadataHandle.getProperties().put("reviewed", true); metadataHandle.getProperties().put("myString", "foo"); metadataHandle.getProperties().put("myInteger", 10); metadataHandle.getProperties().put("myDecimal", 34.56678); metadataHandle.getProperties().put("myCalendar", Calendar.getInstance().get(Calendar.YEAR)); metadataHandle.setQuality(23); return metadataHandle; }
.withCollections(collection, whbTestCollection);
@Test public void testResultIgnore() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle().withCollections(collection); // write the document client.newDocumentManager().writeAs(collection + "/test2.json", meta, "{ \"testProperty\": \"test2\" }"); StructuredQueryDefinition query = sqb.value(sqb.jsonProperty("testProperty"), "test2"); ServerTransform transform = new ServerTransform(transformName2) .addParameter("newValue", "test2a"); ApplyTransformListener listener = new ApplyTransformListener() .withTransform(transform) .withApplyResult(ApplyResult.IGNORE); QueryBatcher batcher = moveMgr.newQueryBatcher(query) .onUrisReady(listener); JobTicket ticket = moveMgr.startJob( batcher ); batcher.awaitCompletion(); moveMgr.stopJob(ticket); JsonNode docContents = docMgr.readAs(collection + "/test2.json", JsonNode.class); assertEquals( "the transform should have changed testProperty to 'test2a'", "test2a", docContents.get("testProperty").textValue() ); }
@Test public void testResultReplace() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle().withCollections(collection); // write the document client.newDocumentManager().writeAs(collection + "/test1.json", meta, "{ \"testProperty\": \"test1\" }"); StructuredQueryDefinition query = sqb.value(sqb.jsonProperty("testProperty"), "test1"); ServerTransform transform = new ServerTransform(transformName1) .addParameter("newValue", "test1a"); ApplyTransformListener listener = new ApplyTransformListener() .withTransform(transform) .withApplyResult(ApplyResult.REPLACE); QueryBatcher batcher = moveMgr.newQueryBatcher(query) .onUrisReady(listener); JobTicket ticket = moveMgr.startJob( batcher ); batcher.awaitCompletion(); moveMgr.stopJob(ticket); JsonNode docContents = docMgr.readAs(collection + "/test1.json", JsonNode.class); assertEquals( "the transform should have changed testProperty to 'test1a'", "test1a", docContents.get("testProperty").textValue() ); }
public static void setup() throws Exception { assertEquals( "Since the doc doesn't exist, documentManager.exists() should return null", null, client.newDocumentManager().exists(collection + "/doc_1.json") ); WriteBatcher writeBatcher = moveMgr.newWriteBatcher() .withBatchSize(100); moveMgr.startJob(writeBatcher); // a collection so we're only looking at docs related to this test DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(collection, qhbTestCollection); for ( int i=1; i <= numDocs; i++ ) { writeBatcher.addAs(collection + "/doc_" + i + ".json", meta, new StringHandle("{name:\"John Doe\",dept:\"HR\"}").withFormat(JSON)); } writeBatcher.flushAsync(); writeBatcher.awaitCompletion(); }
DocumentMetadataHandle meta = new DocumentMetadataHandle().withCollections("xml", "products"); Common.client.newXMLDocumentManager().writeAs("test.xml", meta, xml); QueryManager queryMgr = Common.client.newQueryManager();
.withCollections(collection); WriteBatcher writeBatcher = moveMgr.newWriteBatcher(); moveMgr.startJob(writeBatcher);
public static void setup() throws Exception { WriteBatcher writeBatcher = moveMgr.newWriteBatcher(); moveMgr.startJob(writeBatcher); // a collection so we're only looking at docs related to this test DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(collection, qhbTestCollection); // all the docs are one-word text docs writeBatcher.addAs(uri1, meta, new StringHandle("{name:\"John Doe\", department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri2, meta, new StringHandle("{name:\"Jane Doe\", department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri3, meta, new StringHandle("{name:\"John Smith\", department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri4, meta, new StringHandle("{name:\"John Lennon\",department:\"HR\"}").withFormat(JSON)); writeBatcher.addAs(uri5, meta, new StringHandle("{name:\"John Man\", department:\"Engineering\"}").withFormat(JSON)); writeBatcher.flushAsync(); writeBatcher.awaitCompletion(); moveMgr.stopJob(writeBatcher); StringHandle options = new StringHandle( "<options xmlns='http://marklogic.com/appservices/search'>" + "<constraint name='dept'>" + "<value>" + "<json-property>department</json-property>" + "</value>" + "</constraint>" + "</options>") .withFormat(XML); QueryOptionsManager queryOptionsMgr = Common.connectAdmin().newServerConfigManager().newQueryOptionsManager(); queryOptionsMgr.writeOptions("employees", options); }