use of com.marklogic.client.document.DocumentUriTemplate in project components by Talend.
the class MarkLogicWriter method generateDocId.
private String generateDocId(AbstractWriteHandle genericHandle) {
DocumentUriTemplate template = docMgr.newDocumentUriTemplate(docIdSuffix);
if (StringUtils.isNotEmpty(properties.docIdPrefix.getStringValue()) && !"\"\"".equals(properties.docIdPrefix.getStringValue())) {
String realPrefix = properties.docIdPrefix.getStringValue();
if (!(realPrefix.endsWith("/") || realPrefix.endsWith("\\"))) {
realPrefix = realPrefix + "/";
}
template.setDirectory(realPrefix.replaceAll("\\\\", "/"));
}
DocumentDescriptor docDesc = docMgr.create(template, genericHandle);
return docDesc.getUri();
}
use of com.marklogic.client.document.DocumentUriTemplate in project components by Talend.
the class MarkLogicWriterTest method testUpsertWithAutoGenerateDocId.
@Test
public void testUpsertWithAutoGenerateDocId() throws IOException {
MarkLogicSink sink = new MarkLogicSink();
MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
properties.init();
properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
properties.docType.setValue(MarkLogicOutputProperties.DocType.BINARY);
properties.action.setValue(MarkLogicOutputProperties.Action.UPSERT);
properties.autoGenerateDocId.setValue(true);
properties.docIdPrefix.setValue("somePrefix");
sink.ioProperties = properties;
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient mockedClient = mock(DatabaseClient.class);
Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
DocumentManager markLogicDocMngrMock = mock(DocumentManager.class);
DocumentUriTemplate uriTemplateMock = mock(DocumentUriTemplate.class);
DocumentDescriptor descriptorMock = mock(DocumentDescriptor.class);
when(markLogicDocMngrMock.newDocumentUriTemplate(anyString())).thenReturn(uriTemplateMock);
when(markLogicDocMngrMock.create(any(DocumentUriTemplate.class), any(AbstractWriteHandle.class))).thenReturn(descriptorMock);
when(descriptorMock.getUri()).thenReturn("somePrefix/docId");
MarkLogicWriter writer = sink.createWriteOperation().createWriter(mockedContainer);
GenericData.Record indexedRecord = new GenericData.Record(properties.datasetProperties.main.schema.getValue());
indexedRecord.put(0, "docId");
File docContent = new File("someFile");
indexedRecord.put(1, docContent);
writer.open("123");
writer.docMgr = markLogicDocMngrMock;
writer.write(indexedRecord);
verify(markLogicDocMngrMock).write(eq("somePrefix/docId"), any(FileHandle.class));
assertFalse(((Collection<IndexedRecord>) writer.getSuccessfulWrites()).isEmpty());
}
Aggregations