コード例 #1
0
  public TransactionDBTO toTransactionDBTO(
      Transaction transaction, String username, String category, Date date, String currency) {
    TransactionDBTO transactionDBTO = new TransactionDBTO();
    BeanUtils.copyProperties(transaction, transactionDBTO, "user", "date", "currency", "category");

    UserDBTO userDBTO = userDBTORepository.getByUsername(username);
    transactionDBTO.setUser(userDBTO);

    if (categoryDBTORepository.findByName(category) != null) {
      transactionDBTO.setCategory(categoryDBTORepository.findByName(category));
    } else {
      CategoryDBTO categoryDBTO = new CategoryDBTO();
      categoryDBTO.setName(category);
      transactionDBTO.setCategory(categoryDBTO);
    }

    if (currencyDBTORepository.findByType(currency) != null) {
      transactionDBTO.setCurrency(currencyDBTORepository.findByType(currency));
    } else {
      CurrencyDBTO currencyDBTO = new CurrencyDBTO();
      currencyDBTO.setType(currency);
      transactionDBTO.setCurrency(currencyDBTO);
    }

    if (dateDBTORepository.findByDate(date) != null) {
      transactionDBTO.setDate(dateDBTORepository.findByDate(date));
    } else {
      DateDBTO dateDBTO = new DateDBTO();
      dateDBTO.setDate(date);
      transactionDBTO.setDate(dateDBTO);
    }

    return transactionDBTO;
  }
コード例 #2
0
  public Transaction toTransaction(TransactionDBTO transactionDBTO) {
    Transaction transaction = new Transaction();
    BeanUtils.copyProperties(transactionDBTO, transaction, "user", "date", "currency", "category");

    UserDBTO userDBTO = transactionDBTO.getUser();
    User user = userAdapter.toUser(userDBTO);
    transaction.setUser(user);

    DateDBTO dateDBTO = transactionDBTO.getDate();
    it.ow.stage.persistence.model.Date date = dateAdapter.toDate(dateDBTO);
    transaction.setDate(date);

    CategoryDBTO categoryDBTO = transactionDBTO.getCategory();
    Category category = categoryAdapter.toCategory(categoryDBTO);
    transaction.setCategory(category);

    CurrencyDBTO currencyDBTO = transactionDBTO.getCurrency();
    Currency currency = currencyAdapter.toCurrency(currencyDBTO);
    transaction.setCurrency(currency);

    return transaction;
  }