added check for no-image and add placeholder
This commit is contained in:
parent
417aee9cc1
commit
f2f941f4d6
1 changed files with 32 additions and 15 deletions
|
@ -22,7 +22,6 @@ public class Speaker_MongoDB_Impl extends Speaker implements MongoOperations<Spe
|
|||
this.setName(mongoDocument.getString("name"));
|
||||
this.setFirstName(mongoDocument.getString("firstName"));
|
||||
this.setTitle(mongoDocument.getString("title"));
|
||||
Logger.debug("First part parsed succesfully");
|
||||
this.setGeburtsdatum(parseTimestampSafely(mongoDocument.getDate("geburtsdatum")));
|
||||
this.setGeburtsort(mongoDocument.getString("geburtsort"));
|
||||
this.setSterbedatum(parseTimestampSafely(mongoDocument.getDate("sterbedatum")));
|
||||
|
@ -53,7 +52,6 @@ public class Speaker_MongoDB_Impl extends Speaker implements MongoOperations<Spe
|
|||
|
||||
public LocalDate parseTimestampSafely(Date timestamp) {
|
||||
try {
|
||||
Logger.debug("Parsing timestamp: " + timestamp);
|
||||
return LocalDate.parse(timestamp.toString());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
@ -96,33 +94,52 @@ public class Speaker_MongoDB_Impl extends Speaker implements MongoOperations<Spe
|
|||
|
||||
public String toTeX() {
|
||||
// Save image to file
|
||||
File outputFile = null;
|
||||
byte[] imageBytes = null;
|
||||
// Decode the Base64 string to a byte array
|
||||
byte[] imageBytes = Base64.getDecoder().decode(getMemberPhoto(this.getId()));
|
||||
try {
|
||||
imageBytes = Base64.getDecoder().decode(getMemberPhoto(this.getId()));
|
||||
|
||||
// Define the output PNG file
|
||||
File outputFile = new File(TEMP_EXPORT_DIR + "speaker_photo_" + this.getId() + ".png");
|
||||
// check if imageBytes is empty
|
||||
if (imageBytes.length != 0) {
|
||||
// Define the output PNG file
|
||||
outputFile = new File(TEMP_EXPORT_DIR + "speaker_photo_" + this.getId() + ".png");
|
||||
|
||||
// Write the decoded byte array to the file
|
||||
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
|
||||
fos.write(imageBytes);
|
||||
System.out.println("PNG file has been saved successfully.");
|
||||
} catch (IOException e) {
|
||||
Logger.error("Failed to save member PNG file.");
|
||||
Logger.error(e.getMessage());
|
||||
// Write the decoded byte array to the file
|
||||
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
|
||||
fos.write(imageBytes);
|
||||
System.out.println("PNG file has been saved successfully.");
|
||||
} catch (IOException e) {
|
||||
Logger.error("Failed to save member PNG file.");
|
||||
Logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.warn("Failed to decode member photo. Maybe its missing from the DB?");
|
||||
Logger.debug(Arrays.toString(e.getStackTrace()));
|
||||
}
|
||||
|
||||
// Spkeaer metadata LaTeX code with image, Full Name + title, party, religion, dob, dod, pob, gender, ID
|
||||
StringBuilder tex = new StringBuilder();
|
||||
// image on the left, metadata on the right
|
||||
tex.append("\\begin{minipage}{0.5\\textwidth}\n");
|
||||
tex.append("\\includegraphics[width=0.5\\textwidth]{").append(outputFile.getName()).append("}\n");
|
||||
Logger.pink(String.valueOf(outputFile));
|
||||
if (imageBytes != null) {
|
||||
tex.append("\\includegraphics[width=0.5\\textwidth]{").append("speaker_photo_" + this.getId() + ".png").append("}\n");
|
||||
} else {
|
||||
tex.append("(No image available)\n");
|
||||
}
|
||||
tex.append("\\end{minipage}\n");
|
||||
tex.append("\\begin{minipage}{0.5\\textwidth}\n");
|
||||
tex.append("\\begin{tabular}{r l}\n");
|
||||
tex.append("Name & ").append(this.getTitle()).append(" ").append(this.getFirstName()).append(" ").append(this.getName()).append("\\\\\n");
|
||||
tex.append("Fraktion & ").append(this.getParty()).append("\\\\\n");
|
||||
tex.append("Religion & ").append(this.getReligion()).append("\\\\\n");
|
||||
tex.append("Geburtsdatum & ").append(this.getGeburtsdatum()).append("\\\\\n");
|
||||
if (this.getReligion() != null) {
|
||||
tex.append("Religion & ").append(this.getSterbedatum()).append("\\\\\n"); // only show if available
|
||||
}
|
||||
if (this.getGeburtsdatum() != null) {
|
||||
tex.append("Geburtsdatum & ").append(this.getGeburtsdatum()).append("\\\\\n");
|
||||
}
|
||||
if (this.getSterbedatum() != null) {
|
||||
tex.append("Sterbedatum & ").append(this.getSterbedatum()).append("\\\\\n"); // only show if available
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue