paddatrapper / CaseTracker

Case tracking and management software for the National SPCA
GNU Lesser General Public License v3.0
3 stars 6 forks source link

Initial setup for user management server side #16

Closed sphaso closed 9 years ago

sphaso commented 9 years ago

Starting point to develop more involved user functionalities.

sphaso commented 9 years ago

Tests were failing when they were going fine a few days ago. I don't know if something on the DB changed, if DB is down or what. This is the issue with calling the DB inside tests. I'll rewrite them once we add an isolation framework. I'm sorry I had to take such a drastic approach.

paddatrapper commented 9 years ago

All in all I really like what you've done. What sort of things should go into the datalayer - factories and repositories, or is it simply objects that represent data with no business logic attached?

sphaso commented 9 years ago

Thanks Padda, and sorry again for the mess. I'll implement a better version tonight. On the datalayer I usually put classes that have to do with stuff in the "outside world" so DB, Web services, FTP... but mainly DB. So yeah, repositories and their factories (but not factories in general).

paddatrapper commented 9 years ago

No worries, that's why there's such a thing as collaboration. :) Datalayer makes perfect sense then. Good job!

paddatrapper commented 9 years ago

Also just realised the server writes a Response object out when logging in, but the client reads a String and parses a boolean from that... I'm not sure how sending objects over the network works, if it does at all - I've always converted to Strings and sent those. Perhaps we need to serialise and write out over a DataOutputStream and read DataInputStream and not the PrintWriter and BufferedReader we are currently using

sphaso commented 9 years ago

You can declare objects as Serializable. I don't know exactly how it works because I've never actually done it. But we'll figure it out.

paddatrapper commented 9 years ago

Google is our friend! I've serialized images before, but never custom classes. Will do some investigation

sphaso commented 9 years ago

Do we still have an "inspector" user in the DB? I'm sure those tests were passing a few days ago...

paddatrapper commented 9 years ago

Yes we do. Check reddit messages for your database username, etc. That test is failing because of the client expecting a boolean I would think

sphaso commented 9 years ago

The test is on the server and is throwing a RowToModelParseException (the custom exception I throw in the Repository). I'll investigate.

paddatrapper commented 9 years ago

Because of the broad catch statement?

sphaso commented 9 years ago

Just noticed there are empty catches in DatabasePersistence. They were hiding the real exception.

paddatrapper commented 9 years ago

IRC? My internet is being sketchy. Think those were intended for logging, but not implemented yet (I'll get onto it once this is finalised). If you want to change it up feel free.

paddatrapper commented 9 years ago

Both fail because the Response object is being read as a string and parsed into a boolean. Need to use ObjectInputStream and ObjectOutputStream to send/receive Response objects then tests will pass.

The other issue is that the catch statements for fetching data from the DB in UserRepository are still too broad and so are catching a NullPointerException when username is incorrect as an error reading from database. Should rather throw an AuthenticationException.

sphaso commented 9 years ago

1) I see. Can you give me a snippet \ example so I can implement it ASA I get back home?

2) OK, I'll throw an AuthenticationException if I get null from DatabasePersistence

paddatrapper commented 9 years ago

Replace new BufferedReader with new ObjectInputStream and new PrintWriter with new ObjectOutputStream in ClientConnectionThread and ServerConnection. You must also implement Serializable in the Response object.

To write an object out:

out.writeObject(response);

To read an object:

Response response = (Response) in.readObject();

ObjectOutputStream and ObjectInputStream

paddatrapper commented 9 years ago

Merged :dancers: