Search in sources :

Example 1 with DocContentReader

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);
}
Also used : DocContentReader(org.talend.components.marklogic.runtime.input.strategies.DocContentReader) Test(org.junit.Test)

Example 2 with DocContentReader

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);
}
Also used : DocContentReader(org.talend.components.marklogic.runtime.input.strategies.DocContentReader) Schema(org.apache.avro.Schema)

Example 3 with DocContentReader

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);
}
Also used : MarkLogicConnection(org.talend.components.marklogic.connection.MarkLogicConnection) SearchHandle(com.marklogic.client.io.SearchHandle) DocContentReader(org.talend.components.marklogic.runtime.input.strategies.DocContentReader)

Example 4 with DocContentReader

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);
}
Also used : DocContentReader(org.talend.components.marklogic.runtime.input.strategies.DocContentReader) ArrayList(java.util.ArrayList) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericData(org.apache.avro.generic.GenericData) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) Test(org.junit.Test)

Aggregations

DocContentReader (org.talend.components.marklogic.runtime.input.strategies.DocContentReader)4 Test (org.junit.Test)2 SearchHandle (com.marklogic.client.io.SearchHandle)1 ArrayList (java.util.ArrayList)1 Schema (org.apache.avro.Schema)1 GenericData (org.apache.avro.generic.GenericData)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 MarkLogicConnection (org.talend.components.marklogic.connection.MarkLogicConnection)1 MarkLogicInputProperties (org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties)1