Search in sources :

Example 6 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicWriter method patchRecord.

private void patchRecord(String docId, String docContent) {
    StringHandle patchHandle = new StringHandle(docContent);
    if (MarkLogicOutputProperties.DocType.JSON == docType) {
        patchHandle.withFormat(Format.JSON);
    } else if (MarkLogicOutputProperties.DocType.XML == docType) {
        patchHandle.withFormat(Format.XML);
    } else {
        throw new MarkLogicException(new MarkLogicErrorCode("Cant patch for docType " + docType));
    }
    docMgr.patch(docId, patchHandle);
}
Also used : StringHandle(com.marklogic.client.io.StringHandle) MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode)

Example 7 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicRowProcessor method write.

@Override
public void write(Object indexedRecordDatum) throws IOException {
    if (indexedRecordDatum == null) {
        return;
    }
    cleanWrites();
    IndexedRecord indexedRecord = (IndexedRecord) indexedRecordDatum;
    Schema indexedRecordSchema = indexedRecord.getSchema();
    int docIdFieldIndex = indexedRecordSchema.getFields().indexOf(indexedRecordSchema.getField(inputProperties.docIdColumn.getStringValue()));
    if (docIdFieldIndex == -1) {
        throw new MarkLogicException(new MarkLogicErrorCode("Can't find docId column " + inputProperties.docIdColumn.getStringValue() + " in input row"));
    }
    String docId = (String) indexedRecord.get(docIdFieldIndex);
    GenericData.Record matchedDocument = docContentReader.readDocument(docId);
    totalCounter++;
    documents.add(matchedDocument);
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) GenericData(org.apache.avro.generic.GenericData)

Example 8 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicCriteriaReader method getCurrent.

@Override
public IndexedRecord getCurrent() throws NoSuchElementException {
    ++documentCounter;
    MatchDocumentSummary currentSummary = currentPage[pageCounter];
    current = new GenericData.Record(settings.outputSchema);
    try {
        String docId = currentSummary.getUri();
        current = docContentReader.readDocument(docId);
        result.totalCountLong++;
        result.successCountLong++;
        pageCounter++;
        return current;
    } catch (Exception e) {
        throw new MarkLogicException(new MarkLogicErrorCode("Can't read document from MarkLogic database"), e);
    }
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) MatchDocumentSummary(com.marklogic.client.query.MatchDocumentSummary) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) GenericData(org.apache.avro.generic.GenericData) NoSuchElementException(java.util.NoSuchElementException) MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) IOException(java.io.IOException)

Aggregations

MarkLogicException (org.talend.components.marklogic.exceptions.MarkLogicException)8 MarkLogicErrorCode (org.talend.components.marklogic.exceptions.MarkLogicErrorCode)7 IOException (java.io.IOException)3 Schema (org.apache.avro.Schema)2 GenericData (org.apache.avro.generic.GenericData)2 DatabaseClient (com.marklogic.client.DatabaseClient)1 DatabaseClientFactory (com.marklogic.client.DatabaseClientFactory)1 SecurityContext (com.marklogic.client.DatabaseClientFactory.SecurityContext)1 StringHandle (com.marklogic.client.io.StringHandle)1 MatchDocumentSummary (com.marklogic.client.query.MatchDocumentSummary)1 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 MarkLogicConnectionProperties (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1