use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.
the class ContactTransferService method performTransfer.
/**
* Performs the transfer.
*/
private SpeechletResponse performTransfer(Intent intent, Session session) {
Object contactsFoundObj = SESSION_STORAGE.getObject(session.getSessionId(), SESSION_PREFIX + ".contactsFound");
if (contactsFoundObj == null || !(contactsFoundObj instanceof List)) {
return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
}
Object choiceObj = session.getAttribute(SESSION_PREFIX + ".choice");
if (choiceObj == null || !(choiceObj instanceof Integer)) {
return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
}
Object amountObj = session.getAttribute(SESSION_PREFIX + ".amount");
if (amountObj == null || !(amountObj instanceof Double || amountObj instanceof Integer)) {
return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
}
Contact contact = ((List<Contact>) contactsFoundObj).get((int) choiceObj - 1);
double amount;
if (amountObj instanceof Double) {
amount = (double) amountObj;
} else {
amount = (int) amountObj;
}
DateTimeFormatter apiTransactionFmt = DateTimeFormat.forPattern("yyyy-MM-dd");
String valueDate = DateTime.now().toString(apiTransactionFmt);
Transaction transaction = TransactionAPI.createTransaction((int) amount, /*"DE50100000000000000001"*/
AmosAlexaSpeechlet.ACCOUNT_IBAN, contact.getIban(), valueDate, "Beschreibung", "Hans", null);
Account account = AccountAPI.getAccount(ACCOUNT_NUMBER);
String balanceAfterTransaction = String.valueOf(account.getBalance());
// save transaction id to save in db
session.setAttribute(TRANSACTION_ID_ATTRIBUTE, transaction.getTransactionId().toString());
// add category ask to success response
String categoryAsk = "Zu welcher Kategorie soll die Transaktion hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText();
return getAskResponse(CONTACT_TRANSFER_CARD, "Erfolgreich. " + amount + " Euro wurden an " + contact.getName() + " überwiesen. Dein neuer Kontostand beträgt " + balanceAfterTransaction + " Euro. " + categoryAsk);
}
use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.
the class BudgetManager method getTransactionAmount.
private double getTransactionAmount(String categoryId, DateTime start, DateTime end) {
double sum = 0;
Collection<Transaction> apiTransactions = TransactionAPI.getTransactionsForAccount(AmosAlexaSpeechlet.ACCOUNT_ID);
List<TransactionDB> dbTransactions = dynamoDbMapper.loadAll(TransactionDB.class);
for (TransactionDB transactionDB : dbTransactions) {
if (transactionDB.getCategoryId() == null || !transactionDB.getCategoryId().equals(categoryId)) {
continue;
}
for (Transaction transaction : apiTransactions) {
if (transactionDB.getTransactionId().equals(transaction.getTransactionId().toString())) {
if (transaction.getValueDateAsDateTime().isAfter(start) && transaction.getValueDateAsDateTime().isBefore(end)) {
sum += Math.abs(transaction.getAmount().doubleValue());
}
}
}
}
return sum;
}
use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.
the class TransactionAPI method getTransactionForAccount.
public static Transaction getTransactionForAccount(String accountNumber, String transactionId) {
// Search for transaction
// TODO this is only a temporary solution
// TODO wait for API extension to get transaction detail request call /transactions/{transactionId}
List<Transaction> allTransactions = getTransactionsForAccount(accountNumber);
Number transactionNumber = Integer.valueOf(transactionId);
Transaction transaction = null;
for (Transaction t : allTransactions) {
if (transactionNumber.equals(t.getTransactionId())) {
transaction = t;
}
}
return transaction;
}
use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.
the class AmosAlexaSimpleTestImpl method contactTest.
@Test
public void contactTest() throws IllegalAccessException, NoSuchFieldException, IOException {
newSession();
// Get today´s date in the right format
Date now = new Date();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String todayDate = formatter.format(now);
// Create a transaction that we can use for ContactAddIntent (ingoing transaction)
Transaction transaction = TransactionAPI.createTransaction(1, AmosAlexaSpeechlet.ACCOUNT_IBAN, /*"DE60100000000000000001"*/
"DE50100000000000000001", todayDate, "Ueberweisung fuer Unit Test", null, "Sandra");
/*
int transactionId1 = 18877; //transaction.getTransactionId().intValue();
int transactionId2 = 6328; //transaction without remitter or payee
int transactionId3 = 23432423; //transaction not existent
*/
int transactionId1 = transaction.getTransactionId().intValue();
// int transactionId2 = 6328; //transaction without remitter or payee
// transaction not existent
int transactionId3 = 23432423;
// for transactionId1 //transaction.getRemitter();
String transactionRemitter = "Sandra";
// Test add contact no transaction number given
testIntent("ContactAddIntent", "TransactionNumber: ", "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.");
// Test add contact successful
testIntent("ContactAddIntent", "TransactionNumber:" + transactionId1, "Moechtest du " + transactionRemitter + " als " + "Kontakt speichern?");
testIntent("AMAZON.YesIntent", "Okay! Der Kontakt Sandra wurde angelegt.");
// Test add contact unknown payee/remitter
/*
testIntent(
"ContactAddIntent",
"TransactionNumber:" + transactionId2, "Ich kann fuer diese Transaktion keine Kontaktdaten speichern, weil der Name des Auftraggebers" +
" nicht bekannt ist. Bitte wiederhole deine Eingabe oder breche ab, indem du \"Alexa, Stop!\" sagst.");
*/
// Test add contact transaction not existent
testIntent("ContactAddIntent", "TransactionNumber:" + transactionId3, "Ich habe keine Transaktion mit dieser Nummer gefunden." + " Bitte wiederhole deine Eingabe.");
// Get the contact that we just created by searching for the contact with highest id
List<Contact> allContacts = DynamoDbMapper.getInstance().loadAll(Contact.class);
final Comparator<Contact> comp2 = Comparator.comparingInt(c -> c.getId());
Contact latestContact = allContacts.stream().max(comp2).get();
LOGGER.info("Contact: " + latestContact.getName());
String latestContactId = String.valueOf(latestContact.getId());
// Test contact list
testIntentMatches("ContactListInfoIntent", "Kontakt \\d+: Name: (.*), IBAN: (.*).(.*)");
// Test delete contact. Therefore delete the contact that we just created.
testIntent("ContactDeleteIntent", "ContactID:" + latestContactId, "Moechtest du Kontakt Nummer " + latestContactId + " wirklich " + "loeschen?");
testIntent("AMAZON.YesIntent", "Kontakt wurde geloescht.");
}
use of model.banking.Transaction in project amos-ss17-alexa by c-i-ber.
the class BankAccountService method handleTransactionSpeech.
/**
* responses each transaction from a account
*
* @return SpeechletResponse to alexa
*/
private SpeechletResponse handleTransactionSpeech() {
List<Transaction> transactions = TransactionAPI.getTransactionsForAccount(account.getNumber());
if (transactions == null || transactions.isEmpty()) {
LOGGER.warn("Account: " + account.getNumber() + " has no transactions");
return getResponse(CARD_NAME, EMPTY_TRANSACTIONS_TEXT);
}
StringBuilder stringBuilder = new StringBuilder(Transaction.getTransactionSizeText(transactions.size()));
int i;
for (i = 0; i < TRANSACTION_LIMIT; i++) {
stringBuilder.append(Transaction.getTransactionText(transactions.get(i)));
}
if (i - 1 < transactions.size()) {
stringBuilder.append(Transaction.getAskMoreTransactionText());
SessionStorage sessionStorage = SessionStorage.getInstance();
sessionStorage.putObject(sessionID, CONTEXT_FURTHER_TRANSACTION_INDEX, i);
} else {
return getResponse(CARD_NAME, LIST_END_TRANSACTIONS_TEXT);
}
return getSSMLAskResponse(CARD_NAME, stringBuilder.toString(), REPROMPT_TEXT);
}
Aggregations