Skip to content

Commit

Permalink
chore: reliability sonar fix (#90)
Browse files Browse the repository at this point in the history
* chore: reliability sonar fix

* chore: some cognitive complexity + maintainability fixes

* chore: new sonar warnings fix

* chore: sonarqube button layout warning fix

* chore: more maintainability fixes

* chore: regex & foreach fixes

* chore: proper regex

---------

Co-authored-by: Sergey Grigoriev <sergey.grigoriev@sbb.ch>
  • Loading branch information
Jumas and grigoriev authored Jul 17, 2024
1 parent e561df7 commit b138fa4
Show file tree
Hide file tree
Showing 20 changed files with 398 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public HtmlProcessor(FileResourceProvider fileResourceProvider, LocalizationSett

public String processHtmlForPDF(@NotNull String html, @NotNull ExportParams exportParams, @NotNull List<String> selectedRoleEnumValues) {
// Replace all dollar-characters in HTML document before applying any regular expressions, as it has special meaning there
html = html.replaceAll("\\$", "&dollar;");
html = html.replace("$", "&dollar;");

html = removePd4mlTags(html);
html = html.replace("/ria/images/enums/", "/icons/default/enums/");
Expand Down Expand Up @@ -823,36 +823,46 @@ public String adjustImageSize(@NotNull String html, @NotNull Orientation orienta
float maxWidth = orientation == Orientation.PORTRAIT ? MAX_PORTRAIT_WIDTHS.get(paperSize) : MAX_LANDSCAPE_WIDTHS.get(paperSize);
float maxHeight = orientation == Orientation.PORTRAIT ? MAX_PORTRAIT_HEIGHTS.get(paperSize) : MAX_LANDSCAPE_HEIGHTS.get(paperSize);

float width = Float.parseFloat(regexEngine.group(WIDTH));
if (MEASURE_EX.equals(regexEngine.group(MEASURE_WIDTH))) {
width = width * EX_TO_PX_RATIO;
}
float height = Float.parseFloat(regexEngine.group(HEIGHT));
if (MEASURE_EX.equals(regexEngine.group(MEASURE_HEIGHT))) {
height = height * EX_TO_PX_RATIO;
}
float width = parseDimension(regexEngine, WIDTH, MEASURE_WIDTH);
float height = parseDimension(regexEngine, HEIGHT, MEASURE_HEIGHT);

float widthExceedingRatio = width / maxWidth;
float heightExceedingRatio = height / maxHeight;
if (widthExceedingRatio > 1 || heightExceedingRatio > 1) {
String prepend = regexEngine.group("prepend");
String append = regexEngine.group("append");
final float adjustedWidth;
final float adjustedHeight;
if (widthExceedingRatio > heightExceedingRatio) {
adjustedWidth = width / widthExceedingRatio;
adjustedHeight = height / widthExceedingRatio;
} else {
adjustedWidth = width / heightExceedingRatio;
adjustedHeight = height / heightExceedingRatio;
}
return "<img" + prepend + "width: " + ((int) adjustedWidth) + "px; height: " + ((int) adjustedHeight) + "px" + append + ">";
} else {
return null;
}
String prepend = regexEngine.group("prepend");
String append = regexEngine.group("append");

return generateAdjustedImageTag(prepend, append, width, height, maxWidth, maxHeight);
});
}

private float parseDimension(IRegexEngine regexEngine, String dimension, String measure) {
float value = Float.parseFloat(regexEngine.group(dimension));
if (MEASURE_EX.equals(regexEngine.group(measure))) {
value *= EX_TO_PX_RATIO;
}
return value;
}

private String generateAdjustedImageTag(String prepend, String append, float width, float height, float maxWidth, float maxHeight) {
float widthExceedingRatio = width / maxWidth;
float heightExceedingRatio = height / maxHeight;

if (widthExceedingRatio <= 1 && heightExceedingRatio <= 1) {
return null;
}

final float adjustedWidth;
final float adjustedHeight;

if (widthExceedingRatio > heightExceedingRatio) {
adjustedWidth = width / widthExceedingRatio;
adjustedHeight = height / widthExceedingRatio;
} else {
adjustedWidth = width / heightExceedingRatio;
adjustedHeight = height / heightExceedingRatio;
}

return "<img" + prepend + "width: " + ((int) adjustedWidth) + "px; height: " + ((int) adjustedHeight) + "px" + append + ">";
}

@NotNull
@VisibleForTesting
public String adjustTableSize(@NotNull String html, @NotNull Orientation orientation, @NotNull PaperSize paperSize) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/default/cover-page/English/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</div>
<div id="bottom">
<table>
<tr><th></th><th>Created</th><th>Checked</th><th>Released</th></tr>
<tr><th>Name</th><td>{{ docCreatedBy }}</td><td>{{ docCheckedBy }}</td><td>{{ docReleasedBy }}</td></tr>
<tr><th>Date</th><td>{{ docCreationDate }}</td><td>{{ docCheckDate }}</td><td>{{ docReleaseDate }}</td></tr>
<tr><th scope="col"></th><th scope="col">Created</th><th scope="col">Checked</th><th scope="col">Released</th></tr>
<tr><th scope="row">Name</th><td>{{ docCreatedBy }}</td><td>{{ docCheckedBy }}</td><td>{{ docReleasedBy }}</td></tr>
<tr><th scope="row">Date</th><td>{{ docCreationDate }}</td><td>{{ docCheckDate }}</td><td>{{ docReleaseDate }}</td></tr>
</table>
</div>
</article>
6 changes: 3 additions & 3 deletions src/main/resources/default/cover-page/German/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</div>
<div id="bottom">
<table>
<tr><th></th><th>Erstellt</th><th>Geprüft</th><th>Freigegeben</th></tr>
<tr><th>Name</th><td>{{ docCreatedBy }}</td><td>{{ docCheckedBy }}</td><td>{{ docReleasedBy }}</td></tr>
<tr><th>Datum</th><td>{{ docCreationDate }}</td><td>{{ docCheckDate }}</td><td>{{ docReleaseDate }}</td></tr>
<tr><th scope="col"></th><th scope="col">Erstellt</th><th scope="col">Geprüft</th><th scope="col">Freigegeben</th></tr>
<tr><th scope="row">Name</th><td>{{ docCreatedBy }}</td><td>{{ docCheckedBy }}</td><td>{{ docReleasedBy }}</td></tr>
<tr><th scope="row">Datum</th><td>{{ docCreationDate }}</td><td>{{ docCheckDate }}</td><td>{{ docReleaseDate }}</td></tr>
</table>
</div>
</article>
7 changes: 1 addition & 6 deletions src/main/resources/default/dle-pdf-export.css
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ pre {
background-color: #ccffcc;
}

tr:over {
tr:hover {
background-color: #ccffcc;
border: 2px;
border-style: dashed;
Expand Down Expand Up @@ -872,11 +872,6 @@ li span {
.header-footer-center {
max-width: 30%;
text-align: center;
/* display: flex;
flex: 0 0 auto;
justify-content: center;
align-items: center;
*/
}

.header-footer-right {
Expand Down
Loading

0 comments on commit b138fa4

Please sign in to comment.