sevab / picture-house

A system for managing networked self-service cinema machines
0 stars 1 forks source link

CW3: Implementation #6

Closed sevab closed 10 years ago

sevab commented 10 years ago

So it's time for us to start coding. Let's arrange a time to meet on Facebook and do it. Here's a rough outline of things we need to do: 1) Setup DB 2) Run migrations on DB (i.e. create tables & stuff) 3) Agree which app we all are going to use to code, so we can share code on GitHub. 4) Install ActiveJDBC using Maven 5) Create Model and Controller classes and corresponding test files as specified on the UML diagram 6) Implement one model and controller together, so everyone understands what we are doing 7) Divide models and controllers implementation among each other, set deadlines and start coding

The question is when should we meet? I can do Monday.

CC: @hornets, @akshay378, @armand64

akshay378 commented 10 years ago

Yes, lets get started. I am good with Monday too!

sevab commented 10 years ago

So I'm trying to install ActiveJDBC following their tutorial, for NetBeans, but I'm stuck on the Add "Compile" libraries from https://activejdbc.googlecode.com/svn/trunk/examples/ant-example/lib/ bit. There's no such option in my version of NetBeans. Asked on StackOverflow, waiting for a response. If anyone manages to install ActiveJDBC on their computer, let me know.

sevab commented 10 years ago

I've made some progress with trying to integrate ActiveJDBC, but I'm now completely stuck. We might have to ask someone to help us set the environment up and get the library up and running. @hornets could you try setting ActiveJDBC up in Netbeans or Eclipse (seems easier in NetBeans though).

hornets commented 10 years ago

@sevab But you shouldn't be trying to trying to use ActiveJDBC directly, we'd have to put a huge amount of work to get it right and we don't have time for that. Again it's not bad, it's just hard and pointless to work so much on something that's been already done and validated by 100000 others. We need to use an ORM. Like Hibernate. Here's a tutorial http://javapostsforlearning.blogspot.in/2013/01/introduction-to-hibernate-framework.html

hornets commented 10 years ago

And as a side note , I use eclipse. So, let's set the software on which we all work on, because last time I tried to move a project from netbeans to eclipse was rather painful. So let's vote. I say eclipse. :+1:

akshay378 commented 10 years ago

And why did you want to move a project from netbeans to eclipse? Just curious :) I use Eclipse too!

armand64 commented 10 years ago

then let's use Eclipse if you all use it. I'm using Netbeans but as you want. what do you say @sevab ?

hornets commented 10 years ago

Something didn't work in netbeans from what i remember, but it did in eclipse, so I moved it. I think for the Module App. But anyway, doesn't really matter as long we all use the same software. Also, I know armand would like Bluej but that's not really possible anymore =))))

sevab commented 10 years ago

I have no experience using Eclipse, but sure, doesn't matter. Btw, ActiveJDBC is also an ORM. The reason I chose it over Hibernate, the framework @hornets just proposed, was because ActiveJDBC is much cleaner, apparently easier to setup than Hibernate and is faster as well. See a 'biased' comparison here. You have to write much less to in ActiveJDBC than you do in Hibernate, obviously we want to finish this off ASAP.

sevab commented 10 years ago

I mean ActiveJDBC is really simple: Connect to a database: Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test", "user1", "xxxxx");

Write a model (no need to write any methods, everything's there automatically)

import activejdbc.Model;
public class Employee extends Model {}

Add a new record to the database:

Employee e = new Employee();
e.set("first_name", "John");
e.set("last_name", "Doe");
e.saveIt();

Find a record: Employee e = Employee.findFirst("first_name = ?", "John");

In comparison, here's how this class and method look in Hibirnate:

@Table(name = "employees")
public class Employee implements Serializable {
    public Employee() {}
    @Id
    @Column(name = "id")
    @GeneratedValue
    Integer id;
    @Column(name = "first_name")
    String firstName;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", first_name='" + firstName + '\'' +
                '}';
    }
}
hornets commented 10 years ago

Hibernate is used since 1998, I tend to trust something that's been around for ages, developed by Redhat rather something done by an Igor. And that tutorial I sent looks simple as well. But whatever, as long as it works doesn't really matter.

