コード例 #1
0
ファイル: TaskServlet.java プロジェクト: mainakibui/akvo-flow
 @Override
 protected RestResponse handleRequest(RestRequest request) throws Exception {
   RestResponse response = new RestResponse();
   TaskRequest taskReq = (TaskRequest) request;
   if (TaskRequest.PROCESS_FILE_ACTION.equalsIgnoreCase(taskReq.getAction())) {
     ingestFile(taskReq);
   } else if (TaskRequest.ADD_ACCESS_POINT_ACTION.equalsIgnoreCase(taskReq.getAction())) {
     addAccessPoint(taskReq);
   }
   return response;
 }
コード例 #2
0
ファイル: TaskServlet.java プロジェクト: mainakibui/akvo-flow
  /**
   * handles the callback from the device indicating that a new data file is available. This method
   * will call processFile to retrieve the file and persist the data to the data store it will then
   * add access points for each water point in the survey responses.
   *
   * @param req
   */
  @SuppressWarnings("rawtypes")
  private void ingestFile(TaskRequest req) {
    if (req.getFileName() != null) {
      log.info("	Task->processFile");
      ArrayList<SurveyInstance> surveyInstances =
          processFile(req.getFileName(), req.getPhoneNumber(), req.getChecksum(), req.getOffset());
      Map<Long, Survey> surveyMap = new HashMap<Long, Survey>();
      SurveyDAO surveyDao = new SurveyDAO();
      Queue summQueue = QueueFactory.getQueue("dataSummarization");
      Queue defaultQueue = QueueFactory.getDefaultQueue();
      for (SurveyInstance instance : surveyInstances) {
        Survey s = surveyMap.get(instance.getSurveyId());
        if (s == null) {
          s = surveyDao.getById(instance.getSurveyId());
          surveyMap.put(instance.getSurveyId(), s);
        }
        if (s != null && s.getRequireApproval() != null && s.getRequireApproval()) {
          // if the survey requires approval, don't run any of the
          // processors
          instance.setApprovedFlag("False");
          continue;
        } else {
          ProcessingAction pa = dispatch(instance.getKey().getId() + "");
          TaskOptions options = TaskOptions.Builder.withUrl(pa.getDispatchURL());
          Iterator it = pa.getParams().keySet().iterator();
          while (it.hasNext()) {
            options.param("key", (String) it.next());
          }
          log.info(
              "Received Task Queue calls for surveyInstanceKey: " + instance.getKey().getId() + "");
          aph.processSurveyInstance(instance.getKey().getId() + "");
          summQueue.add(
              TaskOptions.Builder.withUrl("/app_worker/datasummarization")
                  .param("objectKey", instance.getKey().getId() + "")
                  .param("type", "SurveyInstance"));
          // process the "new" domain structure

          defaultQueue.add(
              TaskOptions.Builder.withUrl("/app_worker/surveyalservlet")
                  .param(
                      SurveyalRestRequest.ACTION_PARAM, SurveyalRestRequest.INGEST_INSTANCE_ACTION)
                  .param(
                      SurveyalRestRequest.SURVEY_INSTANCE_PARAM, instance.getKey().getId() + ""));
        }
      }
    }
  }
コード例 #3
0
ファイル: TaskServlet.java プロジェクト: mainakibui/akvo-flow
  private void addAccessPoint(TaskRequest req) {
    Long surveyInstanceId = req.getSurveyId();
    log.info("Received Task Queue calls for surveyInstanceId: " + surveyInstanceId);

    aph.processSurveyInstance(surveyInstanceId.toString());
  }