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 org.apache.commons.io.IOUtils;
25 import org.apache.commons.lang3.StringUtils;
26 import org.apache.syncope.common.lib.to.JobTO;
27 import org.apache.syncope.common.lib.to.MailTemplateTO;
28 import org.apache.syncope.common.lib.to.NotificationTO;
29 import org.apache.syncope.common.lib.types.JobAction;
30 import org.apache.syncope.common.lib.types.MailTemplateFormat;
31 import org.apache.syncope.common.rest.api.service.MailTemplateService;
32 import org.apache.syncope.common.rest.api.service.NotificationService;
33
34 public class NotificationRestClient extends BaseRestClient {
35
36 private static final long serialVersionUID = 6328933265096511690L;
37
38 public List<NotificationTO> list() {
39 return getService(NotificationService.class).list();
40 }
41
42 public JobTO getJob() {
43 return getService(NotificationService.class).getJob();
44 }
45
46 public void actionJob(final JobAction jobAction) {
47 getService(NotificationService.class).actionJob(jobAction);
48 }
49
50 public NotificationTO read(final String key) {
51 return getService(NotificationService.class).read(key);
52 }
53
54 public void create(final NotificationTO notificationTO) {
55 getService(NotificationService.class).create(notificationTO);
56 }
57
58 public void update(final NotificationTO notificationTO) {
59 getService(NotificationService.class).update(notificationTO);
60 }
61
62 public void delete(final String key) {
63 getService(NotificationService.class).delete(key);
64 }
65
66 public List<MailTemplateTO> listTemplates() {
67 return getService(MailTemplateService.class).list();
68 }
69
70 public void createTemplate(final MailTemplateTO mailTemplateTO) {
71 getService(MailTemplateService.class).create(mailTemplateTO);
72 }
73
74 public void deleteTemplate(final String key) {
75 getService(MailTemplateService.class).delete(key);
76 }
77
78 public MailTemplateTO readTemplate(final String key) {
79 return getService(MailTemplateService.class).read(key);
80 }
81
82 public String readTemplateFormat(final String key, final MailTemplateFormat format) {
83 try {
84 return IOUtils.toString(InputStream.class.cast(
85 getService(MailTemplateService.class).getFormat(key, format).getEntity()), StandardCharsets.UTF_8);
86 } catch (Exception e) {
87 LOG.error("Error retrieving mail template {} as {}", key, format, e);
88 return StringUtils.EMPTY;
89 }
90 }
91
92 public void updateTemplateFormat(final String key, final String content, final MailTemplateFormat format) {
93 getService(MailTemplateService.class).setFormat(
94 key, format, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
95 }
96 }