<commit_before>package com.onegini.util;

import static com.onegini.OneginiCordovaPluginConstants.ERROR_PLUGIN_INTERNAL_ERROR;
import static org.apache.cordova.PluginResult.Status.ERROR;
import static org.apache.cordova.PluginResult.Status.OK;

import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;

import org.apache.cordova.PluginResult;
import org.json.JSONException;
import org.json.JSONObject;

import com.onegini.mobile.sdk.android.handlers.error.OneginiError;
import com.onegini.mobile.sdk.android.model.OneginiClientConfigModel;
import com.onegini.mobile.sdk.android.model.entity.OneginiMobileAuthenticationRequest;
import com.onegini.mobile.sdk.android.model.entity.UserProfile;
import com.onegini.mobileAuthentication.Callback;
import retrofit.client.Response;

public class PluginResultBuilder {

  private JSONObject payload;
  private PluginResult.Status status;
  private Boolean shouldKeepCallback = false;

  public PluginResultBuilder() {
    payload = new JSONObject();
  }

  public PluginResultBuilder withSuccess() {
    status = OK;
    return this;
  }

  public PluginResultBuilder withError() {
    status = ERROR;
    return this;
  }

  public PluginResultBuilder shouldKeepCallback() {
    this.shouldKeepCallback = true;

    return this;
  }

  public PluginResultBuilder withErrorDescription(final String description) {
    status = ERROR;

    try {
      payload.put("description", description);
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }

  public PluginResultBuilder withOneginiError(final OneginiError oneginiError) {
    this.status = ERROR;

    try {
      payload.put("code", oneginiError.getErrorType());
      payload.put("description", oneginiError.getErrorDescription());
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }

  public PluginResultBuilder withOneginiMobileAuthenticationRequest(final OneginiMobileAuthenticationRequest mobileAuthenticationRequest) {
    try {
      payload.put("type", mobileAuthenticationRequest.getType());
      payload.put("message", mobileAuthenticationRequest.getMessage());
      payload.put("profileId", mobileAuthenticationRequest.getUserProfile().getProfileId());
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }

  public PluginResultBuilder withMobileAuthenticationEvent(final String eventName) {
    try {
      payload.put("mobileAuthenticationEvent", eventName);
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }<commit_msg>CORDOPLUG-181: Keep plugin result payload clean.<commit_after>package com.onegini.util;

import static com.onegini.OneginiCordovaPluginConstants.ERROR_PLUGIN_INTERNAL_ERROR;
import static org.apache.cordova.PluginResult.Status.ERROR;
import static org.apache.cordova.PluginResult.Status.OK;

import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;

import org.apache.cordova.PluginResult;
import org.json.JSONException;
import org.json.JSONObject;

import com.onegini.mobile.sdk.android.handlers.error.OneginiError;
import com.onegini.mobile.sdk.android.model.OneginiClientConfigModel;
import com.onegini.mobile.sdk.android.model.entity.OneginiMobileAuthenticationRequest;
import com.onegini.mobile.sdk.android.model.entity.UserProfile;
import com.onegini.mobileAuthentication.Callback;
import retrofit.client.Response;

public class PluginResultBuilder {

  private JSONObject payload;
  private PluginResult.Status status;
  private Boolean shouldKeepCallback = false;

  public PluginResultBuilder() {
    payload = new JSONObject();
  }

  public PluginResultBuilder withSuccess() {
    status = OK;
    return this;
  }

  public PluginResultBuilder withError() {
    status = ERROR;
    return this;
  }

  public PluginResultBuilder shouldKeepCallback() {
    this.shouldKeepCallback = true;

    return this;
  }

  public PluginResultBuilder withErrorDescription(final String description) {
    status = ERROR;

    try {
      payload.put("description", description);
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }

  public PluginResultBuilder withOneginiError(final OneginiError oneginiError) {
    this.status = ERROR;

    if (oneginiError == null) {
      return this;
    }

    try {
      payload.put("code", oneginiError.getErrorType());
      payload.put("description", oneginiError.getErrorDescription());
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }

  public PluginResultBuilder withOneginiMobileAuthenticationRequest(final OneginiMobileAuthenticationRequest mobileAuthenticationRequest) {
    try {
      payload.put("type", mobileAuthenticationRequest.getType());
      payload.put("message", mobileAuthenticationRequest.getMessage());
      payload.put("profileId", mobileAuthenticationRequest.getUserProfile().getProfileId());
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }

  public PluginResultBuilder withMobileAuthenticationEvent(final String eventName) {
    try {
      payload.put("mobileAuthenticationEvent", eventName);
    } catch (JSONException e) {
      handleException(e);
    }

    return this;
  }
{'fraction_non_alphanumeric': 0.09392160575648552, 'fraction_numerical': 0.0005680742283658398, 'mean_word_length': 4.329969727547931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1564743', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1465, 'n_words': 290}