コード例 #1
0
  public boolean deleteAllocation(int assetClassId) {
    ExceptionHandler handler = new ExceptionHandler(getContext(), this);
    AssetClassRepository repo = new AssetClassRepository(getContext());

    // todo: use transaction? (see bulkUpdate)

    // Delete all child elements.
    List<Integer> childIds = getAllChildrenIds(assetClassId);
    repo.deleteAll(childIds);

    // delete any stock links
    AssetClassStockRepository stockRepo = new AssetClassStockRepository(getContext());
    boolean linksDeleted = stockRepo.deleteAllForAssetClass(assetClassId);
    if (!linksDeleted) {
      handler.showMessage("Error deleting stock links.");
      return false;
    }

    // delete allocation record
    boolean assetClassDeleted = repo.delete(assetClassId);
    if (!assetClassDeleted) {
      handler.showMessage("Error deleting asset class.");
      return false;
    }

    return true;
  }
コード例 #2
0
  public boolean assignStockToAssetClass(String stockSymbol, Integer assetClassId) {
    AssetClassStock link = AssetClassStock.create(assetClassId, stockSymbol);

    AssetClassStockRepository repo = new AssetClassStockRepository(context);
    boolean success = repo.insert(link);

    if (!success) {
      ExceptionHandler handler = new ExceptionHandler(context, this);
      handler.showMessage(context.getString(R.string.error));
    }
    return success;
  }
コード例 #3
0
  private void loadStocks(AssetClass assetClass) {
    if (assetClass.getChildren().size() > 0) {
      // Group. Load values for child elements.
      for (AssetClass child : assetClass.getChildren()) {
        loadStocks(child);
      }
    } else {
      // No child elements. This is the actual allocation. Load value from linked stocks.

      assetClass.setType(ItemType.Allocation);

      // load stock links
      AssetClassStockRepository linkRepo = new AssetClassStockRepository(this.context);
      List<AssetClassStock> links = linkRepo.loadForClass(assetClass.getId());
      assetClass.setStockLinks(links);

      if (assetClass.getStockLinks().size() == 0) return;

      //            String[] symbols = Queryable.from(assetClass.getStockLinks())
      //                .map(new Converter<AssetClassStock, String>() {
      //                    @Override
      //                    public String convert(AssetClassStock element) {
      //                        return element.getStockSymbol();
      //                    }
      //                }).toArray();

      int size = assetClass.getStockLinks().size();
      String[] symbols = new String[size];
      for (int i = 0; i < size; i++) {
        AssetClassStock link = assetClass.getStockLinks().get(i);
        symbols[i] = link.getStockSymbol();
      }

      StockRepository stockRepo = new StockRepository(getContext());
      List<Stock> stocks = stockRepo.loadForSymbols(symbols);
      assetClass.setStocks(stocks);
    }
  }