@Override
 public Language getLanguageFromXmlString(String languageStructure)
     throws CantGetLanguageException {
   try {
     Language language = new Language();
     language = (Language) XMLParser.parseXML(languageStructure, language);
     return language;
   } catch (Exception e) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         e);
     throw new CantGetLanguageException(
         CantGetLanguageException.DEFAULT_MESSAGE, e, "Cant get language", "");
   }
 }
 /**
  * i get the path and name of the file and i load it
  *
  * @param walletLanguage of the language you're trying to get
  * @return language class structure
  * @throws CantGetLanguageException
  * @throws LanguageNotFoundException
  */
 @Override
 public Language getLanguage(WalletLanguage walletLanguage)
     throws CantGetLanguageException, LanguageNotFoundException {
   if (walletLanguage != null) {
     try {
       String languageFileName = getLanguageFileName(walletLanguage);
       PluginTextFile pluginTextFile =
           pluginFileSystem.getTextFile(
               pluginId,
               WALLET_LANGUAGES_PATH,
               languageFileName,
               FilePrivacy.PRIVATE,
               FileLifeSpan.PERMANENT);
       pluginTextFile.loadFromMedia();
       String xml = pluginTextFile.getContent();
       Language language = new Language();
       language = (Language) XMLParser.parseXML(xml, language);
       return language;
     } catch (CantCreateFileException | CantLoadFileException e) {
       errorManager.reportUnexpectedPluginException(
           Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE,
           UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
           e);
       throw new CantGetLanguageException(
           CantGetLanguageException.DEFAULT_MESSAGE, e, "Cant get language", "");
     } catch (FileNotFoundException e) {
       errorManager.reportUnexpectedPluginException(
           Plugins.BITDUBAI_WALLET_LANGUAGE_MIDDLEWARE,
           UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
           e);
       throw new LanguageNotFoundException(
           LanguageNotFoundException.DEFAULT_MESSAGE, e, "Language not found.", "");
     }
   } else {
     throw new CantGetLanguageException(
         CantGetLanguageException.DEFAULT_MESSAGE, null, "Wallet Language is null.", "");
   }
 }
  /**
   * (non-javadoc)
   *
   * @see FermatMessageProcessor#processingMessage(FermatMessage, JsonObject)
   */
  @Override
  public void processingMessage(FermatMessage fermatMessage, JsonObject jsonMsjContent) {

    try {

      /*
       * Get the XML representation of the Digital Asset Metadata
       */
      String digitalAssetMetadataXml =
          jsonMsjContent.get(AssetTransmissionJsonAttNames.DIGITAL_ASSET_METADATA).getAsString();
      PlatformComponentType senderType =
          gson.fromJson(
              jsonMsjContent.get(AssetTransmissionJsonAttNames.SENDER_TYPE).getAsString(),
              PlatformComponentType.class);
      PlatformComponentType receiverType =
          gson.fromJson(
              jsonMsjContent.get(AssetTransmissionJsonAttNames.RECEIVER_TYPE).getAsString(),
              PlatformComponentType.class);

      /*
       * Convert the xml to object
       */
      DigitalAssetMetadata digitalAssetMetadata =
          (DigitalAssetMetadata)
              XMLParser.parseXML(digitalAssetMetadataXml, new DigitalAssetMetadata());

      /*
       * Construct a new digitalAssetMetadataTransaction
       */
      DigitalAssetMetadataTransactionImpl digitalAssetMetadataTransaction =
          new DigitalAssetMetadataTransactionImpl();
      digitalAssetMetadataTransaction.setGenesisTransaction(
          digitalAssetMetadata.getGenesisTransaction());
      digitalAssetMetadataTransaction.setSenderId(fermatMessage.getSender());
      digitalAssetMetadataTransaction.setSenderType(senderType);
      digitalAssetMetadataTransaction.setReceiverId(fermatMessage.getReceiver());
      digitalAssetMetadataTransaction.setReceiverType(receiverType);
      digitalAssetMetadataTransaction.setDigitalAssetMetadata(digitalAssetMetadata);
      digitalAssetMetadataTransaction.setDistributionStatus(DistributionStatus.ASSET_DISTRIBUTED);
      digitalAssetMetadataTransaction.setType(
          DigitalAssetMetadataTransactionType.META_DATA_TRANSMIT);
      digitalAssetMetadataTransaction.setProcessed(
          DigitalAssetMetadataTransactionImpl.NO_PROCESSED);

      /*
       * Save into data base for audit control
       */
      getAssetTransmissionNetworkServicePluginRoot()
          .getDigitalAssetMetaDataTransactionDao()
          .create(digitalAssetMetadataTransaction);

      /*
       * Mark the message as read
       */
      ((FermatMessageCommunication) fermatMessage)
          .setFermatMessagesStatus(FermatMessagesStatus.READ);
      ((CommunicationNetworkServiceConnectionManager)
              getAssetTransmissionNetworkServicePluginRoot().getNetworkServiceConnectionManager())
          .getIncomingMessageDao()
          .update(fermatMessage);

      /*
       * Notify to the interested
       */
      FermatEvent event =
          getAssetTransmissionNetworkServicePluginRoot()
              .getEventManager()
              .getNewEvent(EventType.RECEIVED_NEW_DIGITAL_ASSET_METADATA_NOTIFICATION);
      event.setSource(AssetTransmissionNetworkServicePluginRoot.EVENT_SOURCE);
      getAssetTransmissionNetworkServicePluginRoot().getEventManager().raiseEvent(event);

    } catch (Exception e) {
      getAssetTransmissionNetworkServicePluginRoot()
          .getErrorManager()
          .reportUnexpectedPluginException(
              Plugins.BITDUBAI_DAP_ASSET_TRANSMISSION_NETWORK_SERVICE,
              UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
              e);
    }
  }
    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");
      }
    }