use of org.talend.components.marklogic.runtime.input.strategies.DocContentReader in project components by Talend.
the class MarkLogicRowProcessorTest method testWriteNull.
@Test
public void testWriteNull() throws IOException {
MarkLogicRowProcessor rowProcessor = new MarkLogicRowProcessor(null, null, null);
DocContentReader mockedDocContentReader = mock(DocContentReader.class);
rowProcessor.docContentReader = mockedDocContentReader;
rowProcessor.write(null);
verifyZeroInteractions(mockedDocContentReader);
}
use of org.talend.components.marklogic.runtime.input.strategies.DocContentReader in project components by Talend.
the class MarkLogicRowProcessor method open.
@Override
public void open(String uId) throws IOException {
this.uId = uId;
client = inputWriteOperation.getSink().connect(container);
Schema.Field docContentField = inputProperties.datasetProperties.main.schema.getValue().getFields().get(1);
docContentReader = new DocContentReader(client.newDocumentManager(), inputProperties.datasetProperties.main.schema.getValue(), docContentField);
}
use of org.talend.components.marklogic.runtime.input.strategies.DocContentReader in project components by Talend.
the class MarkLogicCriteriaReader method start.
@Override
public boolean start() throws IOException {
MarkLogicConnection connection = (MarkLogicConnection) getCurrentSource();
result = new ResultWithLongNB();
connectionClient = connection.connect(container);
if (connectionClient == null) {
return false;
}
docManager = connectionClient.newDocumentManager();
boolean isDocContentFieldPresent = (settings.outputSchema.getFields().size() >= 2);
if (isDocContentFieldPresent) {
docContentField = settings.outputSchema.getFields().get(1);
}
docContentReader = new DocContentReader(docManager, settings.outputSchema, docContentField);
if (settings.useQueryOption && StringUtils.isNotEmpty(settings.queryOptionName)) {
prepareQueryOption();
}
queryManager = connectionClient.newQueryManager();
stringQueryDefinition = (settings.useQueryOption) ? queryManager.newStringDefinition(settings.queryOptionName) : queryManager.newStringDefinition();
stringQueryDefinition.setCriteria(settings.criteria);
searchHandle = queryManager.search(stringQueryDefinition, new SearchHandle());
matchedDocuments = searchHandle.getTotalResults();
pageSize = (settings.pageSize <= 0) ? matchedDocuments : settings.pageSize;
// if < 0 - it will be ignored
maxRetrieve = settings.maxRetrieve;
queryManager.setPageLength(pageSize);
documentCounter = 1;
readNextPage();
return (matchedDocuments > 0);
}
use of org.talend.components.marklogic.runtime.input.strategies.DocContentReader in project components by Talend.
the class MarkLogicRowProcessorTest method testWriteCorrectRecord.
@Test
public void testWriteCorrectRecord() throws IOException {
MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
inputProperties.init();
inputProperties.docIdColumn.setValue(inputProperties.datasetProperties.main.schema.getValue().getFields().get(0).name());
MarkLogicInputSink inputSink = new MarkLogicInputSink();
MarkLogicInputWriteOperation inputWriteOperation = new MarkLogicInputWriteOperation(inputSink, inputProperties);
MarkLogicRowProcessor rowProcessor = inputWriteOperation.createWriter(null);
DocContentReader mockedDocContentReader = mock(DocContentReader.class);
rowProcessor.docContentReader = mockedDocContentReader;
GenericData.Record correctRecord = new GenericData.Record(inputProperties.datasetProperties.main.schema.getValue());
correctRecord.put(0, "docId");
rowProcessor.write(correctRecord);
verify(mockedDocContentReader).readDocument("docId");
assertTrue(((ArrayList<IndexedRecord>) rowProcessor.getSuccessfulWrites()).size() > 0);
}
Aggregations