Diferencia entre revisiones de «Ejemplo de proyecto web para ABMs creado con Roo»

De Dos Ideas.
Saltar a: navegación, buscar
Línea 135: Línea 135:
  
 
[http://forum.springsource.org/showthread.php?t=85098 Mas ayuda de la dependencia de Maven con JAXB]
 
[http://forum.springsource.org/showthread.php?t=85098 Mas ayuda de la dependencia de Maven con JAXB]
 +
 +
== Automatizar tarea con script de roo ==
 +
 +
// Spring Roo 1.0.2.RELEASE [rev 638] log opened at 2010-07-13 13:33:20
 +
//crear proyecto
 +
project --topLevelPackage com.springsource.roo.pizzaDosIdeas
 +
//definir persistencia de datos
 +
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
 +
//definir modelo de datos
 +
entity --class ~.domain.Cubierta --testAutomatically
 +
field string --fieldName nombre --notNull --sizeMin 2
 +
entity --class ~.domain.Base --testAutomatically
 +
field string --fieldName nombre --notNull --sizeMin 2
 +
entity --class ~.domain.Pizza --testAutomatically
 +
field string --fieldName nombre --notNull --sizeMin 2
 +
field number --fieldName precio --type java.lang.Float
 +
field set --fieldName coberturas --element ~.domain.Cubierta
 +
field reference --fieldName base --type ~.domain.Base
 +
entity --class ~.domain.Pedido --testAutomatically
 +
field string --fieldName nombre --notNull --sizeMin 2
 +
field string --fieldName direccion --sizeMax 30
 +
field number --fieldName importe --type java.lang.Float
 +
field date --fieldName fechaEntrega --type java.util.Date
 +
field set --fieldName pizzas --element ~.domain.Pizza
 +
//ejecutar test
 +
perform test
 +
//definir IDE
 +
perform eclipse
 +
//agregar capa de presentacion
 +
controller all --package ~.web
 +
selenium test --controller ~.web.CubiertaController
 +
selenium test --controller ~.web.BaseController
 +
selenium test --controller ~.web.PizzaController
 +
selenium test --controller ~.web.PedidoController
 +
//generar paquete
 +
perform package
 +
quit
 +
// Spring Roo 1.0.2.RELEASE [rev 638] log closed at 2010-07-13 14:20:05

Revisión del 19:05 13 jul 2010

Herramientas y Versiones

  • JDK 1.6 UPDATE 21
  • Spring Roo 1.0.2
  • Apache Maven 2.2.1


Con la correspondiente configuración en las variables de entorno de la pc (PATH y JAVA_HOME).

Configuraciones iniciales

   <proxy>
     <active>true</active>
     <protocol>http</protocol>
     <username>nombre del usuario de conexion</username>
     <password>clave</password>
     <host>servidor</host>
     <port>puerto</port>
</proxy>

Creación del proyecto

El proyecto ejemplo es para una aplicación web básica para atender pedidos en una pizzeria. Donde se contará con la posibilidad de tomar pedidos de pizza/s y de crear nuevos tipos de pizzas. Una pizza está compuesta de una base y una o más cubiertas.

El diagrama de clases representa un modelo simplificado del dominio problema de la pizzeria.

Es un buen punto de partida para el proyecto en cuestión a fin de entregar un primer prototipo de la aplicación para el dueño del producto.

DiagramaDominioPizzeria.jpg

  • Paso 1: Crear carpeta del proyecto

mkdir pizzaDosIdeas cd pizzaDosIdeas roo

Nota: con el comando 'hint' se obtiene cual es el siguiente paso para generar el proyecto.

  • Paso 2: Crear el proyecto Java

project --topLevelPackage com.springsource.roo.pizzaDosIdeas

  • Paso 3: Configurar el ORM y la base de datos del sistema

persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY

  • Paso 4: Crear las entidades, atributos y como se relacionan

entity --class ~.domain.Cubierta --testAutomatically field string --fieldName nombre --notNull --sizeMin 2

entity --class ~.domain.Base --testAutomatically field string --fieldName nombre --notNull --sizeMin 2

entity --class ~.domain.Pizza --testAutomatically field string --fieldName nombre --notNull --sizeMin 2 field number --fieldName precio --type java.lang.Float field set --fieldName coberturas --element ~.domain.Cubierta field reference --fieldName base --type ~.domain.Base

entity --class ~.domain.Pedido --testAutomatically field string --fieldName nombre --notNull --sizeMin 2 field string --fieldName direccion --sizeMax 30 field number --fieldName importe --type java.lang.Float field date --fieldName fechaEntrega --type java.util.Date field set --fieldName pizzas --element ~.domain.Pizza

  • Paso 5: Ejecutar test y, según IDE desarrollo, ejecutar tarea para estructurar proyecto. Se puede utilizar STS.

perform tests perform eclipse

  • Paso 6: Crear la capa web con los test de selenium para esa capa

controller all --package ~.web selenium test --controller ~.web.CubiertaController selenium test --controller ~.web.BaseController selenium test --controller ~.web.PizzaController selenium test --controller ~.web.PedidoController

Y ahora sí, generamos el paquete y lo desplegamos en un contenedor web:

perform package quit (salimos de roo) mvn tomcat:run (en la carpeta raiz del proyecto)

Y tenemos la aplicación corriendo en http://localhost:8080/pizzadosideas/ !!!!

Tareas de solución de problemas

  • Si al desplegar el proyecto en el servidor de aplicaciones, Maven perdió la dependencia con JAXB, entoces necesitarás agregar la dependencia en pom.xml del proyecto:

<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.1</version> <exclusions> <exclusion> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> </exclusion> <exclusion> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> </exclusion> </exclusions> </dependency> <dependency>

       <groupId>com.sun.xml.bind</groupId>

<artifactId>jaxb-impl</artifactId> <version>2.1.5</version> <scope>runtime</scope> </dependency>

Mas ayuda de la dependencia de Maven con JAXB

Automatizar tarea con script de roo

// Spring Roo 1.0.2.RELEASE [rev 638] log opened at 2010-07-13 13:33:20 //crear proyecto project --topLevelPackage com.springsource.roo.pizzaDosIdeas //definir persistencia de datos persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY //definir modelo de datos entity --class ~.domain.Cubierta --testAutomatically field string --fieldName nombre --notNull --sizeMin 2 entity --class ~.domain.Base --testAutomatically field string --fieldName nombre --notNull --sizeMin 2 entity --class ~.domain.Pizza --testAutomatically field string --fieldName nombre --notNull --sizeMin 2 field number --fieldName precio --type java.lang.Float field set --fieldName coberturas --element ~.domain.Cubierta field reference --fieldName base --type ~.domain.Base entity --class ~.domain.Pedido --testAutomatically field string --fieldName nombre --notNull --sizeMin 2 field string --fieldName direccion --sizeMax 30 field number --fieldName importe --type java.lang.Float field date --fieldName fechaEntrega --type java.util.Date field set --fieldName pizzas --element ~.domain.Pizza //ejecutar test perform test //definir IDE perform eclipse //agregar capa de presentacion controller all --package ~.web selenium test --controller ~.web.CubiertaController selenium test --controller ~.web.BaseController selenium test --controller ~.web.PizzaController selenium test --controller ~.web.PedidoController //generar paquete perform package quit // Spring Roo 1.0.2.RELEASE [rev 638] log closed at 2010-07-13 14:20:05