@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); }
private Request.Builder addVersionHeader(DocumentDescriptor desc, Request.Builder requestBldr, String name) { if ( desc != null && desc instanceof DocumentDescriptorImpl && !((DocumentDescriptorImpl) desc).isInternal()) { long version = desc.getVersion(); if (version != DocumentDescriptor.UNKNOWN_VERSION) { return requestBldr.header(name, "\"" + String.valueOf(version) + "\""); } } return requestBldr; }
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; if (desc.getFormat() != null) handleBase.setFormat(desc.getFormat()); if (desc.getMimetype() != null) handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException if (desc.getUri() == null) { throw new IllegalArgumentException( "Document write for document identifier without uri"); Format descFormat = desc.getFormat(); String contentMimetype = (descFormat != null && descFormat != Format.UNKNOWN) ? desc.getMimetype() : null; if (contentMimetype == null && contentBase != null) { Format contentFormat = contentBase.getFormat();
desc.setFormat(Format.XML); desc.setVersion(badVersion); desc.setVersion(DocumentDescriptor.UNKNOWN_VERSION); docMgr.write(desc, contentHandle); long goodVersion = desc.getVersion(); assertTrue("Failed to read version", goodVersion != DocumentDescriptor.UNKNOWN_VERSION); assertXMLEqual("Failed to read document content",result,GenericDocumentTest.content); desc.setVersion(badVersion); assertTrue("Read with bad version did not get content", docMgr.read(desc, new StringHandle()).get() != null); desc.setVersion(goodVersion); assertTrue("Read with good version did not skip content", docMgr.read(desc, new StringHandle()) == null); String documentUri = desc.getUri(); try { docMgr.write(documentUri, contentHandle); statusCode = 0; try { desc.setVersion(badVersion); docMgr.write(desc, contentHandle); } catch (FailedRequestException e) { desc.setVersion(goodVersion);
throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException String uri = desc.getUri(); "document create produced location without uri: " + location); desc.setUri(uri); updateVersion(desc, responseHeaders); updateDescriptor(desc, responseHeaders);
private void updateVersion(DocumentDescriptor descriptor, Headers headers) { long version = DocumentDescriptor.UNKNOWN_VERSION; String value = headers.get(HEADER_ETAG); if (value != null && value.length() > 0) { // trim the double quotes version = Long.parseLong(value.substring(1, value.length() - 1)); } descriptor.setVersion(version); }
@Test public void testReadWrite() throws IOException, XpathException { String docId = "/test/binary-sample.png"; String mimetype = "image/png"; BinaryDocumentManager docMgr = Common.client.newBinaryDocumentManager(); docMgr.setMetadataExtraction(MetadataExtraction.PROPERTIES); docMgr.write(docId, new BytesHandle().with(BYTES_BINARY).withMimetype(mimetype)); DocumentDescriptor desc = docMgr.exists(docId); assertTrue("Binary exists did not get number of bytes", desc.getByteLength() != DocumentDescriptor.UNKNOWN_LENGTH); assertEquals("Binary exists got wrong number of bytes", BYTES_BINARY.length, desc.getByteLength()); byte[] buf = docMgr.read(docId, new BytesHandle()).get(); assertEquals("Binary document read wrong number of bytes", BYTES_BINARY.length, buf.length); buf = Common.streamToBytes(docMgr.read(docId, new InputStreamHandle()).get()); assertTrue("Binary document read binary empty input stream",buf.length > 0); BytesHandle handle = new BytesHandle(); buf = docMgr.read(docId, handle, 9, 10).get(); assertEquals("Binary range read wrong number of bytes", 10, buf.length); assertEquals("Binary range did not set length in handle", 10, handle.getByteLength()); docMgr.setMetadataCategories(Metadata.PROPERTIES); Document metadataDocument = docMgr.readMetadata(docId, new DOMHandle()).get(); assertXpathEvaluatesTo("image/png","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='content-type'])", metadataDocument); assertXpathEvaluatesTo("text HD-HTML","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument); assertXpathEvaluatesTo("815","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='size'])", metadataDocument); }
throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { String uri = desc.getUri(); throw new MarkLogicInternalException( "document create produced location without uri: " + location); desc.setUri(uri); updateVersion(desc, responseHeaders); updateDescriptor(desc, responseHeaders);
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { if (desc.getUri() == null) throw new IllegalArgumentException( "Document write for document identifier without uri"); Format descFormat = desc.getFormat(); String contentMimetype = (descFormat != null && descFormat != Format.UNKNOWN) ? desc .getMimetype() : null; if (contentMimetype == null && contentBase != null) { Format contentFormat = contentBase.getFormat();
private void updateVersion(DocumentDescriptor descriptor, MultivaluedMap<String, String> headers) { long version = DocumentDescriptor.UNKNOWN_VERSION; if (headers.containsKey("ETag")) { List<String> values = headers.get("ETag"); if (values != null) { // trim the double quotes String value = values.get(0); version = Long.valueOf(value.substring(1, value.length() - 1)); } } descriptor.setVersion(version); }
@Override public DocumentWriteSet add(DocumentDescriptor desc, AbstractWriteHandle contentHandle) { add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE, desc.getUri(), null, contentHandle)); return this; }
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; handleBase.setFormat(desc.getFormat()); handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
private WebResource.Builder addVersionHeader(DocumentDescriptor desc, WebResource.Builder builder, String name) { if (desc != null && desc instanceof DocumentDescriptorImpl && !((DocumentDescriptorImpl) desc).isInternal()) { long version = desc.getVersion(); if (version != DocumentDescriptor.UNKNOWN_VERSION) { return builder.header(name, "\"" + String.valueOf(version) + "\""); } } return builder; }
@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; } }
throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { String uri = desc.getUri(); throw new MarkLogicInternalException( "document create produced location without uri: " + location); desc.setUri(uri); updateVersion(desc, responseHeaders); updateDescriptor(desc, responseHeaders);
logger.info("insert:" + uri + "," + desc.getVersion());
@Override public DocumentWriteSet add(DocumentDescriptor desc, DocumentMetadataWriteHandle metadataHandle, AbstractWriteHandle contentHandle) { add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE, desc.getUri(), metadataHandle, contentHandle)); return this; }
@Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(incrementer.nextLongValue()); XMLDocumentManager xmlDocMgr = databaseClient.newXMLDocumentManager(); String uri = SPRING_BATCH_DIR + jobExecution.getJobInstance().getId().toString() + ".xml"; DocumentDescriptor desc = xmlDocMgr.exists(uri); JAXBHandle<MarkLogicJobInstance> handle = new JAXBHandle<>(jaxbContext()); xmlDocMgr.read(uri, handle); MarkLogicJobInstance mji = handle.get(); mji.addJobExecution(jobExecution); //Set document metadata DocumentMetadataHandle jobInstanceMetadata = new DocumentMetadataHandle(); jobInstanceMetadata.getCollections().add(COLLECTION_JOB_INSTANCE); xmlDocMgr.write(desc, jobInstanceMetadata, handle); logger.info("insert JobExecution:" + uri + "," + desc.getVersion()); }