64
Developing for Plone using ArchGenXML / ArgoUML Plone Magic Camp Brooklyn, NY July 24, 2006 Nate Aune Jazkarta Consulting www.jazkarta.com

Developing for Plone using ArchGenXML / ArgoUML

Embed Size (px)

DESCRIPTION

July 24, 2006. The training materials for the Plone Magic Camp in Brooklyn, NY. This day-long course helps you get started with rapid application development using ArchGenXML and ArgoUML. We walk through an example of building an Artist and Group classes in ArgoUML, and auto-generate the Plone product code using ArchGenXML.

Citation preview

Page 1: Developing for Plone using ArchGenXML / ArgoUML

Developing for Plone using ArchGenXML / ArgoUML

Plone Magic CampBrooklyn, NYJuly 24, 2006

Nate AuneJazkarta Consultingwww.jazkarta.com

Page 2: Developing for Plone using ArchGenXML / ArgoUML

Who am I?

• Founder and developer, Jazkarta Consulting (www.jazkarta.com)

• Musician - saxophonist and composer (www.nateaune.com/music/)

• Founder of Plone4Artists project (www.plone4artists.org)

Page 3: Developing for Plone using ArchGenXML / ArgoUML

Agenda

• What is Archetypes?

• What is UML?

• What is ArchGenXML?

• Build a model using ArgoUML

• Transform the model into a Plone product

• Questions?

Page 4: Developing for Plone using ArchGenXML / ArgoUML

What is Archetypes?

• Framework for developing Plone products

• Automatically creates view and edit pages

• Maintains unique object IDs

• Creates references between objects

Page 5: Developing for Plone using ArchGenXML / ArgoUML

Archetypes framework

• Field validation

• Standard security setup

• Alternate storage options

• Data transformation capabilities

Page 6: Developing for Plone using ArchGenXML / ArgoUML

Archetypes schemas

• Schema

• Field

• Widget

• Field

• Widget

• ...

Page 7: Developing for Plone using ArchGenXML / ArgoUML

Example Archetype: Artist

schema= Schema(( StringField('title'), ImageField('photo'), LinesField('instrument'),))

class Artist(BaseContent) schema = BaseSchema + schema

registerType(Artist,PROJECTNAME)

Page 8: Developing for Plone using ArchGenXML / ArgoUML

Widgetsschema= Schema(( StringField('title', widget=StringWidget( label=’Artist name’, size=20), ), ImageField('photo', widget=ImageWidget( label=’Headshot’), ), LinesField('instrument', widget=MultiSelectionWidget( label=’Instruments’), multiValue=1, ),))

Page 9: Developing for Plone using ArchGenXML / ArgoUML

What is UML?

• UML = Uniform Modeling Language

• Standard widely-adopted graphical language

• Describes the artifacts of software systems

• Focus on conceptual representations

Page 10: Developing for Plone using ArchGenXML / ArgoUML

Artist: Described in UML

Page 11: Developing for Plone using ArchGenXML / ArgoUML

Poseidon UML tool

Page 12: Developing for Plone using ArchGenXML / ArgoUML

What is ArchGenXML?

• Command line utility

• Auto-generates code from a UML model

• No round-trip support yet

• Custom code is preserved upon regeneration

Page 13: Developing for Plone using ArchGenXML / ArgoUML

Why use ArchGenXML? (part 1)

• You want to save time

• You are a lazy programmer

• You don’t like to reinvent the wheel

• You don’t like copying and pasting code

• You make heavy use of references and interfaces

Page 14: Developing for Plone using ArchGenXML / ArgoUML

Why use ArchGenXML? (part 2)

• You have big projects with many different content types

• You want or need a well-documented interface to your product

• You like structured model- and pattern-driven software development

• You want to maintain your project in the future without getting a headache

Page 15: Developing for Plone using ArchGenXML / ArgoUML

UML to Archetypes using ArchGenXML

