Assignment 2b

Deadline Date September 27th, 23:59

You must pass this assignment to pass the course. Meet up to your lab sessions to ask your group teacher if you have any questions.

NOTE: Run mvn install in project root BEFORE importing to eclipse.

Overview

In this assignment you will be implementing functionality for a simple web-based student system. The system consists of three layers: persistence, service, and presentation layers. Your task is to implement the functionality of the first two layers. Expected functionalities of the two layers are defined in interfaces which are provided for you. You need to implement these interfaces and create unit tests which prove that your implementations are correct according to the interfaces. The graphical user interface (presentation layer) is provided, and can be configured to use your implementations to get a fully working system.

Case description

The case is a simple student system for keeping track of students, courses and degrees. Students can attend courses and get degrees, courses have attendants, and degrees have required courses. In order for a student to get a degree the student must attend all courses which are required by the degree. To keep the model simple there is no time aspect in the system. The system does not claim to be a realistic student system.

Provided source code

Note: You’re not allowed to change any of the provided code except the root pom.xml and the pom.xml of the GUI project. Also, you if you want to use Hibernate annotations you can annotate the classes in the api project. See the detailed description below for information about where to find the initial project code.

Before importing to eclipse

Run "mvn install" in project root:

 mvn install

assignment2-api

The API project contains the model and the interfaces you will be implementing. The model consists of three classes: Student, Course, and Degree. The properties of these classes are kept to a minimum to make life simpler. The Student has a Set of Courses and a Set of Degrees. The Course has a Set of Students (attendants), so the Student-Course relation is bidirectional. The Degree has a Set of required Courses. (Tip: Make a drawing of all the relations). For each of these classes you will find a corresponding DAO interface (Data Access Object) with simple methods to persist (“store”) and to retrieve persisted objects. The main functionality of the system is defined by the StudentSystem service interface. Your implementation of this interface will use the DAOs to persist objects.

assignment2-gui

The GUI project contains a fully working GUI based on Spring MVC. The GUI will use your implementation of the API when you run it.

Requirements

All your code must be in a separate Maven 2 project (assignment2b-deliverable) alongside the provided modules. You must make your project available in a git repository on git.uio.no. Your repository should be called

gitolite@git.uio.no:/inf5750/<userid>/assignment2b_<userid>

You can use ‘git clone’ or the instructions from assignment 1 to create this repository (see below for hints).

You then need add this URL (in a text file) to devilry as a delivery to Assignment 2.

You must create hibernate mapping files that enable Hibernate to map the assignment2-api model (java interfaces) to the relational databases’ tables and columns. There will be mapping files for the model files Course, Degree and Student. It is useful to draw up a diagram of how these relate to help you create the mapping files.

The Data Access Object (DAO) interfaces must be implemented according to the description in the interfaces and in the assignment using Hibernate for persistence. Usage of Spring ORM/Hibernate support is mandatory. The DAO implementation provides methods to create, save and do other operations on the database, using Hibernate’s “sessionFactory.getCurrentSession().” as the interface to the database. It’s probably simplest to autowire the sessionFactory into your DAO implementations.

The service interface (StudentSystem) must be implemented, and must use the DAO interfaces for storing and retrieving the model objects. This is a higher level interface that provides operations that involve Courses, Students and Degrees. The interface is already defined in the api-package, but you have to create an implementation.

All methods must be unit tested according to the defined behaviour of the implementations. You have to write these tests. The tests must run successfully with Maven and use Spring to instantiate the components which are going to be tested. Usage of Spring test support is mandatory.

Please implement test classes both for the DAO objects and the StudentSystem object.

Example code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:/META-INF/assignment2/beans.xml"})
@Transactional
public class StudentSystemTest
{

    @Autowired
    private StudentSystem studentSystem;


    @Test
    public void testAddGetDegree()

    {
        int id = studentSystem.addDegree( "Master" );
        Degree degree = studentSystem.getDegree( id );
        assertEquals( degree.getType(), "Master" );
    }

...

The components of the system must be wired together using the Spring container and the dependency injection principle. You can choose whether to use the XML or annotation based configuration.

The code must have a consistent and readable code style. (Use Eclipse CTRL-SHIFT-F to help format your code). Using the formatting tool of your IDE is a very good practice to make good-looking code fast.

The provided GUI must be fully functional.

The directory structure of the reference implementation is showed in the figure below:

What should the user interface look like?

You do not have to implement a user interface, since the project already comes with one. Hint: Click ‘Init database’ to populate your db with some data.

You only need to implemement the storage layer and the test classes. Here are some screen shots of the user interface:

Which database to use

In Assignment 1, you used the in-memory database H2. This is very simple, but you get no visibility of the tables that Hibernate is creating for you. You can also use H2 in this assignment, but many people will find it simpler to do the job of using Postgres instead. We highly recommend doing this since it is likely to make your learning more efficient and actually help you implement the project faster.

To use postgres, you need to install postgres on your computer (or get a UIO postgres account), create a database called for example ‘inf5750’ with a user ‘dhis’ and password ‘dhis’, and then reconfigure the beans.xml file in your deliverable to use Postgres instead of H2. If you do this, please Include a note in the delivery text file that you’ve done the assignment using Postgres.

If you want to configure Postgres as your Hibernate-database, your beans.xml would contain this configuration (this is not the complete beans.xml). In this case, the database is called inf5750, the user=dhis and the password=dhis.

…

<property name="hibernateProperties">

