cleanup and unit tests
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -45,7 +45,6 @@ public class PdfUtils {
|
||||
|
||||
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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -44,11 +44,8 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
||||
assertEquals(3, customerCount());
|
||||
assertEquals(5, pictureCount());
|
||||
|
||||
//String authorization = getBasicHeader();
|
||||
//LOG.info("authorization: " + authorization);
|
||||
String path = deploymentURL + PATH;
|
||||
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);
|
||||
|
||||
HttpResponse httpResponse = executeRequest(request);
|
||||
@@ -102,22 +99,6 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
||||
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
|
||||
@Order(2)
|
||||
public void doTest() throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user