Announcement Announcement Module
No announcement yet.
Asymetric operations. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Asymetric operations.

    Hi I've just started to attempt a new project using Roo.

    My initail impressions after getting used to the shock of seeing empty class files are very favourable. However I've only really just setup a subset of my domain model. From what I'm seeing however what it produces may be of very little use in a non CRUD environment.

    Anyway assuming I'm only scaffolding my admin pages I've a number of difficulties I don't know how to solve mostly due to asymetry.

    I've implemented a user class like this.

    package com.artiststogether.domain;
    import java.util.Collection;
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
    import javax.annotation.Resource;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.ManyToMany;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.persistence.Transient;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Pattern;
    import javax.validation.constraints.Size;
    import org.apache.commons.lang3.RandomStringUtils;
    import org.springframework.format.annotation.DateTimeFormat;
    import org.springframework.roo.addon.javabean.RooJavaBean;
    import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
    import org.springframework.roo.addon.serializable.RooSerializable;
    import org.springframework.roo.addon.tostring.RooToString;
    @RooToString(excludeFields = { "password", "registrationDate", "follows" })
    @RooJpaActiveRecord(finders = { "findUsersByUsernameEquals" })
    public class User implements UserDetails {
    	public User() {
    	@Column(unique = true)
    	@Size(min = 6, max = 20)
    	@Pattern(regexp = "[A-Za-z0-9_\\-]+")
    	private String username;
    	private String password;
    	@DateTimeFormat(style = "M-")
    	private Date registrationDate;
    	@ManyToMany(cascade = CascadeType.ALL)
    	private Set<Artist> follows = new HashSet<Artist>();
    	private boolean isAccountExpired;
    	private boolean isAccountLocked;
    	private boolean isCredentialsExpired;
    	private String salt;
    	public boolean isAccountNonExpired() {
    		return !isAccountExpired;
    	// ****************************
    	// Not a field of user
    	// ****************************
    	MessageDigestPasswordEncoder passwordEncoder;
    	public void setPassword(String rawPassword) {
    		password = passwordEncoder.encodePassword(rawPassword, salt);
    	public Collection<? extends GrantedAuthority> getAuthorities() {
    		// TODO Auto-generated method stub
    		return null;
    	public boolean isAccountNonLocked() {
    		return !isAccountLocked;
    	public boolean isCredentialsNonExpired() {
    		return !isCredentialsExpired;
    	public boolean isEnabled() {
    		return !(isAccountExpired && isAccountLocked && isCredentialsExpired);
    This class is pretty good for showing the problems with asymmetry. For example in the scaffolding views I wouldn't want the password to be shown for obvious reasons. However it should be in the update user view. This is view field asymetry.

    Secondly as a custom set is set for set password the database validation is by necessity different to the view validation. The database validation is pretty much non-existent but in the view I'd like a regex expression that enforces a minimum complexity. This is validation asymmetry.

    Although the salt is a field of the user class, it really shouldn't appear in any of the views again this is a specialised case of field asymmetry.

    I've looked for @Roo annotations to see if there was any OmitFromView or similar tags. The probem with this is that I guess it inconstant for fields. I'm also surprised to find transient fields displayed in the view.

    Is there any work around for these situations?