schema= Schema(( StringField('title', widget=StringWidget( label=’Artist name’, size=20), ), ImageField('photo', widget=ImageWidget( label=’Headshot’), ), LinesField('instrument', widget=MultiSelectionWidget( label=’Instruments’), multiValue=1, ),))

Page 16: Developing for Plone using ArchGenXML / ArgoUML

UML speak to AT speak• product

• content type

• method

• field

• property

• subclass, view, etc.

• package

• class

• operation

• attribute

• tagged value

• stereotype

Page 17: Developing for Plone using ArchGenXML / ArgoUML

In practice

1. Save your model to the Products dir

2. Run the ArchGenXML script

3. Restart Zope

4. Install the newly generated product

Page 18: Developing for Plone using ArchGenXML / ArgoUML

ArchGenXML components

• ArchGenXML

• Optional:

• i18ndude

• stripogram

• ATBackRef

• ATVocabularyManager

• Relations

Page 19: Developing for Plone using ArchGenXML / ArgoUML

Install ArchGenXML• Get PloneMagicCamp-bundle

$ svn co svn://svn.plone4artists.org/trunk/PloneMagicCamp-bundle(* if you don’t have SVN, download the .zip file)

$ cd $INSTANCE/Products

$ ln -s /path/to/PloneMagicCamp-bundle/* .

$ cd i18ndude; sudo /path/to/python setup.py install

$ cd ../; ./getStripogram.sh

$ cd stripogram; sudo /path/to/python setup.py install

* If you don’t have SVN client, get the ZIP file.$ wget http://www.jazkarta.com/PloneMagicCamp-bundle.zip$ unzip PloneMagicCamp-bundle.zip

Page 20: Developing for Plone using ArchGenXML / ArgoUML

Install ArgoUML• Use the pre-configured one that comes with the bundle• --OR-- download from http://argouml.tigris.org

$ wget http://argouml-downloads.tigris.org/nonav/argouml-0.20/ArgoUML-0.20.tar.gz

$ tar xvfz ArgoUML-0.20.tar.gz

$ cd ArgoUML-0.20

$ cp $INSTANCE_HOME/Products/ArchGenXML/argouml/argouml_profile.xmi .

$ cp argouml.sh argouml.sh.orig; vi argouml.sh

change line 48 to:

${JAVACMD} -Dargo.defaultModel=argouml_profile.xmi -jar ${ARGO_HOME}/argouml-mdr.jar $*

$ sh argouml.sh (to launch ArgoUML)--OR--$ java -Dargo.defaultModel=argouml_profile.xmi -jar argouml-mdr.jar

Page 21: Developing for Plone using ArchGenXML / ArgoUML

AGX options in ArgoUML!

Page 22: Developing for Plone using ArchGenXML / ArgoUML

Create Artist class

Page 23: Developing for Plone using ArchGenXML / ArgoUML

Add description and icon

Page 24: Developing for Plone using ArchGenXML / ArgoUML

Repurpose Title field

Page 25: Developing for Plone using ArchGenXML / ArgoUML

Set the photo sizes

Page 26: Developing for Plone using ArchGenXML / ArgoUML

Add instrument vocabulary

Page 27: Developing for Plone using ArchGenXML / ArgoUML

Running the script

$ cd $INSTANCE_HOME/Products

$ ArchGenXML/ArchGenXML.py -o ArtistSite ArtistSite.zargo

ArchGenXML Version 1.5.0 svn/devel(c) 2003-2006 BlueDynamics, Austria, GNU General Public License 2.0 or laterINFO Parsing...INFO Directory in which we're generating the files: 'ArtistSite'.INFO Generating...INFO Starting new Product: 'ArtistSite'.INFO Generating package 'content'.INFO Generating class 'Artist'.

$

• Save project to $INSTANCE_HOME/Products/ArtistSite.zargo

Page 28: Developing for Plone using ArchGenXML / ArgoUML

ArtistSite product dir

$ cd $INSTANCE_HOME/Products/ArtistSite

$ lscontent __init__.py i18n skinsExtensions config.py refresh.txt version.txt

$ cd content

$ ls__init__.py Artist.py

$ vi Artist.py

Page 29: Developing for Plone using ArchGenXML / ArgoUML

Inspect Artist.py• Inserts documentation

• Placeholders for custom code

• i18n message ids

• Using ArtistSite/model/generate_source.sh

• inserts author information (ArtistSite.conf)

• creates i18n generated.pot file (i18ndude)

• strips HTML from doc strings (stripogram)

Page 30: Developing for Plone using ArchGenXML / ArgoUML

Add new artist1. Restart Zope2. Install ArtistSite using QuickInstaller3. Add new Artist

Page 31: Developing for Plone using ArchGenXML / ArgoUML

Edit artist form

Page 32: Developing for Plone using ArchGenXML / ArgoUML

View artist

Page 33: Developing for Plone using ArchGenXML / ArgoUML

Move model into product

• Close ArgoUML since we are going to move the file

$ cd $INSTANCE/Products

$ mkdir ArtistSite/model

$ mv ArtistSite.zargo ArtistSite/model

$ ArchGenXML/ArchGenXML.py --sample-config > ArtistSite/model/ArtistSite.conf

$ cp PloneMagicCamp-bundle/generate_source.sh ArtistSite/model/

Page 34: Developing for Plone using ArchGenXML / ArgoUML

Edit ArtistSite.conf

• Add your own author, email and copyright

[DOCUMENTATION]

strip-html: yesauthor: Nate Aunee-mail: natea (at) jazkarta (dot) comcopyright: Jazkarta

[GENERAL]outfile: ArtistSite

Page 35: Developing for Plone using ArchGenXML / ArgoUML

Edit generate_source.sh

• Change PYTHON_BIN to your Python

#! /usr/bin/env bash

PRODUCT_NAME="ArtistSite"PRODUCTS_HOME="`pwd`"PYTHON_BIN="/sw/bin/python2.4"

$PYTHON_BIN $PRODUCTS_HOME/ArchGenXML/ArchGenXML.py -c /$PRODUCTS_HOME/$PRODUCT_NAME/model/$PRODUCT_NAME.conf /$PRODUCTS_HOME/$PRODUCT_NAME/model/$PRODUCT_NAME.zargo

Page 36: Developing for Plone using ArchGenXML / ArgoUML

Run generate_source.sh

$ cd $INSTANCE_HOME/Products

$ ArtistSite/model/generate_source.sh

ArchGenXML Version 1.5.0 svn/devel(c) 2003-2006 BlueDynamics, Austria, GNU General Public License 2.0 or laterINFO Parsing...INFO Directory in which we're generating the files: 'ArtistSite'.INFO Generating...INFO Starting new Product: 'ArtistSite'.INFO Generating package 'content'.INFO Generating class 'Artist'.

$

Page 37: Developing for Plone using ArchGenXML / ArgoUML

Dynamic vocabulary

Page 38: Developing for Plone using ArchGenXML / ArgoUML

Add ATVM as dependency

• Edit ArtistSite/AppConfig.py

• Add line to:

• DEPENDENCIES = ['ATVocabularyManager']

• Restart Zope

• Reinstall ArtistSite

Page 39: Developing for Plone using ArchGenXML / ArgoUML

Vocabulary Library• Go to Plone Setup and choose Vocabulary Library

Page 40: Developing for Plone using ArchGenXML / ArgoUML

Add a vocabulary term

Page 41: Developing for Plone using ArchGenXML / ArgoUML

Hierarchical vocabularies

Page 42: Developing for Plone using ArchGenXML / ArgoUML

Tagged values

• cd $INSTANCE/Products/ArchGenXML

• ./TaggedValueSupport.py | more

• ./TaggedValueSupport.py > tagged-values.txt

Page 43: Developing for Plone using ArchGenXML / ArgoUML

Containment

Use the solid rhomb to make a strict containment‘Artist’ instances can only be added to an ‘Artists’ instance

Page 44: Developing for Plone using ArchGenXML / ArgoUML

Use <<large>> stereotype

Page 45: Developing for Plone using ArchGenXML / ArgoUML

Give it a friendly name

Page 46: Developing for Plone using ArchGenXML / ArgoUML

Add Artists container

Page 47: Developing for Plone using ArchGenXML / ArgoUML

References

Create a direct association

results in:

Reference fieldgroup to artist(s)

Page 48: Developing for Plone using ArchGenXML / ArgoUML

Create direct association

Page 49: Developing for Plone using ArchGenXML / ArgoUML

Change the multiplicity (0..*)• Right-click the end point

• Select Multiplicity 0..* (many artists in a group)

Page 50: Developing for Plone using ArchGenXML / ArgoUML

Group edit form

Group is associated with artists

Page 51: Developing for Plone using ArchGenXML / ArgoUML

Reference Browser Widget as default

Page 52: Developing for Plone using ArchGenXML / ArgoUML

Configure browser widget

Select the end point

Make multivaluedSpecify relationship

Define query

Page 53: Developing for Plone using ArchGenXML / ArgoUML

Adding references

Page 54: Developing for Plone using ArchGenXML / ArgoUML

Add back reference

Page 55: Developing for Plone using ArchGenXML / ArgoUML

Add ATBackRef as dependency

• Edit ArtistSite/AppConfig.py

• Change line to:

• DEPENDENCIES = ['ATVocabularyManager', ‘ATBackRef’]

• Restart Zope

• Reinstall ArtistSite

Page 56: Developing for Plone using ArchGenXML / ArgoUML

Backreferences

Groups that artist belongs to

Page 57: Developing for Plone using ArchGenXML / ArgoUML

Custom view for group folder

Page 58: Developing for Plone using ArchGenXML / ArgoUML

Assign member stereotype

Add the ‘member’ stereotype to tell ArchGenXML to subclass CMFMember

Page 59: Developing for Plone using ArchGenXML / ArgoUML

Computed field

Page 60: Developing for Plone using ArchGenXML / ArgoUML

Registration form

• SiteMember is installed

• Replaces default member

• Easy way to create new member types

Page 61: Developing for Plone using ArchGenXML / ArgoUML
Page 62: Developing for Plone using ArchGenXML / ArgoUML

PloneMall

• Example of a sophisticated e-commerce framework built using UML

• See the UML model here:

• http://www.plonemall.com/uml/UML-beta2.png/image_view_fullscreen

Page 63: Developing for Plone using ArchGenXML / ArgoUML

What I didn’t cover

• Additional Stereotypes

• actions, portal_tool, abstract, stub, ordered

• portlets, configlet, customization policy

• Generalization (Interfaces)

• Workflow

• Unit testing, doctests

Page 64: Developing for Plone using ArchGenXML / ArgoUML

Links• ArchGenXML presentation - http://www.jazkarta.com/presentations/archgenxml-presentation

• ArchGenXML product page - http://plone.org/products/archgenxml

• ArchGenXML getting started tutorial by Jens Klein

• http://plone.org/documentation/tutorial/archgenxml-getting-started

• PDF formatted: http://www.fraterdeus.com/downloads/ArchGenXML_PDF_0.2.1/view

• Intro to Archetypes by Sidnei da Silva, published on ZopeMag.com

• http://www.zopemag.com/Issue006/Section_Articles/article_IntroToArchteypes.html

• Archetypes: Customizing Plone in 60 seconds (PDF) by Andy McKay

• http://www.enfoldsystems.com/About/Talks/archetypes.pdf

• Archetypes Quick Reference by Maik Röder

• http://plone.org/products/archetypes/documentation/manual/quickref/referencemanual-all-pages

• Archetypes API

• http://api.plone.org/