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.exentity;
17  
18  import java.time.LocalDateTime;
19  import java.time.ZoneId;
20  import java.time.ZonedDateTime;
21  import java.time.format.DateTimeFormatter;
22  import java.util.Map;
23  
24  import org.codelibs.fess.es.log.bsentity.BsUserInfo;
25  
26  /**
27   * @author FreeGen
28   */
29  public class UserInfo extends BsUserInfo {
30  
31      private static final long serialVersionUID = 1L;
32  
33      private Map<String, Object> fields;
34  
35      public String getId() {
36          return asDocMeta().id();
37      }
38  
39      public void setId(final String id) {
40          asDocMeta().id(id);
41      }
42  
43      public Long getVersionNo() {
44          return asDocMeta().version();
45      }
46  
47      public void setVersionNo(final Long version) {
48          asDocMeta().version(version);
49      }
50  
51      public void addField(final String key, final Object value) {
52          fields.put(key, value);
53      }
54  
55      @Override
56      public Map<String, Object> toSource() {
57          final Map<String, Object> sourceMap = super.toSource();
58          if (fields != null) {
59              sourceMap.putAll(fields);
60          }
61          return sourceMap;
62      }
63  
64      @Override
65      protected void addFieldToSource(final Map<String, Object> sourceMap, final String field, final Object value) {
66          if (value instanceof LocalDateTime) {
67              final LocalDateTime ldt = (LocalDateTime) value;
68              final ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
69              super.addFieldToSource(sourceMap, field, DateTimeFormatter.ISO_INSTANT.format(zdt));
70          } else {
71              super.addFieldToSource(sourceMap, field, value);
72          }
73      }
74  
75      @Override
76      public String toString() {
77          return "UserInfo [createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", docMeta=" + docMeta + "]";
78      }
79  }