Skip to content

Commit cc8fd41

Browse files
committed
LaboratoryController: Use java DOM API instead of StringBuilder
1 parent c4d5b64 commit cc8fd41

1 file changed

Lines changed: 46 additions & 45 deletions

File tree

laboratory/src/org/labkey/laboratory/LaboratoryController.java

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.labkey.api.security.permissions.UpdatePermission;
8080
import org.labkey.api.util.ErrorRenderer;
8181
import org.labkey.api.util.ExceptionUtil;
82+
import org.labkey.api.util.HtmlString;
8283
import org.labkey.api.util.JsonUtil;
8384
import org.labkey.api.util.Pair;
8485
import org.labkey.api.util.URLHelper;
@@ -106,6 +107,16 @@
106107
import java.util.Map;
107108
import java.util.Set;
108109

110+
import static org.labkey.api.util.DOM.BR;
111+
import static org.labkey.api.util.DOM.INPUT;
112+
import static org.labkey.api.util.DOM.P;
113+
import static org.labkey.api.util.DOM.TABLE;
114+
import static org.labkey.api.util.DOM.TD;
115+
import static org.labkey.api.util.DOM.TR;
116+
import static org.labkey.api.util.DOM.at;
117+
import static org.labkey.api.util.DOM.createHtmlFragment;
118+
import static org.labkey.api.util.DOM.Attribute.style;
119+
109120

