nosi.core.webapp.bpmn.BPMNHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of igrp-core Show documentation
Show all versions of igrp-core Show documentation
IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.
package nosi.core.webapp.bpmn;
import nosi.core.gui.components.IGRPLink;
import nosi.core.webapp.Core;
import nosi.core.webapp.Igrp;
import nosi.core.webapp.activit.rest.business.ProcessDefinitionIGRP;
import nosi.core.webapp.activit.rest.entities.HistoricTaskService;
import nosi.core.webapp.activit.rest.entities.ProcessDefinitionService;
import nosi.core.webapp.activit.rest.entities.TaskService;
import nosi.core.webapp.activit.rest.services.ResourceServiceRest;
import nosi.core.webapp.activit.rest.services.TaskServiceRest;
import nosi.core.webapp.helpers.DateHelper;
import nosi.core.webapp.helpers.FileHelper;
import nosi.core.xml.XMLWritter;
import nosi.webapps.igrp.dao.ActivityExecute;
import nosi.webapps.igrp.dao.RepTemplateSource;
import nosi.webapps.igrp.dao.TaskFile;
import nosi.webapps.igrp.dao.TipoDocumentoEtapa;
import nosi.webapps.igrp_studio.pages.bpmndesigner.ReserveCodeControllerTask;
import java.util.*;
import static nosi.core.i18n.Translator.gt;
/**
* Emanuel
* 7 May 2018
*/
public final class BPMNHelper {
private BPMNHelper() {}
public static String getGenerateXML(String app,String process_key,String task_key,String form_key,String path) {
XMLWritter xml = new XMLWritter();
ReserveCodeControllerTask resevreCode = new ReserveCodeControllerTask();
resevreCode.extract(FileHelper.readFile(path, task_key+"Controller.java"));
xml.startElement("rows");
xml.setElement("process_key", process_key);
xml.setElement("task_key", task_key);
xml.setElement("app", app);
xml.setElement("page", form_key!=null?form_key.toLowerCase():"");
xml.setElement("form_key", form_key);
xml.setElement("user_name", Core.getCurrentUser().getEmail());
xml.setElement("data_created", Core.getCurrentDate());
xml.setElement("reserve_import",resevreCode.getReserveCodeImports());
xml.setElement("reserve_index", resevreCode.getReserveCodeActionIndex());
xml.setElement("reserve_save", resevreCode.getReserveCodeActionSave());
xml.setElement("reserve_update", resevreCode.getReserveCodeActionUpdate());
xml.setElement("reserve_customs", resevreCode.getReserveCodeCustomActions());
xml.endElement();
return xml.toString();
}
public static Object getValue(String type,String name){
Object value = Igrp.getInstance().getRequest().getParameter("p_"+name.toLowerCase());
try {
switch (type.toLowerCase()) {
case "date":
return DateHelper.convertDate(value.toString(), "dd-MM-yyyy", "dd-MM-yyyy h:mm");
case "long":
if(Core.isNotNull(value))
return ""+ Long.parseLong(value.toString());
case "double":
if(Core.isNotNull(value))
return ""+Double.parseDouble(value.toString());
case "float":
if(Core.isNotNull(value))
return ""+Float.parseFloat(value.toString());
case "boolean":
return ""+value.toString().equals("1");
case "enum":
case "string":
return value.toString();
default:
return "0";
}
}catch(NullPointerException ignored) {}
return "";
}
//Add file separator, allow to upload your file
public static String addFileSeparator(String taskDad,String processDefinition,String taskDefinition,List history) {
DisplayDocmentType displayDocsInput = new DisplayDocmentType();
List listInOutDoc = getInputOutputDocumentType(taskDad, processDefinition, taskDefinition, history);
displayDocsInput.setListDocmentType(listInOutDoc);
return displayDocsInput.displayAllDocsInSameFormList();
}
public static List getInputOutputDocumentType(String taskDad,String processDefinition,String taskDefinition,List history) {
DisplayDocmentType display = new DisplayDocmentType();
if(history!=null && !history.isEmpty()) {
display.addListDocumentType(getOutputDocumentType(taskDad,history.get(0).getProcessDefinitionId(),taskDefinition));
}else {
display.addListDocumentType(getOutputDocumentType(taskDad,processDefinition,taskDefinition));
}
display.setListDocmentType(getInputDocumentTypeHistory(taskDad,processDefinition, taskDefinition));
return display.getListDocmentType();
}
public static List getInputDocumentTypeHistory(String taskDad,String processDefinition, String taskDefinition) {
List tipoDocsIN = getInputDocumentType(taskDad,processDefinition, taskDefinition);
final var currentTaskId = getCurrentTaskId();
if(tipoDocsIN!=null && !tipoDocsIN.isEmpty()) {
if (RuntimeTask.getRuntimeTask().isDetails()) {
//If details will show the inputed file for this task
tipoDocsIN.forEach(t->{
t.setFileId(-1);
IGRPLink link = new IGRPLink();
if(t.getTipoDocumento() != null) {
TaskFile taskFile = new TaskFile().find()
.where("taskId","=",currentTaskId)
.andWhere("tipo_doc_task.tipoDocumento.id","=",t.getTipoDocumento().getId())
.one();
if(taskFile!=null) {
if(taskFile.getClob().getUuid()!=null)
link.setLink(Core.getLinkFileByUuid(taskFile.getClob().getUuid()));
else
link.setLink(Core.getLinkFile(taskFile.getClob().getId()));
t.setFileId(taskFile.getClob().getId());
t.setUser(taskFile.getClob().getUser().getEmail()+" a "+Core.dateToString(taskFile.getClob().getDt_created(),"dd-MMM-yy"));
}
}
if(t.getRepTemplate()!=null) {
link = new IGRPLink(Core.getLinkReport(t.getRepTemplate().getCode()).addParam(BPMNConstants.PRM_TASK_ID, currentTaskId));
}
link.setLink_desc(gt("Mostrar"));
t.setLink(link);
});
} else {
//will show the last document inputed if exists
final List tasksF = getTaskFiles(tipoDocsIN);
for (TaskFile taskFile : tasksF) {
for (int i=0; i<=tipoDocsIN.size();i++) {
if (Objects.equals(tipoDocsIN.get(i).getTipoDocumento().getId(), taskFile.getTipo_doc_task().getTipoDocumento().getId())) {
IGRPLink link = new IGRPLink();
tipoDocsIN.get(i).setFileId(-1);
if (taskFile.getClob().getUuid() != null)
link.setLink(Core.getLinkFileByUuid(taskFile.getClob().getUuid()));
else
link.setLink(Core.getLinkFile(taskFile.getClob().getId()));
tipoDocsIN.get(i).setFileId(taskFile.getClob().getId());
tipoDocsIN.get(i).setUser(taskFile.getClob().getUser().getEmail()+" a "+Core.dateToString(taskFile.getClob().getDt_created(),"dd-MMM-yy"));
link.setLink_desc(gt("Mostrar"));
tipoDocsIN.get(i).setLink(link);
break;
}
}
}
}
}
return tipoDocsIN;
}
public static List getInputDocumentType(String taskDad, String processDefinition, String taskDefinition){
return new TipoDocumentoEtapa()
.find()
.andWhere("processId", "=",Core.isNotNull(processDefinition)?processDefinition:"-1")
.andWhere("taskId", "=",Core.isNotNull(taskDefinition)?taskDefinition:"-1")
.andWhere("status", "=",1)
.andWhere("tipo", "=","IN")
.andWhere("tipoDocumento.application.dad", "=",taskDad)
.all();
}
private static String getCurrentTaskId() {
String taskId = RuntimeTask.getRuntimeTask().getPreviewTaskId();
if (Core.isNull(taskId))
return RuntimeTask.getRuntimeTask().getTask().getId();
return taskId;
}
public static List getOutputDocumentType(String currentTaskApp, String currentProcessDefinition_,
String currentTaskDefinition) {
String currentProcessDefinition = resolveProcessDenifition(currentProcessDefinition_);
List docsReport = getDocumentOutputReport(currentTaskApp,currentProcessDefinition, currentTaskDefinition);
List docsOthers = getDocumentOutputOthers(currentTaskApp,currentProcessDefinition, currentTaskDefinition);
List tipoDocs = new ArrayList<>();
if(docsReport!=null)
tipoDocs.addAll(docsReport);
if(docsOthers!=null)
tipoDocs.addAll(docsOthers);
return tipoDocs;
}
private static List getDocumentOutputOthers(String taskDad, String processDefinition,
String taskDefinition) {
List tipoDocs = new TipoDocumentoEtapa()
.find()
.andWhere("processId", "=",Core.isNotNull(processDefinition)?processDefinition:"-1")
.andWhere("taskId", "=",Core.isNotNull(taskDefinition)?taskDefinition:"-1")
.andWhere("status", "=", 1)
.andWhere("tipo", "=","OUT")
.andWhere("tipoDocumento", "notnull")
.andWhere("tipoDocumento.application.dad", "=",taskDad)
.all();
if(tipoDocs!=null && !tipoDocs.isEmpty()){
final List tasksF = getTaskFiles(tipoDocs);
for (TaskFile taskFile : tasksF) {
for (int i=0; i<=tipoDocs.size();i++) {
if (Objects.equals(tipoDocs.get(i).getTipoDocumento().getId(), taskFile.getTipo_doc_task().getTipoDocumento().getId())) {
tipoDocs.get(i).setTipo("OUT");
IGRPLink link = new IGRPLink();
tipoDocs.get(i).setFileId(-1);
tipoDocs.get(i).setRequired(taskFile.getTipo_doc_task().getRequired());
if(taskFile.getClob().getUuid()!=null)
link.setLink(Core.getLinkFileByUuid(taskFile.getClob().getUuid()));
else
link.setLink(Core.getLinkFile(taskFile.getClob().getId()));
tipoDocs.get(i).setFileId(taskFile.getClob().getId());
tipoDocs.get(i).setUser(taskFile.getClob().getUser().getEmail()+" a "+Core.dateToString(taskFile.getClob().getDt_created(),"dd-MMM-yy"));
link.setLink_desc(gt("Mostrar"));
tipoDocs.get(i).setLink(link);
break;
}
}
}
}
return tipoDocs;
}
private static List getTaskFiles(List tipoDocs) {
RuntimeTask runtimeTask = RuntimeTask.getRuntimeTask();
Integer[] tpIds = tipoDocs.stream()
.filter(t -> t.getTipoDocumento() != null)
.map(t -> t.getTipoDocumento().getId())
.toArray(Integer[]::new);
List