コード例 #1
0
 public ChatMiddlewareRecorderService(
     ChatMiddlewareDatabaseDao chatMiddlewareDatabaseDao,
     EventManager eventManager,
     ErrorManager errorManager,
     ChatMiddlewareMonitorAgent chatMiddlewareMonitorAgent)
     throws CantStartServiceException {
   try {
     this.chatMiddlewareMonitorAgent = chatMiddlewareMonitorAgent;
     setDatabaseDao(chatMiddlewareDatabaseDao);
     setEventManager(eventManager);
     this.errorManager = errorManager;
   } catch (CantSetObjectException exception) {
     errorManager.reportUnexpectedPluginException(
         Plugins.CHAT_MIDDLEWARE,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         FermatException.wrapException(exception));
     throw new CantStartServiceException(
         exception,
         "Cannot set the customer ack offline merchandise database handler",
         "The database handler is null");
   } catch (Exception exception) {
     errorManager.reportUnexpectedPluginException(
         Plugins.CHAT_MIDDLEWARE,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         FermatException.wrapException(exception));
     throw new CantStartServiceException(exception, "Unexpected error", "Unexpected exception");
   }
 }
コード例 #2
0
 @Override
 public void setTransactionDescription(UUID transactionID, String description)
     throws CantFindTransactionException, CantStoreMemoException {
   try {
     assetIssuerWalletDao = new AssetIssuerWalletDao(database);
     assetIssuerWalletDao.setPluginFileSystem(pluginFileSystem);
     assetIssuerWalletDao.setPlugin(pluginId);
     assetIssuerWalletDao.updateMemoField(transactionID, description);
   } catch (CantStoreMemoException exception) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_ASSET_WALLET_ISSUER,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         FermatException.wrapException(exception));
     throw exception;
   } catch (Exception exception) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_ASSET_WALLET_ISSUER,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         FermatException.wrapException(exception));
     throw new CantStoreMemoException(
         CantStoreMemoException.DEFAULT_MESSAGE,
         FermatException.wrapException(exception),
         null,
         null);
   }
 }
コード例 #3
0
 @Override
 public List<AssetIssuerWalletTransaction> gettLastActorTransactionsByTransactionType(
     BalanceType balanceType, TransactionType transactionType, int max, int offset)
     throws CantGetTransactionsException {
   try {
     assetIssuerWalletDao = new AssetIssuerWalletDao(database);
     assetIssuerWalletDao.setPluginFileSystem(pluginFileSystem);
     assetIssuerWalletDao.setPlugin(pluginId);
     return assetIssuerWalletDao.getTransactionsByTransactionType(transactionType, max, offset);
   } catch (CantGetTransactionsException exception) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_ASSET_WALLET_ISSUER,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         FermatException.wrapException(exception));
     throw exception;
   } catch (Exception exception) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_ASSET_WALLET_ISSUER,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         FermatException.wrapException(exception));
     throw new CantGetTransactionsException(
         CantGetTransactionsException.DEFAULT_MESSAGE,
         FermatException.wrapException(exception),
         null,
         null);
   }
 }
コード例 #4
0
  private byte[] getActorUserProfileImagePrivateKey(final String publicKey)
      throws CantGetActorAssetProfileImageException, FileNotFoundException {

    try {
      PluginBinaryFile file =
          this.pluginFileSystem.getBinaryFile(
              pluginId,
              PROFILE_IMAGE_DIRECTORY_NAME,
              buildProfileImageFileName(publicKey),
              FilePrivacy.PRIVATE,
              FileLifeSpan.PERMANENT);

      file.loadFromMedia();

      return file.getContent();

    } catch (CantLoadFileException e) {
      throw new CantGetActorAssetProfileImageException(
          CantGetActorAssetProfileImageException.DEFAULT_MESSAGE, e, "Error loaded file.", null);

    } catch (FileNotFoundException | CantCreateFileException e) {

      throw new FileNotFoundException(e, "", null);
    } catch (Exception e) {

      throw new CantGetActorAssetProfileImageException(
          CantGetActorAssetProfileImageException.DEFAULT_MESSAGE,
          FermatException.wrapException(e),
          "",
          "");
    }
  }
