Package com.couchace.core.api

Examples of com.couchace.core.api.CouchException


                String id = document.getDocumentId();
                String revision = document.getDocumentRevision();
                WriteResponse deleteResponse = new DeleteRequest(this, DeleteRequest.Type.DOCUMENT, id, revision)
                        .execute();
                if (deleteResponse.isError()) {
                    throw new CouchException(deleteResponse.getStatusCode(), "Error deleting design document " + id);
                }
            }
            couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();

        } else if (request.getType() == DeleteRequest.Type.ALL_DESIGNS) {
            String path = "/_all_docs?startkey=%22_design/%22&endkey=%22_design0%22";
            GetDocumentResponse getResponse = new GetDocumentRequest(this, path, null).execute();
            for (TextDocument document : getResponse) {
                String id = document.getDocumentId();
                if (id.startsWith("_design")) {
                    String revision = document.getDocumentRevision();
                    WriteResponse deleteResponse = new DeleteRequest(this, DeleteRequest.Type.DOCUMENT, id, revision)
                            .execute();
                    if (deleteResponse.isError()) {
                        throw new CouchException(deleteResponse.getStatusCode(), "Error deleting design document " + id);
                    }
                }
            }
            couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();

        } else if (request.getType() == DeleteRequest.Type.ALL_NON_DESIGNS) {
            String path = "_all_docs";
            GetDocumentResponse getResponse = new GetDocumentRequest(this, path, null).execute();
            for (TextDocument document : getResponse) {
                String id = document.getDocumentId();
                if (id != null && !id.startsWith("_design")) {
                    String revision = document.getDocumentRevision();
                    WriteResponse deleteResponse = new DeleteRequest(this, DeleteRequest.Type.DOCUMENT, id, revision)
                            .execute();
                    if (deleteResponse.isError()) {
                        String msg = String.format("Error deleting document %s rev(%s) - %s", id, revision, deleteResponse.getErrorReason());
                        throw new CouchException(deleteResponse.getStatusCode(), msg);
                    }
                }
            }
            couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();
        } else {
View Full Code Here


                if (value != null) {
                    couchHttpResponse = writeAttachment(attachmentMeta, couchHttpResponse.getDocumentId(), couchHttpResponse.getDocumentRevision(), value);
                }
            } catch (CouchException e) {
                log.error(e);
                throw new CouchException(CouchStatusCode.INTERNAL_SERVER_ERROR, "Exception saving attachment: " + e.getMessage(), e);
            }
        }
        return couchHttpResponse;
    }
View Full Code Here

        if (couchHttpResponse.isError()) {
            CouchErrorContent errorContent = CouchErrorContent.parseJson(couchHttpResponse.getStringContent());
            String msg = String.format("Store of document successful but failed in storage of attachment with status: %s and error content: %s",
                    couchHttpResponse.getStatusCode().getReason(),
                    errorContent.toString());
            throw new CouchException(couchHttpResponse.getStatusCode(), msg);
        }

        return couchHttpResponse;

    }
View Full Code Here

            String id = document.getDocumentId();
            String revision = document.getDocumentRevision();
            WriteResponse deleteResponse = new DeleteDocumentRequest(this, DeleteDocumentRequest.Type.DOCUMENT, id, revision)
                    .execute();
            if (deleteResponse.isError()) {
                throw new CouchException(deleteResponse.getStatusCode(), "Error deleting design document " + id);
            }
        }
        couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();
        return new WriteResponse(couchHttpResponse);
    }
View Full Code Here

            if (id.startsWith("_design")) {
                String revision = document.getDocumentRevision();
                WriteResponse deleteResponse = new DeleteDocumentRequest(this, DeleteDocumentRequest.Type.DOCUMENT, id, revision)
                        .execute();
                if (deleteResponse.isError()) {
                    throw new CouchException(deleteResponse.getStatusCode(), "Error deleting design document " + id);
                }
            }
        }
        couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();
        return new WriteResponse(couchHttpResponse);
View Full Code Here

                String revision = document.getDocumentRevision();
                WriteResponse deleteResponse = new DeleteDocumentRequest(this, DeleteDocumentRequest.Type.DOCUMENT, id, revision)
                        .execute();
                if (deleteResponse.isError()) {
                    String msg = String.format("Error deleting document %s rev(%s) - %s", id, revision, deleteResponse.getErrorReason());
                    throw new CouchException(deleteResponse.getStatusCode(), msg);
                }
            }
        }
        couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();
        return new WriteResponse(couchHttpResponse);
View Full Code Here

                if (value != null) {
                    couchHttpResponse = writeAttachment(attachmentMeta, couchHttpResponse.getDocumentId(), couchHttpResponse.getDocumentRevision(), value);
                }
            } catch (CouchException e) {
                log.error(e);
                throw new CouchException(CouchStatusCode.INTERNAL_SERVER_ERROR, "Exception saving attachment: " + e.getMessage(), e);
            }
        }
        return couchHttpResponse;
    }
View Full Code Here

        if (couchHttpResponse.isError()) {
            CouchErrorContent errorContent = CouchErrorContent.parseJson(couchHttpResponse.getStringContent());
            String msg = String.format("Store of document successful but failed in storage of attachment with status: %s and error content: %s",
                    couchHttpResponse.getStatusCode().getReason(),
                    errorContent.toString());
            throw new CouchException(couchHttpResponse.getStatusCode(), msg);
        }

        return couchHttpResponse;

    }
View Full Code Here

            String id = document.getDocumentId();
            String revision = document.getDocumentRevision();
            WriteResponse deleteResponse = new DeleteDocumentRequest(this, DeleteDocumentRequest.Type.DOCUMENT, id, revision)
                    .execute();
            if (deleteResponse.isError()) {
                throw new CouchException(deleteResponse.getStatusCode(), "Error deleting design document " + id);
            }
        }
        couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();
        return new WriteResponse(couchHttpResponse);
    }
View Full Code Here

            if (id.startsWith("_design")) {
                String revision = document.getDocumentRevision();
                WriteResponse deleteResponse = new DeleteDocumentRequest(this, DeleteDocumentRequest.Type.DOCUMENT, id, revision)
                        .execute();
                if (deleteResponse.isError()) {
                    throw new CouchException(deleteResponse.getStatusCode(), "Error deleting design document " + id);
                }
            }
        }
        couchHttpResponse = CouchHttpResponse.builder(CouchMethodType.DELETE, httpClient.uri(path), CouchStatusCode.OK).build();
        return new WriteResponse(couchHttpResponse);
View Full Code Here

TOP

Related Classes of com.couchace.core.api.CouchException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.