Beispiel #1
0
 @Override
 protected RestRequest convertRequest() throws Exception {
   HttpServletRequest req = getRequest();
   RestRequest restRequest = new TaskRequest();
   restRequest.populateFromHttpRequest(req);
   return restRequest;
 }
  /**
   * looks up the appropriate summarizer in the summarizer map (using the Type passed in on the
   * request) then finds the name of the summarization and, if found, runs it. After running, if
   * there are more summarizations left in the list, it updates the action on the request with the
   * next value and puts the request back on the queue.
   */
  @SuppressWarnings("rawtypes")
  @Override
  protected RestResponse handleRequest(RestRequest request) throws Exception {
    RestResponse response = new RestResponse();
    DataSummarizationRequest summarizationRequest = (DataSummarizationRequest) request;

    int idx = 0;
    List<String> applicableSummarizers = summarizers.get(summarizationRequest.getType());
    if (applicableSummarizers != null) {
      if (request.getAction() != null) {
        while (idx < applicableSummarizers.size()) {
          if (applicableSummarizers.get(idx).trim().equals(summarizationRequest.getAction())) {
            break;
          }
          idx++;
        }
      }
      if (idx < applicableSummarizers.size()) {
        boolean isCompleted = false;
        DataSummarizer summarizer = null;
        try {
          Class cls = Class.forName(applicableSummarizers.get(idx));
          summarizer = (DataSummarizer) cls.newInstance();
          isCompleted =
              summarizer.performSummarization(
                  summarizationRequest.getObjectKey(),
                  summarizationRequest.getType(),
                  summarizationRequest.getValue(),
                  summarizationRequest.getOffset(),
                  summarizationRequest.getCursor());
        } catch (Exception e) {
          log(
              "Could not invoke summarizer. Setting complete to true to continue with processing",
              e);
          isCompleted = true;
        }
        if (!isCompleted && summarizer != null) {
          // if we're not done, increment offset and call the same
          // summarizer
          summarizationRequest.setAction(applicableSummarizers.get(idx));
          summarizationRequest.setOffset(
              summarizationRequest.getOffset() + DataSummarizer.BATCH_SIZE);
          summarizationRequest.setCursor(summarizer.getCursor());
          invokeSummarizer(summarizationRequest);
        } else {
          if (idx < applicableSummarizers.size() - 1) {
            summarizationRequest.setAction(applicableSummarizers.get(idx + 1));
            // put the item back on the queue with the action
            // updated to the next summarization in the chain
            invokeSummarizer(summarizationRequest);
          }
        }
      }
    } else {
      log("No summarizers configured for type " + summarizationRequest.getType());
    }
    return response;
  }
  @Override
  protected RestResponse handleRequest(RestRequest req) throws Exception {
    DeviceApplicationRestResponse resp = new DeviceApplicationRestResponse();
    Properties props = System.getProperties();
    String autoUpdateApk = props.getProperty("autoUpdateApk");
    if (DeviceApplicationRestRequest.GET_LATEST_VERSION_ACTION.equalsIgnoreCase(req.getAction())
        && autoUpdateApk != null
        && autoUpdateApk.equalsIgnoreCase("true")) {

      DeviceApplicationRestRequest daReq = (DeviceApplicationRestRequest) req;
      List<DeviceApplication> devAppList =
          devAppDao.listByDeviceTypeAndAppCode(daReq.getDeviceType(), daReq.getAppCode(), 1);
      if (devAppList != null && devAppList.size() > 0) {
        resp.setVersion(devAppList.get(0).getVersion());
        resp.setFileName(devAppList.get(0).getFileName());
        resp.setMd5Checksum(devAppList.get(0).getMd5Checksum());
      }
    }
    return resp;
  }