コード例 #5
0
  public String getAssetIssuerIdentityPrivateKey(String publicKey)
      throws CantGetAssetRedeemPointIdentityPrivateKeyException {
    String privateKey = "";
    try {
      PluginTextFile file =
          this.pluginFileSystem.getTextFile(
              pluginId,
              DeviceDirectory.LOCAL_USERS.getName(),
              ReedemPointIdentityPluginRoot.ASSET_REDEEM_POINT_PRIVATE_KEYS_FILE_NAME
                  + "_"
                  + publicKey,
              FilePrivacy.PRIVATE,
              FileLifeSpan.PERMANENT);

      file.loadFromMedia();

      privateKey = file.getContent();

    } catch (CantLoadFileException e) {
      throw new CantGetAssetRedeemPointIdentityPrivateKeyException(
          "CAN'T GET PRIVATE KEY ", e, "Error loaded file.", null);

    } catch (FileNotFoundException | CantCreateFileException e) {
      throw new CantGetAssetRedeemPointIdentityPrivateKeyException(
          "CAN'T GET PRIVATE KEY ", e, "Error getting developer identity private keys file.", null);
    } catch (Exception e) {
      throw new CantGetAssetRedeemPointIdentityPrivateKeyException(
          "CAN'T GET PRIVATE KEY ", FermatException.wrapException(e), "", "");
    }

    return privateKey;
  }
コード例 #6
0
  public byte[] getAssetIssuerProfileImagePrivateKey(String publicKey)
      throws CantGetAssetRedeemPointIdentityProfileImageException {
    byte[] profileImage;
    try {
      PluginBinaryFile file =
          this.pluginFileSystem.getBinaryFile(
              pluginId,
              DeviceDirectory.LOCAL_USERS.getName(),
              ReedemPointIdentityPluginRoot.ASSET_REDEEM_POINT_PROFILE_IMAGE_FILE_NAME
                  + "_"
                  + publicKey,
              FilePrivacy.PRIVATE,
              FileLifeSpan.PERMANENT);

      file.loadFromMedia();

      profileImage = file.getContent();

    } catch (CantLoadFileException e) {
      throw new CantGetAssetRedeemPointIdentityProfileImageException(
          "CAN'T GET IMAGE PROFILE ", e, "Error loaded file.", null);

    } catch (FileNotFoundException | CantCreateFileException e) {
      // Not image found return byte null
      profileImage = new byte[0];
      // throw new CantGetIntraWalletUserIdentityProfileImageException("CAN'T GET IMAGE PROFILE ",
      // e, "Error getting developer identity private keys file.", null);
    } catch (Exception e) {
      throw new CantGetAssetRedeemPointIdentityProfileImageException(
          "CAN'T GET IMAGE PROFILE ", FermatException.wrapException(e), "", "");
    }

    return profileImage;
  }
  @Override
  public void handleEvent(FermatEvent fermatEvent) throws FermatException {
    if (this.customerAckOnlineMerchandiseRecorderService.getStatus() == ServiceStatus.STARTED) {

      try {
        this.customerAckOnlineMerchandiseRecorderService
            .BrokerSubmitMerchandiseConfirmedEventHandler(
                (BrokerSubmitMerchandiseConfirmed) fermatEvent);
      } catch (CantSaveEventException exception) {
        throw new CantSaveEventException(
            exception, "Handling the BrokerSubmitMerchandiseConfirmed", "Check the cause");
      } catch (ClassCastException exception) {
        // Logger LOG = Logger.getGlobal();
        // LOG.info("EXCEPTION DETECTOR----------------------------------");
        // exception.printStackTrace();
        throw new CantSaveEventException(
            FermatException.wrapException(exception),
            "Handling the BrokerSubmitMerchandiseConfirmed",
            "Cannot cast this event");
      } catch (Exception exception) {
        throw new CantSaveEventException(
            exception, "Handling the BrokerSubmitMerchandiseConfirmed", "Unexpected exception");
      }

    } else {
      throw new TransactionServiceNotStartedException();
    }
  }
  @Override
  public void handleEvent(FermatEvent fermatEvent) throws FermatException {

    if (this.assetDistributionRecorderService.getStatus() == ServiceStatus.STARTED) {

      try {
        this.assetDistributionRecorderService
            .incomingAssetReversedOnCryptoNetworkWaitingTransferenceAssetUserEvent(
                (IncomingAssetReversedOnCryptoNetworkNetworkWaitingTransferenceAssetUserEvent)
                    fermatEvent);
      } catch (CantSaveEventException exception) {
        throw new CantSaveEventException(
            exception,
            "Handling the IncomingAssetReversedOnCryptoNetworkNetworkWaitingTransferenceAssetUserEvent",
            "Check the cause");
      } catch (ClassCastException exception) {
        // Logger LOG = Logger.getGlobal();
        // LOG.info("EXCEPTION DETECTOR----------------------------------");
        // exception.printStackTrace();
        throw new CantSaveEventException(
            FermatException.wrapException(exception),
            "Handling the IncomingAssetReversedOnCryptoNetworkNetworkWaitingTransferenceAssetUserEvent",
            "Cannot cast this event");
      } catch (Exception exception) {
        throw new CantSaveEventException(
            exception,
            "Handling the IncomingAssetReversedOnCryptoNetworkNetworkWaitingTransferenceAssetUserEvent",
            "Unexpected exception");
      }

    } else {
      throw new TransactionServiceNotStartedException();
    }
  }
