View Javadoc
1   /*
2    * Copyright 2012-2017 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.es.log.exbhv;
17  
18  import java.time.Instant;
19  import java.time.LocalDateTime;
20  import java.time.ZoneId;
21  import java.time.format.DateTimeFormatter;
22  import java.time.format.DateTimeParseException;
23  
24  import org.codelibs.fess.es.log.bsbhv.BsUserInfoBhv;
25  import org.codelibs.fess.util.ComponentUtil;
26  import org.dbflute.util.DfTypeUtil;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  /**
31   * @author FreeGen
32   */
33  public class UserInfoBhv extends BsUserInfoBhv {
34  
35      private static final Logger logger = LoggerFactory.getLogger(UserInfoBhv.class);
36  
37      @Override
38      protected String asEsIndex() {
39          return ComponentUtil.getFessConfig().getIndexLogIndex();
40      }
41  
42      @Override
43      protected LocalDateTime toLocalDateTime(final Object value) {
44          if (value != null) {
45              try {
46                  final Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(value.toString()));
47                  final LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
48                  return date;
49              } catch (final DateTimeParseException e) {
50                  logger.debug("Invalid date format: " + value, e);
51              }
52          }
53          return DfTypeUtil.toLocalDateTime(value);
54      }
55  }