public static void addPartitionKeyInformation(AbstractDocumentServiceRequest request, Document document, RequestOptions options, DocumentCollection collection){ DocumentClient.addPartitionKeyInformation(request, document, options, collection); }
private DocumentServiceRequest getAttachmentRequest(String documentLink, InputStream mediaStream, MediaOptions options, OperationType operationType) { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } if (mediaStream == null) { throw new IllegalArgumentException("mediaStream"); } String path = Utils.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT); Map<String, String> requestHeaders = this.getMediaHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(operationType, ResourceType.Attachment, path, mediaStream, requestHeaders); request.setIsMedia(true); this.addPartitionKeyInformation(request, null, null); return request; }
private DocumentServiceRequest getAttachmentRequest(String documentLink, Attachment attachment, RequestOptions options, OperationType operationType) { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } if (attachment == null) { throw new IllegalArgumentException("attachment"); } DocumentClient.validateResource(attachment); String path = Utils.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(operationType, ResourceType.Attachment, path, attachment, requestHeaders); this.addPartitionKeyInformation(request, null, options); return request; }
/** * Reads a document by the document link. * * @param documentLink the document link. * @param options the request options. * @return the resource response with the read document. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Document> readDocument(String documentLink, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } logger.debug("Reading a Document. documentLink: [{}]", documentLink); String path = Utils.joinPath(documentLink, null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Read, ResourceType.Document, path, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Document>(this.doRead(request), Document.class); }
/** * Deletes a conflict. * * @param conflictLink the conflict link. * @param options the request options. * @return the resource response. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Conflict> deleteConflict(String conflictLink, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(conflictLink)) { throw new IllegalArgumentException("conflictLink"); } logger.debug("Deleting a Conflicts. conflictLink [{}]", conflictLink); String path = Utils.joinPath(conflictLink, null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Delete, ResourceType.Conflict, path, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Conflict>(this.doDelete(request), Conflict.class); }
/** * Deletes a document by the document link. * * @param documentLink the document link. * @param options the request options. * @return the resource response. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Document> deleteDocument(String documentLink, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } logger.debug("Deleting a Document. documentLink: [{}]", documentLink); String path = Utils.joinPath(documentLink, null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Delete, ResourceType.Document, path, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Document>(this.doDelete(request), Document.class); }
/** * Reads a conflict. * * @param conflictLink the conflict link. * @param options the request options. * @return the resource response with the read conflict. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Conflict> readConflict(String conflictLink, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(conflictLink)) { throw new IllegalArgumentException("conflictLink"); } logger.debug("Reading a Conflict. conflictLink [{}]", conflictLink); String path = Utils.joinPath(conflictLink, null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Read, ResourceType.Conflict, path, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Conflict>(this.doRead(request), Conflict.class); }
/** * Deletes an attachment. * * @param attachmentLink the attachment link. * @param options the request options. * @return the resource response. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Attachment> deleteAttachment(String attachmentLink, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(attachmentLink)) { throw new IllegalArgumentException("attachmentLink"); } logger.debug("Deleting a Attachment. attachmentLink [{}]", attachmentLink); String path = Utils.joinPath(attachmentLink, null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Delete, ResourceType.Attachment, path, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Attachment>(this.doDelete(request), Attachment.class); }
/** * Reads an attachment. * * @param attachmentLink the attachment link. * @param options the request options. * @return the resource response with the read attachment. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Attachment> readAttachment(String attachmentLink, RequestOptions options) throws DocumentClientException { if (StringUtils.isEmpty(attachmentLink)) { throw new IllegalArgumentException("attachmentLink"); } logger.debug("Reading a Attachment. attachmentLink [{}]", attachmentLink); String path = Utils.joinPath(attachmentLink, null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Read, ResourceType.Attachment, path, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Attachment>(this.doRead(request), Attachment.class); }
private DocumentServiceRequest getCreateDocumentRequest(String documentCollectionLink, Object document, RequestOptions options, boolean disableAutomaticIdGeneration, OperationType operationType) { if (StringUtils.isEmpty(documentCollectionLink)) { throw new IllegalArgumentException("documentCollectionLink"); } if (document == null) { throw new IllegalArgumentException("document"); } Document typedDocument = Document.FromObject(document, objectMapper); DocumentClient.validateResource(typedDocument); if (typedDocument.getId() == null && !disableAutomaticIdGeneration) { // We are supposed to use GUID. Basically UUID is the same as GUID // when represented as a string. typedDocument.setId(Utils.getSecureRandomUUID().toString()); } String path = Utils.joinPath(documentCollectionLink, Paths.DOCUMENTS_PATH_SEGMENT); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(operationType, ResourceType.Document, path, typedDocument, requestHeaders); this.addPartitionKeyInformation(request, typedDocument, options); return request; }
/** * Replaces an attachment. * * @param attachment the attachment to use. * @param options the request options. * @return the resource response with the replaced attachment. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Attachment> replaceAttachment(Attachment attachment, RequestOptions options) throws DocumentClientException { if (attachment == null) { throw new IllegalArgumentException("attachment"); } logger.debug("Replacing a Attachment. attachment id [{}]", attachment.getId()); DocumentClient.validateResource(attachment); String path = Utils.joinPath(attachment.getSelfLink(), null); Map<String, String> requestHeaders = getRequestHeaders(options); DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Replace, ResourceType.Attachment, path, attachment, requestHeaders); this.addPartitionKeyInformation(request, null, options); return new ResourceResponse<Attachment>(this.doReplace(request), Attachment.class); }
private ResourceResponse<Document> replaceDocumentInternal(String documentLink, Document document, RequestOptions options) throws DocumentClientException { if (document == null) { throw new IllegalArgumentException("document"); } logger.debug("Replacing a Document. documentLink: [{}]", documentLink); final String documentCollectionName = Utils.getCollectionName(documentLink); final String documentCollectionLink = this.getTargetDocumentCollectionLink(documentCollectionName, document); final String path = Utils.joinPath(documentLink, null); final Map<String, String> requestHeaders = getRequestHeaders(options); final DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Replace, ResourceType.Document, path, document, requestHeaders); this.addPartitionKeyInformation(request, document, options); final boolean shouldRetry = options == null || options.getPartitionKey() == null; DocumentClient.validateResource(document); RetryCreateDocumentDelegate replaceDelegate = new RetryCreateDocumentDelegate() { @Override public ResourceResponse<Document> apply() throws DocumentClientException { return new ResourceResponse<Document>(doReplace(request), Document.class); } }; return shouldRetry ? RetryUtility.executeCreateDocument(replaceDelegate, this.collectionCache, documentCollectionLink) : replaceDelegate.apply(); }
request.setPartitionKeyRangeIdentity(partitionKeyRangeId); } else { this.addPartitionKeyInformation(request, null, options);