コード例 #9
0
  /** Private Methods */
  private void persistNewUserPrivateKeysFile(String publicKey, String privateKey)
      throws CantPersistPrivateKeyException {
    try {
      PluginTextFile file =
          this.pluginFileSystem.createTextFile(
              pluginId,
              DeviceDirectory.LOCAL_USERS.getName(),
              ArtistIdentityPluginRoot.ARTIST_PRIVATE_KEYS_FILE_NAME + "_" + publicKey,
              FilePrivacy.PRIVATE,
              FileLifeSpan.PERMANENT);

      file.setContent(privateKey);

      file.persistToMedia();
    } catch (CantPersistFileException e) {
      throw new CantPersistPrivateKeyException(
          "CAN'T PERSIST PRIVATE KEY ", e, "Error persist file.", null);
    } catch (CantCreateFileException e) {
      throw new CantPersistPrivateKeyException(
          "CAN'T PERSIST PRIVATE KEY ", e, "Error creating file.", null);
    } catch (Exception e) {
      throw new CantPersistPrivateKeyException(
          "CAN'T PERSIST PRIVATE KEY ", FermatException.wrapException(e), "", "");
    }
  }
コード例 #10
0
ファイル: AssetReceptionDao.java プロジェクト: yeniree/fermat
  private List<String> getValueListFromTableByColumn(
      String referenceValue, String table, String referenceColumn, String returningColumn)
      throws CantCheckAssetReceptionProgressException {

    try {
      this.database = openDatabase();
      DatabaseTable databaseTable;
      List<String> returningList = new ArrayList<>();
      databaseTable = database.getTable(table);
      databaseTable.addStringFilter(referenceColumn, referenceValue, DatabaseFilterType.EQUAL);
      databaseTable.loadToMemory();
      for (DatabaseTableRecord record : databaseTable.getRecords()) {
        returningList.add(record.getStringValue(returningColumn));
      }

      return returningList;
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantCheckAssetReceptionProgressException(
          exception, "Getting " + referenceColumn + " list", "Cannot load table to memory");
    } catch (CantExecuteDatabaseOperationException exception) {

      throw new CantCheckAssetReceptionProgressException(
          exception,
          "Getting " + referenceColumn + " list",
          "Cannot open or find the Asset Reception database");
    } catch (Exception exception) {

      throw new CantCheckAssetReceptionProgressException(
          FermatException.wrapException(exception),
          "Getting " + referenceColumn + " list",
          "Unexpected exception");
    }
  }
コード例 #11
0
ファイル: AssetReceptionDao.java プロジェクト: yeniree/fermat
  private boolean isAssetsByReceptionStatus(ReceptionStatus receptionStatus)
      throws CantExecuteQueryException {
    try {
      this.database = openDatabase();
      DatabaseTable databaseTable;
      databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_RECEPTION_STATUS_COLUMN_NAME,
          receptionStatus.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME,
          CryptoStatus.PENDING_SUBMIT.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.loadToMemory();

      return !databaseTable.getRecords().isEmpty();
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantExecuteQueryException(
          "Error executing query in DB.",
          exception,
          "Getting assets by reception status.",
          "Cannot load table to memory.");
    } catch (Exception exception) {

      throw new CantExecuteQueryException(
          CantExecuteQueryException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          "Getting assets by reception status.",
          "Unexpected exception");
    }
  }
