1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.es.user.exbhv;
17
18 import java.util.Map;
19 import java.util.stream.Collectors;
20
21 import org.codelibs.core.misc.Pair;
22 import org.codelibs.fess.es.user.bsbhv.BsRoleBhv;
23 import org.codelibs.fess.es.user.exentity.Role;
24 import org.codelibs.fess.util.ComponentUtil;
25 import org.dbflute.exception.IllegalBehaviorStateException;
26 import org.dbflute.util.DfTypeUtil;
27
28
29
30
31 public class RoleBhv extends BsRoleBhv {
32 @Override
33 protected String asEsIndex() {
34 return ComponentUtil.getFessConfig().getIndexUserIndex();
35 }
36
37 @Override
38 protected <RESULT extends Role> RESULT createEntity(final Map<String, Object> source, final Class<? extends RESULT> entityType) {
39 try {
40 final RESULT result = entityType.newInstance();
41 result.setName(DfTypeUtil.toString(source.get("name")));
42 result.setAttributes(source.entrySet().stream().filter(e -> !"name".equals(e.getKey()))
43 .map(e -> new Pair<>(e.getKey(), (String) e.getValue()))
44 .collect(Collectors.toMap(t -> t.getFirst(), t -> t.getSecond())));
45 return result;
46 } catch (InstantiationException | IllegalAccessException e) {
47 final String msg = "Cannot create a new instance: " + entityType.getName();
48 throw new IllegalBehaviorStateException(msg, e);
49 }
50 }
51 }