private void doTheMainTask() throws CannotSendContractHashException, CantUpdateRecordException { try { openContractBusinessTransactionDao = new OpenContractBusinessTransactionDao(pluginDatabaseSystem, pluginId, database); /** Check if exist in database new contracts to send */ List<String> contractPendingToSubmitList = openContractBusinessTransactionDao.getPendingToSubmitContractHash(); String contractXML; ContractPurchaseRecord purchaseContract = new ContractPurchaseRecord(); ContractSaleRecord saleContract = new ContractSaleRecord(); ContractType contractType; UUID transactionId; if (!contractPendingToSubmitList.isEmpty()) { for (String hashToSubmit : contractPendingToSubmitList) { System.out.println("OPEN CONTRACT - Hash to submit:\n" + hashToSubmit); contractXML = openContractBusinessTransactionDao.getContractXML(hashToSubmit); contractType = openContractBusinessTransactionDao.getContractType(hashToSubmit); transactionId = openContractBusinessTransactionDao.getTransactionId(hashToSubmit); switch (contractType) { case PURCHASE: purchaseContract = (ContractPurchaseRecord) XMLParser.parseXML(contractXML, purchaseContract); transactionTransmissionManager.sendContractHashToCryptoBroker( transactionId, purchaseContract.getPublicKeyCustomer(), purchaseContract.getPublicKeyBroker(), hashToSubmit, purchaseContract.getNegotiationId()); break; case SALE: saleContract = (ContractSaleRecord) XMLParser.parseXML(contractXML, saleContract); transactionTransmissionManager.sendContractHashToCryptoCustomer( transactionId, saleContract.getPublicKeyBroker(), saleContract.getPublicKeyCustomer(), hashToSubmit, saleContract.getNegotiationId()); break; } // Update the ContractTransactionStatus openContractBusinessTransactionDao.updateContractTransactionStatus( hashToSubmit, ContractTransactionStatus.CHECKING_HASH); } } /** Check if pending contract to confirm */ List<String> contractPendingToConfirmList = openContractBusinessTransactionDao.getPendingToConfirmContractHash(); if (!contractPendingToConfirmList.isEmpty()) { for (String hashToSubmit : contractPendingToSubmitList) { System.out.println("OPEN CONTRACT - Hash to confirm:\n" + hashToSubmit); contractXML = openContractBusinessTransactionDao.getContractXML(hashToSubmit); contractType = openContractBusinessTransactionDao.getContractType(hashToSubmit); switch (contractType) { case PURCHASE: purchaseContract = (ContractPurchaseRecord) XMLParser.parseXML(contractXML, purchaseContract); transactionTransmissionManager.sendTransactionNewStatusNotification( purchaseContract.getPublicKeyCustomer(), purchaseContract.getPublicKeyBroker(), hashToSubmit, ContractTransactionStatus.CONTRACT_CONFIRMED); break; case SALE: saleContract = (ContractSaleRecord) XMLParser.parseXML(contractXML, saleContract); transactionTransmissionManager.sendTransactionNewStatusNotification( purchaseContract.getPublicKeyBroker(), purchaseContract.getPublicKeyCustomer(), hashToSubmit, ContractTransactionStatus.CONTRACT_CONFIRMED); break; } // Update the ContractTransactionStatus openContractBusinessTransactionDao.updateContractTransactionStatus( hashToSubmit, ContractTransactionStatus.CONTRACT_CONFIRMED); } } /** Check if pending events */ List<String> pendingEventsIdList = openContractBusinessTransactionDao.getPendingEvents(); for (String eventId : pendingEventsIdList) { checkPendingEvent(eventId); } } catch (CantGetContractListException e) { throw new CannotSendContractHashException( e, "Sending contract hash", "Cannot get the contract list from database"); } catch (UnexpectedResultReturnedFromDatabaseException e) { throw new CannotSendContractHashException( e, "Sending contract hash", "Unexpected result in database"); } catch (CantSendBusinessTransactionHashException e) { throw new CannotSendContractHashException( e, "Sending contract hash", "Error in Transaction Transmission Network Service"); } }