コード例 #12
0
  /*
   * Service Interface implementation
   */
  @Override
  public void start() {
    try {
      this.outgoingIntraActorDao =
          new OutgoingIntraActorDao(getErrorManager(), this.pluginDatabaseSystem);
      this.outgoingIntraActorDao.initialize(this.pluginId);
      this.transactionHandlerFactory =
          new OutgoingIntraActorTransactionHandlerFactory(
              this.eventManager,
              this.cryptoWalletManager,
              this.outgoingIntraActorDao,
              this.lossProtectedWalletManager);
      this.transactionProcessorAgent =
          new OutgoingIntraActorTransactionProcessorAgent(
              getErrorManager(),
              this.cryptoVaultManager,
              this.cryptoFermatVaultManager,
              this.bitcoinNetworkManager,
              this.cryptoWalletManager,
              this.outgoingIntraActorDao,
              this.transactionHandlerFactory,
              this.cryptoTransmissionNetworkServiceManager,
              this.eventManager,
              this.broadcaster,
              this.lossProtectedWalletManager);
      this.transactionProcessorAgent.start();

      this.serviceStatus = ServiceStatus.STARTED;

    } catch (CantInitializeOutgoingIntraActorDaoException e) {
      reportUnexpectedException(e);
    } catch (Exception e) {
      reportUnexpectedException(FermatException.wrapException(e));
    }
  }
コード例 #13
0
  /*
   * Service interface implementation
   */
  @Override
  public void start() throws CantStartPluginException {
    System.out.println("CASHUNHOLD - PluginRoot START");

    try {
      unholdTransactionManager =
          new CashMoneyTransactionUnholdManager(
              cashMoneyWalletManager, pluginDatabaseSystem, pluginId, errorManager);

    } catch (Exception e) {
      errorManager.reportUnexpectedPluginException(
          Plugins.BITDUBAI_CSH_MONEY_TRANSACTION_UNHOLD,
          UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
          e);
      throw new CantStartPluginException(
          CantStartPluginException.DEFAULT_MESSAGE, FermatException.wrapException(e), null, null);
    }

    processorAgent =
        new CashMoneyTransactionUnholdProcessorAgent(
            errorManager, unholdTransactionManager, cashMoneyWalletManager);
    processorAgent.start();

    serviceStatus = ServiceStatus.STARTED;
    // testCreateCashUnholdTransaction();
  }
コード例 #14
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    try {

      int id = item.getItemId();

      CharSequence itemTitle = item.getTitle();

      // Esto podria ser un enum de item menu que correspondan a otro menu
      if (itemTitle.equals("New Identity")) {
        changeActivity(Activities.CWP_INTRA_USER_CREATE_ACTIVITY.getCode());
      }
      //            if(id == R.id.action_connection_request){
      //                Toast.makeText(getActivity(),"Intra user
      // request",Toast.LENGTH_SHORT).show();
      //            }
      if (item.getItemId() == R.id.action_notifications) {
        changeActivity(Activities.CCP_SUB_APP_INTRA_USER_COMMUNITY_REQUEST.getCode());
        return true;
      }

    } catch (Exception e) {
      errorManager.reportUnexpectedUIException(
          UISource.ACTIVITY,
          UnexpectedUIExceptionSeverity.UNSTABLE,
          FermatException.wrapException(e));
      makeText(getActivity(), "Oooops! recovering from system error", LENGTH_LONG).show();
    }
    return super.onOptionsItemSelected(item);
  }
 public BrokerSubmitOfflineMerchandiseRecorderService(
     BrokerSubmitOfflineMerchandiseBusinessTransactionDao
         brokerSubmitOfflineMerchandiseBusinessTransactionDao,
     EventManager eventManager,
     ErrorManager errorManager)
     throws CantStartServiceException {
   try {
     this.errorManager = errorManager;
     setDatabaseDao(brokerSubmitOfflineMerchandiseBusinessTransactionDao);
     setEventManager(eventManager);
   } catch (CantSetObjectException exception) {
     this.errorManager.reportUnexpectedPluginException(
         Plugins.BROKER_SUBMIT_OFFLINE_MERCHANDISE,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         exception);
     throw new CantStartServiceException(
         exception,
         "Cannot set the submit offline merchandise recorder service",
         "The database handler is null");
   } catch (Exception exception) {
     this.errorManager.reportUnexpectedPluginException(
         Plugins.BROKER_SUBMIT_OFFLINE_MERCHANDISE,
         UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
         exception);
     throw new CantStartServiceException(
         CantStartServiceException.DEFAULT_MESSAGE,
         FermatException.wrapException(exception),
         "Cannot set the submit offline merchandise recorder service",
         "Unexpected error");
   }
 }