sevab commented 10 years ago

@hornets Could you send me the tutorial? I agree that it doesn't matter. As long as we don't need to spend too much time setting it up an configuring.

sevab commented 10 years ago

I just read that Hibernate is quite bulky, has tons of dependencies and has a lot to configure because it's very popular with big Enterprises. While ActiveJDBC is very lightweight, and simple to use and doesn't need any configuration because it's used for more simple projects like ours. But again, if you can configure it, I don't care which one we use.

hornets commented 10 years ago

Already did http://javapostsforlearning.blogspot.in/2013/01/introduction-to-hibernate-framework.html

sevab commented 10 years ago

Managed to setup ActiveJDBC in Netbeans, connect to a remote MySQL database and add a new record! Setting up ActiveJDBC was actually really easy, I just had to drop the jar file in the right folder. Here's all the code that I had to write: SQL to create an Employee table with a first_name and a last_name:

CREATE TABLE employees (
      id  int(11) DEFAULT NULL auto_increment PRIMARY KEY,
      first_name VARCHAR(56),
      last_name VARCHAR(56)
  );

Employee.java model:

import org.javalite.activejdbc.Model;
public class Employee extends Model {}

Adding John Doe as a new employee:

import org.javalite.activejdbc.Base;

public class JavaApplication3 {
    public static void main(String[] args) {
        Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://sql3.freemysqlhosting.net:3306/sql329898", "sql329898", "pS6%tX1%");
        Employee e = new Employee();
        e.set("first_name", "John");
        e.set("last_name", "Doe");
        e.saveIt();
        Base.close();
    }
}

I left out the password to the database, so feel free to connect and check for yourself.

Again, if you guys want to use Hibernate, let's do that. I just doubt it's gonna be as easy to use and as simple to setup as ActiveJDBC (from what I heard). As you can see, we don't even need to implement any methods for the Employer class (e.g. setFirstName, setLastName) which apparently you do need to do in Hibernate. No biggie, but less code to write is always good. ActiveJDBC provides method .set() that does all for you!

sevab commented 10 years ago

So shall we meet on Saturday? We've got only one week to finish all of the back end and do the diagrams.

sevab commented 10 years ago

Hey guys following our discussion on facebook, let's write the sql file. Let's split the work in this way: @hornets screening, movie tables @akshay378 moviereview, ticketbooking @armand64 admin, newsletter The SQL is for a mysql database, but you can write it for oracle if you don't know MySQl and I'll correct it. Here's an example code:

CREATE TABLE employees (
      id  int(11) DEFAULT NULL auto_increment PRIMARY KEY,
      first_name VARCHAR(56),
      last_name VARCHAR(56)
  );
hornets commented 10 years ago

@sevab Thank for the example Seva, can you please also explain a bit what does it mean? I'm a bit confused.

sevab commented 10 years ago

@hornets using the class diagram as a reference write SQL to create tables for the classes I've assigned you to. You can write it either in MySQL SQL or Oracle SQL if you aren't familiar with MySQL

hornets commented 10 years ago

@sevab Thanks the assignment! But I'm still confused about that bit of SQL. I will absolutely try to do what you have assigned in the following hour. If I encounter any difficulties will you be able to assist?

sevab commented 10 years ago

ahahaha @hornets, stop trolling. Yes, don't hesitate to ask me, if you need help with SQL

armand64 commented 10 years ago

ok guys, stop trolling and let's get to work

hornets commented 10 years ago

Here it is

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";

Database: cinema


Table structure for table admin

CREATE TABLE admin ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(240) NOT NULL, password varchar(240) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Table structure for table customer

CREATE TABLE customer ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(240) NOT NULL, creditCard int(30) NOT NULL, password varchar(240) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Table structure for table movie

