Ejemplo n.º 1
0
  private TransactionDTO getTransactionDTO(TransactionTable tt) {
    if (null == tt) {
      return null;
    }

    TransactionDTO d = new TransactionDTO();
    d.setTransactionId(tt.getTxnId());
    d.setNotes(tt.getNotes());
    d.setDate(tt.getCreationDate());
    d.setName(tt.getTxnName());
    d.setEntryType(tt.getEntryType());

    for (Tag t : tt.getTags()) {
      d.getSelectedTags().add(t.getTagName());
    }

    for (TransactionEntry te : tt.getTransactionEntries()) {
      d.getTransactionEntries().add(getTransactionEntryDTO(te));
    }

    d.setGroupId(tt.getTransactionGroup().getTxnGroupId());
    d.setGroupName(tt.getTransactionGroup().getTgName());

    return d;
  }
Ejemplo n.º 2
0
  @Override
  public TransactionDTO getTransactionDetail(Long transactionId) {
    TransactionTable tt =
        SearchHelper.getFacade().readModelWithId(TransactionTable.class, transactionId, true);

    // check for userId is same or not
    if (getCurrentUser(this.getThreadLocalRequest().getSession())
        != tt.getTransactionGroup().getUser().getUid()) {
      return null; // request for a transaction of a different user
    }

    return getTransactionDTO(tt);
  }
Ejemplo n.º 3
0
  @Override
  public boolean deleteTransaction(long transactionId, boolean deleteFullTransaction) {
    List<Object> toBeSaved = new ArrayList<Object>();
    List<Object> toBeDeleted = new ArrayList<Object>();

    long txnId = -1;

    if (deleteFullTransaction) { // delete the whole transaction
      TransactionTable tt =
          SearchHelper.getFacade().readModelWithId(TransactionTable.class, transactionId, true);

      if (getCurrentUser(this.getThreadLocalRequest().getSession())
          != tt.getTransactionGroup().getUser().getUid()) {
        logger.error(
            "Unauthorized removal of Transaction with id: "
                + transactionId
                + ", User: "******", Actual User: "******"toBeDeleted"));
      toBeSaved.addAll(modifiedMap.get("toBeSaved"));

      // now remove all the te's from the tt collection
      for (Object te : toBeDeleted) {
        tt.getTransactionEntries().remove(te);
      }

      toBeDeleted.add(tt);
    } else { // delete the specified transaction entry
      TransactionEntry te =
          SearchHelper.getFacade().readModelWithId(TransactionEntry.class, transactionId, false);

      if (getCurrentUser(this.getThreadLocalRequest().getSession())
          != te.getTransaction().getTransactionGroup().getUser().getUid()) {
        logger.error(
            "Unauthorized removal of Transaction with id: "
                + transactionId
                + ", User: "******", Actual User: "******"sub"));
      toBeSaved.add(updateCurrentBalance(te.getOutwardAccount(), te.getAmount(), "add"));
      toBeDeleted.add(te);

      txnId = te.getTransaction().getTxnId();
    }

    boolean result = SearchHelper.getFacade().saveDeleteModels(toBeSaved, toBeDeleted);

    if (!deleteFullTransaction) {
      // check if the transaction has no transaction entry then delete the transaction also
      Map<String, Object> criteria = new LinkedHashMap<String, Object>();
      criteria.put("transaction.txnId", txnId);
      int count = SearchHelper.getFacade().getCount(TransactionEntry.class, criteria, false);
      if (0 == count) {
        SearchHelper.getFacade()
            .deleteModel(
                SearchHelper.getFacade().readModelWithId(TransactionTable.class, txnId, false));
      }
    }

    return result;
  }