コード例 #16
0
 public BankMoneyWalletImpl(
     UUID pluginId,
     PluginDatabaseSystem pluginDatabaseSystem,
     ErrorManager errorManager,
     String publicKey)
     throws CantStartPluginException {
   this.pluginId = pluginId;
   this.pluginDatabaseSystem = pluginDatabaseSystem;
   this.errorManager = errorManager;
   this.publicKey = publicKey;
   this.bankMoneyWalletDao =
       new BankMoneyWalletDao(
           this.pluginId, this.pluginDatabaseSystem, this.errorManager, publicKey);
   try {
     this.bankMoneyWalletDao.initialize();
   } catch (CantInitializeBankMoneyWalletDatabaseException e) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_BNK_HOLD_MONEY_TRANSACTION,
         UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
         e);
     throw new CantStartPluginException(Plugins.BITDUBAI_BNK_HOLD_MONEY_TRANSACTION);
   } catch (Exception e) {
     errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_BNK_BANK_MONEY_WALLET,
         UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
         e);
     throw new CantStartPluginException(
         CantStartPluginException.DEFAULT_MESSAGE, FermatException.wrapException(e), null, null);
   }
 }
コード例 #17
0
  private void launchPresentationDialog() {
    try {
      DialogInterface.OnDismissListener onDismissListener =
          new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
              try {
                identity = moduleManager.getSelectedActorIdentity();
                loadSelectedActorIdentityInBackground();
                if (identity == null) getActivity().onBackPressed();
                else {
                  invalidate();
                  onRefresh();
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          };

      if (launchActorCreationDialog) {
        PresentationDialog presentationDialog =
            new PresentationDialog.Builder(getActivity(), appSession)
                .setTemplateType(PresentationDialog.TemplateType.TYPE_PRESENTATION)
                .setBannerRes(R.drawable.ccc_banner)
                .setIconRes(R.drawable.crypto_customer)
                .setSubTitle(R.string.cbp_ccc_launch_action_creation_dialog_sub_title)
                .setBody(R.string.cbp_ccc_launch_action_creation_dialog_body)
                .setTextFooter(R.string.cbp_ccc_launch_action_creation_dialog_footer)
                .setTextNameLeft(R.string.cbp_ccc_launch_action_creation_name_left)
                .setTextNameRight(R.string.cbp_ccc_launch_action_creation_name_right)
                .setIsCheckEnabled(false)
                .build();

        presentationDialog.setOnDismissListener(onDismissListener);
        presentationDialog.show();

      } else if (launchListIdentitiesDialog) {
        ListIdentitiesDialog listIdentitiesDialog =
            new ListIdentitiesDialog(getActivity(), appSession, appResourcesProviderManager);

        listIdentitiesDialog.setOnDismissListener(onDismissListener);
        listIdentitiesDialog.show();

      } else {
        onRefresh();
      }

    } catch (Exception ex) {
      errorManager.reportUnexpectedUIException(
          UISource.ACTIVITY,
          UnexpectedUIExceptionSeverity.CRASH,
          FermatException.wrapException(ex));
      Toast.makeText(
              getActivity().getApplicationContext(),
              "Oooops! recovering from system error",
              Toast.LENGTH_SHORT)
          .show();
    }
  }
コード例 #18
0
ファイル: AssetReceptionDao.java プロジェクト: yeniree/fermat
  private boolean isPendingEventsBySource(EventSource eventSource)
      throws CantExecuteQueryException {
    try {
      this.database = openDatabase();
      DatabaseTable databaseTable;
      databaseTable =
          database.getTable(
              AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_TABLE_NAME);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_STATUS_COLUMN_NAME,
          EventStatus.PENDING.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_SOURCE_COLUMN_NAME,
          eventSource.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.loadToMemory();

      return !databaseTable.getRecords().isEmpty();
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantExecuteQueryException(
          "Error executing query in DB.",
          exception,
          "Getting pending events.",
          "Cannot load table to memory.");
    } catch (Exception exception) {

      throw new CantExecuteQueryException(
          CantExecuteQueryException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          "Getting pending events.",
          "Unexpected exception");
    }
  }
コード例 #19
0
 public Database createDatabase(UUID ownerId, UUID walletId) throws CantCreateDatabaseException {
   Database database = null;
   try {
     database = this.pluginDatabaseSystem.createDatabase(ownerId, walletId.toString());
     createLossProtetedWalletTable(ownerId, database.getDatabaseFactory());
     createLossProtectedWalletBalancesTable(ownerId, database.getDatabaseFactory());
     createLossProtectedWalletSpentTableFactory(ownerId, database.getDatabaseFactory());
     insertInitialBalancesRecord(database);
     database.closeDatabase();
     return database;
   } catch (CantCreateTableException | CantInsertRecordException exception) {
     if (database != null) database.closeDatabase();
     throw new CantCreateDatabaseException(
         CantCreateDatabaseException.DEFAULT_MESSAGE, exception, null, "Check the cause");
   } catch (CantCreateDatabaseException exception) {
     throw exception;
   } catch (Exception exception) {
     if (database != null) database.closeDatabase();
     throw new CantCreateDatabaseException(
         CantCreateDatabaseException.DEFAULT_MESSAGE,
         FermatException.wrapException(exception),
         null,
         null);
   }
 }
コード例 #20
0
ファイル: AssetReceptionDao.java プロジェクト: yeniree/fermat
  public boolean isPendingTransactions(CryptoStatus cryptoStatus) throws CantExecuteQueryException {
    try {
      this.database = openDatabase();
      DatabaseTable databaseTable;
      databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_PROTOCOL_STATUS_COLUMN_NAME,
          ProtocolStatus.TO_BE_NOTIFIED.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME,
          cryptoStatus.getCode(),
          DatabaseFilterType.EQUAL);
      databaseTable.loadToMemory();

      return !databaseTable.getRecords().isEmpty();
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantExecuteQueryException(
          "Error executing query in DB.",
          exception,
          "Getting pending transactions.",
          "Cannot load table to memory.");
    } catch (Exception exception) {

      throw new CantExecuteQueryException(
          CantExecuteQueryException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          "Getting pending transactions.",
          "Unexpected exception");
    }
  }
  // DELETE METHOD FOR TEST
  public void deleteAllForTest()
      throws CantRegisterCustomerBrokerNewNegotiationTransactionException {
    try {

      DatabaseTable table =
          this.database.getTable(
              CustomerBrokerNewNegotiationTransactionDatabaseConstants
                  .CUSTOMER_BROKER_NEW_TABLE_NAME);
      DatabaseTableRecord record = table.getEmptyRecord();
      table.deleteRecord(record);

    } catch (CantDeleteRecordException e) {
      throw new CantRegisterCustomerBrokerNewNegotiationTransactionException(
          e.getMessage(),
          e,
          "Negotiation Transaction, Customer Broker New",
          "Cant delete Register, delete database problems.");
    } catch (Exception e) {
      throw new CantRegisterCustomerBrokerNewNegotiationTransactionException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Negotiation Transaction, Customer Broker New",
          "Cant delete Register, unknown failure.");
    }
  }
