@Override public void delete(DocumentDescriptor desc, Transaction transaction) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { if (desc == null) throw new IllegalArgumentException("Deleting document with null identifier"); if (logger.isInfoEnabled()) logger.info("Deleting {}",desc.getUri()); services.deleteDocument(requestLogger, desc, (transaction == null) ? null : transaction.getTransactionId(), null); }
@Override public DocumentWriteSet add(DocumentDescriptor desc, AbstractWriteHandle contentHandle) { add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE, desc.getUri(), null, contentHandle)); return this; }
@Override public DocumentWriteSet add(DocumentDescriptor desc, DocumentMetadataWriteHandle metadataHandle, AbstractWriteHandle contentHandle, String temporalDocumentURI) { add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE, desc.getUri(), metadataHandle, contentHandle, temporalDocumentURI)); return this; } }
@Override public DocumentWriteSet add(DocumentDescriptor desc, DocumentMetadataWriteHandle metadataHandle, AbstractWriteHandle contentHandle) { add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE, desc.getUri(), metadataHandle, contentHandle)); return this; }
@Override public TemporalDescriptor delete(DocumentDescriptor desc, Transaction transaction, String temporalCollection, java.util.Calendar systemTime) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { if (desc == null) throw new IllegalArgumentException( "Deleting document with null identifier"); if (logger.isInfoEnabled()) logger.info("Deleting {}", desc.getUri()); RequestParameters extraParams = addTemporalParams(new RequestParameters(), temporalCollection, null, systemTime); return services.deleteDocument(requestLogger, desc, transaction, null, extraParams); }
@Override public DocumentWriteSet add(DocumentDescriptor desc, AbstractWriteHandle contentHandle, String temporalDocumentURI) { add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE, desc.getUri(), null, contentHandle, temporalDocumentURI)); return this; }
@Override public <T extends BinaryReadHandle> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadataHandle, T contentHandle, ServerTransform transform, long start, long length, Transaction transaction) { if (logger.isInfoEnabled()) logger.info("Reading range of binary content for {}",desc.getUri()); RequestParameters extraParams = new RequestParameters(); if (length > 0) extraParams.put("range", "bytes="+start+"-"+(start + length)); else extraParams.put("range", "bytes="+String.valueOf(start)); return read(desc, metadataHandle, contentHandle, transform, transaction, extraParams); }
@Override public <T extends BinaryReadHandle> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadataHandle, T contentHandle, ServerTransform transform, long start, long length, Transaction transaction) { if (logger.isInfoEnabled()) logger.info("Reading range of binary content for {}",desc.getUri()); RequestParameters extraParams = new RequestParameters(); if (length > 0) extraParams.put("range", "bytes="+start+"-"+(start + length - 1)); else extraParams.put("range", "bytes="+String.valueOf(start)); return read(desc, metadataHandle, contentHandle, transform, transaction, null, extraParams); }
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(); }
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(); }
private TemporalDescriptor updateTemporalSystemTime(DocumentDescriptor desc, Headers headers) { if (headers == null) return null; DocumentDescriptorImpl temporalDescriptor; if ( desc instanceof DocumentDescriptorImpl ) { temporalDescriptor = (DocumentDescriptorImpl) desc; } else { temporalDescriptor = new DocumentDescriptorImpl(desc.getUri(), false); } temporalDescriptor.setTemporalSystemTime(headers.get(HEADER_X_MARKLOGIC_SYSTEM_TIME)); return temporalDescriptor; }
@Test public void testXMLFormatOnJSON() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testXMLFormatOnJSON"); String filename = "json-original.json"; String uri = "/xml-format-json-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.XML); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testXMLFormatOnXML() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testXMLFormatOnXML"); String filename = "flipper.xml"; String uri = "/xml-format-xml-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager<GenericReadHandle, GenericWriteHandle> docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.XML); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testBinaryFormatOnXML() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testBinaryFormatOnXML"); String filename = "flipper.xml"; String uri = "/bin-format-xml-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.BINARY); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testJSONFormatOnJSON() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testJSONFormatOnJSON"); String filename = "json-original.json"; String uri = "/json-format-json-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.JSON); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testBinaryFormatOnText() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testBinaryFormatOnText"); String filename = "text-original.txt"; String uri = "/bin-format-txt-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.BINARY); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testTextFormatOnXML() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testTextFormatOnXML"); String filename = "flipper.xml"; String uri = "/txt-format-xml-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.TEXT); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testBinaryFormatOnJSON() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testBinaryFormatOnJSON"); String filename = "json-original.json"; String uri = "/bin-format-json-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.BINARY); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void testXMLFormatOnText() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testXMLFormatOnText"); String filename = "text-original.txt"; String uri = "/xml-format-txt-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.XML); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
@Test public void test_A_Delete() throws IOException { GenericDocumentManager docMgr = client.newDocumentManager(); DocumentDescriptor desc = docMgr.exists(docId); assertNotNull("Should find document before delete", desc); assertEquals(desc.getUri(), docId); QueryManager queryMgr = client.newQueryManager(); DeleteQueryDefinition qdef = queryMgr.newDeleteDefinition(); qdef.setDirectory(directory); queryMgr.delete(qdef); desc = docMgr.exists(docId); assertNull("Should not find document after delete", desc); }