/*
 * Copyright 2012-2013 Continuuity,Inc. All Rights Reserved.
 */

package com.continuuity.passport.http.handlers;

import com.google.gson.JsonObject;

/**
 *
 */
public class Utils {

  //TODO: Clean up lot of these helper functions
  public static String getJsonError(String error) {
    JsonObject object = new JsonObject();
    object.addProperty("error", error);
    return object.toString();
  }

  public static String getJsonError(String error, String reason) {
    JsonObject object = new JsonObject();
    object.addProperty("error", error);
    object.addProperty("reason", reason);
    return object.toString();
  }

  public static String getJson(String status, String message) {
    JsonObject object = new JsonObject();
    object.addProperty("status", status);
    object.addProperty("message", message);
    return object.toString();
  }

  public static String getAuthenticatedJson(String result) {
    JsonObject object = new JsonObject();
    object.add("error", null);
    object.addProperty("result", result);
    return object.toString();

  }

  public static String getAuthenticatedJson(String error, String result) {
    JsonObject object = new JsonObject();
    object.addProperty("error", error);
    object.addProperty("result", result);
    return object.toString();
  }

  public static String getNonceJson(String error, int result) {
    JsonObject object = new JsonObject();
    object.addProperty("error", error);
    object.addProperty("result", result);
    return object.toString();
  }

  public static String getIdJson(String error, String id) {
    JsonObject object = new JsonObject();
    object.addProperty("error", error);
    object.addProperty("result", id);
    return object.toString();
  }

  public static String getJsonOK() {
    JsonObject object = new JsonObject();
    object.add("error", null);
    return object.toString();
  }


}

@@ -111,16 +111,62 @@
 dlers;%0A%0A
+import com.continuuity.passport.meta.Account;%0A
 import c
@@ -662,32 +662,198 @@
 oString();%0A  %7D%0A%0A
+  public static String getJsonError(String error, Account account)  %7B%0A    return String.format(%22%7B%5C%22error%5C%22: %5C%22%25s%5C%22, %5C%22reason%5C%22:%25s%7D%22,error, account.toString()) ;%0A  %7D%0A%0A
   public static 
@@ -2093,10 +2093,11 @@
 ;%0A  %7D%0A%0A%0A
+%0A
 %7D%0A

Fix json message incase of account creation failure