public String processDownloadCommand() {
    StringBuffer result = new StringBuffer();

    try {
      for (Iterator iterator =
              mb.listSurveysByImeiDB(imei, TransactionLogVO.STATUS_AVAILABLE).iterator();
          iterator.hasNext(); ) {
        NdgUser userlogged = mb.getUserByImei(imei);

        if (userlogged != null) {
          SurveyVO surveyVO = (SurveyVO) iterator.next();

          StringBuffer currentResult = new StringBuffer(surveyVO.getSurvey());

          // we need to remove last '\n'
          if (currentResult.charAt(currentResult.toString().length() - 1) == '\n') {
            currentResult.deleteCharAt(currentResult.toString().length() - 1);
          }

          result.append(currentResult);
        } else {
          new UserNotFoundException();
        }
      }
    } catch (MSMApplicationException e) {
      e.printStackTrace();
    } catch (MSMSystemException e) {
      e.printStackTrace();
    }

    return new String(result);
  }
  public String processListCommand() {
    String result = new String();
    StringBuffer stb = new StringBuffer();

    stb.append("<surveys>\n");

    try {
      ArrayList<SurveyVO> listOfSurveys =
          (ArrayList<SurveyVO>) mb.listSurveysByImeiDB(imei, TransactionLogVO.STATUS_AVAILABLE);

      for (Iterator iterator = listOfSurveys.iterator(); iterator.hasNext(); ) {
        SurveyVO surveyVO = (SurveyVO) iterator.next();
        String linha =
            "<survey id=\""
                + surveyVO.getIdSurvey()
                + "\""
                + " title=\""
                + surveyVO.getTitle()
                + "\"/>";
        stb.append(linha + "\n");
      }

      stb.append("</surveys>");

      result = stb.toString();
    } catch (MSMApplicationException e) {
      e.printStackTrace();
    } catch (MSMSystemException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return result;
  }
  private void updateStatusSendingSurvey(String status) {
    try {
      mb.updateStatusSendingSurvey(imei, status);

      log.debug("Processing Ack Command to Imei " + imei);
      log.debug("############################################################");
    } catch (MSMApplicationException e) {
      e.printStackTrace();
    } catch (MSMSystemException e) {
      e.printStackTrace();
    }
  }
Example #4
0
  private void createUserSimpleSurvey(String username)
      throws MSMApplicationException, MSMSystemException {
    InputStreamReader in = null;
    String surveyString;
    StringBuffer surveyStringBuffer;
    MSMBusinessDelegate bd = new MSMBusinessDelegate();
    Pattern pattern = Pattern.compile("IDS");
    Matcher matcher;
    try {
      URL url = this.getClass().getClassLoader().getResource("META-INF/survey.xml");

      in = new InputStreamReader(url.openStream(), "UTF-8");

      BufferedReader survey = new BufferedReader(in);

      StringBuilder sb = new StringBuilder();

      String line = null;
      try {
        while ((line = survey.readLine()) != null) {
          sb.append(line + '\n');
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      surveyString = sb.toString();
      matcher = pattern.matcher(surveyString);
      surveyStringBuffer = new StringBuffer(matcher.replaceAll(idSimpleSurvey));

      surveyString = surveyStringBuffer.toString();
      pattern = Pattern.compile("CHKS");
      matcher = pattern.matcher(surveyString);

      // 1º - change string "CHKS" by dummy checksum key,
      // once the method getMD5FromSurvey will remove it
      surveyStringBuffer = new StringBuffer(matcher.replaceAll("00000000000000000000000000000000"));

      // 2º - generate MD5 from survey
      String md5FromSurvey = MD5.getMD5FromSurvey(surveyStringBuffer);

      // 3º - replace dummy checksum key by the real one
      surveyString = surveyStringBuffer.toString();
      pattern = Pattern.compile("00000000000000000000000000000000");
      matcher = pattern.matcher(surveyString);

      surveyStringBuffer = new StringBuffer(matcher.replaceAll(md5FromSurvey));

      // Saving transactionLog and Survey in Database
      TransactionLogVO tVo = new TransactionLogVO();
      tVo.setTransactionType(TransactionLogVO.NEW_USER_ADMIN);
      // tVo.setStatus(TransactionLogVO.STATUS_SUCCESS);
      tVo.setTransmissionMode(TransactionLogVO.MODE_HTTP);
      // tVo.setDtLog(new Timestamp(System.currentTimeMillis()));
      // tVo.setSurveyId(idSimpleSurvey);
      // tVo.setUser(username);

      try {
        bd.postSurvey(username, surveyStringBuffer, tVo, true);
      } catch (SurveyFileAlreadyExistsException e) {
        e.printStackTrace();
      }

    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
  }