Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Coach.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Coach.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Coach.java (working copy) @@ -1,5 +1,6 @@ package org.trails.demo; +import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -24,7 +25,7 @@ @RemoveRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"}) @UpdateRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"}) @ViewRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER"}) -@ClassDescriptor(hasCyclicRelationships = true, hidden = true) +@ClassDescriptor(hasCyclicRelationships = true) public class Coach extends Person { private static final Log log = LogFactory.getLog(Coach.class); @@ -59,7 +60,6 @@ public Coach() { - setERole(ERole.USER); } @Enumerated(value = EnumType.STRING) @@ -69,7 +69,7 @@ return eTeamRole; } - @ManyToOne + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "team_id") @PropertyDescriptor(searchable = true, index = 1) public Team getTeam() @@ -77,7 +77,7 @@ return team; } - @ManyToOne + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "coach_organization_fk", insertable = false, updatable = true, nullable = true) public Organization getOrganization() { @@ -106,30 +106,13 @@ } @Override - public int hashCode() - { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + public int hashCode() { + return super.hashCode(); } @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Coach)) - return false; - final Coach castedObject = (Coach) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + public boolean equals(Object rhs) { + + return super.equals(rhs); } } \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Director.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Director.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Director.java (working copy) @@ -52,8 +52,6 @@ public Director() { - setERole(ERole.USER); - setEApplicationRole(EApplicationRole.DIRECTOR); } @OneToOne(mappedBy = "director") @@ -77,30 +75,13 @@ } @Override - public int hashCode() - { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + public int hashCode() { + return super.hashCode(); } @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Director)) - return false; - final Director castedObject = (Director) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + public boolean equals(Object rhs) { + + return super.equals(rhs); } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/League.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/League.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/League.java (working copy) @@ -23,8 +23,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.validator.NotNull; -import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; -import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.descriptor.annotation.BlobDescriptor; import org.trails.descriptor.annotation.ClassDescriptor; import org.trails.descriptor.annotation.Collection; @@ -29,9 +27,10 @@ import org.trails.descriptor.annotation.ClassDescriptor; import org.trails.descriptor.annotation.Collection; import org.trails.descriptor.annotation.PropertyDescriptor; +import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; +import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.security.annotation.RemoveRequiresRole; import org.trails.security.annotation.UpdateRequiresRole; -import org.trails.demo.DatePattern; import org.trails.validation.ValidateUniqueness; /** @@ -100,8 +99,8 @@ return id; } - @OneToMany(cascade = CascadeType.ALL) - @JoinColumn(name = "league_id", insertable = true, updatable = true, nullable = true) + @OneToMany(cascade=CascadeType.ALL) + @JoinColumn(name = "teamyear_league_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "league") @PropertyDescriptor(readOnly = false, index = 1) @OrderBy("yearStart") @@ -110,7 +109,7 @@ return years; } - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "officer_league_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "league") @PropertyDescriptor(readOnly = false, searchable = true) @@ -120,7 +119,7 @@ return officers; } - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "organization_league_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "league") @PropertyDescriptor(readOnly = false, searchable = true) @@ -300,28 +299,22 @@ @Override public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + return (getId() != null ? getId().hashCode() : 0); } - + + /** + * equals and hashCode need to be hammered out for hibernate to work properly + * + * Check the matrix summary for best practices + * at http://www.hibernate.org/109.html + */ @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof League)) - return false; + public boolean equals(Object rhs) { + if (this == rhs) return true; // instance equality + if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality + final League castedObject = (League) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + + return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Officer.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Officer.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Officer.java (working copy) @@ -1,8 +1,7 @@ package org.trails.demo; +import javax.persistence.CascadeType; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -11,10 +10,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.trails.descriptor.annotation.ClassDescriptor; -import org.trails.descriptor.annotation.PropertyDescriptor; -import org.trails.security.RestrictionType; +import org.trails.security.annotation.RemoveRequiresRole; +import org.trails.security.annotation.UpdateRequiresAssociation; import org.trails.security.annotation.UpdateRequiresRole; -import org.trails.security.annotation.RemoveRequiresRole; +import org.trails.security.annotation.ViewRequiresAssociation; import org.trails.security.annotation.ViewRequiresRole; /** @@ -23,21 +22,15 @@ * @author kenneth.colassi nhhockeyplayer@hotmail.com */ @Entity -@RemoveRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"}) -@UpdateRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER"}) -@ViewRequiresRole({"ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER"}) +@RemoveRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER" }) +@UpdateRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER" }) +@ViewRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER" }) +@ViewRequiresAssociation +@UpdateRequiresAssociation @ClassDescriptor(hasCyclicRelationships = true, hidden = true) -public class Officer extends Person -{ +public class Officer extends Person { private static final Log log = LogFactory.getLog(Officer.class); - protected enum EOfficerRole - { - COMMISSIONER, SECRETARY, TREASURER, OFFICIALS, MEDIA, MARKETING - } - - private EOfficerRole eOfficerRole; - private League league = null; /** @@ -43,15 +36,12 @@ /** * CTOR */ - public Officer(Officer dto) - { + public Officer(Officer dto) { super(dto); - try - { + try { BeanUtils.copyProperties(this, dto); - } catch (Exception e) - { + } catch (Exception e) { log.error(e.toString()); e.printStackTrace(); } @@ -57,32 +47,16 @@ } } - public Officer() - { - setERole(ERole.USER); - } - - @Enumerated(value = EnumType.STRING) - @PropertyDescriptor(summary = true) - public EOfficerRole getEOfficerRole() - { - return eOfficerRole; + public Officer() { } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "officer_league_fk", insertable = false, updatable = true, nullable = true) - public League getLeague() - { + public League getLeague() { return league; } - public void setEOfficerRole(EOfficerRole role) - { - this.eOfficerRole = role; - } - - public void setLeague(League league) - { + public void setLeague(League league) { this.league = league; } @@ -87,8 +61,7 @@ } @Override - public Officer clone() - { + public Officer clone() { return new Officer(this); } @@ -93,30 +66,13 @@ } @Override - public int hashCode() - { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + public int hashCode() { + return super.hashCode(); } @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Officer)) - return false; - final Officer castedObject = (Officer) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + public boolean equals(Object rhs) { + + return super.equals(rhs); } } \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Organization.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Organization.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Organization.java (working copy) @@ -1,9 +1,11 @@ package org.trails.demo; import java.io.Serializable; +import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.persistence.CascadeType; @@ -26,8 +28,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.validator.NotNull; -import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; -import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.descriptor.annotation.BlobDescriptor; import org.trails.descriptor.annotation.ClassDescriptor; import org.trails.descriptor.annotation.Collection; @@ -34,9 +34,10 @@ import org.trails.descriptor.annotation.HardOneToOne; import org.trails.descriptor.annotation.PropertyDescriptor; import org.trails.descriptor.annotation.HardOneToOne.Identity; +import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; +import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.security.annotation.RemoveRequiresRole; import org.trails.security.annotation.UpdateRequiresRole; -import org.trails.demo.DatePattern; import org.trails.validation.ValidateUniqueness; /** @@ -117,7 +118,7 @@ return demographics; } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "organization_league_fk", insertable = false, updatable = true, nullable = true) public League getLeague() { @@ -134,7 +135,7 @@ return director; } - @OneToMany + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "coach_organization_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "organization") @PropertyDescriptor(readOnly = false, searchable = true) @@ -144,7 +145,7 @@ return coaches; } - @OneToMany + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "team_organization_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "organization") @PropertyDescriptor(readOnly = false) @@ -306,28 +307,22 @@ @Override public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + return (getId() != null ? getId().hashCode() : 0); } - + + /** + * equals and hashCode need to be hammered out for hibernate to work properly + * + * Check the matrix summary for best practices + * at http://www.hibernate.org/109.html + */ @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Organization)) - return false; + public boolean equals(Object rhs) { + if (this == rhs) return true; // instance equality + if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality + final Organization castedObject = (Organization) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + + return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Person.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Person.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Person.java (working copy) @@ -11,8 +11,6 @@ import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -22,6 +20,7 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.MappedSuperclass; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Transient; @@ -32,16 +31,17 @@ import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hibernate.validator.NotNull; -import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; -import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; +import org.hibernate.annotations.ForeignKey; import org.trails.descriptor.annotation.BlobDescriptor; import org.trails.descriptor.annotation.ClassDescriptor; import org.trails.descriptor.annotation.PropertyDescriptor; +import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; +import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.security.annotation.RemoveRequiresRole; +import org.trails.security.annotation.UpdateRequiresAssociation; import org.trails.security.annotation.UpdateRequiresRole; +import org.trails.security.annotation.ViewRequiresAssociation; import org.trails.security.annotation.ViewRequiresRole; -import org.trails.demo.DatePattern; import org.trails.validation.ValidateUniqueness; /** @@ -55,54 +55,33 @@ @ViewRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER", "ROLE_USER" }) @ValidateUniqueness(property = "emailAddress") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -// @Inheritance(strategy = InheritanceType.JOINED) -// @MappedSuperclass +//@Inheritance(strategy = InheritanceType.JOINED) +//@MappedSuperclass @ClassDescriptor(hidden = true) -public class Person implements UserDetails, Cloneable, Serializable -{ +@ViewRequiresAssociation +@UpdateRequiresAssociation +public class Person implements UserDetails, Cloneable, Serializable { private static final Log log = LogFactory.getLog(Person.class); - public enum ERole - { - USER, ADMIN - } - - public enum EApplicationRole - { - MANAGER, DIRECTOR, SALES, MARKETING - } - protected Integer id = null; - protected String firstName; - protected String lastName; - protected Demographics demographics = new Demographics(); - protected Date dob; - protected String emailAddress; - protected String password; - protected ERole eRole; - - protected EApplicationRole eApplicationRole; - protected Set roles = new HashSet(); - protected boolean accountNonExpired = true; - protected boolean accountNonLocked = true; - protected boolean credentialsNonExpired = true; - protected boolean enabled = true; - protected Long created = new Long(GregorianCalendar.getInstance().getTimeInMillis()); + protected Long created = new Long(GregorianCalendar.getInstance() + .getTimeInMillis()); - protected Long accessed = new Long(GregorianCalendar.getInstance().getTimeInMillis()); + protected Long accessed = new Long(GregorianCalendar.getInstance() + .getTimeInMillis()); /** * CTOR @@ -107,14 +86,11 @@ /** * CTOR */ - public Person(Person dto) - { - try - { + public Person(Person dto) { + try { BeanUtils.copyProperties(this, dto); setUsername(emailAddress); - } catch (Exception e) - { + } catch (Exception e) { log.error(e.toString()); e.printStackTrace(); } @@ -120,8 +96,7 @@ } } - public Person() - { + public Person() { } /** @@ -134,8 +109,7 @@ @Id @GeneratedValue(strategy = GenerationType.AUTO) @PropertyDescriptor(readOnly = true, summary = true, index = 0) - public Integer getId() - { + public Integer getId() { return id; } @@ -144,29 +118,12 @@ @BlobDescriptor(renderType = RenderType.IMAGE, contentDisposition = ContentDisposition.ATTACHMENT) @PropertyDescriptor(summary = true, index = 1) @OneToOne(cascade = CascadeType.ALL) - public UploadableMedia getPhoto() - { + public UploadableMedia getPhoto() { return photo; } - @Enumerated(value = EnumType.STRING) - @NotNull(message = "is required") - @PropertyDescriptor(summary = true, index = 2) - public ERole getERole() - { - return eRole; - } - - @Enumerated(value = EnumType.STRING) - @PropertyDescriptor(summary = true, index = 9) - public EApplicationRole getEApplicationRole() - { - return eApplicationRole; - } - @PropertyDescriptor(summary = true, index = 3) - public String getFirstName() - { + public String getFirstName() { return firstName; } @@ -171,8 +128,7 @@ } @PropertyDescriptor(summary = true, index = 4) - public String getLastName() - { + public String getLastName() { return lastName; } @@ -177,8 +133,7 @@ } @PropertyDescriptor(summary = true, index = 5) - public Date getDob() - { + public Date getDob() { return dob; } @@ -183,8 +138,7 @@ } @Embedded - public Demographics getDemographics() - { + public Demographics getDemographics() { return demographics; } @@ -191,8 +145,7 @@ @Column(unique = true) @PrimaryKeyJoinColumn @PropertyDescriptor(summary = true, index = 7) - public String getEmailAddress() - { + public String getEmailAddress() { return emailAddress; } @@ -197,8 +150,7 @@ } @PropertyDescriptor(summary = true, index = 8) - public String getPassword() - { + public String getPassword() { return password; } @@ -203,8 +155,7 @@ } @PropertyDescriptor(hidden = true, summary = false, searchable = false) - public Long getCreated() - { + public Long getCreated() { return created; } @@ -209,8 +160,7 @@ } @PropertyDescriptor(hidden = true, summary = false, searchable = false) - public Long getAccessed() - { + public Long getAccessed() { return accessed; } @@ -216,8 +166,7 @@ @Transient @PropertyDescriptor(hidden = true, summary = false, searchable = false) - public String getCreatedAsString() - { + public String getCreatedAsString() { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(created.longValue()); return DatePattern.sdf.format(cal.getTime()); @@ -225,8 +174,7 @@ @Transient @PropertyDescriptor(hidden = true, summary = false, searchable = false) - public String getAccessedAsString() - { + public String getAccessedAsString() { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(accessed.longValue()); return DatePattern.sdf.format(cal.getTime()); @@ -232,48 +180,31 @@ return DatePattern.sdf.format(cal.getTime()); } - public void setId(Integer id) - { + public void setId(Integer id) { this.id = id; } - public void setPhoto(UploadableMedia photo) - { + public void setPhoto(UploadableMedia photo) { this.photo = photo; } - public void setERole(ERole role) - { - this.eRole = role; - } - - public void setEApplicationRole(EApplicationRole applicationRole) - { - eApplicationRole = applicationRole; - } - - public void setFirstName(String firstName) - { + public void setFirstName(String firstName) { this.firstName = firstName; } - public void setLastName(String lastName) - { + public void setLastName(String lastName) { this.lastName = lastName; } - public void setDob(Date dob) - { + public void setDob(Date dob) { this.dob = dob; } - public void setDemographics(Demographics demographics) - { + public void setDemographics(Demographics demographics) { this.demographics = demographics; } - public void setEmailAddress(String emailAddress) - { + public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; setUsername(emailAddress); } @@ -278,13 +209,11 @@ setUsername(emailAddress); } - public void setPassword(String password) - { + public void setPassword(String password) { this.password = password; } - public void setCreated(Long created) - { + public void setCreated(Long created) { this.created = created; } @@ -290,8 +219,7 @@ @Transient @PropertyDescriptor(hidden = true, summary = false, searchable = false) - public void setCreatedAsString(String value) throws Exception - { + public void setCreatedAsString(String value) throws Exception { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime()); this.created = new Long(cal.getTimeInMillis()); @@ -297,8 +225,7 @@ this.created = new Long(cal.getTimeInMillis()); } - public void setAccessed(Long accessed) - { + public void setAccessed(Long accessed) { this.accessed = accessed; } @@ -304,8 +231,7 @@ @Transient @PropertyDescriptor(hidden = true, summary = false, searchable = false) - public void setAccessedAsString(String value) throws Exception - { + public void setAccessedAsString(String value) throws Exception { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime()); this.accessed = new Long(cal.getTimeInMillis()); @@ -312,8 +238,7 @@ } @Override - public Person clone() - { + public Person clone() { return new Person(this); } @@ -318,76 +243,63 @@ } @Override - public String toString() - { - return getFirstName() + " " + getLastName() + " [" + getUsername() + "]"; + public String toString() { + return getFirstName() + " " + getLastName() + " [" + getUsername() + + "]"; } + @Override public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + return (getId() != null ? getId().hashCode() : 0); } - + + /** + * equals and hashCode need to be hammered out for hibernate to work properly + * + * Check the matrix summary for best practices + * at http://www.hibernate.org/109.html + */ @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Person)) - return false; + public boolean equals(Object rhs) { + if (this == rhs) return true; // instance equality + if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality + final Person castedObject = (Person) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + + return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } - public boolean isAccountNonExpired() - { + public boolean isAccountNonExpired() { return accountNonExpired; } - public void setAccountNonExpired(boolean accountNonExpired) - { + public void setAccountNonExpired(boolean accountNonExpired) { this.accountNonExpired = accountNonExpired; } - public boolean isAccountNonLocked() - { + public boolean isAccountNonLocked() { return accountNonLocked; } - public void setAccountNonLocked(boolean accountNonLocked) - { + public void setAccountNonLocked(boolean accountNonLocked) { this.accountNonLocked = accountNonLocked; } - public boolean isCredentialsNonExpired() - { + public boolean isCredentialsNonExpired() { return credentialsNonExpired; } - public void setCredentialsNonExpired(boolean credentialsNonExpired) - { + public void setCredentialsNonExpired(boolean credentialsNonExpired) { this.credentialsNonExpired = credentialsNonExpired; } - public boolean isEnabled() - { + public boolean isEnabled() { return enabled; } - public void setEnabled(boolean enabled) - { + public void setEnabled(boolean enabled) { this.enabled = enabled; } @@ -393,23 +305,30 @@ @Transient @PropertyDescriptor(hidden = true) - public GrantedAuthority[] getAuthorities() - { + public GrantedAuthority[] getAuthorities() { log.debug("Person " + getUsername() + " has roles " + roles); if (roles == null || roles.size() == 0) - throw new UsernameNotFoundException("Person has no GrantedAuthority"); + throw new UsernameNotFoundException( + "Person has no GrantedAuthority"); return roles.toArray(new GrantedAuthority[roles.size()]); } - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "join_table_person_role", joinColumns = { @JoinColumn(name = "person_fk") }, inverseJoinColumns = { @JoinColumn(name = "role_fk") }) - public Set getRoles() - { + @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH) + @JoinTable( + name = "join_table_person_role", + joinColumns = { @JoinColumn(name = "person_table_primary_key") }, + inverseJoinColumns = { @JoinColumn(name = "role_table_primary_key")} + ) + + //@ForeignKey(name = "person_fk", inverseName = "role_id") + //@Column(unique=true) + //@UpdateRequiresRole({"ROLE_ADMIN"}) + //@RemoveRequiresRole( { "ROLE_ADMIN" }) + public Set getRoles() { return roles; } - public void setRoles(Set roles) - { + public void setRoles(Set roles) { this.roles = roles; } @@ -414,13 +333,11 @@ } @PropertyDescriptor(hidden = true) - public String getUsername() - { + public String getUsername() { return emailAddress; } - public void setUsername(String username) - { + public void setUsername(String username) { this.emailAddress = username; } } \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Player.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Player.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Player.java (working copy) @@ -100,7 +100,7 @@ return dexterity; } - @ManyToOne + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "player_team_fk") public Team getTeam() { @@ -107,7 +107,7 @@ return team; } - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "clips_player_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "player") @PropertyDescriptor(searchable = false, readOnly = false) @@ -117,8 +117,8 @@ return clips; } - @OneToMany(cascade = CascadeType.ALL) - @JoinColumn(name = "playerstat_player_fk") + @OneToMany(cascade=CascadeType.ALL) + @JoinColumn(name = "playerstat_player_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "player") @PropertyDescriptor(searchable = true, readOnly = false) public Set getStats() @@ -183,30 +183,13 @@ } @Override - public int hashCode() - { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + public int hashCode() { + return super.hashCode(); } @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Player)) - return false; - final Player castedObject = (Player) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + public boolean equals(Object rhs) { + + return super.equals(rhs); } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/PlayerStat.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/PlayerStat.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/PlayerStat.java (working copy) @@ -4,6 +4,7 @@ import java.util.Calendar; import java.util.GregorianCalendar; +import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -157,7 +158,7 @@ return shg; } - @ManyToOne + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "playerstat_player_fk", insertable = false, updatable = false, nullable = true) @PropertyDescriptor(readOnly = true, index = 0) public Player getPlayer() Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Role.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Role.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Role.java (working copy) @@ -3,18 +3,7 @@ import java.io.Serializable; import java.util.HashSet; import java.util.Set; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.persistence.Version; +import javax.persistence.*; import org.acegisecurity.GrantedAuthority; import org.hibernate.validator.Length; @@ -33,14 +22,11 @@ { private Integer id; - private String name; - private String description; - private Integer version; + private Set users = new HashSet(); - private Set users = new HashSet(); @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -58,7 +44,7 @@ @PropertyDescriptor(index = 1) @Length(min = 1, max = 20) @NotNull - // @Id @GeneratedValue(strategy = GenerationType.NONE) +// @Id @GeneratedValue(strategy = GenerationType.NONE) public String getName() { return this.name; @@ -82,7 +68,10 @@ } @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "role_ID") }, inverseJoinColumns = { @JoinColumn(name = "user_ID") }) + @JoinTable( + name = "user_role", + joinColumns = {@JoinColumn(name = "role_ID")}, + inverseJoinColumns = {@JoinColumn(name = "user_ID")}) public Set getUsers() { return users; @@ -88,6 +77,7 @@ return users; } + public void setUsers(Set users) { this.users = users; @@ -105,24 +95,26 @@ this.version = version; } - public boolean equals(Object o) - { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - final Role role = (Role) o; - - if (id != null ? !id.equals(role.id) : role.id != null) - return false; - - return true; - } - + @Override public int hashCode() { - return (id != null ? id.hashCode() : super.hashCode()); + return (getId() != null ? getId().hashCode() : 0); + } + + /** + * equals and hashCode need to be hammered out for hibernate to work properly + * + * Check the matrix summary for best practices + * at http://www.hibernate.org/109.html + */ + @Override + public boolean equals(Object rhs) { + if (this == rhs) return true; // instance equality + if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality + + final Role castedObject = (Role) rhs; + + return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } public String toString() Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Team.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Team.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/Team.java (working copy) @@ -24,8 +24,6 @@ import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; -import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.descriptor.annotation.BlobDescriptor; import org.trails.descriptor.annotation.ClassDescriptor; import org.trails.descriptor.annotation.Collection; @@ -30,9 +28,10 @@ import org.trails.descriptor.annotation.ClassDescriptor; import org.trails.descriptor.annotation.Collection; import org.trails.descriptor.annotation.PropertyDescriptor; +import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; +import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; import org.trails.security.annotation.RemoveRequiresRole; import org.trails.security.annotation.UpdateRequiresRole; -import org.trails.demo.DatePattern; /** * A Team has players, coaches, clips and stats @@ -40,8 +39,10 @@ * @author kenneth.colassi nhhockeyplayer@hotmail.com */ @Entity -@RemoveRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER" }) -@UpdateRequiresRole( { "ROLE_ADMIN", "ROLE_MANAGER" }) +@RemoveRequiresRole( +{ "ROLE_ADMIN", "ROLE_MANAGER" }) +@UpdateRequiresRole( +{ "ROLE_ADMIN", "ROLE_MANAGER" }) @ClassDescriptor(hasCyclicRelationships = true) public class Team implements Cloneable, Serializable { @@ -144,7 +145,7 @@ return id; } - @ManyToOne + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "team_organization_fk", insertable = false, updatable = true, nullable = true) public Organization getOrganization() { @@ -151,11 +152,11 @@ return organization; } - @OneToMany - @JoinColumn(name = "team_id") + @OneToMany(cascade=CascadeType.ALL) + @JoinColumn(name = "team_id", insertable = true, updatable = true, nullable = true) @Collection(child = false, inverse = "team") @PropertyDescriptor(readOnly = false, searchable = true) - //@OrderBy("lastName") + // @OrderBy("lastName") public Set getCoaches() { return coaches; @@ -203,7 +204,7 @@ return tier; } - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "clips_team_fk", insertable = true, updatable = true, nullable = true) @Collection(child = true, inverse = "team") @PropertyDescriptor(searchable = false, readOnly = false) @@ -213,11 +214,11 @@ return clips; } - @OneToMany - @JoinColumn(name = "player_team_fk") + @OneToMany(cascade=CascadeType.ALL) + @JoinColumn(name = "player_team_fk", insertable = true, updatable = true, nullable = true) @Collection(child = false, inverse = "team") @PropertyDescriptor(readOnly = false, searchable = true) - //@OrderBy("lastName") + // @OrderBy("lastName") public Set getPlayers() { return players; @@ -233,7 +234,7 @@ return photo; } - @ManyToOne + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinColumn(name = "team_teamyear_fk") @PrimaryKeyJoinColumn @PropertyDescriptor(index = 1) @@ -384,28 +385,22 @@ @Override public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + return (getId() != null ? getId().hashCode() : 0); } - + + /** + * equals and hashCode need to be hammered out for hibernate to work properly + * + * Check the matrix summary for best practices + * at http://www.hibernate.org/109.html + */ @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof Team)) - return false; + public boolean equals(Object rhs) { + if (this == rhs) return true; // instance equality + if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality + final Team castedObject = (Team) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + + return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/TeamYear.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/TeamYear.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/TeamYear.java (working copy) @@ -4,7 +4,9 @@ import java.util.Calendar; import java.util.GregorianCalendar; +import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -19,7 +21,6 @@ import org.trails.descriptor.annotation.PropertyDescriptor; import org.trails.security.annotation.RemoveRequiresRole; import org.trails.security.annotation.UpdateRequiresRole; -import org.trails.demo.DatePattern; /** * @@ -80,8 +81,8 @@ return id; } - @ManyToOne - @JoinColumn(name = "teamyear_league_fk") + @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) + @JoinColumn(name = "teamyear_league_fk", insertable = false, updatable = true, nullable = true) public League getLeague() { return league; @@ -180,29 +181,23 @@ @Override public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((getId() == null) ? 0 : getId().hashCode()); - return result; + return (getId() != null ? getId().hashCode() : 0); } - + + /** + * equals and hashCode need to be hammered out for hibernate to work properly + * + * Check the matrix summary for best practices + * at http://www.hibernate.org/109.html + */ @Override - public boolean equals(Object rhs) - { - if (this == rhs) - return true; - if (rhs == null) - return false; - if (!(rhs instanceof TeamYear)) - return false; + public boolean equals(Object rhs) { + if (this == rhs) return true; // instance equality + if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality + final TeamYear castedObject = (TeamYear) rhs; - if (getId() == null) - { - if (castedObject.getId() != null) - return false; - } else if (!getId().equals(castedObject.getId())) - return false; - return true; + + return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } public String toString() Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/UploadableMedia.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/UploadableMedia.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/UploadableMedia.java (working copy) @@ -3,6 +3,7 @@ import java.util.Calendar; import java.util.GregorianCalendar; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -15,12 +16,11 @@ import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.trails.descriptor.annotation.BlobDescriptor; +import org.trails.descriptor.annotation.PropertyDescriptor; import org.trails.descriptor.extension.ITrailsBlob; import org.trails.descriptor.extension.BlobDescriptorExtension.ContentDisposition; import org.trails.descriptor.extension.BlobDescriptorExtension.RenderType; -import org.trails.descriptor.annotation.BlobDescriptor; -import org.trails.descriptor.annotation.PropertyDescriptor; -import org.trails.demo.DatePattern; /** * @@ -38,7 +38,7 @@ * return photo; } * * private Set clips = new HashSet(); - * @OneToMany(cascade = CascadeType.ALL) + * @OneToMany(cascade=CascadeType.ALL)(cascade = CascadeType.ALL) * @JoinColumn(name = "player_id", insertable = true, updatable = true, nullable = * true) * @Collection(child = true) @@ -168,6 +168,7 @@ @BlobDescriptor(renderType = RenderType.IMAGE, contentDisposition = ContentDisposition.ATTACHMENT) @PropertyDescriptor(summary = true) @Lob + @Column(columnDefinition = "longblob", length = 6291456) // uncomment for mysql - @Column(columnDefinition = "longblob", length = 6291456) public byte[] getBytes() { @@ -284,7 +285,10 @@ public void reset() { - + fileName = null; + filePath = null; + contentType = null; + bytes = null; } public String toString() Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/User.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/User.java (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/java/org/trails/demo/User.java (working copy) @@ -8,19 +8,7 @@ import java.io.Serializable; import java.util.HashSet; import java.util.Set; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.persistence.Version; +import javax.persistence.*; import org.acegisecurity.GrantedAuthority; import org.acegisecurity.userdetails.UserDetails; @@ -34,8 +22,9 @@ import org.trails.security.annotation.UpdateRequiresRole; import org.trails.security.annotation.ViewRequiresAssociation; import org.trails.security.annotation.ViewRequiresRole; +import org.trails.validation.ValidateUniqueness; + import org.trails.security.password.DigestUtil; -import org.trails.validation.ValidateUniqueness; @Entity @Table(name = "TRAILS_USER") @@ -41,7 +30,7 @@ @Table(name = "TRAILS_USER") @ValidateUniqueness(property = "username") @ClassDescriptor(hasCyclicRelationships = true) -@ViewRequiresRole( { "ROLE_MANAGER", "ROLE_ROOT" }) +@ViewRequiresRole({"ROLE_MANAGER", "ROLE_ROOT"} ) @ViewRequiresAssociation @UpdateRequiresAssociation public class User implements UserDetails, Serializable @@ -49,27 +38,16 @@ private static final Log log = LogFactory.getLog(User.class); private Integer id; - private String username; - private String encodedPassword; - private String confirmPassword; - private String firstName; - private String lastName; - private Integer version; - private Set roles = new HashSet(); - private boolean enabled = true; - private boolean accountNonExpired = true; - private boolean accountNonLocked = true; - private boolean credentialsNonExpired = true; @Id @@ -96,30 +74,24 @@ @Transient @NotNull @PropertyDescriptor(index = 2, summary = false) - public String getPassword() - { + public String getPassword() { return encodedPassword; } - public void setPassword(String password) - { - if (password != null && !password.equals(encodedPassword)) - encodedPassword = DigestUtil.encode(password); + public void setPassword(String password) { + if (password!= null && !password.equals(encodedPassword)) encodedPassword= DigestUtil.encode(password); } - + @Column(name = "password", nullable = false) - @PropertyDescriptor(hidden = true) - public String getEncodedPassword() - { + @PropertyDescriptor(hidden=true) + public String getEncodedPassword() { return encodedPassword; } - - public void setEncodedPassword(String encodedPassword) - { + public void setEncodedPassword(String encodedPassword) { this.encodedPassword = encodedPassword; } - // @Transient + //@Transient @NotNull // for validation purposes @PropertyDescriptor(index = 3, summary = false) @@ -128,6 +100,7 @@ return confirmPassword; } + @Column(name = "first_name", length = 50, nullable = false) @NotNull @PropertyDescriptor(index = 4) @@ -145,8 +118,11 @@ } @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_ID") }, inverseJoinColumns = { @JoinColumn(name = "role_ID") }) - @UpdateRequiresRole( { "ROLE_MANAGER" }) + @JoinTable( + name = "user_role", + joinColumns = {@JoinColumn(name = "user_ID")}, + inverseJoinColumns = {@JoinColumn(name = "role_ID")}) + @UpdateRequiresRole({"ROLE_MANAGER"} ) public Set getRoles() { return roles; @@ -189,17 +165,15 @@ this.version = version; } + public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof User)) - return false; + if (this == o) return true; + if (!(o instanceof User)) return false; final User user = (User) o; - if (username != null ? !username.equals(user.getUsername()) : user.getUsername() != null) - return false; + if (username != null ? !username.equals(user.getUsername()) : user.getUsername() != null) return false; return true; } @@ -239,8 +213,7 @@ public GrantedAuthority[] getAuthorities() { log.debug("User " + getUsername() + " has roles " + roles); - if (roles == null || roles.size() == 0) - throw new UsernameNotFoundException("User has no GrantedAuthority"); + if (roles == null || roles.size() == 0) throw new UsernameNotFoundException("User has no GrantedAuthority"); return roles.toArray(new GrantedAuthority[roles.size()]); } @@ -264,4 +237,5 @@ this.enabled = enabled; } + } \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/applicationContext.xml =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/applicationContext.xml (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/applicationContext.xml (working copy) @@ -29,7 +29,6 @@ - @@ -419,6 +418,62 @@ + + + + + trails:Viewers + + + stringViewer + + + + + + + + hidden + + + + trails:Viewers + + + hidden + + + + + + richText + + + + trails:Viewers + + + htmlTextViewer + + + + + + supportsExtension('org.trails.descriptor.extension.BlobDescriptorExtension') + + + + trails:Viewers + + + blobViewer + + + + + + + @@ -429,5 +484,4 @@ - Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/hibernate.properties =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/hibernate.properties (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/resources/hibernate.properties (working copy) @@ -1,11 +1,9 @@ -hibernate.dialect=org.hibernate.dialect.HSQLDialect -# hibernate.show_sql=true +hibernate.dialect=org.hibernate.dialect.MySQLDialect +hibernate.show_sql=true hibernate.hbm2ddl.auto=update - -hibernate.connection.driver_class=org.hsqldb.jdbcDriver -hibernate.connection.url=jdbc:hsqldb:mem:test -hibernate.connection.username=sa -hibernate.connection.password= - -hibernate.max_fetch_depth=9 +hibernate.max_fetch_depth=0 +hibernate.connection.driver_class=com.mysql.jdbc.Driver +hibernate.connection.url=jdbc:mysql://localhost:3306/roster?jdbcCompliantTruncation=false +hibernate.connection.username=root +hibernate.connection.password=admin hibernate.jdbc.batch_versioned_data=true \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.html =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.html (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.html (working copy) @@ -19,7 +19,6 @@ -
+ -
\ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.page =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.page (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultEdit.page (working copy) @@ -1,5 +1,4 @@ - + @@ -9,8 +8,6 @@ - - Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultException.html =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultException.html (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultException.html (working copy) @@ -1,4 +1,3 @@

Error happened

- \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultSearch.page =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultSearch.page (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultSearch.page (working copy) @@ -5,8 +5,6 @@ - - "int" Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultView.html =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultView.html (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultView.html (revision 0) @@ -0,0 +1,27 @@ + + + + + +

+ +

+ +
    + +
+ +
Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultView.page =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultView.page (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/DefaultView.page (revision 0) @@ -0,0 +1,7 @@ + + + + + + + Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/hivemodule.xml =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/hivemodule.xml (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/hivemodule.xml (working copy) @@ -57,7 +57,9 @@ - + + + Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/web.xml =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/web.xml (revision 921) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/main/webapp/WEB-INF/web.xml (working copy) @@ -14,7 +14,11 @@ classpath:applicationContext-seedData.xml - + + + org.acegisecurity.ui.session.HttpSessionEventPublisher + + Acegi Filter Chain Proxy Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/ComponentsReuseTest.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/ComponentsReuseTest.java (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/ComponentsReuseTest.java (revision 0) @@ -0,0 +1,72 @@ +package org.trails.component; + +import java.util.ArrayList; +import java.util.HashSet; + +import junit.framework.TestCase; +import ognl.Ognl; +import ognl.OgnlException; + +import org.apache.tapestry.test.Creator; +import org.trails.demo.Coach; +import org.trails.demo.League; +import org.trails.demo.Organization; + +public class ComponentsReuseTest extends TestCase { + protected Creator creator = new Creator(); + protected League league; + protected Organization organization; + + public void setUp() { + league = (League) creator.newInstance(League.class, new Object[] { + "organizations", new HashSet() }); + assertNotNull(league); + assertNotNull(league.getOrganizations()); + organization = (Organization) creator.newInstance(Organization.class, + new Object[] { "coaches", new ArrayList() }); + assertNotNull(organization); + assertNotNull(organization.getCoaches()); + + assertEquals("size is 0", 0, organization.getCoaches().size()); + organization.getCoaches().add(new Coach()); + assertEquals("size is 1", 1, organization.getCoaches().size()); + } + + public void testAddCoach() { + try { + assertNotNull(Ognl.getValue("coaches", organization)); + assertEquals("size is 1", 1, organization.getCoaches().size()); + organization.getCoaches().add(new Coach()); + assertEquals("size is 2", 2, organization.getCoaches().size()); + assertNotNull(Ognl.getValue("coaches", organization)); + + Coach coach0 = (Coach) organization.getCoaches().toArray()[0]; + assertEquals("size is 0", 0, coach0.getRoles().size()); + assertNotNull(Ognl.getValue("roles", coach0)); + } catch (OgnlException e) { + fail(); + } + } + public void testOgnlBaseClassProperty() { + try { + Coach coach0 = (Coach) organization.getCoaches().toArray()[0]; + assertEquals("size is 0", 0, coach0.getRoles().size()); + assertNotNull(Ognl.getValue("roles", coach0)); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + organization.getCoaches().add(new Coach()); + + for ( Coach coach : organization.getCoaches() ) { + assertNotNull(Ognl.getValue("roles", coach)); + } + } catch (OgnlException e) { + fail(); + } + } +} Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/EditCollectionTest.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/EditCollectionTest.java (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/examples/roster/src/test/java/org/trails/component/EditCollectionTest.java (revision 0) @@ -0,0 +1,164 @@ +/* + * Copyright 2004 Chris Nelson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + */ +package org.trails.component; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import ognl.Ognl; + +import org.apache.tapestry.contrib.palette.SortMode; +import org.apache.tapestry.form.IPropertySelectionModel; +import org.jmock.Mock; +import org.trails.demo.Coach; +import org.trails.demo.League; +import org.trails.demo.Organization; +import org.trails.descriptor.CollectionDescriptor; +import org.trails.descriptor.IClassDescriptor; +import org.trails.descriptor.IdentifierDescriptor; +import org.trails.descriptor.TrailsClassDescriptor; +import org.trails.page.PageResolver; + +public class EditCollectionTest extends ComponentTest { + + League foo; + Organization baz1; + Organization baz2; + Coach bing1; + Coach bing2; + + Mock pageResolverMock = new Mock(PageResolver.class); + + public void setUp() { + foo = new League(); + + baz1 = new Organization(); + baz1.setName("baz 1"); + baz1.setId(new Integer("1")); + baz2 = new Organization(); + baz2.setName("baz 2"); + baz2.setId(new Integer("2")); + foo.getOrganizations().add(baz1); + foo.getOrganizations().add(baz2); + + bing1 = new Coach(); + bing1.setEmailAddress("bing 1"); + bing1.setId(new Integer("3")); + bing2 = new Coach(); + bing2.setEmailAddress("bing 2"); + bing2.setId(new Integer("4")); + baz1.getCoaches().add(bing1); + baz1.getCoaches().add(bing2); + baz2.getCoaches().add(bing1); + baz2.getCoaches().add(bing2); + } + + public void testOgnl() throws Exception { + EditCollection editCollection = buildEditCollection("bings", + Coach.class, null); + Ognl.getValue("collectionDescriptor.childRelationship", editCollection); + } + + public void testBuildSelectedList() throws Exception { + EditCollection editCollection = buildEditCollection("bazzes", + Organization.class, foo.getOrganizations()); + editCollection.setSelected(editCollection.buildSelectedList()); + assertEquals("2 in list", 2, editCollection.getSelected().size()); + Boolean toBeDeleted = (Boolean) editCollection.getSelected().get(1); + assertFalse("not to be deleted", toBeDeleted.booleanValue()); + } + + public void testRemove() throws Exception { + EditCollection editCollection = buildEditCollection("organizations", + Organization.class, foo.getOrganizations()); + ArrayList deletedList = new ArrayList(); + deletedList.add(true); + deletedList.add(false); + + // dunno what order they're in really + Iterator bazIterator = foo.getOrganizations().iterator(); + baz1 = (Organization) bazIterator.next(); + baz2 = (Organization) bazIterator.next(); + editCollection.setSelected(deletedList); + editCollection.remove(); + // System.out.println("size of collection: " + + // foo.getOrganizations().size()); + assertFalse("baz1 removed", foo.getOrganizations().contains(baz1)); + assertTrue("baz2 not removed", foo.getOrganizations().contains(baz2)); + } + + public void testMove() throws Exception { + EditCollection editCollection = buildEditCollection("coaches", + Coach.class, baz1.getCoaches()); + ArrayList selectedList = new ArrayList(); + + selectedList.add(false); + selectedList.add(true); + editCollection.setSelected(selectedList); + editCollection.moveUp(); + assertEquals("still 2", 2, baz1.getCoaches().size()); + assertEquals("bing2 moved up", bing2, baz1.getCoaches().toArray()[0]); + + selectedList.set(0, true); + selectedList.set(1, false); + editCollection.moveDown(); + assertEquals("still 2", 2, baz1.getCoaches().size()); + assertEquals("bing2 moved down", bing2, baz1.getCoaches().toArray()[1]); + } + + public void testSortMode() throws Exception { + EditCollection editCollection = buildEditCollection("bings", + Coach.class, new ArrayList()); + assertEquals("user sortable", SortMode.USER, editCollection + .getSortMode()); + } + + public void testGetSelectionModel() throws Exception { + EditCollection editCollection = buildEditCollection("bings", + Coach.class, new ArrayList()); + Coach bing1 = new Coach(); + bing1.setEmailAddress("bing 1"); + bing1.setId(new Integer("6")); + editCollection.getCollectionDescriptor().setChildRelationship(true); + editCollection.getCollection().add(bing1); + + IClassDescriptor classDescriptor = new TrailsClassDescriptor( + Coach.class); + classDescriptor.getPropertyDescriptors().add( + new IdentifierDescriptor(League.class, Coach.class)); + descriptorServiceMock.expects(once()).method("getClassDescriptor") + .with(eq(Coach.class)).will(returnValue(classDescriptor)); + + IPropertySelectionModel selectionModel = editCollection + .getSelectionModel(); + assertEquals("has 1", 1, selectionModel.getOptionCount()); + assertEquals("is bing1", bing1, selectionModel.getOption(0)); + + } + + private EditCollection buildEditCollection(String property, + Class elementType, Collection collection) { + CollectionDescriptor collectionDescriptor = new CollectionDescriptor( + League.class, property, Set.class); + collectionDescriptor.setElementType(elementType); + collectionDescriptor.setChildRelationship(true); + + return (EditCollection) creator.newInstance(EditCollection.class, + new Object[] { "persistenceService", persistenceMock.proxy(), + "descriptorService", descriptorServiceMock.proxy(), + "pageResolver", pageResolverMock.proxy(), + "collectionDescriptor", collectionDescriptor, + "collection", collection, "model", foo }); + } +}