コード例 #22
0
ファイル: AssetReceptionDao.java プロジェクト: yeniree/fermat
  public boolean isGenesisTransactionRegistered(String genesisTransaction)
      throws CantExecuteQueryException {
    try {
      this.database = openDatabase();
      DatabaseTable databaseTable;
      databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME);
      databaseTable.addStringFilter(
          AssetReceptionDatabaseConstants.ASSET_RECEPTION_GENESIS_TRANSACTION_COLUMN_NAME,
          genesisTransaction,
          DatabaseFilterType.EQUAL);
      databaseTable.loadToMemory();

      return !databaseTable.getRecords().isEmpty();
    } catch (CantLoadTableToMemoryException exception) {

      throw new CantExecuteQueryException(
          "Error executing query in DB.",
          exception,
          "Checking if genesis transaction exists in database.",
          "Cannot load table to memory.");
    } catch (Exception exception) {

      throw new CantExecuteQueryException(
          CantExecuteQueryException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          "Checking if genesis transaction exits in database.",
          "Unexpected exception");
    }
  }
コード例 #23
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    try {
      int id = item.getItemId();

      if (id == SessionConstantsAssetUser.IC_ACTION_USER_HELP_REDEEM) {
        setUpHelpAssetRedeem(
            settingsManager
                .loadAndGetSettings(appSession.getAppPublicKey())
                .isPresentationHelpEnabled());
        return true;
      }

    } catch (Exception e) {
      errorManager.reportUnexpectedUIException(
          UISource.ACTIVITY,
          UnexpectedUIExceptionSeverity.UNSTABLE,
          FermatException.wrapException(e));
      makeText(
              getActivity(),
              getResources().getString(R.string.dap_user_wallet_system_error),
              Toast.LENGTH_SHORT)
          .show();
    }
    return super.onOptionsItemSelected(item);
  }
