Response put ( URI uri , Object object , boolean newEntity ) { assertNotEmpty ( object , "object" ) ; HttpResponse response = null ; try { final JsonObject json = getGson ( ) . toJsonTree ( object ) . getAsJsonObject ( ) ; String id = getAsString ( json , "_id" ) ; String rev = getAsString ( json , "_rev" ) ; if ( newEntity ) { // save assertNull ( rev , "rev" ) ; id = ( id == null ) ? generateUUID ( ) : id ; } else { // update assertNotEmpty ( id , "id" ) ; assertNotEmpty ( rev , "rev" ) ; } final HttpPut put = new HttpPut ( buildUri ( uri ) . pathEncoded ( id ) . build ( ) ) ; setEntity ( put , json . toString ( ) ) ; response = executeRequest ( put ) ; return getResponse ( response ) ; } finally { close ( response ) ; } }
Performs a HTTP PUT request saves or updates a document .