HR-CRM - Tutorial

This guide will demonstrate how to create a bundle of classes and configuration files to use the HR-CRM application. A sample application can be obtain via SVN using
svn co http://hr-crm.svn.sourceforge.net/viewvc/hr-crm/trunk/config-impl config-impl

Requirements

  • a Java SE 6.0
  • a JDBS Driver for your database
  • a JBoss 4.2.2.GA or higher application server

Download

Our first task is to download HR-CRM application. Open a web browser and download the application. You will then see the list of available releases. Click on the latest version, and you will be directed to the HR-CRM release download page. Now download the 'binary distribution' *.zip or *.tar.gz archive compatible with your operating system.

Creating custom jar

To go through this tutorial you need to install maven 2.0.7 or higher and MySQL 5.1 or higher.
The tutorial has the following steps>

  • Create project with maven
  • Create database schema
  • Define and implement domain model
  • Implement adaptors xsd2ddl
  • Create configuration file (application.properties)

Create project with maven

  • on the command line execute: mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app
  • this project needs two provided dependencies: hrcrm-config-api-version and mysql-connector-java-version pom.xml example
  • on the command line execute: mvn eclipse:eclipse to build the project and import it to eclipse IDE
  • remove App.java and AppTest.java files
  • from src/main folder create resources folder and put there application.properties file
  • Implement three domain classes.
  • Implement adaptors for domain classes.
  • customize application.properties (SQL statements, package names, db connection, ...)

Create database schema

Because HR-CRM is application which provides access to legacy databases, you need a database to connect to. Download the sql script and execute it in your MySQL database.

  • Connect to the MySQL database command line: mysql -uusername -ppassword
  • On mysql shell execute mysql>source path_to_project /trunk/config-impl/hrcrm-db.sql

Define and implement domain model

Now it is the time to define and implent the domain model.
NOTE: Your domain classes must have this names:

Follow the link to see the provided implementation.
NOTE: For package name there is no convention.

Implement adaptors xsd2ddl

After the domain model is ready for use you need to implement adaptors. Unfortunately the application can not be smart enough to see common objects and its properties between your domain model and XSD objects. One of the motivation for this sollutions was once again the lagacy databases. Many of them are not defined in english.
Example of the adaptor classes can be seen here:

NOTE: Every adaptor have to implement an interface from the at.ac.tuwien.vitalab.hrcrm.adaptor package.

Create configuration file (application.properties)

The last thing to provide in the project is the configuration file called: application.properties .
NOTE: You must use exactly this name.

This file is separated in 5 parts:

  • Database connection configuration
    hrcrm.database.driver = com.mysql.jdbc.Driver
    hrcrm.database.url = jdbc\:mysql\://localhost\:3306/hrcrm
    hrcrm.database.username = root
    hrcrm.database.password = root
    								
  • WS Security configuration
    hrcrm.authentication.username = username
    hrcrm.authentication.password = password
    								
  • Address configuration
    hrcrm.address.adaptor = at.ac.tuwien.vitalab.hrcrm.adaptor.AddressAdaptorImpl
    hrcrm.address.bo = at.ac.tuwien.vitalab.hrcrm.bo.Address
    hrcrm.address.sql.createAddress = INSERT INTO ADDRESS (ADDRESS_ID, STREET, COUNTRY, CITY) VALUES (#id#, #street#, #country#, #town#)
    hrcrm.address.sql.retrieveAddressById = SELECT ADDRESS_ID as id, STREET, COUNTRY, CITY as town FROM ADDRESS WHERE ADDRESS_ID = #id#
    hrcrm.address.sql.retrieveAllAddresses = SELECT ADDRESS_ID as id, STREET, COUNTRY, CITY as town FROM ADDRESS
    hrcrm.address.sql.updateAddressById = UPDATE ADDRESS SET STREET = #street#, COUNTRY = #country#, CITY = #town# WHERE ADDRESS_ID = #id#
    hrcrm.address.sql.deleteAddressById = DELETE FROM ADDRESS WHERE ADDRESS_ID = #id#
    								
  • Name configuration
    hrcrm.name.adaptor = at.ac.tuwien.vitalab.hrcrm.adaptor.NameAdaptorImpl
    hrcrm.name.bo = at.ac.tuwien.vitalab.hrcrm.bo.Name
    hrcrm.name.sql.createName = INSERT INTO NAME (NAME_ID, FIRST_NAME, LAST_NAME, AGE) VALUES (#id#, #firstName#, #lastName#, #age#)
    hrcrm.name.sql.retrieveNameById = SELECT NAME_ID as id, FIRST_NAME as firstName, LAST_NAME as lastName, AGE FROM NAME WHERE NAME_ID = #id#
    hrcrm.name.sql.retrieveAllNames = SELECT NAME_ID as id, FIRST_NAME as firstName, LAST_NAME as lastName, AGE FROM NAME
    hrcrm.name.sql.updateNameById = UPDATE NAME SET FIRST_NAME = #firstName#, LAST_NAME = #lastName#, AGE = #age# WHERE NAME_ID = #id#
    hrcrm.name.sql.deleteNameById = DELETE FROM NAME WHERE NAME_ID = #id#
    								
  • Party configuration
    hrcrm.party.adaptor = at.ac.tuwien.vitalab.hrcrm.adaptor.PartyAdaptorImpl
    hrcrm.party.bo = at.ac.tuwien.vitalab.hrcrm.bo.Party
    hrcrm.party.sql.createParty = INSERT INTO PARTY (PARTY_ID, status, href) VALUES (#partyId#, #status#, #href#)
    hrcrm.party.sql.retrievePartyById = SELECT PARTY_ID as partyId, status, href FROM PARTY WHERE PARTY_ID = #partyId#
    hrcrm.party.sql.retrieveAllParties = SELECT PARTY_ID as partyId, status, href FROM PARTY
    hrcrm.party.sql.updatePartyById = UPDATE PARTY SET status = #status#, href = #href# WHERE PARTY_ID = #partyId#
    hrcrm.party.sql.deletePartyById = DELETE FROM PARTY WHERE PARTY_ID = #partyId#
    hrcrm.party.sql.addNameToPartyById = UPDATE NAME SET FK_PARTY_ID = #partyId# WHERE NAME_ID = #nameId#
    hrcrm.party.sql.addAddressToPartyById = UPDATE ADDRESS SET FK_PARTY_ID = #partyId# WHERE ADDRESS_ID = #addressId#								
    								
In the last three parst of the configuration file you have to define the fully qualified package name of the domain object and its adaptors. In the *.sql* variables you have to write your SQL statements in iBATIS style.
NOTE: Every SQL statement have to be located on one line
hrcrm.party.sql.deletePartyById = 
DELETE FROM PARTY 
WHERE PARTY_ID = #partyId#
							
will produce error.

Deployment

If you successfully create the jar go to your JBOSS_HOME folder, navigate to the deploy folder and create a new folder called HR-CRM.
In this folder paste:

  • the hr-crm ear file (obtaind in the download section)
  • the jar file (created in the previous section)
  • database connector jar (e.g: mysql-connector-java-5.1.5.jar)
Start the JBoss and see the web services
  • http://localhost:8080/hr-crm/ws/party.wsdl
  • http://localhost:8080/hr-crm/ws/name.wsdl
  • http://localhost:8080/hr-crm/ws/address.wsdl
For testing you can use soapUI , but you need to provide a header with user authentication.