Exemplo n.º 1
0
  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.");
    }
  }
Exemplo n.º 2
0
  /**
   * 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.");
    }
  }