1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.resources.representation.html;
17
18 import static de.smartics.properties.admin.domain.model.AppRelations.CONFIGURATION;
19
20 import java.io.OutputStream;
21 import java.net.URI;
22 import java.util.List;
23
24 import de.smartics.html5.jatl.HtmlResourceContext;
25 import de.smartics.properties.admin.domain.model.ConfigurationKeys;
26 import de.smartics.properties.admin.domain.model.Paths;
27 import de.smartics.properties.admin.domain.model.Roles;
28 import de.smartics.properties.admin.resources.controller.PropertyKeysResource;
29 import de.smartics.properties.admin.resources.representation.html.share.AbstractHtmlRepresentationRenderer;
30 import de.smartics.properties.admin.resources.representation.html.share.ApplicationHtmlRenderingHelper;
31 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
32 import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
33
34
35
36
37 public final class ConfigurationKeysHtmlRepresentationRenderer extends
38 AbstractHtmlRepresentationRenderer<ConfigurationKeys>
39 {
40
41
42
43
44
45
46
47 private static final String TITLE = "Configuration Keys";
48
49
50
51
52
53
54 private final ConfigurationKeys domainObject;
55
56
57
58
59
60
61
62
63
64
65
66
67 public ConfigurationKeysHtmlRepresentationRenderer(
68 final HtmlResourceContext htmlContext,
69 final ConfigurationKeys domainObject, final OutputStream entityStream)
70 {
71 super(htmlContext, entityStream);
72 this.domainObject = domainObject;
73 }
74
75
76
77
78
79
80
81
82
83
84
85 @Override
86 protected void bodyContents()
87 {
88 renderPageTitle(">>>");
89 html.p()
90 .text(
91 "The following list shows the keys to configurations available"
92 + " to the application with the attached data source.").end();
93 final ApplicationHtmlRenderingHelper helper =
94 new ApplicationHtmlRenderingHelper(html, pathHelper,
95 domainObject.getApplication());
96 helper.addApplication();
97
98 if(htmlContext.getContext().isUserInRole(Roles.CREATE_CONFIG))
99 {
100 renderNewConfigurationForm();
101 html.hr().end();
102 }
103
104 html.div().classAttr("alert alert-info");
105 html.button().type("button").classAttr("close").attr("data-dismiss", "alert").raw("×").end();
106 html.h4().text("Secured Values").end();
107 html.text("Please note that secured values are displayed in plain text.");
108 html.end();
109
110 renderKeys();
111 }
112
113 private void renderNewConfigurationForm()
114 {
115 html.form().classAttr("form-inline").method("POST");
116
117 html.fieldset().legend().text("Create new configuration").end();
118 createInputField();
119 createSubmitButton();
120 createHelp();
121 html.end();
122
123 html.end();
124 }
125
126 private void createInputField()
127 {
128 html.input().type("text").id(Paths.PARAM_CONFIGURATION_KEY)
129 .name(Paths.PARAM_CONFIGURATION_KEY).classAttr("input-xlarge");
130
131 html.attr("placeholder", "//:/::");
132 html.end();
133 }
134
135 private void createSubmitButton()
136 {
137 html.button().type("submit").id("submit")
138 .classAttr("btn btn-mini btn-default");
139 html.text("create").end();
140 }
141
142 private void createHelp()
143 {
144
145 html.div()
146 .small()
147 .text(
148 "Pattern: /{user}/{tenant}/{env}:{node}/{app-group}:{app-id}:{version}")
149 .end().end();
150 html.p()
151 .small()
152 .text(
153 "Please consult the documentation of the selected key format to be"
154 + " informed, which values are allowed.").end().end();
155 }
156
157 private void renderKeys()
158 {
159 html.ol();
160 for (final ConfigurationKey<?> key : domainObject.getKeys())
161 {
162 final URI url =
163 htmlContext.getContext().getUriInfo().getBaseUriBuilder()
164 .path(PropertyKeysResource.class, "getAsHtml")
165 .build(new Object[] { key.toString() }, false);
166
167 final String keyString = key.toString();
168 html.li().a().id(keyString).rel(CONFIGURATION).href(url.toString())
169 .text(keyString).end().end();
170 }
171
172 html.end();
173 }
174
175 @Override
176 protected String getTitle()
177 {
178 return TITLE;
179 }
180
181 @Override
182 protected List<LinkDescriptor> breadcrumbLinks()
183 {
184 return breadcrumb.configurations();
185 }
186
187
188
189 }