        <props>

                <prop key="hibernate.show_sql">true</prop>

                <!-- <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop> -->

                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>

                <prop key="hibernate.hbm2ddl.auto">create-drop</prop>

        </props>

</property>

…

<!--<property name="driverClass" value="org.h2.Driver" />

<property name="jdbcUrl" value="jdbc:h2:file:inf5750;DB_CLOSE_ON_EXIT=FALSE" />-->

<property name="jdbcUrl" value="jdbc:postgresql:inf5750" />

<property name="driverClass" value="org.postgresql.Driver" />

<property name="user" value="dhis" />

<property name="password" value="dhis" />

...

Hints and detailed description

The initial source code is available at the repository:

gitolite@git.uio.no:inf5750/roland/assignment2-skeleton 

(the code may also be updated during the assignment period).

You can clone this code by running

git clone gitolite@git.uio.no:inf5750/roland/assignment2-skeleton assignment2b_<userid>

This will clone the repository into your own directory called assignment2_<userid>

Now remove the origin-link to the the original repository

$ git remote rm origin

And add your repository as the new origin

$ git remote add origin gitolite@git.uio.no:inf5750/<userid>/assignment2b_<userid>

And create your version of this repository on git.uio.no (the -u option sets the upstream-url).

$ git push -u origin master

You now have a maven project consisting of three sub-projects. Two of them should remain unchanged (the assignment2-gui and assignment2-api). You should do all your work in the assignment2-deliverable, which you can see is almost empty now.

assignment2_<uio-user-id>/assignment2-api/

assignment2_<uio-user-id>/assignment2-gui/

assignment2_<uio-user-id>/assignment2-deliverable/

In order to implement the API in your project, you need a dependency to assignment2_api.

In order to implement and run unit tests you need a dependency to JUnit (junit) and a dependency to Spring (spring-test). Dependencies are added in your pom.xml files. Since you have sub-projects, you have a master pom in the root directory and sub-poms in the sub-directories. Check if you have dependencies for JUnit and spring-test in your deliverable pom.xml file. We have already given you a pom.xml file in the deliverable directory. Normally you’d have to write this yourself.

Opening up the project in Eclipse:

  • Run mvn install from the root of the project (where pom.xml, assignment2-api, assignment2-gui, etc. is located).
  • Import existing Maven project from the Eclipse GUI. File -> Import -> Existing Maven project.

In order to get the GUI working later on, check that your project is added as a dependency to the pom.xml in the assignment2-gui project.

Use your repository actively! It will prevent lost source code. Check in code locally often.

A screen shot of the reference is provided earlier in this assignment.

Your Hibernate implementations of the DAO interfaces should be named HibernateCourseDAO (and so on) and be placed in a package called no.uio.inf5750.assignment2.dao.hibernate.

Your implementation of the StudentSystem interface should be named DefaultStudentSystem and be placed in package called no.uio.inf5750.assignment2.service.impl.

Your DAO test classes (CourseDAOTest.java, DegreeDAOTest.java and StudentDAOTest.java) should be placed in a package called no.uio.inf5750.assignment2.dao in the “src/test/java” directory.  

Your StudentSystem test class (StudentSystemTest.java) should be placed in a package called no.uio.inf5750.assignment2.service in the “src/test/java” directory.

Look in the Maven lecture notes and/or assignment 1 to understand which directory structure you should follow when you build up your deliverable project. Note that the test classes do not reside together with the other src files, but in a separate directory called /src/test/java.  

The beans.xml file must go into a directory called src/main/resources/META-INF/assignment2/ for the main class in the GUI to find it. Note that this xml file could be called different names in different projects, but that many developers often use the name beans.xml since this is the main definition file for Spring-beans.

Your hibernate mapping files should have the format <interface-name>.hbm.xml, for example Course.hbm.xml and be placed in the src/main/resources/hibernate directory.

To get detailed instructions on how to set up the Spring (spring-orm) and Hibernate POM dependencies and how to use the Spring support for ORM/Hibernate and testing, please consult the Hibernate lecture slides.

To run the GUI, right-click the assignment2-gui project within Eclipse and choose ‘Run on server’. Look at assignment1 for more information. You can also run it within jetty, from command line by running ‘mvn jetty:run’ while in the assignment2-gui folder. For this to work, there needs to be a jetty-plugin defined in the pom.

By default, Eclipse uses the dependencies from the local Maven 2 repository. You may have to choose ‘Maven → update project’ within Eclipse when you’ve updated your pom files. You may also need to add Tomcat dependencies in the build path of your project.

If you are using Spring annotations you must provide a value to the DefaultStudentSystem class annotation like this for the GUI to find it: @Component(“defaultStudentSystem”)

When you’re done, commit all the source code to your Subversion repository and add a  Assignment2b-<username>.txt and the URL to your repository on devilry.

 

Published Sep. 14, 2015 8:08 PM - Last modified Sep. 25, 2015 9:12 PM