|
|
@@ -15,6 +15,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+
|
|
|
import es.uv.saic.shared.domain.Document;
|
|
|
import es.uv.saic.shared.domain.Email;
|
|
|
import es.uv.saic.shared.domain.EvidenciaTransfer;
|
|
|
@@ -314,9 +317,85 @@ public class InstanciaTascaService {
|
|
|
it.setEstat("E");
|
|
|
this.saveChanges(user, it);
|
|
|
}
|
|
|
+ else if(tipus == 23){ /* Generate final evidence */
|
|
|
+
|
|
|
+ /*
|
|
|
+ JSON de ejemplo para el campo opcions
|
|
|
+ {
|
|
|
+ "accions": [
|
|
|
+ { "select_from": [1, 3] },
|
|
|
+ { "select_from": [2, 4] },
|
|
|
+ { "select_from": [5] },
|
|
|
+ { "combine": true }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+
|
|
|
+ JsonNode root = mapper.readTree(it.getTasca().getOpcions());
|
|
|
+ JsonNode actions = root.get("accions");
|
|
|
+
|
|
|
+ List<String> selectedPaths = new ArrayList<>();
|
|
|
+ String outputFile = this.filePath + it.getIdInstanciaTasca().toString() + ".pdf";
|
|
|
+ boolean success = false;
|
|
|
+
|
|
|
+ for (JsonNode action : actions) {
|
|
|
+ if (action.has("select_from")) {
|
|
|
+ List<Integer> values = new ArrayList<>();
|
|
|
+ for (JsonNode value : action.get("select_from")) {
|
|
|
+ values.add(value.asInt());
|
|
|
+ }
|
|
|
+ InstanciaTasca itaux = instanciaTascaRepository.getValidFromIdTascaps(values);
|
|
|
+ String selectedPath = itaux.getEvidencia();
|
|
|
+ if (selectedPath != null && !selectedPath.isEmpty()) {
|
|
|
+ selectedPaths.add(this.filePath + selectedPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (action.has("combine") && action.get("combine").asBoolean()) {
|
|
|
+ success = combineDocuments(selectedPaths, outputFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(success){
|
|
|
+ it.setEvidencia(outputFile);
|
|
|
+ it.setEstat("E");
|
|
|
+ this.saveChanges(user, it);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return it;
|
|
|
}
|
|
|
+
|
|
|
+ public boolean combineDocuments(List<String> inputPaths, String outputPath){
|
|
|
+ List<String> cmd = new ArrayList<String>();
|
|
|
+ cmd.add("pdfunite");
|
|
|
+ for(String path : inputPaths) {
|
|
|
+ cmd.add(path);
|
|
|
+ }
|
|
|
+ cmd.add(outputPath);
|
|
|
+
|
|
|
+ ProcessBuilder builder = new ProcessBuilder();
|
|
|
+ builder.command(cmd.toArray(new String[]{}));
|
|
|
+ try {
|
|
|
+ Process process = builder.start();
|
|
|
+ process.waitFor();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ if (Thread.interrupted()) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void saveChanges(Usuari user, InstanciaTasca it) {
|
|
|
|