コード例 #1
0
  private JsonObject updateStatus(
      JsonObject notif, HashMap<String, JsonObject> response, JsonObject multicastResult) {
    JsonArray returned = multicastResult.getArray("results");
    JsonArray regIds = notif.getArray("registration_ids");
    // should never happen, unless there is a flaw in gcm algorithm
    if (returned.size() != regIds.size()) {
      throw new RuntimeException(
          "Internal error: sizes do not match. regIds: "
              + regIds.size()
              + "; returned: "
              + returned.size());
    }

    JsonArray reTryRegIds = new JsonArray();
    for (int i = returned.size() - 1; i >= 0; i--) {
      response.put((String) regIds.get(i), (JsonObject) returned.get(i));
      boolean resend = doResubmit((JsonObject) returned.get(i));
      if (resend) {
        reTryRegIds.addString((String) regIds.get(i));
      }
    }
    notif.putArray("registration_ids", reTryRegIds);

    return notif;
  }
コード例 #2
0
  @SuppressWarnings("ConstantConditions")
  @Override
  public void handle(Message<JsonObject> message) {
    if (uri == null) {
      sendError(message, "'" + gcm_url + "' is an illegal value for config parameter 'gcm_url'");
      return;
    }

    String apiKey = voidNull(message.body().getString("api_key"));
    if (apiKey.isEmpty()) {
      sendError(message, "Missing mandatory field 'api_key'");
      return;
    }

    JsonObject n = message.body().getObject("notification");
    if (n == null) {
      sendError(message, "Missing mandatory field 'notification'");
      return;
    }

    int ttl = n.getInteger("time_to_live");
    if (ttl > gcm_max_seconds_to_leave) {
      sendError(
          message,
          "Max value of 'time_to_live' exceeded: " + ttl + " > " + gcm_max_seconds_to_leave);
      return;
    }

    JsonArray regIds = n.getArray("registration_ids");
    if (regIds == null || regIds.size() == 0) {
      sendError(message, "Missing mandatory non-empty field 'registration_ids'");
      return;
    }
    if (regIds.size() > gcm_registration_ids_limit) {
      sendError(
          message,
          "Max size of 'registration_ids' exceeded: "
              + regIds.size()
              + " > "
              + gcm_registration_ids_limit);
      return;
    }
    logger.debug("Ready to push notification: " + message.body().encode());
    JsonObject notif = n.copy();

    try {
      send(message, notif, apiKey);
    } catch (Exception e) {
      sendError(message, e.getMessage());
    }
    message.reply("BusMod responded!");
  }
コード例 #3
0
ファイル: Structure.java プロジェクト: hervedevos/entcore
 public void addAttachment() {
   JsonArray functionalAttachment = struct.getArray("functionalAttachment");
   if (functionalAttachment != null
       && functionalAttachment.size() > 0
       && !externalId.equals(functionalAttachment.get(0))) {
     JsonObject params = new JsonObject().putString("externalId", externalId);
     String query;
     if (functionalAttachment.size() == 1) {
       query =
           "MATCH (s:Structure { externalId : {externalId}}), "
               + "(ps:Structure { externalId : {functionalAttachment}}) "
               + "CREATE UNIQUE s-[:HAS_ATTACHMENT]->ps";
       params.putString("functionalAttachment", (String) functionalAttachment.get(0));
     } else {
       query =
           "MATCH (s:Structure { externalId : {externalId}}), (ps:Structure) "
               + "WHERE ps.externalId IN {functionalAttachment} "
               + "CREATE UNIQUE s-[:HAS_ATTACHMENT]->ps";
       params.putArray("functionalAttachment", functionalAttachment);
     }
     getTransaction().add(query, params);
   }
 }
コード例 #4
0
ファイル: Structure.java プロジェクト: hervedevos/entcore
 public static void list(
     JsonArray attributes, Integer skip, Integer limit, TransactionHelper transactionHelper) {
   StringBuilder query = new StringBuilder("MATCH (s:Structure) ");
   JsonObject params = new JsonObject();
   if (attributes != null && attributes.size() > 0) {
     query.append("RETURN DISTINCT");
     for (Object attribute : attributes) {
       query.append(" s.").append(attribute).append(" as ").append(attribute).append(",");
     }
     query.deleteCharAt(query.length() - 1);
     query.append(" ");
   } else {
     query.append("RETURN DISTINCT s ");
   }
   if (skip != null && limit != null) {
     query.append("ORDER BY externalId ASC " + "SKIP {skip} " + "LIMIT {limit} ");
     params.putNumber("skip", skip);
     params.putNumber("limit", limit);
   }
   transactionHelper.add(query.toString(), params);
 }
コード例 #5
0
 private void authorizeDocuments(
     HttpServerRequest request, UserInfos user, String serviceMethod, Handler<Boolean> handler) {
   String ids = request.params().get("ids");
   if (ids != null && !ids.trim().isEmpty()) {
     JsonArray idsArray = new JsonArray(ids.split(","));
     String query =
         "{ \"_id\": { \"$in\" : "
             + idsArray.encode()
             + "}, "
             + "\"$or\" : [{ \"owner\": \""
             + user.getUserId()
             + "\"}, {\"shared\" : { \"$elemMatch\" : "
             + orSharedElementMatch(user, serviceMethod)
             + "}}]}";
     executeCountQuery(
         request,
         DocumentDao.DOCUMENTS_COLLECTION,
         new JsonObject(query),
         idsArray.size(),
         handler);
   } else {
     handler.handle(false);
   }
 }