Permalink
Browse files

made changes to create more task based screens

  • Loading branch information...
1 parent c5ef1d5 commit 5cd858f4512a103acc712d0af433d2cdb57dbf31 @jettro committed Apr 14, 2010
@@ -8,6 +8,7 @@ import org.axonframework.commandhandling.SimpleCommandBus
import org.axonframework.eventhandling.SimpleEventBus
import org.axonframework.eventstore.fs.FileSystemEventStore
import org.axonframework.eventstore.XStreamEventSerializer
+import nl.gridshore.sample.addressbook.command.handler.RemoveAddressCommandHandler
// Place your Spring DSL code here
beans = {
@@ -22,6 +23,7 @@ beans = {
updateContactCommandHandler(UpdateContactCommandHandler, ref("contactRepository"), ref("commandBus"))
removeContactCommandHandler(RemoveContactCommandHandler, ref("contactRepository"), ref("commandBus"))
registerAddressCommandHandler(RegisterAddressCommandHandler, ref("contactRepository"), ref("commandBus"))
+ removeAddressCommandHandler(RemoveAddressCommandHandler, ref("contactRepository"), ref("commandBus"))
// axon beans
commandBus(SimpleCommandBus)
@@ -14,12 +14,21 @@ class ContactEntryController {
def scaffold = ContactEntry
ContactCommandHandlerService contactCommandHandlerService
- static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
+ static allowedMethods = [save: "POST", update: "POST", delete: "POST", saveAddress: "POST"]
def index = {
redirect(action: "list", params: params)
}
+ def show = {
+ def contactEntryInstance = ContactEntry.get(params.id)
+ def contactIdentifier = contactEntryInstance.identifier
+ def addressEntriesForContact = AddressEntry.findAllByContactIdentifier(contactIdentifier)
+
+ [addressEntryInstanceList: addressEntriesForContact, contactEntryInstance: contactEntryInstance]
+ }
+
+
def save = {
def contactEntryInstance = new ContactEntry(params)
if (contactEntryInstance.validate()) {
@@ -81,4 +90,39 @@ class ContactEntryController {
}
}
+ def registerAddress = {
+ def contactEntryInstance = ContactEntry.get(params.id)
+ def addressEntryInstance = new AddressEntry();
+ addressEntryInstance.contactIdentifier = contactEntryInstance.identifier
+ addressEntryInstance.contactName = contactEntryInstance.name
+ [addressEntryInstance: addressEntryInstance]
+ }
+
+ def saveAddress = {
+ def addressEntryInstance = new AddressEntry(params)
+ if (addressEntryInstance.validate()) {
+ def foundContact = ContactEntry.findByIdentifier(addressEntryInstance.contactIdentifier)
+ contactCommandHandlerService.registerAddress(
+ addressEntryInstance.addressType,
+ addressEntryInstance.contactIdentifier,
+ addressEntryInstance.streetAndNumber,
+ addressEntryInstance.zipCode,
+ addressEntryInstance.city)
+ flash.message = "${message(code: 'default.created.message', args: [message(code: 'addressEntry.label', default: 'AddressEntry'), addressEntryInstance.city])}"
+ redirect(action: "show", params:[id:foundContact.id])
+ }
+ else {
+ render(view: "registerAddress", model: [addressEntryInstance: addressEntryInstance])
+ }
+ }
+
+ def deleteAddress = {
+ def addressEntryInstance = AddressEntry.get(params.id)
+ if (addressEntryInstance) {
+ contactCommandHandlerService.removeAddress(addressEntryInstance.addressType, addressEntryInstance.contactIdentifier)
+ }
+ def foundContact = ContactEntry.findByIdentifier(addressEntryInstance.contactIdentifier)
+ redirect(action: "show", id: foundContact.id)
+ }
+
}
@@ -53,3 +53,7 @@ typeMismatch.java.lang.Long=Property {0} must be a valid number
typeMismatch.java.lang.Short=Property {0} must be a valid number
typeMismatch.java.math.BigDecimal=Property {0} must be a valid number
typeMismatch.java.math.BigInteger=Property {0} must be a valid number
+
+# Other labels
+orderEntry.register.address=Register Address
+orderEntry.button.registerAddress.label=Register Address
@@ -6,6 +6,7 @@ import nl.gridshore.sample.addressbook.command.RemoveContactCommand
import nl.gridshore.sample.addressbook.command.UpdateContactCommand
import nl.gridshore.sample.addressbook.domain.AddressType
import org.axonframework.commandhandling.CommandBus
+import nl.gridshore.sample.addressbook.command.RemoveAddressCommand
class ContactCommandHandlerService {
@@ -35,4 +36,8 @@ class ContactCommandHandlerService {
city: city)
)
}
+
+ def removeAddress(AddressType addressType, String identifier) {
+ commandBus.dispatch(new RemoveAddressCommand(addressType: addressType, identifier: identifier))
+ }
}
@@ -0,0 +1,13 @@
+<%--
+ Created by IntelliJ IDEA.
+ User: jcoenradie
+ Date: Apr 14, 2010
+ Time: 9:42:55 PM
+ To change this template use File | Settings | File Templates.
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" %>
+<html>
+ <head><title>Simple GSP page</title></head>
+ <body>Place your content here</body>
+</html>
@@ -24,7 +24,6 @@
<g:sortableColumn property="name" title="${message(code: 'contactEntry.name.label', default: 'Name')}" />
- <th>&nbsp;</th>
</tr>
</thead>
<tbody>
@@ -33,12 +32,10 @@
<td><g:link action="show" id="${contactEntryInstance.id}">${fieldValue(bean: contactEntryInstance, field: "id")}</g:link></td>
-
<td>${fieldValue(bean: contactEntryInstance, field: "identifier")}</td>
<td>${fieldValue(bean: contactEntryInstance, field: "name")}</td>
- <td>add images</td>
</tr>
</g:each>
</tbody>
@@ -0,0 +1,93 @@
+
+<%@ page import="nl.gridshore.sample.addressbook.AddressEntry" %>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta name="layout" content="main" />
+ <g:set var="entityName" value="${message(code: 'addressEntry.label', default: 'AddressEntry')}" />
+ <title><g:message code="default.create.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <div class="nav">
+ <span class="menuButton"><a class="home" href="${createLink(uri: '/')}">Home</a></span>
+ <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
+ </div>
+ <div class="body">
+ <h1><g:message code="default.create.label" args="[entityName]" /></h1>
+ <g:if test="${flash.message}">
+ <div class="message">${flash.message}</div>
+ </g:if>
+ <g:hasErrors bean="${addressEntryInstance}">
+ <div class="errors">
+ <g:renderErrors bean="${addressEntryInstance}" as="list" />
+ </div>
+ </g:hasErrors>
+ <g:form action="saveAddress" method="post" >
+ <div class="dialog">
+ <table>
+ <tbody>
+
+ <tr class="prop">
+ <td valign="top" class="name">
+ <label for="streetAndNumber"><g:message code="addressEntry.streetAndNumber.label" default="Street And Number" /></label>
+ </td>
+ <td valign="top" class="value ${hasErrors(bean: addressEntryInstance, field: 'streetAndNumber', 'errors')}">
+ <g:textField name="streetAndNumber" value="${addressEntryInstance?.streetAndNumber}" />
+ </td>
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name">
+ <label for="contactIdentifier"><g:message code="addressEntry.contactIdentifier.label" default="Contact Identifier" /></label>
+ </td>
+ <td valign="top" class="value ${hasErrors(bean: addressEntryInstance, field: 'contactIdentifier', 'errors')}">
+ <g:textField name="contactIdentifier" value="${addressEntryInstance?.contactIdentifier}" />
+ </td>
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name">
+ <label for="contactName"><g:message code="addressEntry.contactName.label" default="Contact Name" /></label>
+ </td>
+ <td valign="top" class="value ${hasErrors(bean: addressEntryInstance, field: 'contactName', 'errors')}">
+ <g:textField name="contactName" value="${addressEntryInstance?.contactName}" />
+ </td>
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name">
+ <label for="zipCode"><g:message code="addressEntry.zipCode.label" default="Zip Code" /></label>
+ </td>
+ <td valign="top" class="value ${hasErrors(bean: addressEntryInstance, field: 'zipCode', 'errors')}">
+ <g:textField name="zipCode" value="${addressEntryInstance?.zipCode}" />
+ </td>
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name">
+ <label for="addressType"><g:message code="addressEntry.addressType.label" default="Address Type" /></label>
+ </td>
+ <td valign="top" class="value ${hasErrors(bean: addressEntryInstance, field: 'addressType', 'errors')}">
+ <g:select name="addressType" from="${nl.gridshore.sample.addressbook.domain.AddressType?.values()}" value="${addressEntryInstance?.addressType}" />
+ </td>
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name">
+ <label for="city"><g:message code="addressEntry.city.label" default="City" /></label>
+ </td>
+ <td valign="top" class="value ${hasErrors(bean: addressEntryInstance, field: 'city', 'errors')}">
+ <g:textField name="city" value="${addressEntryInstance?.city}" />
+ </td>
+ </tr>
+
+ </tbody>
+ </table>
+ </div>
+ <div class="buttons">
+ <span class="button"><g:submitButton name="save" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
+ </div>
+ </g:form>
+ </div>
+ </body>
+</html>
@@ -1,53 +1,76 @@
-
<%@ page import="nl.gridshore.sample.addressbook.ContactEntry" %>
<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <meta name="layout" content="main" />
- <g:set var="entityName" value="${message(code: 'contactEntry.label', default: 'ContactEntry')}" />
- <title><g:message code="default.show.label" args="[entityName]" /></title>
- </head>
- <body>
- <div class="body">
- <h1><g:message code="default.show.label" args="[entityName]" /></h1>
- <g:if test="${flash.message}">
- <div class="message">${flash.message}</div>
- </g:if>
- <div class="dialog">
- <table>
- <tbody>
-
- <tr class="prop">
- <td valign="top" class="name"><g:message code="contactEntry.id.label" default="Id" /></td>
-
- <td valign="top" class="value">${fieldValue(bean: contactEntryInstance, field: "id")}</td>
-
- </tr>
-
- <tr class="prop">
- <td valign="top" class="name"><g:message code="contactEntry.name.label" default="Name" /></td>
-
- <td valign="top" class="value">${fieldValue(bean: contactEntryInstance, field: "name")}</td>
-
- </tr>
-
- <tr class="prop">
- <td valign="top" class="name"><g:message code="contactEntry.identifier.label" default="Identifier" /></td>
-
- <td valign="top" class="value">${fieldValue(bean: contactEntryInstance, field: "identifier")}</td>
-
- </tr>
-
- </tbody>
- </table>
- </div>
- <div class="buttons">
- <g:form>
- <g:hiddenField name="id" value="${contactEntryInstance?.id}" />
- <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
- <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
- </g:form>
- </div>
- </div>
- </body>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <meta name="layout" content="main"/>
+ <g:set var="entityName" value="${message(code: 'contactEntry.label', default: 'ContactEntry')}"/>
+ <title><g:message code="default.show.label" args="[entityName]"/></title>
+</head>
+<body>
+<div class="body">
+ <h1><g:message code="default.show.label" args="[entityName]"/></h1>
+ <g:if test="${flash.message}">
+ <div class="message">${flash.message}</div>
+ </g:if>
+ <div class="dialog">
+ <table>
+ <tbody>
+
+ <tr class="prop">
+ <td valign="top" class="name"><g:message code="contactEntry.id.label" default="Id"/></td>
+
+ <td valign="top" class="value">${fieldValue(bean: contactEntryInstance, field: "id")}</td>
+
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name"><g:message code="contactEntry.name.label" default="Name"/></td>
+
+ <td valign="top" class="value">${fieldValue(bean: contactEntryInstance, field: "name")}</td>
+
+ </tr>
+
+ <tr class="prop">
+ <td valign="top" class="name"><g:message code="contactEntry.identifier.label" default="Identifier"/></td>
+
+ <td valign="top" class="value">${fieldValue(bean: contactEntryInstance, field: "identifier")}</td>
+
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="list">
+ <table>
+ <thead>
+ <tr>
+ <td>&nbsp;</td>
+ <g:sortableColumn property="streetAndNumber" title="${message(code: 'addressEntry.streetAndNumber.label', default: 'Street And Number')}"/>
+ <g:sortableColumn property="zipCode" title="${message(code: 'addressEntry.zipCode.label', default: 'Zip Code')}"/>
+ <g:sortableColumn property="addressType" title="${message(code: 'addressEntry.addressType.label', default: 'Address Type')}"/>
+ </tr>
+ </thead>
+ <tbody>
+ <g:each in="${addressEntryInstanceList}" status="i" var="addressEntryInstance">
+ <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
+ <td>
+ <g:link action="deleteAddress" id="${addressEntryInstance.id}"><img src="${resource(dir:'images/skin',file:'database_delete.png')}" alt="delete"></g:link>
+ </td>
+ <td>${fieldValue(bean: addressEntryInstance, field: "streetAndNumber")}</td>
+ <td>${fieldValue(bean: addressEntryInstance, field: "zipCode")}</td>
+ <td>${fieldValue(bean: addressEntryInstance, field: "addressType")}</td>
+ </tr>
+ </g:each>
+ </tbody>
+ </table>
+ </div>
+ <div class="buttons">
+ <g:form>
+ <g:hiddenField name="id" value="${contactEntryInstance?.id}"/>
+ <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}"/></span>
+ <span class="button"><g:actionSubmit class="add" action="registerAddress" value="${message(code: 'orderEntry.button.registerAddress.label', default: 'Register Address')}"/></span>
+ <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"/></span>
+ </g:form>
+ </div>
+</div>
+</body>
</html>
@@ -0,0 +1,9 @@
+package nl.gridshore.sample.addressbook.command
+
+/**
+ * @author Jettro Coenradie
+ */
+class RemoveAddressCommand {
+ def addressType
+ def identifier
+}
@@ -0,0 +1,25 @@
+package nl.gridshore.sample.addressbook.command.handler
+
+import nl.gridshore.sample.addressbook.command.RemoveAddressCommand
+import nl.gridshore.sample.addressbook.domain.ContactAggregate
+import nl.gridshore.sample.addressbook.repository.ContactRepository
+import org.axonframework.commandhandling.CommandHandler
+
+/**
+ * @author Jettro Coenradie
+ */
+class RemoveAddressCommandHandler implements CommandHandler<RemoveAddressCommand> {
+ ContactRepository contactRepository
+
+ def RemoveAddressCommandHandler(contactRepository, commandBus) {
+ this.contactRepository = contactRepository;
+ commandBus.subscribe(RemoveAddressCommand.class, this)
+ }
+
+ Object handle(RemoveAddressCommand command) {
+ ContactAggregate contact = contactRepository.load(UUID.fromString(command.identifier))
+ contact.removeAddress(command.addressType)
+ contactRepository.save contact
+ }
+
+}
Oops, something went wrong.

0 comments on commit 5cd858f

Please sign in to comment.