feat: add affiliation pdf generator
This commit is contained in:
@@ -33,12 +33,15 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static fr.titionfire.ffsaf.domain.service.ClubService.getPdf;
|
||||
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
@@ -506,6 +509,7 @@ public class MembreService {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
cmd.add("/tmp/" + uuid + ".pdf");
|
||||
cmd.add("membre");
|
||||
cmd.add(m.getFname());
|
||||
cmd.add(m.getLname());
|
||||
cmd.add(m.getGenre().str);
|
||||
@@ -526,50 +530,6 @@ public class MembreService {
|
||||
cmd.add("/dev/null");
|
||||
}
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
|
||||
processBuilder.redirectErrorStream(true);
|
||||
Process process = processBuilder.start();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
builder.append(line).append("\n");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
int code = -1;
|
||||
if (!process.waitFor(30, TimeUnit.SECONDS)) {
|
||||
process.destroy();
|
||||
builder.append("Timeout...");
|
||||
} else {
|
||||
code = process.exitValue();
|
||||
}
|
||||
|
||||
if (t.isAlive())
|
||||
t.interrupt();
|
||||
|
||||
LOGGER.debug("PDF maker: " + builder);
|
||||
|
||||
if (code != 0) {
|
||||
throw new IOException("Error code: " + code);
|
||||
} else {
|
||||
File file = new File("/tmp/" + uuid + ".pdf");
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
byte[] buff = fis.readAllBytes();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
return buff;
|
||||
} catch (IOException e) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return getPdf(cmd, uuid, LOGGER);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user