Esempio n. 1
0
  /*
   * Get the JSON array containing the details of all the triggers
   * which have activated a given survey at the moment.
   */
  public static JSONArray getActiveTriggerInfo(Context context, String campaignUrn, String survey) {
    JSONObject jInfo = new JSONObject();
    JSONArray jTrigs = new JSONArray();

    TriggerDB db = new TriggerDB(context);
    db.open();

    Cursor c = db.getAllTriggers(campaignUrn);
    if (c.moveToFirst()) {
      do {
        if (getActiveSurveys(context, c).contains(survey)) {
          addTriggerInfoToArray(context, c, jTrigs);
        }

      } while (c.moveToNext());
    }
    c.close();
    db.close();

    try {
      jInfo.put(KEY_ACTIVE_TRIGGERS, jTrigs);
    } catch (JSONException e) {
      return null;
    }

    return jTrigs;
  }
Esempio n. 2
0
  /*
   * Get all the active surveys corresponding to a specific trigger.
   */
  public static Set<String> getActiveSurveysForTrigger(Context context, int trigId) {
    HashSet<String> actSurveys = new HashSet<String>();

    TriggerDB db = new TriggerDB(context);
    db.open();

    Cursor c = db.getTrigger(trigId);
    if (c.moveToFirst()) {
      actSurveys.addAll(getActiveSurveys(context, c));
    }

    c.close();
    db.close();

    return actSurveys;
  }
Esempio n. 3
0
  /*
   * Get the list of all surveys active at the moment. This
   * function creates a set of all active surveys from all
   * active triggers.
   *
   * This function is used by the Notifier to prepare the
   * notification item.
   */
  public static Set<String> getAllActiveSurveys(Context context, String campaignUrn) {
    HashSet<String> actSurveys = new HashSet<String>();

    TriggerDB db = new TriggerDB(context);
    db.open();

    Cursor c = db.getAllTriggers(campaignUrn);
    if (c.moveToFirst()) {
      do {

        actSurveys.addAll(getActiveSurveys(context, c));

      } while (c.moveToNext());
    }
    c.close();
    db.close();

    return actSurveys;
  }
Esempio n. 4
0
  /*
   * To be called when a trigger expires. This function logs using
   * SystemLog, the list of all surveys not taken by the user
   * but were activated by the given trigger.
   */
  public static void handleExpiredTrigger(Context context, int trigId) {
    TriggerDB db = new TriggerDB(context);
    db.open();

    String sActDesc = db.getActionDescription(trigId);
    String sTrigDesc = db.getTriggerDescription(trigId);
    String sTrigType = db.getTriggerType(trigId);
    String sRTDesc = db.getRunTimeDescription(trigId);
    String sCampaignUrn = db.getCampaignUrn(trigId);

    db.close();

    if (sActDesc == null
        || sTrigDesc == null
        || sTrigType == null
        || sCampaignUrn == null
        || sRTDesc == null) {

      return;
    }

    TriggerActionDesc actDesc = new TriggerActionDesc();
    if (!actDesc.loadString(sActDesc)) {
      return;
    }

    TriggerRunTimeDesc rtDesc = new TriggerRunTimeDesc();
    if (!rtDesc.loadString(sRTDesc)) {
      return;
    }

    LinkedList<String> untakenList = new LinkedList<String>();
    for (String survey : actDesc.getSurveys()) {

      if (!IsSurveyTaken(context, sCampaignUrn, survey, rtDesc.getTriggerTimeStamp())) {

        untakenList.add(survey);
      }
    }

    if (untakenList.size() == 0) {
      return;
    }

    JSONArray jSurveyList = new JSONArray();
    for (String survey : actDesc.getSurveys()) {
      jSurveyList.put(survey);
    }

    JSONArray jUntakenSurveys = new JSONArray();
    for (String unTakenSurvey : untakenList) {
      jUntakenSurveys.put(unTakenSurvey);
    }

    JSONObject jExpired = new JSONObject();

    try {
      jExpired.put(KEY_TRIGGER_TYPE, sTrigType);
      jExpired.put(KEY_TRIGGER_DESC, new JSONObject(sTrigDesc));
      jExpired.put(KEY_SURVEY_LIST, jSurveyList);
      jExpired.put(KEY_UNTAKEN_SURVEYS, jUntakenSurveys);
      jExpired.put(KEY_CAMPAIGN_URN, sCampaignUrn);
    } catch (JSONException e) {
      return;
    }

    // Log the info
    String msg = "Expired trigger has surveys not taken: " + jExpired.toString();

    Log.i(DEBUG_TAG, "NotifSurveyAdaptor: SystemLogging the following message: ");
    Log.i(DEBUG_TAG, msg);

    systemLog(context, msg);
  }