src/main/java/de/blau/android/tasks/OsmoseServer.java
/**
     * Change the state of the bug on the server
     * 
     * @param context the Android context
     * @param bug bug with the state the server side bug should be changed to
     * @return true if successful
     */
Change the state of the bug on the server

@param context the Android context
@param bug bug with the state the server side bug should be changed to
@return true if successful
Change the state of the bug on the server @param context the Android context @param bug bug with the state the server side bug should be changed to @return true if successful
@NonNull
    public static UploadResult changeState(@NonNull Context context, OsmoseBug bug) {
        if (bug.getState() == State.OPEN) {
            return new UploadResult(ErrorCodes.BAD_REQUEST);
        }
        try {
            URL url = new URL(getServerURL(context) + "error/" + bug.getId() + "/" + (bug.getState() == State.CLOSED ? "done" : "false"));
            Log.d(DEBUG_TAG, "changeState " + url.toString());
            Request request = new Request.Builder().url(url).build();
            OkHttpClient client = App.getHttpClient().newBuilder().connectTimeout(TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
                    .build();
            Call osmoseCall = client.newCall(request);
            Response osmoseCallResponse = osmoseCall.execute();
            if (!osmoseCallResponse.isSuccessful()) {
                int responseCode = osmoseCallResponse.code();
                Log.d(DEBUG_TAG, "changeState respnse code " + responseCode);
                if (responseCode == HttpURLConnection.HTTP_GONE) {
                    bug.setChanged(false); 
                    App.getTaskStorage().setDirty();
                }
                UploadResult result = new UploadResult(ErrorCodes.UPLOAD_PROBLEM);
                String message = Server.readStream(osmoseCallResponse.body().byteStream());
                result.setHttpError(responseCode);
                result.setMessage(message);
                return result;
            }
            bug.setChanged(false);
            App.getTaskStorage().setDirty();
        } catch (IOException e) {
            Log.e(DEBUG_TAG, "changeState got exception " + e.getMessage());
            UploadResult result = new UploadResult(ErrorCodes.UPLOAD_PROBLEM);
            result.setMessage(e.getMessage());
            return result;
        }
        Log.d(DEBUG_TAG, "changeState success");
        return new UploadResult(ErrorCodes.OK);
    }
@ NonNull public static UploadResult changeState ( @ NonNull Context context , OsmoseBug bug ) { if ( bug . getState ( ) == State . OPEN ) { return new UploadResult ( ErrorCodes . BAD_REQUEST ) ; } try { URL url = new URL ( getServerURL ( context ) + "error/" + bug . getId ( ) + "/" + ( bug . getState ( ) == State . CLOSED ? "done" : "false" ) ) ; Log . d ( DEBUG_TAG , "changeState " + url . toString ( ) ) ; Request request = new Request . Builder ( ) . url ( url ) . build ( ) ; OkHttpClient client = App . getHttpClient ( ) . newBuilder ( ) . connectTimeout ( TIMEOUT , TimeUnit . MILLISECONDS ) . readTimeout ( TIMEOUT , TimeUnit . MILLISECONDS ) . build ( ) ; Call osmoseCall = client . newCall ( request ) ; Response osmoseCallResponse = osmoseCall . execute ( ) ; if ( ! osmoseCallResponse . isSuccessful ( ) ) { int responseCode = osmoseCallResponse . code ( ) ; Log . d ( DEBUG_TAG , "changeState respnse code " + responseCode ) ; if ( responseCode == HttpURLConnection . HTTP_GONE ) { bug . setChanged ( false ) ; App . getTaskStorage ( ) . setDirty ( ) ; } UploadResult result = new UploadResult ( ErrorCodes . UPLOAD_PROBLEM ) ; String message = Server . readStream ( osmoseCallResponse . body ( ) . byteStream ( ) ) ; result . setHttpError ( responseCode ) ; result . setMessage ( message ) ; return result ; } bug . setChanged ( false ) ; App . getTaskStorage ( ) . setDirty ( ) ; } catch ( IOException e ) { Log . e ( DEBUG_TAG , "changeState got exception " + e . getMessage ( ) ) ; UploadResult result = new UploadResult ( ErrorCodes . UPLOAD_PROBLEM ) ; result . setMessage ( e . getMessage ( ) ) ; return result ; } Log . d ( DEBUG_TAG , "changeState success" ) ; return new UploadResult ( ErrorCodes . OK ) ; }
Change the state of the bug on the server
Change the state of the bug on the server
// http://osmose.openstreetmap.fr/de/api/0.2/error/3313305479/done // http://osmose.openstreetmap.fr/de/api/0.2/error/3313313045/false // open is the default state and we shouldn't actually get here // don't retry