@Override
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws Exception {

    SysMsgCommand msgCmd = (SysMsgCommand) command;
    log.info("SysMsgDetailController:onSubmit called.");

    NotificationDto sysMessage = msgCmd.getMsg();
    String btn = request.getParameter("btn");
    if ("delete".equalsIgnoreCase(btn)) {
      if (sysMessage.getType() == NotificationType.SYSTEM) {
        return null;
      }
      sysMessageService.removeMessage(sysMessage.getMsgId());
      ModelAndView mav = new ModelAndView("/deleteconfirm");
      mav.addObject("msg", "Location has been successfully deleted.");
      return mav;
    } else {
      if (msgCmd.getTemplateMethod() == 0) {
        MultipartFile providerScriptFile = msgCmd.getProviderScriptFile();
        String providerScriptFileName = "";
        if (providerScriptFile != null && providerScriptFile.getSize() > 0) {
          providerScriptFileName = providerScriptFile.getOriginalFilename();
          String filePath = res.getString("scriptRoot") + "/msgprovider/" + providerScriptFileName;
          File dest = new File(filePath);
          try {
            providerScriptFile.transferTo(dest);
            sysMessage.setProviderScriptName(providerScriptFileName);
            sysMessage.setMailTemplate(null);
          } catch (IllegalStateException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      } else {
        MailTemplateDto mailTemplateDto =
            mailTemplateWebService
                .getTemplateById(msgCmd.getSelectedTemplateId())
                .getMailTemplate();
        sysMessage.setMailTemplate(mailTemplateDto);
        sysMessage.setProviderScriptName(null);
      }

      if (StringUtils.isEmpty(sysMessage.getMsgId())) {
        sysMessageService.addMessage(sysMessage);
      } else {
        sysMessageService.updateMessage(sysMessage);
      }
    }

    ModelAndView mav = new ModelAndView(new RedirectView(redirectView, true));
    mav.addObject("sysMsgCmd", msgCmd);

    return mav;
  }
Пример #2
0
  public String readResponse(HttpResponse response) {
    String output = "";

    HttpEntity entity = response.getEntity();

    try {
      trapException(response.getStatusLine().getStatusCode());
    } catch (CrowdFlowerException e1) {
      e1.printStackTrace();
    }

    InputStream instream;
    try {
      instream = entity.getContent();
      BufferedReader reader = new BufferedReader(new InputStreamReader(instream));

      // do something useful with the response
      output = output + reader.readLine();
      instream.close();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return output;
  }
Пример #3
0
  /**
   * Set a new timer.
   *
   * @param duration the number of milliseconds the vibrator should be run
   */
  private void setTimer(int duration) {

    cancelTimer();
    try {
      task = new TimerClient();
      // execute for the duration in milli seconds
      timerService.schedule(task, duration);
    } catch (IllegalStateException e) {
      e.printStackTrace();
      cancelTimer();
    }
  }
Пример #4
0
  /**
   * Group search API for the new filter type search and sort criteria
   *
   * @author DiepLe
   * @param searchAndSortCriteria
   * @return
   */
  @RequestMapping(value = "/search", method = RequestMethod.POST)
  @ResponseBody
  public ApiResponse<Object> getGroupSummaryByNewFilterTypeSearchAndSortCriteria(
      @RequestBody SearchAndSortCriteria searchAndSortCriteria) {

    final ApiResponse<Object> apiResponse = new ApiResponse<>();
    List<PermissionGroupSummaryDTO> permissionGroupSummaryDTO = null;
    Long totalRecords = null;
    PermissionGroupSummariesDTO summaries = null;

    try {
      permissionGroupSummaryDTO =
          groupService.getGroupSummaryByNewSearchAndSortCriteria(searchAndSortCriteria);
      totalRecords = groupService.getTotalCountForSearchAndSortCriteria(searchAndSortCriteria);
      summaries = new PermissionGroupSummariesDTO();
      summaries.setGroupList(permissionGroupSummaryDTO);
      summaries.setTotalRecords(totalRecords);
    } catch (IllegalStateException e) {
      e.printStackTrace();
      apiResponse.setStatus("failure");
      apiResponse.setData(null);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1069");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1069", new Object[] {e.getMessage()}, LocaleContextHolder.getLocale()));
      return apiResponse;
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      apiResponse.setStatus("failure");
      apiResponse.setData(null);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1070");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1070", new Object[] {e.getMessage()}, LocaleContextHolder.getLocale()));
      return apiResponse;
    } catch (Exception e) {
      throw new LucasRuntimeException(LucasRuntimeException.INTERNAL_ERROR, e);
    }

    apiResponse.setData(summaries);

    return apiResponse;
  }
  public static HttpResponse doPost(String urlExtension, Map<String, String> parmas) {
    HttpResponse httpResponse = null;
    ArrayList<BasicNameValuePair> pairs = convertMapToNameValuePair(parmas);

    try {
      DefaultHttpClient client = new DefaultHttpClient();
      HttpPost httpPost = new HttpPost(BASE_URL + urlExtension);
      UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs, "utf-8");
      httpPost.setEntity(p_entity);
      httpResponse = client.execute(httpPost);
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return httpResponse;
  }