@Override
 public String convertToString(Map context, Object output) {
   if (output != null && output instanceof LocalDateTime) {
     LocalDateTime result = (LocalDateTime) output;
     return result.toString();
   }
   return null;
 }
 public String getBirthdayAsFormattedString() {
   DateTimeFormatter formatter =
       DateTimeFormat.forPattern(AppConstants.DateFormat.DF_yyyyMMdd_minus);
   if (birthday != null) {
     return birthday.toString(formatter);
   } else {
     return "0000-00-00";
   }
 }
  public Content postEvent(
      String headline,
      double latitude,
      double longitude,
      String body,
      String link,
      MediaFile image,
      VideoAttachment video,
      String noticeboard,
      LocalDateTime startDate,
      LocalDateTime endDate,
      Reoccurence reoccurence,
      LocalDateTime reoccursTo)
      throws N0ticeException {
    final OAuthRequest request = createOauthRequest(Verb.POST, apiUrl + "/event/new");

    final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    addEntityPartParameter(entity, "headline", headline);
    addEntityPartParameter(entity, "noticeboard", noticeboard);
    addEntityPartParameter(entity, "latitude", Double.toString(latitude));
    addEntityPartParameter(entity, "longitude", Double.toString(longitude));
    populateUpdateFields(body, link, image, video, entity);

    addEntityPartParameter(entity, "startDate", startDate.toString(LOCAL_DATE_TIME_FORMAT));
    addEntityPartParameter(entity, "endDate", endDate.toString(LOCAL_DATE_TIME_FORMAT));
    if (reoccurence != null && reoccursTo != null) {
      addEntityPartParameter(entity, "reoccurs", reoccurence.toString());
      addEntityPartParameter(entity, "reoccursTo", reoccursTo.toString(LOCAL_DATE_TIME_FORMAT));
    }

    request.addHeader("Content-Type", entity.getContentType().getValue());
    addMultipartEntity(request, entity);
    oauthSignRequest(request);

    Response response = request.send();

    final String responseBody = response.getBody();
    if (response.getCode() == 200) {
      return searchParser.parseReport(responseBody);
    }

    handleExceptions(response);
    throw new N0ticeException(response.getBody());
  }
  public void newBatchProcess(String id, LocalDateTime requestDateTime, List<String> records) {
    Element recordsElement = new Element(RECORDS);
    addErrorsToDocument(records, recordsElement);

    Element requestDateTimeElement =
        new Element(REQUEST_DATE_TIME).setText(requestDateTime.toString());
    Element idElement = new Element(ID).setText(id);
    Element errorsElement = new Element(ERRORS);

    Element batchProcessElement = new Element(BATCH_PROCESS);
    batchProcessElement.addContent(idElement);
    batchProcessElement.addContent(requestDateTimeElement);
    batchProcessElement.addContent(recordsElement);
    batchProcessElement.addContent(errorsElement);

    document.setRootElement(batchProcessElement);
  }
 /**
  * From LocalDateTime to String
  *
  * @param v to convert
  * @return String
  * @throws Exception
  */
 public String marshal(LocalDateTime v) throws Exception {
   if (v == null) {
     return null;
   }
   return v.toString();
 }
Beispiel #6
0
  @Transactional
  public CheckMonitor saveProduceOfCheckMonitor(CheckMonitor checkMonitor) {

    LocalDateTime now = LocalDateTime.now();

    // 关联消息ID
    String relatemsgid = checkMonitor.getMsgid();
    if (StringUtils.hasLength(relatemsgid)) {
      CheckMonitor relateCheckMonitor = checkMonitorRepository.findOne(relatemsgid);
      // 查岗消息时间
      LocalDateTime checktime;
      if (relateCheckMonitor != null) {
        relateCheckMonitor.setStatus(1);
        checkMonitorRepository.save(relateCheckMonitor);
        checktime = relateCheckMonitor.getTimestamp();

        // 获取时间差,设置查岗类型
        long diff = now.getMillisOfDay() - checktime.getMillisOfDay();

        long diffSec = diff / 1000;
        if (diffSec > relateCheckMonitor.getResponsetime()) {
          checkMonitor.setChecktype("TG");
        } else {
          checkMonitor.setChecktype("ZG");
        }
      }
    }

    if (!StringUtils.hasLength(checkMonitor.getUserid())) {}

    // 设置关联MSGID
    checkMonitor.setRelatemsg(relatemsgid);

    // 生成UUID
    String msgid = UUID.randomUUID().toString().replaceAll("-", "");
    checkMonitor.setMsgid(msgid);

    // 当前发送时间
    checkMonitor.setTimestamp(now);
    checkMonitor.setStatus(1);

    // 保存响应的查岗消息
    checkMonitor = checkMonitorRepository.save(checkMonitor);

    // 构造查岗消息字符串
    final String message =
        String.format(
            "{\"msgid\":\"%s\",\"msgtype\":\"%s\",\"syscode\":\"%s\",\"timestamp\":\"%s\",\"checktype\":\"%s\",\"relatemsg\":\"%s\",\"description\":\"%s\",\"userid\":\"\",\"usertel\":\"\"}",
            msgid,
            "CG",
            checkMonitor.getSyscode(),
            now.toString("yyyy-MM-dd'T'HH:mm:ss"),
            checkMonitor.getChecktype(),
            checkMonitor.getRelatemsg(),
            checkMonitor.getDescription(),
            checkMonitor.getUserid(),
            checkMonitor.getUsertel());

    // 发送查岗消息
    jmsTemplate.send(
        "checkmonitor",
        new MessageCreator() {

          public Message createMessage(Session session) throws JMSException {

            logger.info("response checkmonitor:" + message);

            return session.createTextMessage(message);
          }
        });

    return checkMonitor;
  }
 @Override
 public String marshal(LocalDateTime localDateTime) throws Exception {
   return (localDateTime != null ? localDateTime.toString() : "");
 }
  @Test
  public void testConvertToLocalDateTimeString() {
    LocalDateTime datum = new LocalDateTime();

    assertEquals(datum.toString("dd-MM-yyyy HH:mm"), converter.convertTo(datum, null));
  }
Beispiel #9
0
 public String getDateAsString() {
   return date == null ? null : date.toString();
 }