Announcement Announcement Module
Collapse
No announcement yet.
Asymetric operations. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Code:
    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;
    import org.springframework.security.authentication.encoding.MessageDigestPasswordEncoder;
    import org.springframework.security.core.GrantedAuthority;
    import org.springframework.security.core.userdetails.UserDetails;
    
    @RooJavaBean()
    @RooToString(excludeFields = { "password", "registrationDate", "follows" })
    @RooJpaActiveRecord(finders = { "findUsersByUsernameEquals" })
    @RooSerializable
    public class User implements UserDetails {
    
    	public User() {
    		salt=RandomStringUtils.randomAlphabetic(20);
    	}
    
    	@NotNull
    	@Column(unique = true)
    	@Size(min = 6, max = 20)
    	@Pattern(regexp = "[A-Za-z0-9_\\-]+")
    	private String username;
    
    	@NotNull
    	private String password;
    
    	@NotNull
    	@Temporal(TemporalType.TIMESTAMP)
    	@DateTimeFormat(style = "M-")
    	private Date registrationDate;
    
    	@ManyToMany(cascade = CascadeType.ALL)
    	private Set<Artist> follows = new HashSet<Artist>();
    
    	@NotNull
    	private boolean isAccountExpired;
    
    	@NotNull
    	private boolean isAccountLocked;
    
    	@NotNull
    	private boolean isCredentialsExpired;
    
    	@NotNull
    	private String salt;
    
    	//@Override
    	public boolean isAccountNonExpired() {
    		return !isAccountExpired;
    	}
    
    	// ****************************
    	// Not a field of user
    	// ****************************
    	@Resource
    	@Transient
    	MessageDigestPasswordEncoder passwordEncoder;
    
    	public void setPassword(String rawPassword) {
    		password = passwordEncoder.encodePassword(rawPassword, salt);
    	}
    
    	@Override
    	public Collection<? extends GrantedAuthority> getAuthorities() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@Override
    	public boolean isAccountNonLocked() {
    		return !isAccountLocked;
    	}
    
    	@Override
    	public boolean isCredentialsNonExpired() {
    		return !isCredentialsExpired;
    	}
    
    	@Override
    	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?
Working...
X