Friday, September 4, 2009

AndroMDA <> entities

AndroMDA is an excellent open source solution for auto-magically generating code from a UML model. This is a description of my experience trying out the <> stereotype. This stereotype appears to allow you to auto-generate data entry screens just by adding the <> stereotype to an entity.

My steps to generate a manageable entity:

Just a little background, I am developing EJB3 entities using JPA /Hibernate/Mysql.
My EJB/Servlet server is Sun Glassfish v2.1 running the Liferay Portal v5.2.3
Maven v2.0.9, Java JDK v1.6.0_13

'out of the box', Andromda will NOT generate any projects properly for Glassfish. I had to make a modified ejb3 cartridge which works on GLASSFISH. I am not going to describe what I had to do in this post, but will try to remember to detail that at a later time. If anyone needs that info, or just wants a copy of the modified ejb3 cartridge I am using, feel free to ping me.

Step 1 - create a new Andromda project.

From command line>

mvn org.andromda.maven.plugins:andromdapp-maven-plugin:3.3:generate

A variety of questions will be asked, below are the options I selected:
Options: 
Rich Client
J2EE
c:/development/andromda_test_portlet
Brad Rideout
UML2
Brad Test Portlet
bradtestportlet
1.0-SNAPSHOT
com.mdahatter.bradportlettest
ear
ejb3
mysql
no
yes
jsf
jsf2
portlet
no
no
Step 2 - modify mda/pom.xml
Since I am using Maven 2.0.9 I had to modify the mda/pom.xml v2.0.8 does not require this step...
find the model.uri section and change it to:

file:${pom.basedir}/src/main/uml/bradportlettest.uml2

Step 3 - Open /mda/src/main/uml/bradportlettest.xml with your uml tool.
I use Magicdraw community version.
The first time you open the project, make sure you set the maven2.repository to your .m2/repository. This can be done in the Options-Environment Options tab.

Step 4 - Create a class diagram
In MagicDraw, right click on the 'Data' folder and click 'New Element--Model', name it 'mdahatter'
Right click on 'mdahatter' and select 'New Element'--'Package' name it com.mdahatter.bradportlettest
Right click on com.mdahatter.bradportlettest and select 'New Diagram'-'class diagram' .. name it 'VOPC'
Add a new class called 'User' with 3 string attributes: 'firstName', lastName', 'email'
Make sure all attributes are public, and use the String [datatype]
Right click on the class and go to the 'Stereotypes' section, select 'Entity' and 'Manageable'... Note: make sure you select the stereotypes from the org.andromda.profile.persistence profile

Step 5 - Export model
Save the model, and select File-Export-EMF UML2 (v1.x) XMI

Step 6 - modify maven pom.xml files

Step 6(A) open the pom.xml in the root of your project.
I modify the org.andromda.cartridge dependency to point to my 1.0-GLASSFISH version of the cartridge. If you are using JBOSS, you should be able to leave this...

org.andromda.cartridges
andromda-ejb3-cartridge
1.0-GLASSFISH
runtime


I also added the Apache maven repository under the area:


apache
Apache Repository
http://people.apache.org/repo/m2-snapshot-repository/


Step 6 (B) Modify the web/pom.xml

In the web/pom.xml find the 'org.apache.myfaces.tomahawk' dependency, and change it like so:


org.apache.myfaces.tomahawk
tomahawk
1.1.7-SNAPSHOT
jar


Step 7 - Run the maven build

From the command line, navigate to the root of the new project and run the command: mvn

**** Right now this creates all of the files, etc. but there is still a bug preventing it from totally compiling for me ****** more once I get that bug fixed!

3 comments:

  1. Hei friend,
    Could you post the steps that you follow in order to change EJB3 cartridge ???

    Thanks a lot !

    ReplyDelete
  2. Hei friend
    Could you post the steps in order to change ejb3 cartridge ??

    ReplyDelete
  3. I have also made a number of updates to the EJB3 cartridge, and plan on committing them to andromda in the future. Could you send your copy of the EJB3 cartridge so that we can consolidate any needed changes? We are planning on making the EJB3 cartridge part of the andromda core, rather than a separate plugin cartridge.

    ReplyDelete