1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.services;
20
21 import fr.cnes.doi.logging.business.JsonMessage;
22 import fr.cnes.doi.settings.Consts;
23 import fr.cnes.doi.settings.DoiSettings;
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26 import org.apache.logging.log4j.LogManager;
27 import org.apache.logging.log4j.Logger;
28 import org.restlet.Application;
29 import org.restlet.Request;
30 import org.restlet.Response;
31 import org.restlet.data.LocalReference;
32 import org.restlet.data.MediaType;
33 import org.restlet.data.Status;
34 import org.restlet.ext.freemarker.TemplateRepresentation;
35 import org.restlet.representation.Representation;
36 import org.restlet.resource.ClientResource;
37 import org.restlet.service.StatusService;
38
39
40
41
42
43
44 public class CnesStatusService extends StatusService {
45
46
47
48
49 private static final Logger LOG = LogManager.getLogger(CnesStatusService.class.getName());
50
51
52
53 private final DoiSettings settings;
54
55
56
57
58 public CnesStatusService() {
59 super();
60 this.settings = DoiSettings.getInstance();
61 }
62
63
64
65
66
67
68
69
70
71 @Override
72 public Representation getRepresentation(final Status status,
73 final Request request,
74 final Response response) {
75 final Map<String, String> dataModel = createDataModel(response);
76 final Representation mailFtl = new ClientResource(LocalReference.createClapReference(
77 "class/CnesStatus.ftl")).get();
78 return new TemplateRepresentation(mailFtl, dataModel, MediaType.TEXT_HTML);
79 }
80
81
82
83
84
85
86
87
88 private Map<String, String> createDataModel(final Response response) {
89 LOG.traceEntry(new JsonMessage(response));
90 final Map<String, String> dataModel = new ConcurrentHashMap<>();
91 dataModel.put("applicationName", Application.getCurrent().getName());
92 dataModel.put("statusCode", String.valueOf(response.getStatus().getCode()));
93 dataModel.put("statusName", response.getStatus().getReasonPhrase());
94 dataModel.put("statusDescription", response.getStatus().getDescription());
95 dataModel.put("logo", "/resources/images/Cnes-logo.png");
96 dataModel.put("contactAdmin", settings.getString(Consts.SERVER_CONTACT_ADMIN, ""));
97 return LOG.traceExit(dataModel);
98 }
99 }