Thursday, December 22, 2011

Cleared Check Server v2 - what about adding data?

Yes it's ugly and full of smells but it works. However, what about adding in new cleared checks as they are downloaded or pulled from a cd.

First thing to do is pull out some of the logic into its own class and also add methods to append to the csv file.

Then lets add some more routes to app.rb, most of this was borrowed from the internet

and then some more borrowed code

Still smelly? You betcha. Still need tests? Absolutely.

Cleared Check Server v1

Here's the simplest solution I could come up with for serving cleared checks using sinatra and loading the csv into a global variable. All sorts of bad but its all about the iteration...

Wednesday, December 21, 2011

Opening a dbf file

The final piece of backing up the bank cds came from the last few months where the bank cds switched from using a xml file to a dbf file. Since it was only a few months, I decided to just open the dbf files rather than creating a script. But what opens a dbf file...the answer is OpenOffice which opened the files perfectly. I know its not very elegant but I then copied and pasted the data into the csv file created from the last post. Now, I'm ready to create a server piece so that all employees can discover if a check has cleared.

Creating a csv file from xml using groovy

Following up on the last article where I backed up the bank cds, I wanted to be able to query all of the cds at once to see if a check had cleared. In order to accomplish this, I mounted one of the backed up iso files, explored and found that most of the months used an xml file to list the cleared checks. I pulled the xml file from each iso into a directory and then used the following groovy code to read the file. Why groovy?, I guess it was the flavor of the day

This accomplished reading the file but then I wanted to output to a csv file. I decided to use the opencsv java package. After adding the import to the groovy script for import au.com.bytecode.opencsv.*, I then wrote the following code

Unfortunately the script did not run as opencsv expects a Listof String[] and did not like the groovy lists that it was given. Here's the exception:
Caught: java.lang.ClassCastException: [Ljava.util.ArrayList; cannot be cast to java.util.List at CheckClearer$_run_closure2.doCall(CheckClearer.groovy:30) at CheckClearer.run(CheckClearer.groovy:30)
I explicitly had to create String[]s and then pass them to CSVWriter. Here's the final script:

Backing up cds using a macbook and snow leopard

Our cleared checks come on a cd from the bank each month. The cds desperately needed to be backed up.  Here are the steps I used to accomplish.  


Using a macbook with snow leopard and a slashdot article on creating an iso from a cd slightly modified, I was able to accomplish this fairly easily.


First, find where the disc is located


drutil status


Look for the name output, which in my case was


/dev/disk1


On the slashdot article, they were able to dd /dev/disk1 but in my case I had to go one step further and first list the sessions


ls /dev/disk1*


which listed 


/dev/disk1 and /dev/disk1s0


Next unmount the cd using


diskutil unmountDisk /dev/disk1


and then create an iso file from the cd


dd if=/dev/disk1s0 of=file.iso bs=2048


I know this can be automated even further but I chose the long way and went through the steps for each cd. I was able to eliminate the drutil and ls commands on subsequent runs as /dev/disk1s0 remained constant with every cd.