110121
public class LaboratoryController extends SpringActionController
111122
{
@@ -126,13 +137,13 @@ public ModelAndView getView(PlanExptRunForm form, BindException errors) throws E
126137
Integer assayId = form.getAssayId();
127138
if (assayId == null)
128139
{
129-
return new HtmlView("Error: must provide a rowId for the assay");
140+
return new HtmlView(HtmlString.of("Error: must provide a rowId for the assay"));
130141
}
131142

132143
AssayDataProvider ad = LaboratoryService.get().getDataProviderForAssay(assayId);
133144
if (ad == null || !ad.supportsRunTemplates())
134145
{
135-
return new HtmlView("Error: this assay does not support requests");
146+
return new HtmlView(HtmlString.of("Error: this assay does not support requests"));
136147
}
137148

138149
Module labModule = ModuleLoader.getInstance().getModule(LaboratoryModule.NAME);
@@ -172,15 +183,13 @@ public void validateCommand(Object form, Errors errors)
172183
@Override
173184
public ModelAndView getConfirmView(Object form, BindException errors) throws Exception
174185
{
175-
StringBuilder msg = new StringBuilder();
176-
msg.append("Certain assays can have performance improved by the addition of indexes, which can be suggested by modules. The following indexes are recommended for the assays installed on this server:<p>");
177-
178186
List<String> msgs = LaboratoryManager.get().createIndexes(getUser(), false, false);
179-
msg.append(StringUtils.join(msgs, "<br>"));
180187

181-
msg.append("<p>Do you want to continue?");
182-
183-
return new HtmlView(msg.toString());
188+
return new HtmlView(createHtmlFragment(
189+
"Certain assays can have performance improved by the addition of indexes, which can be suggested by modules. The following indexes are recommended for the assays installed on this server:",
190+
P(msgs.stream().map(msg -> createHtmlFragment(msg, BR()))),
191+
P("Do you want to continue?")
192+
));
184193
}
185194

186195
@Override
@@ -231,17 +240,12 @@ public ModelAndView getConfirmView(EnsureAssayFieldsForm form, BindException err
231240
{
232241
try
233242
{
234-
StringBuilder sb = new StringBuilder();
235-
sb.append("This action will iterate all protocols for the assay " + form.getProviderName() + " and append any columns present in the definition, but lacking from that instance of the assay. The following changes will be made:<br><br>");
236243
List<String> messages = AssayHelper.ensureAssayFields(getUser(), form.getProviderName(), form.isRenameConflicts(), true);
237-
for (String msg : messages)
238-
{
239-
sb.append(msg).append("<br><br>");
240-
}
241-
242-
sb.append("<br>Do you want to continue?");
243-
244-
return new HtmlView(sb.toString());
244+
return new HtmlView(createHtmlFragment(
245+
"This action will iterate all protocols for the assay " + form.getProviderName() + " and append any columns present in the definition, but lacking from that instance of the assay. The following changes will be made:", BR(), BR(),
246+
messages.stream().map(msg -> createHtmlFragment(msg, BR(), BR())),
247+
BR(), "Do you want to continue?"
248+
));
245249
}
246250
catch (ChangePropertyDescriptorException e)
247251
{
@@ -307,25 +311,23 @@ public void validateCommand(SetTableIncrementForm form, Errors errors)
307311
@Override
308312
public ModelAndView getConfirmView(SetTableIncrementForm form, BindException errors) throws Exception
309313
{
310-
StringBuilder sb = new StringBuilder();
311-
sb.append("This allows you to reset the current value for an auto-incrementing table<br><br>");
312-
sb.append("<table style='border-collapse: collapse;'>");
313-
314314
String schema = form.getSchemaName() == null ? "" : form.getSchemaName();
315-
sb.append("<tr><td>Schema:</td><td><input name=\"schema\" value=\"" + schema + "\"></td></tr>");
316-
317315
String query = form.getQueryName() == null ? "" : form.getQueryName();
318-
sb.append("<tr><td>Query:</td><td><input name=\"query\" value=\"" + query + "\"></td></tr>");
319316

320317
ContainerIncrementingTable ti = getTable(schema, query, errors, false);
321-
Integer value = null;
318+
Integer currentId = null;
322319
if (ti != null)
323-
value = ti.getCurrentId(getContainer());
324-
325-
sb.append("<tr><td>Value:</td><td><input name=\"value\" value=\"" + (value == null ? "" : value) + "\"></td></tr>");
326-
sb.append("</table><br>Do you want to continue?");
320+
currentId = ti.getCurrentId(getContainer());
327321

328-
return new HtmlView(sb.toString());
322+
return new HtmlView(createHtmlFragment(
323+
"This allows you to reset the current value for an auto-incrementing table", BR(), BR(),
324+
TABLE(at(style, "border-collapse: collapse;"),
325+
TR(TD("Schema:"), TD(INPUT(at().name("schema").value(schema)))),
326+
TR(TD("Query:"), TD(INPUT(at().name("query").value(query)))),
327+
TR(TD("Value:"), TD(INPUT(at().name("value").value(currentId == null ? "" : currentId.toString()))))
328+
),
329+
BR(), "Do you want to continue?"
330+
));
329331
}
330332

331333
@Override
@@ -467,7 +469,7 @@ public void validateCommand(Object form, Errors errors)
467469
@Override
468470
public ModelAndView getConfirmView(Object form, BindException errors) throws Exception
469471
{
470-
return new HtmlView("This action will iterate all workbooks in the current folder and create laboratory experiments for them as needed");
472+
return new HtmlView(HtmlString.of("This action will iterate all workbooks in the current folder and create laboratory experiments for them as needed"));
471473
}
472474

473475
@Override
@@ -506,20 +508,18 @@ public void validateCommand(SetTableIncrementForm form, Errors errors)
506508
@Override
507509
public ModelAndView getConfirmView(SetTableIncrementForm form, BindException errors) throws Exception
508510
{
509-
StringBuilder sb = new StringBuilder();
510-
sb.append("This allows you to initialize the autoincrementing column for the provided schema/query<br><br>");
511-
sb.append("This is very rarely required and was created as a helper for admins with a good deal of knowledge about this module. Under most cases these columns will be automatically populated and you will not need to worry about this. If you are unsure about this page, please post on the LabKey help forums, which are read by the authors of this module.<br><br>");
512-
sb.append("<table style='border-collapse: collapse;'>");
513-
514511
String schema = form.getSchemaName() == null ? "" : form.getSchemaName();
515-
sb.append("<tr><td>Schema:</td><td><input name=\"schema\" value=\"" + schema + "\"></td></tr>");
516-
517512
String query = form.getQueryName() == null ? "" : form.getQueryName();
518-
sb.append("<tr><td>Query:</td><td><input name=\"query\" value=\"" + query + "\"></td></tr>");
519-
520-
sb.append("</table><br>Do you want to continue?");
521513

522-
return new HtmlView(sb.toString());
514+
return new HtmlView(createHtmlFragment(
515+
"This allows you to initialize the autoincrementing column for the provided schema/query", BR(), BR(),
516+
"This is very rarely required and was created as a helper for admins with a good deal of knowledge about this module. Under most cases these columns will be automatically populated and you will not need to worry about this. If you are unsure about this page, please post on the LabKey help forums, which are read by the authors of this module.", BR(), BR(),
517+
TABLE(at(style, "border-collapse: collapse;"),
518+
TR(TD("Schema:"), TD(INPUT(at().name("schema").value(schema)))),
519+
TR(TD("Query:"), TD(INPUT(at().name("query").value(query))))
520+
),
521+
BR(), "Do you want to continue?"
522+
));
523523
}
524524

525525

@@ -578,7 +578,8 @@ public void validateCommand(Object form, Errors errors)
578578
@Override
579579
public ModelAndView getConfirmView(Object form, BindException errors) throws Exception
580580
{
581-
return new HtmlView("This action will reset webparts and tabs for the current folder and all children to the default Laboratory FolderType, if these folders are either Laboratory Folders or Expt Workbooks");
581+
HtmlString message = HtmlString.of("This action will reset webparts and tabs for the current folder and all children to the default Laboratory FolderType, if these folders are either Laboratory Folders or Expt Workbooks");
582+
return new HtmlView(message);
582583
}
583584

584585
@Override

0 commit comments

Comments
 (0)