public void updateIdentityArtistUser(
      String publicKey,
      String alias,
      byte[] profileImage,
      String externalUserName,
      String externalAccessToken,
      ExternalPlatform externalPlatform,
      ExposureLevel exposureLevel,
      ArtistAcceptConnectionsType artistAcceptConnectionsType)
      throws CantUpdateArtistIdentityException {
    try {
      /** 1) Get the table. */
      DatabaseTable table =
          this.database.getTable(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME);

      if (table == null) {
        /** Table not found. */
        throw new CantUpdateArtistIdentityException(
            "Cant get Redeem Point Identity list, table not found.",
            "Redeem Point Identity",
            "Cant get Redeem Point identity list, table not found.");
      }

      // 2) Find the Intra users.
      table.addStringFilter(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME,
          publicKey,
          DatabaseFilterType.EQUAL);
      table.loadToMemory();

      // 3) Get Intra users.
      for (DatabaseTableRecord record : table.getRecords()) {
        // set new values
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME, publicKey);
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME, alias);
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_USER_NAME_COLUMN_NAME,
            externalUserName);
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_ACCESS_TOKEN_COLUMN_NAME,
            externalAccessToken);
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_PLATFORM_COLUMN_NAME,
            externalPlatform.getCode());
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXPOSURE_LEVEL_COLUMN_NAME,
            exposureLevel.getCode());
        record.setStringValue(
            ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ACEEPTS_CONNECTIONS_TYPE_COLUMN_NAME,
            artistAcceptConnectionsType.getCode());

        table.updateRecord(record);
      }

      if (profileImage != null) persistNewUserProfileImage(publicKey, profileImage);

    } catch (CantUpdateRecordException e) {
      throw new CantUpdateArtistIdentityException(
          e.getMessage(),
          e,
          "Redeem Point Identity",
          "Cant update Redeem Point Identity, database problems.");
    } catch (CantPersistProfileImageException e) {
      throw new CantUpdateArtistIdentityException(
          e.getMessage(),
          e,
          "Redeem Point Identity",
          "Cant update Redeem Point Identity, persist image error.");
    } catch (Exception e) {
      throw new CantUpdateArtistIdentityException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Redeem Point Identity",
          "Cant update Redeem Point Identity, unknown failure.");
    }
  }
  public Artist getIdentityArtist(String publicKey) throws CantGetArtistIdentityException {

    // Setup method.
    Artist artist = null;
    DatabaseTable table; // Intra User table.

    // Get Asset Issuers identities list.
    try {

      /** 1) Get the table. */
      table = this.database.getTable(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME);

      if (table == null) {
        /** Table not found. */
        throw new CantUpdateArtistIdentityException(
            "Cant get Asset Issuer identity list, table not found.",
            "Asset IssuerIdentity",
            "Cant get Intra User identity list, table not found.");
      }

      // 2) Find the Identity Issuers.

      table.addStringFilter(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME,
          publicKey,
          DatabaseFilterType.EQUAL);
      table.loadToMemory();

      // 3) Get Identity Issuers.

      for (DatabaseTableRecord record : table.getRecords()) {

        // Add records to list.
        /*artist = new IdentityAssetRedeemPointImpl(
        record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME),
        record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME),
        getArtistProfileImagePrivateKey(record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME)));*/
        artist =
            new ArtistIdentityImp(
                record.getStringValue(
                    ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME),
                record.getStringValue(
                    ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME),
                getArtistProfileImagePrivateKey(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME)),
                record.getStringValue(
                    ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_USER_NAME_COLUMN_NAME),
                record.getStringValue(
                    ArtistIdentityDatabaseConstants
                        .ARTIST_IDENTITY_EXTERNAL_ACCESS_TOKEN_COLUMN_NAME),
                ExternalPlatform.getByCode(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants
                            .ARTIST_IDENTITY_EXTERNAL_PLATFORM_COLUMN_NAME)),
                ExposureLevel.getByCode(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants
                            .ARTIST_IDENTITY_EXPOSURE_LEVEL_COLUMN_NAME)),
                ArtistAcceptConnectionsType.getByCode(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants
                            .ARTIST_IDENTITY_ACEEPTS_CONNECTIONS_TYPE_COLUMN_NAME)),
                pluginFileSystem,
                pluginId);
      }
    } catch (CantLoadTableToMemoryException e) {
      throw new CantGetArtistIdentityException(
          e.getMessage(),
          e,
          "Asset Redeem Point Identity",
          "Cant load "
              + ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME
              + " table in memory.");
    } catch (Exception e) {
      throw new CantGetArtistIdentityException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Asset Redeem Point Identity",
          "Cant get Asset Redeem Point identity list, unknown failure.");
    }

    // Return the list values.
    return artist;
  }
  /**
   * first i persist private key on a file second i insert the record in database third i save the
   * profile image file
   *
   * @param alias
   * @param publicKey
   * @param privateKey
   * @param deviceUser
   * @param profileImage
   * @throws CantCreateArtistIdentityException
   */
  public void createNewUser(
      String alias,
      String publicKey,
      String privateKey,
      DeviceUser deviceUser,
      byte[] profileImage,
      String externalUserName,
      String externalAccessToken,
      ExternalPlatform externalPlatform,
      ExposureLevel exposureLevel,
      ArtistAcceptConnectionsType artistAcceptConnectionsType)
      throws CantCreateArtistIdentityException {

    try {
      if (aliasExists(alias)) {
        throw new CantCreateArtistIdentityException(
            "Cant create new Redeem Point Identity, alias exists.",
            "Redeem Point Identity",
            "Cant create new Redeem Point, alias exists.");
      }

      persistNewUserPrivateKeysFile(publicKey, privateKey);

      DatabaseTable table =
          this.database.getTable(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME);
      DatabaseTableRecord record = table.getEmptyRecord();

      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME, publicKey);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_DEVICE_USER_PUBLIC_KEY_COLUMN_NAME,
          deviceUser.getPublicKey());
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME, alias);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_USER_NAME_COLUMN_NAME,
          externalUserName);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_ACCESS_TOKEN_COLUMN_NAME,
          externalAccessToken);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_PLATFORM_COLUMN_NAME,
          externalPlatform.getCode());
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXPOSURE_LEVEL_COLUMN_NAME,
          exposureLevel.getCode());
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ACEEPTS_CONNECTIONS_TYPE_COLUMN_NAME,
          artistAcceptConnectionsType.getCode());

      table.insertRecord(record);

      if (profileImage != null) persistNewUserProfileImage(publicKey, profileImage);

    } catch (CantInsertRecordException e) {
      // Cant insert record.
      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          e,
          "Redeem Point Identity",
          "Cant create new Redeem Point, insert database problems.");

    } catch (CantPersistPrivateKeyException e) {
      // Cant insert record.
      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          e,
          "ARedeem Point Identity",
          "Cant create new Redeem Point, persist private key error.");

    } catch (Exception e) {
      // Failure unknown.

      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Redeem Point Identity",
          "Cant create new Redeem Point, unknown failure.");
    }
  }