package org.camunda.bpm.getstarted.chargedata; import java.util.Collections; import java.util.logging.Logger; import org.camunda.bpm.client.ExternalTaskClient; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Types; public class NVerifyIfDataExistWorker { private final static Logger LOGGER = Logger.getLogger(NVerifyIfDataExistWorker.class.getName()); private final static String DB_URL = "jdbc:sqlserver://localhost;databaseName=BikeStores;integratedSecurity=true;"; public static void main(String[] args) { // TODO Auto-generated method stub try (Connection con = DriverManager.getConnection(DB_URL);CallableStatement cstmt = con.prepareCall("{call spVerifyTheExistenceOfTheData(?, ?)}");) { LOGGER.info("Connection à la base de donnée réussie"); ExternalTaskClient client = ExternalTaskClient.create() .baseUrl("http://localhost:8080/engine-rest") .asyncResponseTimeout(50000) // long polling timeout .build(); LOGGER.info("Création du client dans le système réussie"); // subscribe to an external task topic as specified in the process client.subscribe("t-verify-îf-data-exist") .lockDuration(10000) // the default lock duration is 20 seconds, but you can override this .handler((externalTask, externalTaskService) -> { // Put your business logic here System.out.println("inscription au topic de tâche externe en cours \n exécution de la tâche"); LOGGER.info("inscription àau topic de tâche externe en cours"); LOGGER.info("exécution de la tâche"); // Get a process variable int Category_Id = (int) externalTask.getVariable("Category_Id"); String Category_Name = (String) externalTask.getVariable("Category_Name"); LOGGER.info("vérification de l'existance de la donnée '"+ Category_Name +"' avec l'ID '" + Category_Id + "'à ajouter"); Boolean Exist = false; try { cstmt.setInt(1, Category_Id); cstmt.registerOutParameter(2, Types.BOOLEAN); cstmt.execute(); Exist = cstmt.getBoolean(2); } catch (SQLException e) { e.printStackTrace(); } if (Exist) { LOGGER.info("la categorie "+ Category_Name +" avec la valeur d'ID "+ Category_Id +" existe" ); } else { LOGGER.info("la categorie "+ Category_Name +" avec la valeur d'ID "+ Category_Id +" n'existe pas" ); } System.out.println(Exist.TYPE.getTypeName()); externalTaskService.complete(externalTask, Collections.singletonMap("Exist", Exist)); }) .open(); } // Handle any errors that may have occurred. catch (SQLException e) { e.printStackTrace(); } } }