示例#1
0
  @Override
  public ArrayList<TransactionAndEntryDTO> getAllTransactionsForGroupId(
      Long groupId, FilterDTO filter, int startPosition, int offset) {
    ArrayList<TransactionAndEntryDTO> taedto = null;

    long uid = getCurrentUser(this.getThreadLocalRequest().getSession());

    Map<String, Object> criteria = new LinkedHashMap<String, Object>();

    Map<String, String> alias = new LinkedHashMap<String, String>();
    alias.put("txn", "transaction");
    alias.put("txnGroup", "transaction.transactionGroup");

    ///////////// Pull Transactions
    Map<String, Integer> orderBy = new LinkedHashMap<String, Integer>();
    orderBy.put("txn.creationDate", SearchHelper.ORDERBY_DESC);

    if (null != groupId) {
      criteria.put("txnGroup.txnGroupId,eq", groupId);
    } else {
      // TODO write a code to fetch records from all the TransactionGroups
      criteria.put("txnGroup.user.uid,eq", uid);
    }

    criteria.put("txn.creationDate,ge", filter.getStartingDate());
    criteria.put("txn.creationDate,le", filter.getEndingDate());

    if (0 < filter.getDirection()) {
      criteria.put("txn.entryType,eq", filter.getDirection());
    }

    List<TransactionEntry> tTables =
        SearchHelper.getFacade()
            .readAllObjects(
                TransactionEntry.class,
                criteria,
                true,
                alias,
                startPosition,
                offset,
                true,
                orderBy);

    if (null != tTables) {
      taedto = new ArrayList<TransactionAndEntryDTO>();
      if (!tTables.isEmpty()) {
        long tUid = tTables.get(0).getTransaction().getTransactionGroup().getUser().getUid();
        if (uid != tUid) {
          logger.error(
              "Request for unauthorized access from: "
                  + uid
                  + "\nTrying to access Transactions of UID: "
                  + tUid);
          return null;
        }
      }

      for (TransactionEntry te : tTables) {
        taedto.add(
            new TransactionAndEntryDTO(
                getTransactionDTO(
                    SearchHelper.getFacade()
                        .readModelWithId(
                            TransactionTable.class, te.getTransaction().getTxnId(), true)),
                getTransactionEntryDTO(te)));
      }
    }

    //////////// transaction pulling ends here

    return taedto;
  }
示例#2
0
  @Override
  public FilteredTransactionListData getFilterInfo(Long transactionGroup, FilterDTO filter) {
    FilteredTransactionListData ftd = new FilteredTransactionListData();

    long uid = getCurrentUser(this.getThreadLocalRequest().getSession());

    Map<String, Object> criteria = new LinkedHashMap<String, Object>();
    if (null != transactionGroup) {
      criteria.put("txnGroup.txnGroupId,eq", transactionGroup);
    } else {
      // TODO write a code to fetch records from all the TransactionGroups
      criteria.put("txnGroup.user.uid,eq", uid);
    }

    criteria.put("txn.creationDate,ge", filter.getStartingDate());
    criteria.put("txn.creationDate,le", filter.getEndingDate());

    if (0 < filter.getDirection()) {
      criteria.put("txn.entryType,eq", filter.getDirection());
    }

    Map<String, String> alias = new LinkedHashMap<String, String>();
    alias.put("txn", "transaction");
    alias.put("txnGroup", "transaction.transactionGroup");

    //////////// get the total count of transactions
    Number number =
        (Number)
            SearchHelper.getFacade()
                .getProjection(
                    TransactionEntry.class,
                    criteria,
                    alias,
                    null,
                    SearchHelper.PROJECTION_COUNT,
                    true);
    if (null != number) {
      ftd.setCount(number.intValue());
    }
    //////////// count of transactions ends here

    //////////// fetch the total amount
    ////// inward amount
    criteria.put("txn.entryType,eq", TransactionDTO.ET_INWARD_TG);
    Double amt =
        (Double)
            SearchHelper.getFacade()
                .getProjection(
                    TransactionEntry.class,
                    criteria,
                    alias,
                    "amount",
                    SearchHelper.PROJECTION_SUM,
                    true);
    if (null == amt) {
      amt = 0d;
    }
    ftd.setTotalInwadAmount(amt);

    ////// outward amount
    criteria.put("txn.entryType,eq", TransactionDTO.ET_OUTWARD_TG);
    amt =
        (Double)
            SearchHelper.getFacade()
                .getProjection(
                    TransactionEntry.class,
                    criteria,
                    alias,
                    "amount",
                    SearchHelper.PROJECTION_SUM,
                    true);
    if (null == amt) {
      amt = 0d;
    }
    ftd.setTotalOutwardAmount(amt);
    //////////// fetching total amount ends here

    return ftd;
  }