コード例 #24
0
  public void updateTxHash(UUID transactionId, String newHash)
      throws OutgoingIntraActorCantInsertRecordException {
    try {
      DatabaseTable transactionTable =
          this.database.getTable(
              OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TABLE_NAME);
      transactionTable.addStringFilter(
          OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_ID_COLUMN_NAME,
          transactionId.toString(),
          DatabaseFilterType.EQUAL);
      transactionTable.loadToMemory();

      if (transactionTable.getRecords().isEmpty()) throw new RecordsNotFoundException();

      DatabaseTableRecord record = transactionTable.getRecords().get(0);
      record.setStringValue(
          OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_HASH_COLUMN_NAME,
          newHash);
      transactionTable.updateRecord(record);
    } catch (Exception exception) {
      throw new com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer
          .bitdubai.version_1.exceptions.OutgoingIntraActorCantInsertRecordException(
          com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai
              .version_1.exceptions.OutgoingIntraActorCantInsertRecordException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          null,
          null);
    }
  }
コード例 #25
0
  public void initialize(UUID walletId) throws CantInitializeAssetIssuerWalletException {
    if (walletId == null)
      throw new CantInitializeAssetIssuerWalletException(
          "InternalId is null",
          null,
          "Parameter walletId is null",
          "loadWallet didn't find the asociated id");

    try {
      database = this.pluginDatabaseSystem.openDatabase(this.pluginId, walletId.toString());
    } catch (CantOpenDatabaseException cantOpenDatabaseException) {
      throw new CantInitializeAssetIssuerWalletException(
          "I can't open database",
          cantOpenDatabaseException,
          "WalletId: " + walletId.toString(),
          "");
    } catch (DatabaseNotFoundException databaseNotFoundException) {
      throw new CantInitializeAssetIssuerWalletException(
          "Database does not exists",
          databaseNotFoundException,
          "WalletId: " + walletId.toString(),
          "");
    } catch (Exception exception) {
      throw new CantInitializeAssetIssuerWalletException(
          CantInitializeAssetIssuerWalletException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          null,
          null);
    }
  }
コード例 #26
0
  public void setToCryptoStatus(
      OutgoingDraftTransactionWrapper transactionWrapper, CryptoStatus cryptoStatus)
      throws CantUpdateRecordException, CantLoadTableToMemoryException,
          com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai
              .version_1.exceptions.OutgoingIntraActorInconsistentTableStateException {
    try {
      DatabaseTable transactionTable =
          this.database.getTable(
              OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TABLE_NAME);
      DatabaseTableRecord recordToUpdate = getByPrimaryKey(transactionWrapper.getRequestId());

      recordToUpdate.setStringValue(
          OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME,
          cryptoStatus.getCode());
      transactionTable.addStringFilter(
          OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_ID_COLUMN_NAME,
          transactionWrapper.getRequestId().toString(),
          DatabaseFilterType.EQUAL);

      transactionTable.updateRecord(recordToUpdate);

    } catch (CantUpdateRecordException
        | com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai
            .version_1.exceptions.OutgoingIntraActorInconsistentTableStateException
        | CantLoadTableToMemoryException exception) {
      throw exception;
    } catch (Exception exception) {
      throw new CantLoadTableToMemoryException(
          CantLoadTableToMemoryException.DEFAULT_MESSAGE,
          FermatException.wrapException(exception),
          null,
          null);
    }
  }
