Skip to content

Commit

Permalink
Modificaciones recomendadas por codenarc
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmr committed Aug 31, 2011
1 parent 78d500f commit 39cc9cf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ grails.project.dependency.resolution = {
}
}

codenarc.propertiesFile=codenarc.properties
codenarc.propertiesFile='codenarc.properties'
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RegistroPacienteController {
def usuario = new Usuario(params)
if (usuario.save(flush:true)) {
def rol = Rol.findByAuthority('ROLE_PACIENTE')
def ur = UsuarioRol.create(usuario, rol, true)
UsuarioRol.create(usuario, rol, true)
flash.message = "El usuario $usuario.username ha sido creado"
redirect(action:'ver',id:usuario.id)
} else {
Expand Down
20 changes: 20 additions & 0 deletions grails-app/domain/general/Rol.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package general

import org.apache.commons.lang.builder.HashCodeBuilder

class Rol {

String authority
Expand All @@ -11,4 +13,22 @@ class Rol {
static constraints = {
authority blank: false, unique: true
}

boolean equals(other) {
if (!(other instanceof Rol)) {
return false
}

other.id == this.id
}

int hashCode() {
def builder = new HashCodeBuilder()
builder.append(this.id)
builder.toHashCode()
}

String toString() {
return authority
}
}
20 changes: 20 additions & 0 deletions grails-app/domain/general/Usuario.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package general

import org.apache.commons.lang.builder.HashCodeBuilder

class Usuario {

transient springSecurityService
Expand Down Expand Up @@ -37,4 +39,22 @@ class Usuario {
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}

boolean equals(other) {
if (!(other instanceof Usuario)) {
return false
}

other.id == this.id
}

int hashCode() {
def builder = new HashCodeBuilder()
builder.append(this.id)
builder.toHashCode()
}

String toString() {
return username
}
}
4 changes: 4 additions & 0 deletions grails-app/domain/general/UsuarioRol.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class UsuarioRol implements Serializable {
builder.toHashCode()
}

String toString() {
return "${usuario?.username} | ${rol?.authority}"
}

static UsuarioRol get(long usuarioId, long rolId) {
find 'from UsuarioRol where usuario.id=:usuarioId and rol.id=:rolId',
[usuarioId: usuarioId, rolId: rolId]
Expand Down

0 comments on commit 39cc9cf

Please sign in to comment.