Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONObject


                    }
                }
            }

            if (clazz.isInterface()) {
                JSONObject object;

                if (map instanceof JSONObject) {
                    object = (JSONObject) map;
                } else {
                    object = new JSONObject(map);
                }

                return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                                                  new Class<?>[] { clazz }, object);
            }
View Full Code Here


public class JustTest {
  private static final Logger log = Logger.getLogger(JustTest.class.getName());

  @ApiMethod(name = "t01", httpMethod = HttpMethod.GET)
  public JSONObject getCarPhoneRandomNumberList() {
    JSONObject retObj = new JSONObject();
    retObj.put("message", "test msg");

    List<String> devices = new ArrayList<String>();
    devices
        .add("APA91bHeYhgI7-zfNI-X47bqwHsRESL5iimgyDpirRPKGQ-MmuMD0wnvQo6ZKyTgmD2Fh0Qlvre0czu3ewJkhvvm99sW2TO3lXaxfCaXMnz9PEMNxc8egT69uHQGXXr0pdEdrCyJ1v9oqSWVv5gMdiJMijEy0VdZlg");
View Full Code Here

  }

  @ApiMethod(name = "cppn.merge", httpMethod = HttpMethod.POST)
  // public JSONObject postCPPushNotification(@Named("carID") String carID, JSONObject json) {
  public JSONObject postCPPushNotification(JSONObject json) {
    JSONObject retJson = null;

    // 檢查push notification 是否有 title 和 message
    if (null == json || null == json.getString("carID") || null == json.getString("title") || null == json.getString("message"))
      throw new Error("提供的訊息內容字串格式不正確");

    String carID = json.getString("carID");
    String title = json.getString("title");
    String message = json.getString("message");
    if (StringUtils.isBlank(carID) || StringUtils.isBlank(title) || StringUtils.isBlank(message))
      throw new Error("提供的訊息內容中,carID, title 或 message 字串錯誤 !");
    log.info("get carID = " + carID);
    System.out.println("get carID = " + carID);

    // 檢查carID是否合法
    CarReg cr = cr_service.getDataByID(carID);
    if (null == cr)
      throw new Error("該carID尚未註冊");

    // 找出和該carID連結的phoneID list
    String filter = String.format("carID=='%s'", carID);
    List<CarPhoneRelation> cpr_list = cpr_service.getPaginationData(filter).getResultList();
    if (null == cpr_list || cpr_list.size() == 0)
      throw new Error("該carID尚未有配對的phone");

    if (null == json.getJSONObject("rowdata"))
      throw new Error("提供的訊息內容物件格式不正確");

    JSONObject rowdata = json.getJSONObject("rowdata");

    // 正確的儲存push notification
    PushNotificationMessage pnm = new PushNotificationMessage();
    pnm.setAddTime(CTCommon.getNowTime());
    pnm.setTitle(title);
    pnm.setMessage(message);
    if (null != rowdata)
      pnm.setRowdata(rowdata.toJSONString());
    pnm_service.add(pnm);

    retJson = new JSONObject();
    retJson.put("messageID", pnm.getEncodedKey());
    for (CarPhoneRelation o : cpr_list) {
      CarPhonePushNotification cppn = new CarPhonePushNotification();
      cppn.setAddTime(CTCommon.getNowTime());
      cppn.setCarID(carID);
View Full Code Here

  }

  @ApiMethod(name = "pcpn.merge", httpMethod = HttpMethod.POST)
  // public JSONObject postPCPushNotification(@Named("phoneID") String phoneID, JSONObject json) {
  public JSONObject postPCPushNotification(JSONObject json) {
    JSONObject retJson = null;

    // 檢查push notification 是否有 title 和 message
    if (null == json || null == json.getString("phoneID") || null == json.getString("carID") || null == json.getString("title")
        || null == json.getString("message"))
      throw new Error("提供的訊息內容字串格式不正確");

    String phoneID = json.getString("phoneID");
    String carID = json.getString("carID");
    String title = json.getString("title");
    String message = json.getString("message");
    if (StringUtils.isBlank(phoneID) || StringUtils.isBlank(carID) || StringUtils.isBlank(title) || StringUtils.isBlank(message))
      throw new Error("提供的訊息內容中,phoneID, carID, title 或 message 字串錯誤 !");

    System.out.println("get phoneID = " + phoneID);
    System.out.println("get carID = " + carID);

    // 檢查phoneID是否合法
    PhoneReg pr = pr_service.getDataByID(phoneID);
    if (null == pr)
      throw new Error("該phoneID尚未註冊");

    // 找出和該phoneID連結的carID list
    String filter = String.format("phoneID=='%s'", phoneID);
    List<CarPhoneRelation> cpr_list = cpr_service.getPaginationData(filter).getResultList();
    if (null == cpr_list || cpr_list.size() == 0)
      throw new Error("該phoneID尚未有配對的phone");

    if (null == json.getJSONObject("rowdata"))
      throw new Error("提供的訊息內容物件格式不正確");

    JSONObject rowdata = json.getJSONObject("rowdata");

    // 正確的儲存push notification
    PushNotificationMessage pnm = new PushNotificationMessage();
    pnm.setAddTime(CTCommon.getNowTime());
    pnm.setTitle(title);
    pnm.setMessage(message);
    if (null != rowdata)
      pnm.setRowdata(rowdata.toJSONString());
    pnm_service.add(pnm);

    retJson = new JSONObject();
    retJson.put("messageID", pnm.getEncodedKey());
    for (CarPhoneRelation o : cpr_list) {
      if (o.getCarID().equals(carID)) {
        PhoneCarPushNotification pcpn = new PhoneCarPushNotification();
        pcpn.setAddTime(CTCommon.getNowTime());
View Full Code Here

    return retJson;
  }

  @ApiMethod(name = "pcpn.send", httpMethod = HttpMethod.POST)
  public JSONObject postPCPushNotificationSend(@Named("phoneID") String phoneID, @Named("messageID") String messageID) {
    JSONObject retJson = null;
    // 檢查phoneID是否合法
    PhoneReg pr = pr_service.getDataByID(phoneID);
    if (null == pr)
      throw new Error("該phoneID尚未註冊");
View Full Code Here

    return retJson;
  }

  @ApiMethod(name = "cppn.send", httpMethod = HttpMethod.POST)
  public JSONObject postCPPushNotificationSend(@Named("carID") String carID, @Named("messageID") String messageID) {
    JSONObject retJson = null;
    // 檢查carID是否合法
    CarReg cr = cr_service.getDataByID(carID);
    if (null == cr)
      throw new Error("該carID尚未註冊");
View Full Code Here

    return du_service.getPaginationData(null, "addTime desc").getResultList();
  }

  @ApiMethod(name = "du.list", httpMethod = HttpMethod.POST)
  public JSONObject postDeviceUploadList(JSONObject json) {
    JSONObject retJson = null;

    // 檢查push notification 是否有 phoneID 和 carID
    if (null == json || null == json.getString("phoneID") || null == json.getString("carID"))
      throw new Error("提供的訊息內容字串格式不正確");

    String phoneID = json.getString("phoneID");
    String carID = json.getString("carID");
    // String uploadID = json.getString("uploadID");
    String lastTime = json.getString("lastTime");
    if (StringUtils.isBlank(phoneID) || StringUtils.isBlank(carID))
      throw new Error("提供的訊息內容中,phoneID 或 carID字串錯誤 !");

    if (StringUtils.isBlank(lastTime))
      log.info("提供的訊息內容中,lastTime字串錯誤 !, 將提供全部資料");
    log.info("get phoneID = " + phoneID);
    log.info("get carID = " + carID);
    log.info("get lastTime = " + lastTime);

    // 檢查phoneID是否合法
    PhoneReg pr = pr_service.getDataByID(phoneID);
    if (null == pr)
      throw new Error("該phoneID尚未註冊");

    // 檢查carID是否合法
    CarReg cr = cr_service.getDataByID(carID);
    if (null == cr)
      throw new Error("該carID尚未註冊");

    // 找出和該phoneID連結的carID list
    String filter = String.format("phoneID=='%s' && carID=='%s'", phoneID, carID);
    List<CarPhoneRelation> cpr_list = cpr_service.getPaginationData(filter).getResultList();
    if (null != cpr_list && cpr_list.size() > 1) {
      throw new Error("連結資料異常:carID:" + carID + ", phoneID=" + phoneID);
    }
    if (null == cpr_list || cpr_list.size() == 0)
      throw new Error("該phoneID與carID並未配對");

    // 是否有指定某時段之後的資料?
    if (StringUtils.isBlank(lastTime))
      filter = String.format("devID=='%s'", carID);
    else
      filter = String.format("devID=='%s' && addTime>'%s'", carID, lastTime);

    List<DeviceUpload> du_list = du_service.getPaginationData(filter, "addTime asc").getResultList();
    retJson = new JSONObject();
    JSONArray array = new JSONArray();
    for (DeviceUpload du : du_list) {
      JSONObject duJson = new JSONObject();
      duJson.put("addTime", du.getAddTime());
      duJson.put("mySerial", du.getMySerial());
      duJson.put("blob_key", du.getBlob_key());
      duJson.put("serving_url", du.getServing_url());
      array.add(duJson);
    }
    retJson.put("items", array);

    return retJson;
View Full Code Here

  private static PhoneRegService pr_service = new PhoneRegServiceImpl();
  private static final Logger log = Logger.getLogger(CarTraceImageUploadAPI.class.getName());

  @ApiMethod(name = "image_upload_url", httpMethod = HttpMethod.POST)
  public JSONObject postCTUploadURL(@Named("devID") String devID) {
    JSONObject retJson = null;
    // 檢查是否為合法的carID
    CarReg cr = cr_service.getDataByID(devID);
    if (null == cr) {
      // 檢查是否為合法的phoneID
      PhoneReg pr = pr_service.getDataByID(devID);
      if (null == pr)
        throw new Error("提供的ID尚未註冊, devID = " + devID);
    }

    retJson = new JSONObject();
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    String uploadURL = blobstoreService.createUploadUrl("/image_upload");
    retJson.put("image_upload_url", uploadURL);

    return retJson;
  }
View Full Code Here

    }
    blobstoreService.serve(blobKey, res);
  }

  private void sendError(HttpServletResponse res, String errorMessage) throws IOException {
    JSONObject json = new JSONObject();
    json.put("errorMessage", errorMessage);

    res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    res.setContentType("application/json");
    PrintWriter out = res.getWriter();
    out.print(json.toString());
    out.flush();
    out.close();
  }
View Full Code Here

    res.setStatus(HttpServletResponse.SC_OK);
    res.setContentType("application/json");

    // 二種方式都能存取上傳的圖檔
    JSONObject json = new JSONObject();
    // json.put("serving_url", servingUrl);
    // json.put("blob_key", blobKey.getKeyString());
    // json.put("direct_url", "/serve?blob_key=" + blobKey.getKeyString());

    // 儲存在db的動作
    DeviceUpload du = new DeviceUpload();
    du.setDevID(devID);
    du.setMySerial(mySerial);
    du.setServing_url(servingUrl);
    du.setBlob_key(blobKey.getKeyString());
    du.setAddTime(CTCommon.getNowTime());
    du_service.add(du);
    log.info("新增一筆設備上傳記錄:" + JSON.toJSONString(du));

    // 直接新增message info到db
    // 並直接把message content發給相關的devices
    JSONObject retJson = new JSONObject();
    CarTracePushNotificationAPI ctpn_api = new CarTracePushNotificationAPI();
    if (null != cr) {
      String carID = cr.getEncodedKey();
      String title = "設備上傳記錄";
      String message = String.format("設備於%s上傳圖片", du.getAddTime());
      JSONObject rowdata = new JSONObject();
      rowdata.put("carID", carID);
      rowdata.put("addTime", du.getAddTime());
      JSONObject cpJson = new JSONObject();
      cpJson.put("carID", carID);
      cpJson.put("title", title);
      cpJson.put("message", message);
      cpJson.put("rowdata", rowdata);

      retJson = ctpn_api.postCPPushNotification(cpJson);
      String messageID = retJson.getString("messageID");
      // JSONArray phoneArray = retJson.getJSONArray("phoneArray");
      retJson = ctpn_api.postCPPushNotificationSend(carID, messageID);
    } else if (null != pr) {
      String phoneID = pr.getEncodedKey();
      String title = "設備上傳記錄";
      String message = String.format("設備於%s上傳圖片", du.getAddTime());
      JSONObject rowdata = new JSONObject();
      rowdata.put("phoneID", phoneID);
      rowdata.put("addTime", du.getAddTime());
      JSONObject cpJson = new JSONObject();
      cpJson.put("phoneID", phoneID);
      cpJson.put("title", title);
      cpJson.put("message", message);
      cpJson.put("rowdata", rowdata);

      retJson = ctpn_api.postPCPushNotification(cpJson);
      String messageID = retJson.getString("messageID");
      // JSONArray phoneArray = retJson.getJSONArray("phoneArray");
      retJson = ctpn_api.postPCPushNotificationSend(phoneID, messageID);
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.