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 {