-1

I am a junior software developer and have been tasked with building an API. It's my first time doing such advanced tasks.

My api will manage text files which contain payments. My problem is I do not know where to start or what to do.

My task is to build an API to handle text files. My software will load the file and treat it. My solution to include the handler for the file formats. The handler should call the methods in the attached Java interface Payment Receiver

My interface, method signatures

import java.math.BigDecimal;
import java.util.Date;

public interface PaymentReceiver {
/**
 * Called to mark the start of a new payment bundle.
 * @param accountNumber The account number where funds are deposited.
 * @param paymentDate The date at which the funds were/will be deposited on the specified account.
 * @param currency The currency of the payments in the bundle.
 */
public void startPaymentBundle(String accountNumber, Date paymentDate, String currency);

/**
 * Called to notify the receiver of a single payment within a bundle.
 * @param amount The payment amount.
 * @param reference The payment reference.
 */
public void payment(BigDecimal amount, String reference);

/**
 * Called to mark the end of a payment bundle. This means that there will be no more calls      to payment() 
 * for this bundle, and that the receiver can process the bundle.
 */
public void endPaymentBundle();
}
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
simsalabim33
  • 75
  • 1
  • 2
  • 8
  • 1
    You need to be more specific on where you're stuck exactly. On how you'll read the files? On how you should design this? Or something else? – Swapnil Jul 16 '14 at 17:31
  • 1
    Do you really want to invent a new format? You can keep your data in XML/json or a similar format. You will find lot of libraries to read/write your data. Good luck. – Gowtham Jul 16 '14 at 17:32
  • @Swapnil i already have the code where i read in the file and thee i'm stuck. I don't understand what to do next. – simsalabim33 Jul 16 '14 at 17:33
  • @Gowtham I don't think that i'm inventing a new format. I know that XML/json is an alternative but i must be in java, and just java. – simsalabim33 Jul 16 '14 at 17:35
  • Since I don't have detailed understanding of what you're trying to do, if you're stuck at parsing the files, you need to pick a file format to persist your data (XML, JSON or something else). Then you need to use a library like Apache Commons IO to interact with the files. Now what you'll do after reading those files is the business logic the other part of your software needs to handle. – Swapnil Jul 16 '14 at 17:38
  • There are XML/JSON parser libraries (open source) for Java, you don't need to redo all the work that has been done in that bucket. – Swapnil Jul 16 '14 at 17:39
  • Google is your friend - See http://stackoverflow.com/questions/7373567/java-how-to-read-and-write-xml-files. Just ask any specific question that you may have. – Gowtham Jul 16 '14 at 17:41
  • @Swapnil Now, you do understand me. I'm not stuck at parsing the files , i'm stuck in the business logic. I do now know what to do and i don't know what this method signatures above are. – simsalabim33 Jul 16 '14 at 17:42
  • @Gowtham I appreciate that you trying to help me but like i said before the problem isn't when reading the textfile. The problem is i don't know how to builid that API – simsalabim33 Jul 16 '14 at 17:45
  • 1
    @simsalabim33 Surely I can't help you out with the business logic since I don't have a clue :) Your best bet is to talk to the PM or your manager or whoever assigned you this task. It's important you've good understanding of the requirements before you start writing the code. – Swapnil Jul 16 '14 at 17:48

1 Answers1

1

The interface you displayed is a listener-type interface. What your handler needs to do is:

  • be configured with a data source (file) and a receiver instance
  • parse the given data source
  • while parsing the data source, pass the data as you read it to the given receiver instance
jtahlborn
  • 52,909
  • 5
  • 76
  • 118
  • Thank you, now everything is much clearer. But do you have an code example you can show? Or maybe you know a tutorial? – simsalabim33 Jul 16 '14 at 17:56
  • @simsalabim33 - i bet google can find an answer to that question faster than i can. – jtahlborn Jul 16 '14 at 18:01
  • Trust me i have already tried but i don't know what to google on. That's why i asked you guys here. :P but i will try once again. – simsalabim33 Jul 16 '14 at 18:10
  • @simsalabim33 - here's an example csv parser which has a listener based api: https://github.com/droolsjbpm/drools/blob/master/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/csv/CsvParser.java (found from google with "java csv listener") – jtahlborn Jul 16 '14 at 18:28