public ActorAssetNetworkServiceRecord changeActorAssetNotificationDescriptor(
      final String senderPublicKey,
      final AssetNotificationDescriptor assetNotificationDescriptor,
      final ActorAssetProtocolState actorAssetProtocolState)
      throws CantUpdateRecordDataBaseException, CantUpdateRecordException,
          CantGetActorAssetNotificationException {

    if (senderPublicKey == null)
      throw new CantUpdateRecordDataBaseException("senderPublicKey null ", null);

    if (assetNotificationDescriptor == null)
      throw new CantUpdateRecordDataBaseException("protocolState null", null);

    try {

      DatabaseTable cryptoPaymentRequestTable = getDatabaseTable();

      cryptoPaymentRequestTable.addStringFilter(
          AssetUserNetworkServiceDatabaseConstants
              .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME,
          senderPublicKey,
          DatabaseFilterType.EQUAL);

      cryptoPaymentRequestTable.loadToMemory();

      List<DatabaseTableRecord> records = cryptoPaymentRequestTable.getRecords();

      if (!records.isEmpty()) {
        DatabaseTableRecord record = records.get(records.size() - 1); // Last pending

        record.setStringValue(
            AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_DESCRIPTOR_COLUMN_NAME,
            assetNotificationDescriptor.getCode());
        record.setStringValue(
            AssetUserNetworkServiceDatabaseConstants
                .INCOMING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME,
            actorAssetProtocolState.getCode());

        cryptoPaymentRequestTable.updateRecord(record);

        return buildAssetUserNetworkServiceRecord(record);
      } else {
        throw new CantGetActorAssetNotificationException(
            "senderPublicKey: " + senderPublicKey,
            "Cannot find a connection request with the given id.");
      }

    } catch (CantLoadTableToMemoryException e) {

      throw new CantUpdateRecordDataBaseException(
          "Exception not handled by the plugin, there is a problem in database and i cannot load the table.",
          e);
    } catch (CantUpdateRecordException exception) {

      throw new CantUpdateRecordDataBaseException("Cant update record exception.", exception);
    } catch (InvalidParameterException e) {
      throw new CantUpdateRecordDataBaseException("Cant get the updated record exception.", e);
    }
  }
  public List<ActorAssetNetworkServiceRecord> listRequestsByProtocolStateAndType(
      final ActorAssetProtocolState actorAssetProtocolState,
      final AssetNotificationDescriptor assetNotificationDescriptor)
      throws CantGetActorAssetNotificationException {

    if (actorAssetProtocolState == null)
      throw new CantGetActorAssetNotificationException(
          "protocolState null", null, "The protocolState is required, can not be null", "");

    if (assetNotificationDescriptor == null)
      throw new CantGetActorAssetNotificationException(
          "type null", null, "The RequestType is required, can not be null", "");

    try {
      DatabaseTable cryptoPaymentRequestTable = getDatabaseTable();

      cryptoPaymentRequestTable.addStringFilter(
          AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME,
          actorAssetProtocolState.getCode(),
          DatabaseFilterType.EQUAL);
      cryptoPaymentRequestTable.addStringFilter(
          AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_DESCRIPTOR_COLUMN_NAME,
          assetNotificationDescriptor.getCode(),
          DatabaseFilterType.EQUAL);

      cryptoPaymentRequestTable.loadToMemory();

      List<DatabaseTableRecord> records = cryptoPaymentRequestTable.getRecords();

      List<ActorAssetNetworkServiceRecord> cryptoPaymentList = new ArrayList<>();

      for (DatabaseTableRecord record : records) {
        cryptoPaymentList.add(buildAssetUserNetworkServiceRecord(record));
      }
      return cryptoPaymentList;
    } catch (CantLoadTableToMemoryException e) {
      throw new CantGetActorAssetNotificationException(
          "",
          e,
          "Exception not handled by the plugin, there is a problem in database and i cannot load the table.",
          "");
    } catch (InvalidParameterException exception) {
      throw new CantGetActorAssetNotificationException(
          "", exception, "Exception invalidParameterException.", "");
    }
  }
  public void changeProtocolState(
      final UUID requestId, final ActorAssetProtocolState actorAssetProtocolState)
      throws CantUpdateRecordDataBaseException, CantUpdateRecordException,
          CantGetActorAssetNotificationException {

    if (requestId == null) throw new CantUpdateRecordDataBaseException("requestId null ", null);

    if (actorAssetProtocolState == null)
      throw new CantUpdateRecordDataBaseException("protocolState null", null);

    try {

      DatabaseTable cryptoPaymentRequestTable = getDatabaseTable();

      cryptoPaymentRequestTable.addUUIDFilter(
          AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_ID_COLUMN_NAME,
          requestId,
          DatabaseFilterType.EQUAL);

      cryptoPaymentRequestTable.loadToMemory();

      List<DatabaseTableRecord> records = cryptoPaymentRequestTable.getRecords();

      if (!records.isEmpty()) {
        DatabaseTableRecord record = records.get(records.size() - 1);

        record.setStringValue(
            AssetUserNetworkServiceDatabaseConstants
                .INCOMING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME,
            actorAssetProtocolState.getCode());

        cryptoPaymentRequestTable.updateRecord(record);
      } else {
        throw new CantGetActorAssetNotificationException(
            "RequestId: " + requestId, "Cannot find a CryptoPaymentRequest with the given id.");
      }

    } catch (CantLoadTableToMemoryException e) {
      throw new CantUpdateRecordDataBaseException(
          "Exception not handled by the plugin, there is a problem in database and i cannot load the table.",
          e);
    } catch (CantUpdateRecordException exception) {
      throw new CantUpdateRecordDataBaseException("Cant update record exception.", exception);
    }
  }
  private ActorAssetNetworkServiceRecord buildAssetUserNetworkServiceRecord(
      DatabaseTableRecord record) throws InvalidParameterException {
    try {
      BlockchainNetworkType blockchainNetworkType;

      UUID notificationId =
          record.getUUIDValue(
              AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_ID_COLUMN_NAME);
      String senderAlias =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_SENDER_ALIAS_COLUMN_NAME);
      String descriptor =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_DESCRIPTOR_COLUMN_NAME);
      String destinationType =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_RECEIVER_TYPE_COLUMN_NAME);
      String senderType =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_SENDER_TYPE_COLUMN_NAME);
      String senderPublicKey =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME);
      String destinationPublicKey =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_RECEIVER_PUBLIC_KEY_COLUMN_NAME);
      long timestamp =
          record.getLongValue(
              AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_TIMESTAMP_COLUMN_NAME);
      String protocolState =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME);
      String flagRead =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_READ_MARK_COLUMN_NAME);
      String blockChainNetwork =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_BLOCKCHAIN_NETWORK_TYPE_COLUMN_NAME);
      UUID responseToNotificationId =
          record.getUUIDValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_RESPONSE_TO_NOTIFICATION_ID_COLUMN_NAME);

      ActorAssetProtocolState actorAssetProtocolState =
          ActorAssetProtocolState.getByCode(protocolState);
      Boolean read = Boolean.valueOf(flagRead);
      AssetNotificationDescriptor assetNotificationDescriptor =
          AssetNotificationDescriptor.getByCode(descriptor);

      if (blockChainNetwork != null)
        blockchainNetworkType = BlockchainNetworkType.getByCode(blockChainNetwork);
      else blockchainNetworkType = BlockchainNetworkType.getDefaultBlockchainNetworkType();

      Actors actorDestinationType = Actors.getByCode(destinationType);
      Actors actorSenderType = Actors.getByCode(senderType);

      byte[] profileImage;

      try {
        profileImage =
            getActorUserProfileImagePrivateKey(
                record.getStringValue(
                    AssetUserNetworkServiceDatabaseConstants
                        .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME));
      } catch (FileNotFoundException e) {
        profileImage = new byte[0];
      }

      return new ActorAssetNetworkServiceRecord(
          notificationId,
          senderAlias,
          //                    senderPhrase,
          profileImage,
          assetNotificationDescriptor,
          actorDestinationType,
          actorSenderType,
          senderPublicKey,
          destinationPublicKey,
          timestamp,
          actorAssetProtocolState,
          read,
          0,
          blockchainNetworkType,
          responseToNotificationId,
          null);
    } catch (Exception e) {
      throw new InvalidParameterException();
    }
  }