Enterprise System Project – Stage 1 Integration Technical setup and DB

Prerequisites • Eclipse • Glassfish • (http://ant.apache.org/) • Apache Ivy (http://ant.apache.org/ivy/) • Mercurial (http://mercurial.selenic.com/wiki/Download) o Graphical interface for mercurial (http://tortoisehg.bitbucket.org/) • MySQL (You should have one in ATS server)

Introduction This practice presents the essential infrastructure that will be used during the development of the project; additionally, it describes the steps for setting the configuration. There are different components that you will need to install, and you will need to get familiarized with. For this reason, it would be advisable to take some time and get to know the tools described in the Prerequisite. We will provide you with a skeleton that you will use as a base for developing your project. The source code will be stored in a Mercurial repository in bitbucket.org. The deliverables of this homework (see end of the document) have to be ready by October 15th, 10:00 am. Late submissions will receive a penalty.

Get the system up and running

1. Download the project from the course webpage and unzip it into your workspace folder (https://courses.cs.ut.ee/2012/esi/uploads/Main/projectPart1.zip) 2. The project includes the following: a. ivy.xml: it contains the description of the dependencies of a module, its published artifacts and its configurations. b. build.xml: it is an Ant script that supplies a number of built-in tasks allowing to compile, assemble, test and run applications. c. set of classes that you will need to complete with methods and annotations. They describe the entities, servlets and session beans. d. a test case for your database. 3. Import the project into Eclipse

2

4. Open the Ant view (Window -> Show View -> Other… -> Ant) and drag build.xml into it. a. Double-click on “war”. (Command line: ant war): This download any dependencies declared in ivy.xml, compile sources and package the project into a war. b. The project should be built and packaged into build/esi.war c. To run tests double-click “test”. (Command line: ant test): Some errors might appear because we have not declare all the components of the existing tests 5. If you don’t have Glassfish already installed a. Help -> Install New Software i. Work with -> Press Add 1. Name - Glassfish 2. Location - http://dlc.sun.com.edgesuite.net/glassfish/eclipse/juno 3. Select Glassfish Application Server and install it. b. A Glassfish server should appear in the Servers view. 6. Right-click on the server and press Start 7. Open a browser and go to localhost:4848, the Administration console should appear. 8. Go to Application, press Deploy 9. Point the server to your esi.war file and press OK. The application should now be deployed on your machine.

Create a mercurial repository

1. Create a team-owned public repository with BitBucket (bitbucket.org). When creating your repository, check that the repository type is Mercurial. 2. A good mercurial tutorial: http://hginit.com/ 3. Push your project to the repository a. In command line: i. go into the folder of your project ii. hg init iii. hg add * iv. hg commit –m “Start line” v. hg push https://[email protected]/xyz/repo_name (look for the corresponding url in your bitbucket repository)

Create a job

1. Go to the Jenkins server (If you use it in ATS server, you can make login using your university credentials) a. Press New job b. Choose a name for your job c. Choose “Build a free-style software project” and press OK d. Under Source Code Management choose mercurial e. Point Jenkins to your newly created repository in repository URL field f. Under Build Triggers choose Poll SCM i. Set it up to poll your repository periodically ii. You can choose the period yourself, you can get help from the Schedule field g. Under Build

3

i. Add a build step that will run your Ant target named “test”. ii. For Ant version choose Ant 1.8.4! (For some reason the “Default” installation doesn’t recognize the junit target used in build.xml) h. You should now be able to build your project in Jenkins (Although the tests should fail).

Start line

1. Populate the database a. Connect to your local database (You can use a graphical tool like MySQL Workbench http://www.mysql.com/products/workbench/) b. Create table for Price List, populate it with a couple of items i. Columns should be based on the PriceListItem class. c. Create table for Hire requests. i. Columns should be based on the HireRequest class.

2. Modify and configure the application to connect to the database a. Create a persistence.xml file (This also requires modifying build.xml so that the file will end up in the right folder in the .war package) i. Some help with the contents http://www.objectdb.com/java/jpa/entity/persistence- unit ii. You should change the build target so that it would copy the file to webapp/WEB- INF/classes/META-INF

3. Create your JDBC resources from the GlassFish admin console a. Another option is to create a glassfish-resources.xml file where you define application- specific JDBC resources.

4. Annotate model classes (HireRequest, PriceListItem) to represent entities in the database. a. Classes of interest should be i. javax.persistence.Entity ii. javax.persistence.Table iii. javax.persistence.Column iv. etc... b. Modify your ivy.xml for downloading the required libraries

5. Modify the application a. Price list should be taken from the database. i. You’ll need to modify PriceListService.getPriceList() b. All new Hire requests should be written into database i. You’ll need to modify HirerequestService.order() c. Rent request list should be taken from the database i. You’ll need to modify HirerequestService.getHireRequests()

6. Modify the application so that the test provided with the project will pass. a. The tests use the properties defined in the setUp method. You should only need to modify parameters JdbcUrl, UserName and Password according to your database. If

4

you have a different name for your DataSource then change the “dataSource” parts to that value. b. The test should create a new PriceListItem object, write it into your database, then use the get() method to read the same item from your database. Then it will delete the same item from your database and verify by asserting that the same get operation will return null.

7. Do not forget to update your code in BitBucket.

8. In order to complete the second part of the first practice (rental requisition creation), you can insert some fake data into your database to simulate the possible machinery that the plant supplier may offer. At this point, you need to be able to create the first document in the process where the site engineer selects a plant and specifies the dates.

Deliverables

• An HG clone named TeamXAssignment1 on your Mercurial repo, where X = your team's number. The HG clone should contain the code of the modified application and the modified test

• The modified application deployed on the GlassFish in ATS Server with the name TeamXAssignment1

• A Jenkins job deployed on the Jenkins server with name TeamXAssignment1 configured to test the application deployed on the Glassfish server. Note: You do not need to send anything to the lab assistant. Just make sure that the HG clone is created, the application is deployed and the Jenkins job is created and runs.