MarkLogicItemWriter implements ItemWriter<DocumentWriteOperation>, ItemStream { @Override public void write(List<? extends DocumentWriteOperation> items) throws Exception { if (isDataMovementSdk) { for (DocumentWriteOperation item : items) { batcher.add(uriTransformer.transform(item.getUri()), item.getMetadata(), item.getContent()); } } else { List<DocumentWriteOperation> newItems = new ArrayList<>(); for (DocumentWriteOperation op : items) { String newUri = uriTransformer.transform(op.getUri()); newItems.add( new DocumentWriteOperationImpl( DocumentWriteOperation.OperationType.DOCUMENT_WRITE, newUri, op.getMetadata(), op.getContent())); } batchWriter.write(newItems); } } MarkLogicItemWriter(DatabaseClient client);  MarkLogicItemWriter(DatabaseClient databaseClient, Format format);  MarkLogicItemWriter(DatabaseClient client, ServerTransform serverTransform);  MarkLogicItemWriter(DatabaseClient client, ServerTransform serverTransform, Format format); @Override void write(List<? extends DocumentWriteOperation> items); @Override void open(ExecutionContext executionContext); @Override void update(ExecutionContext executionContext); @Override void close(); void setServerTransform(ServerTransform serverTransform); void setUriTransformer(UriTransformer uriTransformer); void setContentFormat(Format format); int getBatchSize(); void setBatchSize(int batchSize); int getThreadCount(); void setThreadCount(int threadCount); boolean isWriteAsync(); void setWriteAsync(boolean writeAsync); void setWriteFailureListener(WriteFailureListener listener); void setWriteBatchListener(WriteBatchListener listener);  }
@Test public void writeDocumentWithTransformNoParametersTest() { DocumentWriteOperation writeOp = new DocumentWriteOperationImpl(DocumentWriteOperation.OperationType.DOCUMENT_WRITE, "hello.xml", new DocumentMetadataHandle(), new StringHandle(xml)); List<DocumentWriteOperation> writeOps = new ArrayList<DocumentWriteOperation>(); writeOps.add(writeOp); try { itemWriter = new MarkLogicItemWriter(client, new ServerTransform(transformName)); write(writeOps); } catch (Exception e) { e.printStackTrace(); } StringHandle handle = docMgr.read("hello.xml", new StringHandle()); Fragment frag = new Fragment(handle.toString()); frag.assertElementExists(" frag.assertElementExists(" }
@Test public void writeDocumentWithTransformWithParametersTest() { DocumentWriteOperation writeOp = new DocumentWriteOperationImpl(DocumentWriteOperation.OperationType.DOCUMENT_WRITE, "hello.xml", new DocumentMetadataHandle(), new StringHandle(xml)); List<DocumentWriteOperation> writeOps = new ArrayList<DocumentWriteOperation>(); writeOps.add(writeOp); try { ServerTransform serverTransform = new ServerTransform(transformName); serverTransform.addParameter("monster", "grover"); serverTransform.addParameter("trash-can", "oscar"); itemWriter = new MarkLogicItemWriter(client, serverTransform, Format.XML); write(writeOps); } catch (Exception e) { e.printStackTrace(); } StringHandle handle = docMgr.read("hello.xml", new StringHandle()); Fragment frag = new Fragment(handle.toString()); frag.assertElementExists(" frag.assertElementExists(" frag.assertElementExists(" }
@Test public void conflictingUpdateTest() throws Exception { List<DocumentWriteOperation> handles = getDocuments(); DocumentWriteOperation handle = new DocumentWriteOperationImpl( DocumentWriteOperation.OperationType.DOCUMENT_WRITE, "abc.xml", new DocumentMetadataHandle().withCollections("raw"), new StringHandle("<hello />")); handles.add(handle); itemWriter = new MarkLogicItemWriter(client); write(handles); clientTestHelper.assertCollectionSize("Expecting zero items in raw collection", "raw", 0); }
@Test(expected = NullPointerException.class) public void writeWithNullDataTest() throws Exception { itemWriter = new MarkLogicItemWriter(client); write(null); }