public void getAllBrand(String category_id) {
    String url = ProtocolConst.BRAND;

    BeeCallback<JSONObject> cb =
        new BeeCallback<JSONObject>() {

          @Override
          public void callback(String url, JSONObject jo, AjaxStatus status) {

            AdvanceSearchModel.this.callback(url, jo, status);
            try {
              STATUS responseStatus = STATUS.fromJson(jo.optJSONObject("status"));

              if (responseStatus.succeed == 1) {
                JSONArray dataJsonArray = jo.optJSONArray("data");
                if (null != dataJsonArray && dataJsonArray.length() > 0) {
                  brandList.clear();
                  for (int i = 0; i < dataJsonArray.length(); i++) {
                    JSONObject brandJsonObject = dataJsonArray.getJSONObject(i);
                    BRAND brandItem = BRAND.fromJson(brandJsonObject);
                    brandList.add(brandItem);
                  }
                }
                AdvanceSearchModel.this.OnMessageResponse(url, jo, status);
              }

            } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        };

    SESSION session = SESSION.getInstance();

    JSONObject requestJsonObject = new JSONObject();

    Map<String, String> params = new HashMap<String, String>();
    try {
      requestJsonObject.put("session", session.toJson());
      if (null != category_id) {
        requestJsonObject.put("category_id", category_id);
      }

    } catch (JSONException e) {
      // TODO: handle exception
    }

    params.put("json", requestJsonObject.toString());

    cb.url(url).type(JSONObject.class).params(params);
    ProgressDialog pd = new ProgressDialog(mContext);
    pd.setMessage("请稍后...");
    aq.progress(pd).ajax(cb);
  }
  public void fromJson(JSONObject jsonObject) throws JSONException {
    if (null == jsonObject) {
      return;
    }

    JSONArray subItemArray;

    this.category_id = jsonObject.optString("category_id");
    SESSION session = new SESSION();
    session.fromJson(jsonObject.optJSONObject("session"));
    this.session = session;
    return;
  }
 public JSONObject toJson() throws JSONException {
   JSONObject localItemObject = new JSONObject();
   JSONArray itemJSONArray = new JSONArray();
   localItemObject.put("category_id", category_id);
   if (null != session) {
     localItemObject.put("session", session.toJson());
   }
   return localItemObject;
 }
 private void populateContextFromTokenId(String tokenId) {
   try {
     SSOToken token = SSOTokenManager.getInstance().createSSOToken(tokenId);
     AuditRequestContext.putProperty(USER_ID, getUserId(token));
     AuditRequestContext.putProperty(SESSION.toString(), getContextFromSSOToken(token));
   } catch (SSOException e) {
     debug.warning("No SSO Token found when trying to audit an authentication request.");
   }
 }
  protected void checkPageSource(
      ConnectorPageSource pageSource, List<TestColumn> testColumns, List<Type> types)
      throws IOException {
    try {
      MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, types);

      for (MaterializedRow row : result) {
        for (int i = 0, testColumnsSize = testColumns.size(); i < testColumnsSize; i++) {
          TestColumn testColumn = testColumns.get(i);
          Type type = types.get(i);

          Object actualValue = row.getField(i);
          Object expectedValue = testColumn.getExpectedValue();
          if (actualValue == null) {
            assertEquals(null, expectedValue, String.format("Expected non-null for column %d", i));
          } else if (testColumn.getObjectInspector().getTypeName().equals("float")
              || testColumn.getObjectInspector().getTypeName().equals("double")) {
            assertEquals((double) actualValue, (double) expectedValue, EPSILON);
          } else if (testColumn.getObjectInspector().getTypeName().equals("date")) {
            SqlDate expectedDate = new SqlDate(((Long) expectedValue).intValue());
            assertEquals(actualValue, expectedDate);
          } else if (testColumn.getObjectInspector().getTypeName().equals("timestamp")) {
            SqlTimestamp expectedTimestamp =
                new SqlTimestamp((Long) expectedValue, SESSION.getTimeZoneKey());
            assertEquals(actualValue, expectedTimestamp);
          } else if (testColumn.getObjectInspector().getCategory() == Category.PRIMITIVE) {
            if (expectedValue instanceof Slice) {
              expectedValue = ((Slice) expectedValue).toStringUtf8();
            }

            if (actualValue instanceof Slice) {
              actualValue = ((Slice) actualValue).toStringUtf8();
            }
            if (actualValue instanceof SqlVarbinary) {
              actualValue = new String(((SqlVarbinary) actualValue).getBytes(), UTF_8);
            }
            assertEquals(actualValue, expectedValue, String.format("Wrong value for column %d", i));
          } else {
            BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
            type.writeObject(builder, expectedValue);
            expectedValue = type.getObjectValue(SESSION, builder.build(), 0);
            assertEquals(
                actualValue,
                expectedValue,
                String.format("Wrong value for column %s", testColumn.getName()));
          }
        }
      }
    } finally {
      pageSource.close();
    }
  }
 private void createAndStoreSession(
     final PublicKey publicKey, final String clientId, final USER user, final byte[] certificate) {
   final Date expiresAt = getExpiryDateCalculator().calculateFor(user);
   final PublicKeyWithMechanism publicKeyWithMechanism = new PublicKeyWithMechanism(publicKey);
   final SESSION session = getSessionStore().createTransient();
   session.setUserId(user.getUserId());
   session.setExpiresAt(expiresAt);
   session.setPublicKey(publicKeyWithMechanism.getValue());
   session.setMechanism(publicKeyWithMechanism.getMechanism().getName());
   session.setClientId(clientId);
   session.setCertificate(certificate);
   getSessionStore().save(session);
 }
 /**
  * Sets "contextId" audit log field from property of {@link SSOToken}, iff the provided <code>
  * SSOToken</code> is not <code>null</code>.
  *
  * @param ssoToken The SSOToken from which the contextId value will be retrieved.
  */
 static void putContextIdFromSSOToken(JsonValue jsonValue, SSOToken ssoToken) {
   String ssoTokenContext = getContextFromSSOToken(ssoToken);
   putContexts(jsonValue, Collections.singletonMap(SESSION.toString(), ssoTokenContext));
 }