Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added domain class and controller for repository

  • Loading branch information...
commit 1e25461eac9d065badcc16f963d7dc1573d3d800 1 parent 9600b8e
@jetztgradnet authored
View
109 grails-app/controllers/net/jetztgrad/aldente/RepositoryController.groovy
@@ -0,0 +1,109 @@
+package net.jetztgrad.aldente
+
+import org.springframework.dao.DataIntegrityViolationException
+
+class RepositoryController {
+
+ static allowedMethods = [create: ['GET', 'POST'], edit: ['GET', 'POST'], delete: 'POST']
+
+ def index() {
+ redirect action: 'list', params: params
+ }
+
+ def list() {
+ params.max = Math.min(params.max ? params.int('max') : 10, 100)
+ [repositoryInstanceList: Repository.list(params), repositoryInstanceTotal: Repository.count()]
+ }
+
+ def create() {
+ switch (request.method) {
+ case 'GET':
+ [repositoryInstance: new Repository(params)]
+ break
+ case 'POST':
+ def repositoryInstance = new Repository(params)
+ if (!repositoryInstance.save(flush: true)) {
+ render view: 'create', model: [repositoryInstance: repositoryInstance]
+ return
+ }
+
+ flash.message = message(code: 'default.created.message', args: [message(code: 'repository.label', default: 'Repository'), repositoryInstance.id])
+ redirect action: 'show', id: repositoryInstance.id
+ break
+ }
+ }
+
+ def show() {
+ def repositoryInstance = Repository.get(params.id)
+ if (!repositoryInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'repository.label', default: 'Repository'), params.id])
+ redirect action: 'list'
+ return
+ }
+
+ [repositoryInstance: repositoryInstance]
+ }
+
+ def edit() {
+ switch (request.method) {
+ case 'GET':
+ def repositoryInstance = Repository.get(params.id)
+ if (!repositoryInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'repository.label', default: 'Repository'), params.id])
+ redirect action: 'list'
+ return
+ }
+
+ [repositoryInstance: repositoryInstance]
+ break
+ case 'POST':
+ def repositoryInstance = Repository.get(params.id)
+ if (!repositoryInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'repository.label', default: 'Repository'), params.id])
+ redirect action: 'list'
+ return
+ }
+
+ if (params.version) {
+ def version = params.version.toLong()
+ if (repositoryInstance.version > version) {
+ repositoryInstance.errors.rejectValue('version', 'default.optimistic.locking.failure',
+ [message(code: 'repository.label', default: 'Repository')] as Object[],
+ "Another user has updated this Repository while you were editing")
+ render view: 'edit', model: [repositoryInstance: repositoryInstance]
+ return
+ }
+ }
+
+ repositoryInstance.properties = params
+
+ if (!repositoryInstance.save(flush: true)) {
+ render view: 'edit', model: [repositoryInstance: repositoryInstance]
+ return
+ }
+
+ flash.message = message(code: 'default.updated.message', args: [message(code: 'repository.label', default: 'Repository'), repositoryInstance.id])
+ redirect action: 'show', id: repositoryInstance.id
+ break
+ }
+ }
+
+ def delete() {
+ def repositoryInstance = Repository.get(params.id)
+ if (!repositoryInstance) {
+ flash.message = message(code: 'default.not.found.message', args: [message(code: 'repository.label', default: 'Repository'), params.id])
+ redirect action: 'list'
+ return
+ }
+
+ try {
+ repositoryInstance.delete(flush: true)
+ flash.message = message(code: 'default.deleted.message', args: [message(code: 'repository.label', default: 'Repository'), params.id])
+ redirect action: 'list'
+ }
+ catch (DataIntegrityViolationException e) {
+ flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'repository.label', default: 'Repository'), params.id])
+ redirect action: 'show', id: params.id
+ }
+ }
+}
View
15 grails-app/domain/net/jetztgrad/aldente/Repository.groovy
@@ -1,7 +1,22 @@
package net.jetztgrad.aldente
class Repository {
+ String type = "subversion"
+ String url
+ String displayName
+ String userName
+ String password
+ Date dateCreated
+ Date lastUpdated
+
+ static mapping = {
+ sort "displayName"
+ }
static constraints = {
+ url nullable: false
+ type nullable: false, inList: ["subversion", "git"]
+ displayName nullable: false
+ password password:true
}
}
View
44 grails-app/views/repository/_form.gsp
@@ -0,0 +1,44 @@
+<%@ page import="net.jetztgrad.aldente.Repository" %>
+
+
+
+<div class="fieldcontain ${hasErrors(bean: repositoryInstance, field: 'url', 'error')} ">
+ <label for="url">
+ <g:message code="repository.url.label" default="Url" />
+
+ </label>
+ <g:textField name="url" value="${repositoryInstance?.url}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: repositoryInstance, field: 'type', 'error')} ">
+ <label for="type">
+ <g:message code="repository.type.label" default="Type" />
+
+ </label>
+ <g:select name="type" from="${repositoryInstance.constraints.type.inList}" value="${repositoryInstance?.type}" valueMessagePrefix="repository.type" noSelection="['': '']"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: repositoryInstance, field: 'displayName', 'error')} ">
+ <label for="displayName">
+ <g:message code="repository.displayName.label" default="Display Name" />
+
+ </label>
+ <g:textField name="displayName" value="${repositoryInstance?.displayName}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: repositoryInstance, field: 'password', 'error')} ">
+ <label for="password">
+ <g:message code="repository.password.label" default="Password" />
+
+ </label>
+ <g:passwordField name="password" value="${repositoryInstance?.password}"/>
+</div>
+
+<div class="fieldcontain ${hasErrors(bean: repositoryInstance, field: 'userName', 'error')} ">
+ <label for="userName">
+ <g:message code="repository.userName.label" default="User Name" />
+
+ </label>
+ <g:textField name="userName" value="${repositoryInstance?.userName}"/>
+</div>
+
View
70 grails-app/views/repository/create.gsp
@@ -0,0 +1,70 @@
+<%@ page import="net.jetztgrad.aldente.Repository" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="bootstrap">
+ <g:set var="entityName" value="${message(code: 'repository.label', default: 'Repository')}" />
+ <title><g:message code="default.create.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <div class="row-fluid">
+
+ <div class="span3">
+ <div class="well">
+ <ul class="nav nav-list">
+ <li class="nav-header">${entityName}</li>
+ <li>
+ <g:link class="list" action="list">
+ <i class="icon-list"></i>
+ <g:message code="default.list.label" args="[entityName]" />
+ </g:link>
+ </li>
+ <li class="active">
+ <g:link class="create" action="create">
+ <i class="icon-plus icon-white"></i>
+ <g:message code="default.create.label" args="[entityName]" />
+ </g:link>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="span9">
+
+ <div class="page-header">
+ <h1><g:message code="default.create.label" args="[entityName]" /></h1>
+ </div>
+
+ <g:if test="${flash.message}">
+ <bootstrap:alert class="alert-info">${flash.message}</bootstrap:alert>
+ </g:if>
+
+ <g:hasErrors bean="${repositoryInstance}">
+ <bootstrap:alert class="alert-error">
+ <ul>
+ <g:eachError bean="${repositoryInstance}" var="error">
+ <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
+ </g:eachError>
+ </ul>
+ </bootstrap:alert>
+ </g:hasErrors>
+
+ <fieldset>
+ <g:form class="form-horizontal" action="create" >
+ <fieldset>
+ <f:all bean="repositoryInstance"/>
+ <div class="form-actions">
+ <button type="submit" class="btn btn-primary">
+ <i class="icon-ok icon-white"></i>
+ <g:message code="default.button.create.label" default="Create" />
+ </button>
+ </div>
+ </fieldset>
+ </g:form>
+ </fieldset>
+
+ </div>
+
+ </div>
+ </body>
+</html>
View
75 grails-app/views/repository/edit.gsp
@@ -0,0 +1,75 @@
+<%@ page import="net.jetztgrad.aldente.Repository" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="bootstrap">
+ <g:set var="entityName" value="${message(code: 'repository.label', default: 'Repository')}" />
+ <title><g:message code="default.edit.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <div class="row-fluid">
+
+ <div class="span3">
+ <div class="well">
+ <ul class="nav nav-list">
+ <li class="nav-header">${entityName}</li>
+ <li>
+ <g:link class="list" action="list">
+ <i class="icon-list"></i>
+ <g:message code="default.list.label" args="[entityName]" />
+ </g:link>
+ </li>
+ <li>
+ <g:link class="create" action="create">
+ <i class="icon-plus"></i>
+ <g:message code="default.create.label" args="[entityName]" />
+ </g:link>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="span9">
+
+ <div class="page-header">
+ <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
+ </div>
+
+ <g:if test="${flash.message}">
+ <bootstrap:alert class="alert-info">${flash.message}</bootstrap:alert>
+ </g:if>
+
+ <g:hasErrors bean="${repositoryInstance}">
+ <bootstrap:alert class="alert-error">
+ <ul>
+ <g:eachError bean="${repositoryInstance}" var="error">
+ <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
+ </g:eachError>
+ </ul>
+ </bootstrap:alert>
+ </g:hasErrors>
+
+ <fieldset>
+ <g:form class="form-horizontal" action="edit" id="${repositoryInstance?.id}" >
+ <g:hiddenField name="version" value="${repositoryInstance?.version}" />
+ <fieldset>
+ <f:all bean="repositoryInstance"/>
+ <div class="form-actions">
+ <button type="submit" class="btn btn-primary">
+ <i class="icon-ok icon-white"></i>
+ <g:message code="default.button.update.label" default="Update" />
+ </button>
+ <button type="submit" class="btn btn-danger" name="_action_delete" formnovalidate>
+ <i class="icon-trash icon-white"></i>
+ <g:message code="default.button.delete.label" default="Delete" />
+ </button>
+ </div>
+ </fieldset>
+ </g:form>
+ </fieldset>
+
+ </div>
+
+ </div>
+ </body>
+</html>
View
89 grails-app/views/repository/list.gsp
@@ -0,0 +1,89 @@
+
+<%@ page import="net.jetztgrad.aldente.Repository" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="bootstrap">
+ <g:set var="entityName" value="${message(code: 'repository.label', default: 'Repository')}" />
+ <title><g:message code="default.list.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <div class="row-fluid">
+
+ <div class="span3">
+ <div class="well">
+ <ul class="nav nav-list">
+ <li class="nav-header">${entityName}</li>
+ <li class="active">
+ <g:link class="list" action="list">
+ <i class="icon-list icon-white"></i>
+ <g:message code="default.list.label" args="[entityName]" />
+ </g:link>
+ </li>
+ <li>
+ <g:link class="create" action="create">
+ <i class="icon-plus"></i>
+ <g:message code="default.create.label" args="[entityName]" />
+ </g:link>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="span9">
+
+ <div class="page-header">
+ <h1><g:message code="default.list.label" args="[entityName]" /></h1>
+ </div>
+
+ <g:if test="${flash.message}">
+ <bootstrap:alert class="alert-info">${flash.message}</bootstrap:alert>
+ </g:if>
+
+ <table class="table table-striped">
+ <thead>
+ <tr>
+
+ <g:sortableColumn property="url" title="${message(code: 'repository.url.label', default: 'Url')}" />
+
+ <g:sortableColumn property="type" title="${message(code: 'repository.type.label', default: 'Type')}" />
+
+ <g:sortableColumn property="displayName" title="${message(code: 'repository.displayName.label', default: 'Display Name')}" />
+
+ <g:sortableColumn property="userName" title="${message(code: 'repository.userName.label', default: 'Username')}" />
+
+ <%--<g:sortableColumn property="password" title="${message(code: 'repository.password.label', default: 'Password')}" />--%>
+
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <g:each in="${repositoryInstanceList}" var="repositoryInstance">
+ <tr>
+
+ <td>${fieldValue(bean: repositoryInstance, field: "url")}</td>
+
+ <td>${fieldValue(bean: repositoryInstance, field: "type")}</td>
+
+ <td>${fieldValue(bean: repositoryInstance, field: "displayName")}</td>
+
+ <td>${fieldValue(bean: repositoryInstance, field: "userName")}</td>
+
+ <%--<td>${fieldValue(bean: repositoryInstance, field: "password")}</td>--%>
+
+ <td class="link">
+ <g:link action="show" id="${repositoryInstance.id}" class="btn btn-small">Show &raquo;</g:link>
+ <g:link action="edit" id="${repositoryInstance.id}" class="btn btn-small"><i class="icon-edit"></i>Edit &raquo;</g:link>
+ </td>
+ </tr>
+ </g:each>
+ </tbody>
+ </table>
+ <div class="pagination">
+ <bootstrap:paginate total="${repositoryInstanceTotal}" />
+ </div>
+ </div>
+
+ </div>
+ </body>
+</html>
View
116 grails-app/views/repository/show.gsp
@@ -0,0 +1,116 @@
+
+<%@ page import="net.jetztgrad.aldente.Repository" %>
+<!doctype html>
+<html>
+ <head>
+ <meta name="layout" content="bootstrap">
+ <g:set var="entityName" value="${message(code: 'repository.label', default: 'Repository')}" />
+ <title><g:message code="default.show.label" args="[entityName]" /></title>
+ </head>
+ <body>
+ <div class="row-fluid">
+
+ <div class="span3">
+ <div class="well">
+ <ul class="nav nav-list">
+ <li class="nav-header">${entityName}</li>
+ <li>
+ <g:link class="list" action="list">
+ <i class="icon-list"></i>
+ <g:message code="default.list.label" args="[entityName]" />
+ </g:link>
+ </li>
+ <li>
+ <g:link class="create" action="create">
+ <i class="icon-plus"></i>
+ <g:message code="default.create.label" args="[entityName]" />
+ </g:link>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="span9">
+
+ <div class="page-header">
+ <h1><g:message code="default.show.label" args="[entityName]" /></h1>
+ </div>
+
+ <g:if test="${flash.message}">
+ <bootstrap:alert class="alert-info">${flash.message}</bootstrap:alert>
+ </g:if>
+
+ <dl>
+
+ <g:if test="${repositoryInstance?.url}">
+ <dt><g:message code="repository.url.label" default="Url" /></dt>
+
+ <dd><g:fieldValue bean="${repositoryInstance}" field="url"/></dd>
+
+ </g:if>
+
+ <g:if test="${repositoryInstance?.type}">
+ <dt><g:message code="repository.type.label" default="Type" /></dt>
+
+ <dd><g:fieldValue bean="${repositoryInstance}" field="type"/></dd>
+
+ </g:if>
+
+ <g:if test="${repositoryInstance?.dateCreated}">
+ <dt><g:message code="repository.dateCreated.label" default="Date Created" /></dt>
+
+ <dd><g:formatDate date="${repositoryInstance?.dateCreated}" /></dd>
+
+ </g:if>
+
+ <g:if test="${repositoryInstance?.displayName}">
+ <dt><g:message code="repository.displayName.label" default="Display Name" /></dt>
+
+ <dd><g:fieldValue bean="${repositoryInstance}" field="displayName"/></dd>
+
+ </g:if>
+
+ <g:if test="${repositoryInstance?.lastUpdated}">
+ <dt><g:message code="repository.lastUpdated.label" default="Last Updated" /></dt>
+
+ <dd><g:formatDate date="${repositoryInstance?.lastUpdated}" /></dd>
+
+ </g:if>
+
+ <%--
+ <g:if test="${repositoryInstance?.password}">
+ <dt><g:message code="repository.password.label" default="Password" /></dt>
+
+ <dd><g:fieldValue bean="${repositoryInstance}" field="password"/></dd>
+
+ </g:if>
+ --%>
+
+ <g:if test="${repositoryInstance?.userName}">
+ <dt><g:message code="repository.userName.label" default="User Name" /></dt>
+
+ <dd><g:fieldValue bean="${repositoryInstance}" field="userName"/></dd>
+
+ </g:if>
+
+ </dl>
+
+ <g:form>
+ <g:hiddenField name="id" value="${repositoryInstance?.id}" />
+ <div class="form-actions">
+ <g:link class="btn" action="edit" id="${repositoryInstance?.id}">
+ <i class="icon-pencil"></i>
+ <g:message code="default.button.edit.label" default="Edit" />
+ </g:link>
+ <button class="btn btn-danger" type="submit" name="_action_delete">
+ <i class="icon-trash icon-white"></i>
+ <g:message code="default.button.delete.label" default="Delete" />
+ </button>
+ </div>
+ </g:form>
+
+ </div>
+
+ </div>
+ </body>
+</html>
View
159 test/unit/net/jetztgrad/aldente/RepositoryControllerTests.groovy
@@ -0,0 +1,159 @@
+package net.jetztgrad.aldente
+
+
+
+import org.junit.*
+import grails.test.mixin.*
+
+@TestFor(RepositoryController)
+@Mock(Repository)
+class RepositoryControllerTests {
+
+
+ def populateValidParams(params) {
+ assert params != null
+ // TODO: Populate valid properties like...
+ //params["name"] = 'someValidName'
+ }
+
+ void testIndex() {
+ controller.index()
+ assert "/repository/list" == response.redirectedUrl
+ }
+
+ void testList() {
+
+ def model = controller.list()
+
+ assert model.repositoryInstanceList.size() == 0
+ assert model.repositoryInstanceTotal == 0
+ }
+
+ void testCreate() {
+ def model = controller.create()
+
+ assert model.repositoryInstance != null
+ }
+
+ void testSave() {
+ controller.save()
+
+ assert model.repositoryInstance != null
+ assert view == '/repository/create'
+
+ response.reset()
+
+ populateValidParams(params)
+ controller.save()
+
+ assert response.redirectedUrl == '/repository/show/1'
+ assert controller.flash.message != null
+ assert Repository.count() == 1
+ }
+
+ void testShow() {
+ controller.show()
+
+ assert flash.message != null
+ assert response.redirectedUrl == '/repository/list'
+
+
+ populateValidParams(params)
+ def repository = new Repository(params)
+
+ assert repository.save() != null
+
+ params.id = repository.id
+
+ def model = controller.show()
+
+ assert model.repositoryInstance == repository
+ }
+
+ void testEdit() {
+ controller.edit()
+
+ assert flash.message != null
+ assert response.redirectedUrl == '/repository/list'
+
+
+ populateValidParams(params)
+ def repository = new Repository(params)
+
+ assert repository.save() != null
+
+ params.id = repository.id
+
+ def model = controller.edit()
+
+ assert model.repositoryInstance == repository
+ }
+
+ void testUpdate() {
+ controller.update()
+
+ assert flash.message != null
+ assert response.redirectedUrl == '/repository/list'
+
+ response.reset()
+
+
+ populateValidParams(params)
+ def repository = new Repository(params)
+
+ assert repository.save() != null
+
+ // test invalid parameters in update
+ params.id = repository.id
+ //TODO: add invalid values to params object
+
+ controller.update()
+
+ assert view == "/repository/edit"
+ assert model.repositoryInstance != null
+
+ repository.clearErrors()
+
+ populateValidParams(params)
+ controller.update()
+
+ assert response.redirectedUrl == "/repository/show/$repository.id"
+ assert flash.message != null
+
+ //test outdated version number
+ response.reset()
+ repository.clearErrors()
+
+ populateValidParams(params)
+ params.id = repository.id
+ params.version = -1
+ controller.update()
+
+ assert view == "/repository/edit"
+ assert model.repositoryInstance != null
+ assert model.repositoryInstance.errors.getFieldError('version')
+ assert flash.message != null
+ }
+
+ void testDelete() {
+ controller.delete()
+ assert flash.message != null
+ assert response.redirectedUrl == '/repository/list'
+
+ response.reset()
+
+ populateValidParams(params)
+ def repository = new Repository(params)
+
+ assert repository.save() != null
+ assert Repository.count() == 1
+
+ params.id = repository.id
+
+ controller.delete()
+
+ assert Repository.count() == 0
+ assert Repository.get(repository.id) == null
+ assert response.redirectedUrl == '/repository/list'
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.