コード例 #27
0
  private void persistNewUserProfileImage(String publicKey, byte[] profileImage)
      throws CantPersistProfileImageException {
    try {
      PluginBinaryFile file =
          this.pluginFileSystem.createBinaryFile(
              pluginId,
              DeviceDirectory.LOCAL_USERS.getName(),
              ReedemPointIdentityPluginRoot.ASSET_REDEEM_POINT_PROFILE_IMAGE_FILE_NAME
                  + "_"
                  + publicKey,
              FilePrivacy.PRIVATE,
              FileLifeSpan.PERMANENT);

      file.setContent(profileImage);

      file.persistToMedia();
    } catch (CantPersistFileException e) {
      throw new CantPersistProfileImageException(
          "CAN'T PERSIST PROFILE IMAGE ", e, "Error persist file.", null);

    } catch (CantCreateFileException e) {
      throw new CantPersistProfileImageException(
          "CAN'T PERSIST PROFILE IMAGE ", e, "Error creating file.", null);
    } catch (Exception e) {
      throw new CantPersistProfileImageException(
          "CAN'T PERSIST PROFILE IMAGE ", FermatException.wrapException(e), "", "");
    }
  }
コード例 #28
0
  public CryptoStatus getCryptoStatus(String transactionHash)
      throws OutgoingIntraActorCantGetCryptoStatusException {
    try {
      DatabaseTable transactionTable =
          this.database.getTable(
              OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TABLE_NAME);
      transactionTable.addStringFilter(
          OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_HASH_COLUMN_NAME,
          transactionHash,
          DatabaseFilterType.EQUAL);
      transactionTable.loadToMemory();
      List<DatabaseTableRecord> records = transactionTable.getRecords();
      transactionTable.clearAllFilters();

      return CryptoStatus.getByCode(
          records
              .get(0)
              .getStringValue(
                  OutgoingDraftTransactionDatabaseConstants
                      .OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME));
    } catch (InvalidParameterException | CantLoadTableToMemoryException e) {
      throw new OutgoingIntraActorCantGetCryptoStatusException("An exception happened", e, "", "");
    } catch (Exception e) {
      throw new OutgoingIntraActorCantGetCryptoStatusException(
          "An unexpected exception happened", FermatException.wrapException(e), "", "");
    }
  }
コード例 #29
0
  public CryptoCustomerIdentity createCryptoCustomerIdentity(String alias, byte[] profileImage)
      throws CantCreateCryptoCustomerIdentityException {
    try {
      DeviceUser loggedUser = deviceUserManager.getLoggedInDeviceUser();
      KeyPair keyPair = AsymmetricCryptography.generateECCKeyPair();
      // TODO BY DEFAULT THE CUSTOMER IS PUBLISHED
      CryptoCustomerIdentity cryptoCustomer =
          new CryptoCustomerIdentityImpl(
              alias, keyPair.getPrivateKey(), keyPair.getPublicKey(), profileImage, true);
      cryptoCustomerIdentityDatabaseDao.createNewCryptoCustomerIdentity(
          cryptoCustomer, keyPair.getPrivateKey(), loggedUser);

      return cryptoCustomer;

    } catch (CantGetLoggedInDeviceUserException e) {
      throw new CantCreateCryptoCustomerIdentityException(
          "CAN'T CREATE NEW CRYPTO CUSTOMER IDENTITY",
          e,
          "Error getting current logged in device user",
          "");
    } catch (CantCreateNewDeveloperException e) {
      throw new CantCreateCryptoCustomerIdentityException(
          "CAN'T CREATE NEW CRYPTO CUSTOMER IDENTITY", e, "Error save user on database", "");
    } catch (Exception e) {
      throw new CantCreateCryptoCustomerIdentityException(
          "CAN'T CREATE NEW CRYPTO CUSTOMER IDENTITY", FermatException.wrapException(e), "", "");
    }
  }
コード例 #30
0
  private void persistNewUserProfileImage(String publicKey, byte[] profileImage)
      throws CantPersistProfileImageException {
    try {

      PluginBinaryFile file =
          this.pluginFileSystem.createBinaryFile(
              pluginId,
              PROFILE_IMAGE_DIRECTORY_NAME,
              buildProfileImageFileName(publicKey),
              FilePrivacy.PRIVATE,
              FileLifeSpan.PERMANENT);

      file.setContent(profileImage);
      file.persistToMedia();

    } catch (CantPersistFileException e) {
      throw new CantPersistProfileImageException(
          CantPersistProfileImageException.DEFAULT_MESSAGE, e, "Error persist file.", null);

    } catch (CantCreateFileException e) {

      throw new CantPersistProfileImageException(
          CantPersistProfileImageException.DEFAULT_MESSAGE, e, "Error creating file.", null);
    } catch (Exception e) {

      throw new CantPersistProfileImageException(
          CantPersistProfileImageException.DEFAULT_MESSAGE,
          FermatException.wrapException(e),
          "",
          "");
    }
  }