cleanup and unit tests

This commit is contained in:
verboomp
2026-02-03 12:27:56 +01:00
parent e3d7716133
commit c78560ac3a
5 changed files with 16 additions and 33 deletions

View File

@@ -31,10 +31,10 @@ public class ImageUtil {
private static final Log LOG = LogFactory.getLog(ImageUtil.class);
private static final int NORMAL_MAX_WIDTH = 1200;
private static final float NORMAL_QUALITY = 0.75f;
private static final float NORMAL_QUALITY = 0.75F;
private static final int THUMBNAIL_MAX_WIDTH = 200;
private static final float THUMBNAIL_QUALITY = 0.6f;
private static final float THUMBNAIL_QUALITY = 0.6F;
/**
* size 1 is original
@@ -68,7 +68,6 @@ public class ImageUtil {
}
int originalWidth = image.getWidth();
int originalHeight = image.getHeight();
if (originalWidth <= maxWidth) {
return original;
@@ -76,6 +75,7 @@ public class ImageUtil {
double scale = (double) maxWidth / originalWidth;
int targetWidth = maxWidth;
int originalHeight = image.getHeight();
int targetHeight = (int) (originalHeight * scale);
BufferedImage resized = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);

View File

@@ -33,7 +33,7 @@ import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
*
* created: 2 Feb 2026
*/
@SuppressWarnings({"java:S818", "squid:S818", "squid:S109"})
@SuppressWarnings({ "java:S818", "squid:S818", "squid:S109" })
public class PdfUtils {
private static final Log LOG = LogFactory.getLog(PdfUtils.class);
@@ -42,10 +42,9 @@ public class PdfUtils {
private static final Color COLOR_CUSTOMER_NAME = new Color(0x00, 0x45, 0xFF);
private static final Color COLOR_DATE = new Color(0x00, 0x16, 0x89);
private static final Color COLOR_TEXT_GRAY = new Color(0x2F, 0x2F, 0x2F);
private static final Color COLOR_GREEN = new Color(76, 175, 80);
private static final Color COLOR_YELLOW = new Color(255, 193, 7);
private static final Color COLOR_RED = new Color(244, 67, 54);
@@ -114,7 +113,7 @@ public class PdfUtils {
float rightY = imageY - 32F;
// Date (no label, bold, size 44)
String dateStr = picture.getPictureDate() != null ? DATE_FORMAT.format(picture.getPictureDate()) + " UHR": "";
String dateStr = picture.getPictureDate() != null ? (DATE_FORMAT.format(picture.getPictureDate()) + " UHR") : "";
cs.setFont(fontBold, 32);
cs.setNonStrokingColor(COLOR_DATE);
cs.beginText();
@@ -202,7 +201,7 @@ public class PdfUtils {
float currentY = y;
for (String word : words) {
String testLine = line.isEmpty() ? word : line + " " + word;
String testLine = line.isEmpty() ? word : (line + " " + word);
float textWidth = font.getStringWidth(testLine) / 1000F * 10F;
if (textWidth > maxWidth && !line.isEmpty()) {
cs.beginText();

View File

@@ -22,9 +22,12 @@ public record PictureValue(Long id, String comment, String category, Date pictur
if (picture == null) {
return null;
}
String imageUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=1";
String normalSizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=2";
String thumbnailSizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=3";
String sizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=";
String imageUrl = sizeUrl + "1";
String normalSizeUrl = sizeUrl + "2";
String thumbnailSizeUrl = sizeUrl + "3";
return new PictureValue(picture.getPictureId(), picture.getComment(), picture.getCategory(), picture.getPictureDate(), picture.getUsername(), picture.getEvaluation(), imageUrl, normalSizeUrl, thumbnailSizeUrl);
}
}

View File

@@ -164,7 +164,7 @@ class ImageUtilTest {
// --- Output format ---
@Test
void getImage_size2_outputIsJpeg() throws IOException {
void getImage_size2_outputIsJpeg() {
String base64 = createTestImageBase64(2400, 1600);
byte[] result = imageUtil.getImage(base64, 2);
@@ -176,7 +176,7 @@ class ImageUtilTest {
}
@Test
void getImage_size3_outputIsJpeg() throws IOException {
void getImage_size3_outputIsJpeg() {
String base64 = createTestImageBase64(2400, 1600);
byte[] result = imageUtil.getImage(base64, 3);