1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.rest;
20
21 import java.io.InputStream;
22 import java.nio.charset.StandardCharsets;
23 import java.util.List;
24 import java.util.stream.Collectors;
25 import org.apache.commons.io.IOUtils;
26 import org.apache.commons.lang3.StringUtils;
27 import org.apache.syncope.client.console.SyncopeConsoleSession;
28 import org.apache.syncope.common.lib.to.RoleTO;
29 import org.apache.syncope.common.rest.api.service.RoleService;
30
31
32
33
34 public class RoleRestClient extends BaseRestClient {
35
36 private static final long serialVersionUID = -3161863874876938094L;
37
38 public void delete(final String key) {
39 getService(RoleService.class).delete(key);
40 }
41
42 public RoleTO read(final String key) {
43 return getService(RoleService.class).read(key);
44 }
45
46 public void update(final RoleTO roleTO) {
47 getService(RoleService.class).update(roleTO);
48 }
49
50 public void create(final RoleTO roleTO) {
51 getService(RoleService.class).create(roleTO);
52 }
53
54 public List<RoleTO> list() {
55 return getService(RoleService.class).list();
56 }
57
58 public String readAnyLayout(final String roleKey) {
59 try {
60 return IOUtils.toString(InputStream.class.cast(
61 getService(RoleService.class).getAnyLayout(roleKey).getEntity()),
62 StandardCharsets.UTF_8);
63 } catch (Exception e) {
64 LOG.error("Error retrieving console layout info for role {}", roleKey, e);
65 return StringUtils.EMPTY;
66 }
67 }
68
69 public void setAnyLayout(final String roleKey, final String content) {
70 getService(RoleService.class).setAnyLayout(
71 roleKey, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
72 }
73
74 public void removeAnyLayout(final String roleKey) {
75 getService(RoleService.class).removeAnyLayout(roleKey);
76 }
77
78 public List<String> getAllAvailableEntitlements() {
79 return SyncopeConsoleSession.get().getAnonymousClient().platform().getEntitlements().
80 stream().sorted().collect(Collectors.toList());
81 }
82 }