developing for plone using archgenxml / argouml

Post on 12-May-2015

3.814 Views

Category:

Business

3 Downloads

Preview:

Click to see full reader

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.

TRANSCRIPT

Developing for Plone using ArchGenXML / ArgoUML

Plone Magic CampBrooklyn, NYJuly 24, 2006

Nate AuneJazkarta Consultingwww.jazkarta.com

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)

Agenda

• What is Archetypes?

• What is UML?

• What is ArchGenXML?

• Build a model using ArgoUML

• Transform the model into a Plone product

• Questions?

What is Archetypes?

• Framework for developing Plone products

• Automatically creates view and edit pages

• Maintains unique object IDs

• Creates references between objects

Archetypes framework

• Field validation

• Standard security setup

• Alternate storage options

• Data transformation capabilities

Archetypes schemas

• Schema

• Field

• Widget

• Field

• Widget

• ...

Example Archetype: Artist

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

class Artist(BaseContent) schema = BaseSchema + schema

registerType(Artist,PROJECTNAME)

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, ),))

What is UML?

• UML = Uniform Modeling Language

• Standard widely-adopted graphical language

• Describes the artifacts of software systems

• Focus on conceptual representations

Artist: Described in UML

Poseidon UML tool

What is ArchGenXML?

• Command line utility

• Auto-generates code from a UML model

• No round-trip support yet

• Custom code is preserved upon regeneration

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

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

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, ),))

UML speak to AT speak• product

• content type

• method

• field

• property

• subclass, view, etc.

• package

• class

• operation

• attribute

• tagged value

• stereotype

In practice

1. Save your model to the Products dir

2. Run the ArchGenXML script

3. Restart Zope

4. Install the newly generated product

ArchGenXML components

• ArchGenXML

• Optional:

• i18ndude

• stripogram

• ATBackRef

• ATVocabularyManager

• Relations

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

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

AGX options in ArgoUML!

Create Artist class

Add description and icon

Repurpose Title field

Set the photo sizes

Add instrument vocabulary

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

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

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)

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

Edit artist form

View artist

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/

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

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

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'.

$

Dynamic vocabulary

Add ATVM as dependency

• Edit ArtistSite/AppConfig.py

• Add line to:

• DEPENDENCIES = ['ATVocabularyManager']

• Restart Zope

• Reinstall ArtistSite

Vocabulary Library• Go to Plone Setup and choose Vocabulary Library

Add a vocabulary term

Hierarchical vocabularies

Tagged values

• cd $INSTANCE/Products/ArchGenXML

• ./TaggedValueSupport.py | more

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

Containment

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

Use <<large>> stereotype

Give it a friendly name

Add Artists container

References

Create a direct association

results in:

Reference fieldgroup to artist(s)

Create direct association

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

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

Group edit form

Group is associated with artists

Reference Browser Widget as default

Configure browser widget

Select the end point

Make multivaluedSpecify relationship

Define query

Adding references

Add back reference

Add ATBackRef as dependency

• Edit ArtistSite/AppConfig.py

• Change line to:

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

• Restart Zope

• Reinstall ArtistSite

Backreferences

Groups that artist belongs to

Custom view for group folder

Assign member stereotype

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

Computed field

Registration form

• SiteMember is installed

• Replaces default member

• Easy way to create new member types

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

What I didn’t cover

• Additional Stereotypes

• actions, portal_tool, abstract, stub, ordered

• portlets, configlet, customization policy

• Generalization (Interfaces)

• Workflow

• Unit testing, doctests

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/

top related