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 Log LOG = LogFactory.getLog(ImageUtil.class);
private static final int NORMAL_MAX_WIDTH = 1200; 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 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 * size 1 is original
@@ -68,7 +68,6 @@ public class ImageUtil {
} }
int originalWidth = image.getWidth(); int originalWidth = image.getWidth();
int originalHeight = image.getHeight();
if (originalWidth <= maxWidth) { if (originalWidth <= maxWidth) {
return original; return original;
@@ -76,6 +75,7 @@ public class ImageUtil {
double scale = (double) maxWidth / originalWidth; double scale = (double) maxWidth / originalWidth;
int targetWidth = maxWidth; int targetWidth = maxWidth;
int originalHeight = image.getHeight();
int targetHeight = (int) (originalHeight * scale); int targetHeight = (int) (originalHeight * scale);
BufferedImage resized = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); 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 * created: 2 Feb 2026
*/ */
@SuppressWarnings({"java:S818", "squid:S818", "squid:S109"}) @SuppressWarnings({ "java:S818", "squid:S818", "squid:S109" })
public class PdfUtils { public class PdfUtils {
private static final Log LOG = LogFactory.getLog(PdfUtils.class); private static final Log LOG = LogFactory.getLog(PdfUtils.class);
@@ -45,7 +45,6 @@ public class PdfUtils {
private static final Color COLOR_TEXT_GRAY = new Color(0x2F, 0x2F, 0x2F); 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_GREEN = new Color(76, 175, 80);
private static final Color COLOR_YELLOW = new Color(255, 193, 7); private static final Color COLOR_YELLOW = new Color(255, 193, 7);
private static final Color COLOR_RED = new Color(244, 67, 54); private static final Color COLOR_RED = new Color(244, 67, 54);
@@ -114,7 +113,7 @@ public class PdfUtils {
float rightY = imageY - 32F; float rightY = imageY - 32F;
// Date (no label, bold, size 44) // 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.setFont(fontBold, 32);
cs.setNonStrokingColor(COLOR_DATE); cs.setNonStrokingColor(COLOR_DATE);
cs.beginText(); cs.beginText();
@@ -202,7 +201,7 @@ public class PdfUtils {
float currentY = y; float currentY = y;
for (String word : words) { 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; float textWidth = font.getStringWidth(testLine) / 1000F * 10F;
if (textWidth > maxWidth && !line.isEmpty()) { if (textWidth > maxWidth && !line.isEmpty()) {
cs.beginText(); cs.beginText();

View File

@@ -22,9 +22,12 @@ public record PictureValue(Long id, String comment, String category, Date pictur
if (picture == null) { if (picture == null) {
return null; return null;
} }
String imageUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=1";
String normalSizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=2"; String sizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=";
String thumbnailSizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=3";
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); 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 --- // --- Output format ---
@Test @Test
void getImage_size2_outputIsJpeg() throws IOException { void getImage_size2_outputIsJpeg() {
String base64 = createTestImageBase64(2400, 1600); String base64 = createTestImageBase64(2400, 1600);
byte[] result = imageUtil.getImage(base64, 2); byte[] result = imageUtil.getImage(base64, 2);
@@ -176,7 +176,7 @@ class ImageUtilTest {
} }
@Test @Test
void getImage_size3_outputIsJpeg() throws IOException { void getImage_size3_outputIsJpeg() {
String base64 = createTestImageBase64(2400, 1600); String base64 = createTestImageBase64(2400, 1600);
byte[] result = imageUtil.getImage(base64, 3); byte[] result = imageUtil.getImage(base64, 3);

View File

@@ -44,11 +44,8 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
assertEquals(3, customerCount()); assertEquals(3, customerCount());
assertEquals(5, pictureCount()); assertEquals(5, pictureCount());
//String authorization = getBasicHeader();
//LOG.info("authorization: " + authorization);
String path = deploymentURL + PATH; String path = deploymentURL + PATH;
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8") Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
//.addHeader("Authorization", authorization)
.bodyFile(new File(BASE_UPLOAD + "add.json"), ContentType.APPLICATION_JSON); .bodyFile(new File(BASE_UPLOAD + "add.json"), ContentType.APPLICATION_JSON);
HttpResponse httpResponse = executeRequest(request); HttpResponse httpResponse = executeRequest(request);
@@ -102,22 +99,6 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
System.out.println(text); System.out.println(text);
} }
/*
@Test
@Order(1)
public void doAddCustomerPictureNoAuth() throws IOException {
LOG.info("doAddCustomerPictureNoAuth");
String path = deploymentURL + PATH;
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
.bodyFile(new File(BASE_UPLOAD + "add.json"), ContentType.APPLICATION_JSON);
HttpResponse httpResponse = executeRequest(request);
int code = httpResponse.getStatusLine().getStatusCode();
assertEquals(401, code);
}
*/
@Test @Test
@Order(2) @Order(2)
public void doTest() throws IOException { public void doTest() throws IOException {