CREATE TABLE movie ( id int(11) NOT NULL AUTO_INCREMENT, title varchar(240) NOT NULL, trailerUrl varchar(240) NOT NULL, synopsis varchar(240) NOT NULL, startDate date NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Table structure for table movieReview

CREATE TABLE movieReview ( id int(11) NOT NULL AUTO_INCREMENT, movieId int(11) NOT NULL, customerId int(11) NOT NULL, content varchar(240) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Table structure for table newsletter

CREATE TABLE newsletter ( id int(11) NOT NULL AUTO_INCREMENT, content varchar(240) NOT NULL, date date NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Table structure for table screening

CREATE TABLE screening ( id int(11) NOT NULL AUTO_INCREMENT, movieId int(11) NOT NULL, price double NOT NULL, hashMap varchar(240) NOT NULL, startDateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Table structure for table ticketBooking

CREATE TABLE ticketBooking ( id int(11) NOT NULL AUTO_INCREMENT, customerId int(11) NOT NULL, screeningId int(11) NOT NULL, seat varchar(240) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

akshay378 commented 10 years ago

@hornets thank you for posting my and @armand64 SQL code for the tables. My internet connection seems to be messed up today but managed that somehow :)

sevab commented 10 years ago

All right, I think I'm done implementing Customer model. I have now pushed the code, so so you can pull the project and write your models on top of it. It's a Netbeans project, I haven tried getting it working in Eclipse. Anyways, make sure that you familiarize yourself with the code for tomorrow's meeting as well as ActiveJDBC framework. Have a look at the Getting Started guide here.

In the src directory we basically have 2 main folders: models and controllers. In the models folder we keep all the classes that extend the Model class provided by ActiveJDBC. Model classes are basically classes that wrap corresponding database tables. So Customer model maps to customers table in the database. We don't need to write setters and getters methods for the model. To get Customer's password this is all you need to do Customer.findFirst("username = Seva").get("password"). Click here to read more about setters and getters in ActiveJDBC. Inside every model the class we only declare all of the validators for that model. E.g. validatePresenceOf('username') is a method provided by ActiveJDBC to verify that a username is always supplied when creating a new record in database. Click here to read more about validators in ActiveJDBC

In the Controllers we have Controllers classes that will interact with both the front end and the backend. You can ignore them for now.

Also, make sure you have a look at the tests I wrote and familiarize with how testing is done in ActiveJDBC here.

sevab commented 10 years ago

@hornets , could you add and implement the following method into Screening Model class: public Boolean isSeatBooked(int id, String seat) The method takes id of the Screening to check and returns whether or not the seat is taken.

hornets commented 10 years ago

@sevab Will do, currently created a Seat model, it wasn't on the diagram but I feel that's the best way to handle seat allocation.

hornets commented 10 years ago

So here's my proposal for seat allocation, this is the database structure, I believe to be the smartest and most flexible way we could do. And the implementations on it later could be really sweet. Comment.

CREATE TABLE seat_allocation ( id int(11) NOT NULL AUTO_INCREMENT, customerId int(11) NOT NULL, screeningId int(11) NOT NULL, seatId int(11) NOT NULL, PRIMARY KEY (id) )

CREATE TABLE seat_map ( id int(11) NOT NULL AUTO_INCREMENT, seatNumber int(11) NOT NULL, theater int(11) NOT NULL, position int(11) NOT NULL, PRIMARY KEY (id) )

sevab commented 10 years ago

in the seat_map what is seatNumber, theater and position, Seen?

hornets commented 10 years ago

seatNumber is the actual seat number in the theater, position can be axis of it's position on an image ( thought we could use a neat image map when doing gui and mapping the position like that could come in handy ) and theater, we can have more theaters where we run movies , like multiple rooms.

sevab commented 10 years ago

ehm, let's add position when we need it, not in advance. also, David said we need one room

hornets commented 10 years ago

so ? if we can do something that makes sense? is that bad? I don't think so.

sevab commented 10 years ago

we don't need position and theater now.

hornets commented 10 years ago

well ok. but functionally is the same thing.

sevab commented 10 years ago

also, what is seatId in seat_allocation?

hornets commented 10 years ago

the seatId in the map aka id from seat_map aka seat_map_id as you would define it

sevab commented 10 years ago

ok, so seat map is table that we populate with a room information once, and never add more, right? and seat allocation stores information about which seats are occupied, right? But you are still missing the screening. We need to have a screening for each movie. I.e. Shrek is screened between 2pm-4pm on 16th of March, and 9pm-11pm on 19th of March

hornets commented 10 years ago

exactly seat_map is concrete , only can be maybe managed by the administrator if needed, but that's it, and that feature we don't really need to push.

and seat_allocation about seats occupied indeed

what screening? that's a different thing

i'm talking now strictly about seat allocation

screening will use the seat model

btw

are we going only for one room ?

because in that case, we don't even need seats anymore in the screening

sevab commented 10 years ago

ok, cool, I'm with you. but, remove theater and position from seat_allocation, we'll add those if/when we need them. Also, we don't need to know customer id in seat allocation, cuz we store that in ticketbooking, but sure you can keep it if you want. also, I think we should rename seat_allocation to seat_bookings and seat_map to room_plan, because would be more clear . also make sure you use underscore notation for column names, because that's the way it is in all of the db, so screening_id not screeningID Yes, one room. If we add more rooms, people may get confused

hornets commented 10 years ago

well, i feel it's faster to search for it like that, i think it is the right way to have customer_id in seat allocation, else we'll have a list of taken seats from the map. seat_bookings sounds good, room_plan as well

yeah ok

cool

sevab commented 10 years ago

we don't care who owns that seat, we care if it's taken or not. we have info about who owns that seat in ticketBooking

hornets commented 10 years ago

true

hornets commented 10 years ago

Ok, I'm fairly close to completion of my modules. Just as a note, I removed the seats from the screening table as it is no longer required in the current setup. Also, I have created the isSeated method which takes in the screening_id and the seat_number. I wanted to create a method for booking a seat as I believed to be a tricky one but I believe it belongs to the TicketBooking controller, who was that assigned to?

I will push the code to another branch as soon as i'm done with the test class for screening.

hornets commented 10 years ago

Okay I pushed the code in the vlad branch. Comment.

akshay378 commented 10 years ago

Awesome! I along with @armand64 will make the required changes needed to the class diagram now, update it and put it up here so that all of us can have a look and point out stuff that is un-done and do it before meeting up tomorrow.

akshay378 commented 10 years ago

So here is the updated version of the class diagram. We have made the changes necessary for the existing class diagram and added SeatBooking and RoomPlan models. Have a look and let me or @armand64 know if you spot anything unchanged/not required etc.

classdiagram_v4

sevab commented 10 years ago

@hornets, I think TicketController.create() is supposed to book the seat, but it doesn't since I didn't have your code. I will add it later tomorrow.

@akshay378, the diagram seems to look good, except you forgot to inherit the bottom two classes from the ModelBade. Also, I think we should rename ModelBase to just Model. Will compare method signatures later.

Let's meet at 14 tomorrow. But If anyone is free and wonders what to do, you can start working on your sequence diagrams.

On 28 Feb 2014, at 14:59, hornets notifications@github.com wrote:

Ok, I'm fairly close to completion of my modules. Just as a note, I removed the seats from the screening table as it is no longer required in the current setup. Also, I have created the isSeated method which takes in the screening_id and the seat_number. I wanted to create a method for booking a seat as I believed to be a tricky one but I believe it belongs to the TicketBooking controller, who was that assigned to?

I will push the code to another branch as soon as i'm done with the test class for screening.

— Reply to this email directly or view it on GitHub.

sevab commented 10 years ago

Btw, my UniquenessValidator code have been merged by the framework author and is now officially part of the ActiveJDBC.

On 28 Feb 2014, at 19:11, akshay378 notifications@github.com wrote:

So here is the updated version of the class diagram. We have made the changes necessary for the existing class diagram and added SeatBooking and RoomPlan models. Have a look and let me or @armand64 know if you spot anything unchanged/not required etc.

— Reply to this email directly or view it on GitHub.

hornets commented 10 years ago

@sevab Very good Seva. We are proud of that, our little project just made a small dent in the open source world. Congrats!

David should be happy about what our team has managed to achieve.

sevab commented 10 years ago

@hornets, I assume I delete CustomerExistsValidator?