Author: alevkovsky
Date: 2009-03-25 10:33:05 -0400 (Wed, 25 Mar 2009)
New Revision: 13176
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java
Log:
add equals and hashCode methods for domain objects
change ImageProcessingTools for convert image to 200px format
correct popular tags query
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -51,235 +51,256 @@
/**
* Class for representing Album Entity EJB3 Entity Bean
- *
+ *
* @author Andrey Markhel
*/
-@NamedQueries( { @NamedQuery(name = "album-byAlbumNameAndLogin", query =
"from Album a where a.name=:albumName and a.owner.login=:login") })
+@NamedQueries({
+ @NamedQuery(name = "album-byAlbumNameAndLogin", query = "from Album a
where a.name=:albumName and a.owner.login=:login")})
@Entity
@Name("album")
@Table(name = "albums")
@Role(name = "selectedAlbum", scope = ScopeType.CONVERSATION)
public class Album implements Serializable {
- private static final long serialVersionUID = -7042878411608396483L;
+ private static final long serialVersionUID = -7042878411608396483L;
- @Id
- @GeneratedValue
- @Column(name = "ALBUM_ID")
- private Long id = null;
+ @Id
+ @GeneratedValue
+ @Column(name = "ALBUM_ID")
+ private Long id = null;
- @Column(length = 255, nullable = false)
- @NotNull
- @NotEmpty
- @Length(min = 3)
- private String name;
+ @Column(length = 255, nullable = false)
+ @NotNull
+ @NotEmpty
+ @Length(min = 3)
+ private String name;
- @Column(length = 1024)
- private String description;
+ @Column(length = 1024)
+ private String description;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "ALBUM_USER_ID", referencedColumnName =
"USER_ID")
- private User owner;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "ALBUM_USER_ID", referencedColumnName =
"USER_ID")
+ private User owner;
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "album")
- @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
- private List<Image> images = new ArrayList<Image>();
+ @OneToMany(cascade = CascadeType.ALL, mappedBy = "album")
+ @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
+ private List<Image> images = new ArrayList<Image>();
- @NotNull
- @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- @JoinColumn(name = "PARENT_SHELF_ID", nullable = false)
- @org.hibernate.annotations.ForeignKey(name = "FK_SHELF_PARENT_ID")
- private Shelf shelf;
-
- @Temporal(TemporalType.TIMESTAMP)
+ @NotNull
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @JoinColumn(name = "PARENT_SHELF_ID", nullable = false)
+ @org.hibernate.annotations.ForeignKey(name = "FK_SHELF_PARENT_ID")
+ private Shelf shelf;
+
+ @Temporal(TemporalType.TIMESTAMP)
private Date created;
-
- @Transient
- private List<Image> unvisitedImages = new ArrayList<Image>();
-
- @Transient
- private Long countUnvisitedImages;
- @OneToOne(cascade=CascadeType.ALL, optional=true)
- private Image coveringImage;
+ @Transient
+ private List<Image> unvisitedImages = new ArrayList<Image>();
- // ********************** Accessor Methods ********************** //
+ @Transient
+ private Long countUnvisitedImages;
-
+ @OneToOne(cascade = CascadeType.ALL, optional = true)
+ private Image coveringImage;
- public Shelf getShelf() {
- return shelf;
- }
+ // ********************** Accessor Methods ********************** //
- public void setShelf(Shelf parent) {
- this.shelf = parent;
- }
- /**
- * Getter for property id
- *
- * @return id of album
- */
- public Long getId() {
- return id;
- }
+ public Shelf getShelf() {
+ return shelf;
+ }
- /**
- * Getter for property name
- *
- * @return name of album
- */
- public String getName() {
- return name;
- }
+ public void setShelf(Shelf parent) {
+ this.shelf = parent;
+ }
- /**
- * Setter for property name
- *
- * @param name -
- * name of album
- */
- public void setName(String name) {
- this.name = name;
- }
+ /**
+ * Getter for property id
+ *
+ * @return id of album
+ */
+ public Long getId() {
+ return id;
+ }
- /**
- * Getter for property description
- *
- * @return description of album
- */
- public String getDescription() {
- return description;
- }
+ /**
+ * Getter for property name
+ *
+ * @return name of album
+ */
+ public String getName() {
+ return name;
+ }
- /**
- * Setter for property description
- *
- * @param description -
- * description of album
- */
- public void setDescription(String description) {
- this.description = description;
- }
+ /**
+ * Setter for property name
+ *
+ * @param name -
+ * name of album
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
- // ********************** Business Methods ********************** //
+ /**
+ * Getter for property description
+ *
+ * @return description of album
+ */
+ public String getDescription() {
+ return description;
+ }
- /**
- * This method add image to collection of images of current album
- *
- * @param image -
- * image to add
- */
- public void addImage(Image image) {
- if (image == null) {
- throw new IllegalArgumentException("Null image!");
- }
- if (image.getAlbum() != null && !this.equals(image.getAlbum())) {
- image.getAlbum().getImages().remove(image);
- }
- image.setAlbum(this);
- images.add(image);
- }
+ /**
+ * Setter for property description
+ *
+ * @param description -
+ * description of album
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
- /**
- * This method remove image from collection of images of album
- *
- * @param image -
- * image to remove
- */
- public void removeImage(Image image) {
- if (image == null) {
- throw new IllegalArgumentException("Null image");
- }
- image.setAlbum(null);
- images.remove(image);
- }
+ // ********************** Business Methods ********************** //
- /**
- * This method return count of images of current album
- *
- * @return count of images of this album
- */
- public int getCountImages() {
- return this.getImages() != null ? this.getImages().size() : 0;
+ /**
+ * This method add image to collection of images of current album
+ *
+ * @param image -
+ * image to add
+ */
+ public void addImage(Image image) {
+ if (image == null) {
+ throw new IllegalArgumentException("Null image!");
+ }
+ if (image.getAlbum() != null && !this.equals(image.getAlbum())) {
+ image.getAlbum().getImages().remove(image);
+ }
+ image.setAlbum(this);
+ images.add(image);
+ }
- }
+ /**
+ * This method remove image from collection of images of album
+ *
+ * @param image -
+ * image to remove
+ */
+ public void removeImage(Image image) {
+ if (image == null) {
+ throw new IllegalArgumentException("Null image");
+ }
+ image.setAlbum(null);
+ images.remove(image);
+ }
- public User getOwner() {
- return owner;
- }
+ /**
+ * This method return count of images of current album
+ *
+ * @return count of images of this album
+ */
+ public int getCountImages() {
+ return this.getImages() != null ? this.getImages().size() : 0;
- public List<Image> getImages() {
- return images;
- }
+ }
- public void setOwner(User owner) {
- this.owner = owner;
- }
-
- public int getIndex(Image image) {
- for (int i = 0; i < this.images.size(); i++) {
- if (this.images.get(i).equals(image)) {
- return i;
- }
- }
- return -1;
- }
-
- public Image getCoveringImage(){
- if(coveringImage != null){
- return coveringImage;
- }
- if(images != null && images.size() > 0){
- coveringImage = images.get(0);
- return images.get(0);
- }else{
- return null;
- }
- }
-
- public boolean isEmpty() {
- return images == null || images.size() == 0;
- }
+ public User getOwner() {
+ return owner;
+ }
- /**
- * @return the created
- */
- public Date getCreated() {
- return created;
- }
+ public List<Image> getImages() {
+ return images;
+ }
- /**
- * @param created the created to set
- */
- public void setCreated(Date created) {
- this.created = created;
- }
+ public void setOwner(User owner) {
+ this.owner = owner;
+ }
- public Long getCountUnvisitedImages() {
- return countUnvisitedImages;
- }
+ public int getIndex(Image image) {
+ for (int i = 0; i < this.images.size(); i++) {
+ if (this.images.get(i).equals(image)) {
+ return i;
+ }
+ }
+ return -1;
+ }
- public void setCountUnvisitedImages(Long countUnvisitedImages) {
- this.countUnvisitedImages = countUnvisitedImages;
- }
+ public Image getCoveringImage() {
+ if (coveringImage != null) {
+ return coveringImage;
+ }
+ if (images != null && images.size() > 0) {
+ coveringImage = images.get(0);
+ return images.get(0);
+ } else {
+ return null;
+ }
+ }
- public List<Image> getUnvisitedImages() {
- return unvisitedImages;
- }
+ public boolean isEmpty() {
+ return images == null || images.size() == 0;
+ }
- public void setUnvisitedImages(List<Image> unvisitedImages) {
- this.unvisitedImages = unvisitedImages;
- }
+ /**
+ * @return the created
+ */
+ public Date getCreated() {
+ return created;
+ }
- public void visitImage(Image image) {
- if(unvisitedImages.contains(image)){
- unvisitedImages.remove(image);
- countUnvisitedImages--;
- }
- }
+ /**
+ * @param created the created to set
+ */
+ public void setCreated(Date created) {
+ this.created = created;
+ }
- public void setCoveringImage(Image coveringImage) {
- this.coveringImage = coveringImage;
- }
+ public Long getCountUnvisitedImages() {
+ return countUnvisitedImages;
+ }
+
+ public void setCountUnvisitedImages(Long countUnvisitedImages) {
+ this.countUnvisitedImages = countUnvisitedImages;
+ }
+
+ public List<Image> getUnvisitedImages() {
+ return unvisitedImages;
+ }
+
+ public void setUnvisitedImages(List<Image> unvisitedImages) {
+ this.unvisitedImages = unvisitedImages;
+ }
+
+ public void visitImage(Image image) {
+ if (unvisitedImages.contains(image)) {
+ unvisitedImages.remove(image);
+ countUnvisitedImages--;
+ }
+ }
+
+ public void setCoveringImage(Image coveringImage) {
+ this.coveringImage = coveringImage;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Album album = (Album) o;
+
+ if (id != null ? !id.equals(album.id) : album.id != null) return false;
+ if (!shelf.equals(album.shelf)) return false;
+ if (!name.equals(album.name)) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + name.hashCode();
+ result = 31 * result + shelf.hashCode();
+ return result;
+ }
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -42,68 +42,90 @@
@Entity
@Name("comment")
@Table(name = "comments")
-public class Comment implements Serializable{
+public class Comment implements Serializable {
- private static final long serialVersionUID = 3429270322123226071L;
+ private static final long serialVersionUID = 3429270322123226071L;
- @Id
- @GeneratedValue
- @Column(name = "COMMENT_ID")
- private Long id;
-
- @Temporal(TemporalType.TIMESTAMP)
- private Date date;
-
- @ManyToOne
- @JoinColumn(name="IMAGE_COMMENT_ID",
- referencedColumnName="IMAGE_ID")
- private Image image;
-
- @ManyToOne(fetch = FetchType.LAZY)
+ @Id
+ @GeneratedValue
+ @Column(name = "COMMENT_ID")
+ private Long id;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date date;
+
+ @ManyToOne
+ @JoinColumn(name = "IMAGE_COMMENT_ID", referencedColumnName =
"IMAGE_ID")
+ private Image image;
+
+ @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FROM_USER_ID", nullable = false, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_FROM_USER_ID")
- private User author;
-
- @Column(length = 1024, nullable = false)
+ private User author;
+
+ @Column(length = 1024, nullable = false)
@NotNull
- @NotEmpty
- @Length(min=2)
- private String message;
-
- public Long getId() {
- return id;
- }
+ @NotEmpty
+ @Length(min = 2)
+ private String message;
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- public User getAuthor() {
- return author;
- }
-
- public void setAuthor(User author) {
- this.author = author;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
+ public Long getId() {
+ return id;
+ }
- public Image getImage() {
- return image;
- }
+ public Date getDate() {
+ return date;
+ }
- public void setImage(Image image) {
- this.image = image;
- }
-
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public User getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(User author) {
+ this.author = author;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public void setImage(Image image) {
+ this.image = image;
+ }
+
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Comment comment = (Comment) o;
+
+ if (!author.equals(comment.author)) return false;
+ if (id != null ? !id.equals(comment.id) : comment.id != null) return false;
+ if (!image.equals(comment.image)) return false;
+ if (!message.equals(comment.message)) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + image.hashCode();
+ result = 31 * result + author.hashCode();
+ result = 31 * result + message.hashCode();
+ return result;
+ }
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -56,23 +56,23 @@
import org.jboss.seam.annotations.Role;
@NamedQueries({
- @NamedQuery(
- name = "image-camera",
- query = "select distinct i.cameraModel from Image i"
- )
- }
+ @NamedQuery(
+ name = "image-camera",
+ query = "select distinct i.cameraModel from Image i"
+ )
+ }
)
/**
* Class for representing Image Entity
* EJB3 Entity Bean
- *
+ *
* @author Andrey Markhel
*/
@Entity
@Name("image")
@Table(name = "Images")
-@Role(name="selectedImage", scope = ScopeType.CONVERSATION)
+@Role(name = "selectedImage", scope = ScopeType.CONVERSATION)
public class Image implements Serializable {
private static final long serialVersionUID = -7042878411608396483L;
@@ -81,148 +81,151 @@
@GeneratedValue
@Column(name = "IMAGE_ID")
private Long id = null;
-
+
@Column(length = 255, nullable = false)
@NotNull
- @NotEmpty
- @Length(min=3)
+ @NotEmpty
+ @Length(min = 3)
private String name;
@Transient
private Boolean covering;
@Column(length = 1024, nullable = false)
@NotNull
- @NotEmpty
- @Length(min=3)
+ @NotEmpty
+ @Length(min = 3)
private String path;
-
+
@ManyToMany(cascade = CascadeType.ALL)
- @JoinTable(name="IMAGES_METATAGS",
- joinColumns=
- @JoinColumn(name="CI_IMAGE_ID",
- referencedColumnName="IMAGE_ID"),
- inverseJoinColumns=
- @JoinColumn(name="CI_METATAG_ID",
- referencedColumnName="METATAG_ID"))
- protected List<MetaTag> imageTags;
-
+ @JoinTable(name = "IMAGES_METATAGS",
+ joinColumns =
+ @JoinColumn(name = "CI_IMAGE_ID",
+ referencedColumnName = "IMAGE_ID"),
+ inverseJoinColumns =
+ @JoinColumn(name = "CI_METATAG_ID",
+ referencedColumnName = "METATAG_ID"))
+ protected List<MetaTag> imageTags;
+
+
+ /*
+ * Comma separated tag value
+ * */
+ @Transient
+ private String meta = "";
+
@Column(length = 255)
private String cameraModel;
-
+
private int height;
-
+
private double size;
-
+
private int width;
-
+
@Temporal(TemporalType.TIMESTAMP)
private Date uploaded;
-
+
@Column(length = 1024)
@NotNull
- @NotEmpty
- @Length(min=3)
+ @NotEmpty
+ @Length(min = 3)
private String description;
-
+
@Temporal(TemporalType.TIMESTAMP)
private Date created;
-
- @Transient
- private String meta = "";
-
- @OneToMany(mappedBy = "image", cascade = { CascadeType.ALL }, fetch =
FetchType.LAZY)
+
+ @OneToMany(mappedBy = "image", cascade = {CascadeType.ALL}, fetch =
FetchType.LAZY)
@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
- @org.hibernate.annotations.OrderBy(clause="date asc")
+ @org.hibernate.annotations.OrderBy(clause = "date asc")
private List<Comment> comments = new ArrayList<Comment>();
-
+
@ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name="IMG_ALBUM_ID",
- referencedColumnName="ALBUM_ID")
+ @JoinColumn(name = "IMG_ALBUM_ID", referencedColumnName =
"ALBUM_ID")
private Album album;
-
+
@NotNull
- private boolean allowComments;
+ private boolean allowComments;
- // ********************** Accessor Methods ********************** //
+ // ********************** Accessor Methods ********************** //
/**
- * Getter for property id
- *
- * @return id of image
- */
+ * Getter for property id
+ *
+ * @return id of image
+ */
public Long getId() {
return id;
}
/**
- * Getter for property name
- *
- * @return name of image
- */
+ * Getter for property name
+ *
+ * @return name of image
+ */
public String getName() {
return name;
}
- /**
- * Setter for property name
- *
- * @param name - name of image
- */
+ /**
+ * Setter for property name
+ *
+ * @param name - name of image
+ */
public void setName(String name) {
this.name = name;
}
-
- /**
- * Getter for property description
- *
- * @return description of image
- */
+
+ /**
+ * Getter for property description
+ *
+ * @return description of image
+ */
public String getDescription() {
return description;
}
- /**
- * Setter for property description
- *
- * @param description - description of image
- */
+ /**
+ * Setter for property description
+ *
+ * @param description - description of image
+ */
public void setDescription(String description) {
this.description = description;
}
- public String getPath() {
- return path;
- }
+ public String getPath() {
+ return path;
+ }
- public void setPath(String path) {
- this.path = path;
- }
+ public void setPath(String path) {
+ this.path = path;
+ }
- public Date getCreated() {
- return created;
- }
+ public Date getCreated() {
+ return created;
+ }
- public void setCreated(Date created) {
- this.created = created;
- }
-
- public Album getAlbum() {
- return album;
- }
+ public void setCreated(Date created) {
+ this.created = created;
+ }
- public void setAlbum(Album album) {
- this.album = album;
- }
-
- //---------------------------Business methods
-
+ public Album getAlbum() {
+ return album;
+ }
+
+ public void setAlbum(Album album) {
+ this.album = album;
+ }
+
+ //---------------------------Business methods
+
public void addComment(Comment comment) {
if (comment == null) {
throw new IllegalArgumentException("Null comment!");
- }
+ }
if (comment.getImage() != null && !this.equals(comment.getImage())) {
- comment.getImage().getComments().remove(comment);
- }
+ comment.getImage().getComments().remove(comment);
+ }
comment.setImage(this);
comments.add(comment);
}
@@ -230,138 +233,157 @@
public void removeComment(Comment comment) {
if (comment == null) {
throw new IllegalArgumentException("Null comment");
- }
+ }
comment.setImage(null);
comments.remove(comment);
}
- public List<Comment> getComments() {
- return comments;
- }
+ public List<Comment> getComments() {
+ return comments;
+ }
- public List<MetaTag> getImageTags() {
- return imageTags;
- }
+ public List<MetaTag> getImageTags() {
+ return imageTags;
+ }
- public void setImageTags(List<MetaTag> imageTags) {
- this.imageTags = imageTags;
- }
+ public void setImageTags(List<MetaTag> imageTags) {
+ this.imageTags = imageTags;
+ }
- public String getMeta() {
- StringBuilder s = new StringBuilder();
- for(MetaTag tag: this.imageTags){
- s.append(tag.getTag()+", ");
- }
- String string = s.toString();
- return string.substring(0, string.length() - 2);
- }
+ public String getMeta() {
+ StringBuilder s = new StringBuilder();
+ for (MetaTag tag : this.imageTags) {
+ s.append(tag.getTag()).append(", ");
+ }
- public void setMeta(String meta) {
- this.meta = meta;
- }
-
- public String getMetaString(){
- return meta;
- }
+ return s.substring(0, s.length() - 2);
+ }
- public String getCameraModel() {
- return cameraModel;
- }
+ public void setMeta(String meta) {
+ this.meta = meta;
+ }
- public void setCameraModel(String cameraModel) {
- this.cameraModel = cameraModel;
- }
+ public String getMetaString() {
+ return meta;
+ }
- public int getHeight() {
- return height;
- }
+ public String getCameraModel() {
+ return cameraModel;
+ }
- public void setHeight(int height) {
- this.height = height;
- }
+ public void setCameraModel(String cameraModel) {
+ this.cameraModel = cameraModel;
+ }
- public double getSize() {
- return size;
- }
+ public int getHeight() {
+ return height;
+ }
- public void setSize(double size) {
- this.size = size;
- }
+ public void setHeight(int height) {
+ this.height = height;
+ }
- public int getWidth() {
- return width;
- }
+ public double getSize() {
+ return size;
+ }
- public void setWidth(int width) {
- this.width = width;
- }
+ public void setSize(double size) {
+ this.size = size;
+ }
- public Date getUploaded() {
- return uploaded;
- }
+ public int getWidth() {
+ return width;
+ }
- public void setUploaded(Date uploaded) {
- this.uploaded = uploaded;
- }
-
- public void addMetaTag(MetaTag metatag) {
- if (metatag == null) {
- throw new IllegalArgumentException("Null metatag!");
- }
- if(!imageTags.contains(metatag)){
- metatag.addImage(this);
- imageTags.add(metatag);
- }
- }
-
- public void removeMetaTag(MetaTag metatag) {
- if (metatag == null) {
- throw new IllegalArgumentException("Null metatag!");
- }
- if(imageTags.contains(metatag)){
- metatag.removeImage(this);
- imageTags.remove(metatag);
- }
- }
+ public void setWidth(int width) {
+ this.width = width;
+ }
- /**
- * @return the allowComments
- */
- public boolean isAllowComments() {
- return allowComments;
- }
+ public Date getUploaded() {
+ return uploaded;
+ }
- /**
- * @param allowCommennts the allowComments to set
- */
- public void setAllowComments(boolean allowComments) {
- this.allowComments = allowComments;
- }
+ public void setUploaded(Date uploaded) {
+ this.uploaded = uploaded;
+ }
- public boolean isCovering() {
- return this.equals(this.getAlbum().getCoveringImage());
- }
+ public void addMetaTag(MetaTag metatag) {
+ if (metatag == null) {
+ throw new IllegalArgumentException("Null metatag!");
+ }
+ if (!imageTags.contains(metatag)) {
+ metatag.addImage(this);
+ imageTags.add(metatag);
+ }
+ }
- public void setCovering(boolean covering) {
- this.covering = covering;
- }
+ public void removeMetaTag(MetaTag metatag) {
+ if (metatag == null) {
+ throw new IllegalArgumentException("Null metatag!");
+ }
+ if (imageTags.contains(metatag)) {
+ metatag.removeImage(this);
+ imageTags.remove(metatag);
+ }
+ }
- public boolean containTag(String s) {
- for(MetaTag t : imageTags){
- if(t.getTag().equals(s)){
- return true;
- }
- }
- return false;
- }
+ /**
+ * @return the allowComments
+ */
+ public boolean isAllowComments() {
+ return allowComments;
+ }
- public MetaTag getTagByName(String s) {
- for(MetaTag t : imageTags){
- if(t.getTag().equals(s)){
- return t;
- }
- }
- return null;
- }
-
+ /**
+ * @param allowComments the allowComments to set
+ */
+ public void setAllowComments(boolean allowComments) {
+ this.allowComments = allowComments;
+ }
+
+ public boolean isCovering() {
+ return this.equals(this.getAlbum().getCoveringImage());
+ }
+
+ public void setCovering(boolean covering) {
+ this.covering = covering;
+ }
+
+ public boolean containTag(String s) {
+ for (MetaTag t : imageTags) {
+ if (t.getTag().equals(s)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public MetaTag getTagByName(String s) {
+ for (MetaTag t : imageTags) {
+ if (t.getTag().equals(s)) {
+ return t;
+ }
+ }
+ return null;
+ }
+
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Image image = (Image) o;
+
+ if (id != null ? !id.equals(image.id) : image.id != null) return false;
+ if (path != null ? !path.equals(image.path) : image.path != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (path != null ? path.hashCode() : 0);
+ return result;
+ }
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -39,49 +39,78 @@
@Entity
@Name("metaTag")
@Table(name = "metatags")
-public class MetaTag implements Serializable{
+public class MetaTag implements Serializable {
- private static final long serialVersionUID = -9065024051468971330L;
+ private static final long serialVersionUID = -9065024051468971330L;
- @Id
- @GeneratedValue
- @Column(name = "METATAG_ID")
- private Long id;
-
- @Column(length = 255, nullable = false)
+ @Id
+ @GeneratedValue
+ @Column(name = "METATAG_ID")
+ private Long id;
+
+ @Column(length = 255, nullable = false)
@NotNull
- @NotEmpty
- @Length(min=3)
- private String tag;
-
- @ManyToMany(mappedBy="imageTags")
- private List<Image> images = new ArrayList<Image>();
+ @NotEmpty
+ @Length(min = 3)
+ private String tag;
- public Long getId() {
- return id;
- }
+ @ManyToMany(mappedBy = "imageTags")
+ private List<Image> images = new ArrayList<Image>();
- public String getTag() {
- return tag;
- }
+ public MetaTag() {
+ }
- public void setTag(String tag) {
- this.tag = tag;
- }
+ public MetaTag(Long id) {
+ this.id = id;
+ }
- public List<Image> getImages() {
- return images;
- }
+ public MetaTag(Long id, String tag) {
+ this.id = id;
+ this.tag = tag;
+ }
- public void setImages(List<Image> images) {
- this.images = images;
- }
-
- public void addImage(Image image){
- images.add(image);
- }
-
- public void removeImage(Image image){
- images.remove(image);
- }
+ public Long getId() {
+ return id;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public List<Image> getImages() {
+ return images;
+ }
+
+ public void setImages(List<Image> images) {
+ this.images = images;
+ }
+
+ public void addImage(Image image) {
+ images.add(image);
+ }
+
+ public void removeImage(Image image) {
+ images.remove(image);
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ MetaTag metaTag = (MetaTag) o;
+
+ return (id == null ? metaTag.id == null : id.equals(metaTag.id))
+ && tag.equalsIgnoreCase(metaTag.tag);
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + tag.hashCode();
+ return result;
+ }
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Sex.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -1,29 +1,26 @@
package org.richfaces.realworld.domain;
public enum Sex {
- MALE("1"),
- FEMALE("0");
-
- String key;
-
- private Sex(String key) {
- this.key = key;
- }
+ MALE("1"),
+ FEMALE("0");
- /**
- * @return the key
- */
- public String getKey() {
- return key;
- }
+ String key;
- /**
- * @param key the key to set
- */
- public void setKey(String key) {
- this.key = key;
- }
-
-
-
+ private Sex(String key) {
+ this.key = key;
+ }
+
+ /**
+ * @return the key
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * @param key the key to set
+ */
+ public void setKey(String key) {
+ this.key = key;
+ }
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Shelf.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -32,179 +32,200 @@
@Table(name = "shelfs")
public class Shelf implements Serializable {
- private static final long serialVersionUID = -7042878411608396483L;
+ private static final long serialVersionUID = -7042878411608396483L;
- @Id
- @GeneratedValue
- @Column(name = "SHELF_ID")
- private Long id = null;
+ @Id
+ @GeneratedValue
+ @Column(name = "SHELF_ID")
+ private Long id = null;
- @Column(length = 255, nullable = false)
- @NotNull
- @NotEmpty
- @Length(min = 3)
- private String name;
+ @Column(length = 255, nullable = false)
+ @NotNull
+ @NotEmpty
+ @Length(min = 3)
+ private String name;
- @Column(length = 1024)
- private String description;
+ @Column(length = 1024)
+ private String description;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "SHELF_USER_ID", referencedColumnName =
"USER_ID")
- private User owner;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "SHELF_USER_ID", referencedColumnName =
"USER_ID")
+ private User owner;
- @OneToMany(mappedBy = "shelf", cascade = { CascadeType.ALL })
- @org.hibernate.annotations.OrderBy(clause = "NAME asc")
- private List<Album> albums = new ArrayList<Album>();
- @Transient
- private List<Image> unvisitedImages = new ArrayList<Image>();
- @NotNull
- private boolean shared;
-
- @Temporal(TemporalType.TIMESTAMP)
+ @OneToMany(mappedBy = "shelf", cascade = {CascadeType.ALL})
+ @org.hibernate.annotations.OrderBy(clause = "NAME asc")
+ private List<Album> albums = new ArrayList<Album>();
+ @Transient
+ private List<Image> unvisitedImages = new ArrayList<Image>();
+ @NotNull
+ private boolean shared;
+
+ @Temporal(TemporalType.TIMESTAMP)
private Date created;
-
- @Transient
- private Long countUnvisitedImages;
-
- /**
- * Getter for property id
- *
- * @return id of album
- */
- public Long getId() {
- return id;
- }
- /**
- * Getter for property name
- *
- * @return name of album
- */
- public String getName() {
- return name;
- }
+ @Transient
+ private Long countUnvisitedImages;
- /**
- * Setter for property name
- *
- * @param name -
- * name of album
- */
- public void setName(String name) {
- this.name = name;
- }
+ /**
+ * Getter for property id
+ *
+ * @return id of album
+ */
+ public Long getId() {
+ return id;
+ }
- /**
- * Getter for property description
- *
- * @return description of album
- */
- public String getDescription() {
- return description;
- }
+ /**
+ * Getter for property name
+ *
+ * @return name of album
+ */
+ public String getName() {
+ return name;
+ }
- /**
- * Setter for property description
- *
- * @param description -
- * description of album
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- public List<Album> getAlbums() {
- return albums;
- }
-
- public User getOwner() {
- return owner;
- }
+ /**
+ * Setter for property name
+ *
+ * @param name -
+ * name of album
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setOwner(User owner) {
- this.owner = owner;
- }
+ /**
+ * Getter for property description
+ *
+ * @return description of album
+ */
+ public String getDescription() {
+ return description;
+ }
- public void addAlbum(Album album) {
- if (album == null)
- throw new IllegalArgumentException("Null child!");
- if (album.getShelf() != null)
- album.getShelf().getAlbums().remove(album);
- album.setShelf(this);
- albums.add(album);
- }
+ /**
+ * Setter for property description
+ *
+ * @param description -
+ * description of album
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
- public void removeChildAlbum(Album album) {
- if (album == null)
- throw new IllegalArgumentException("Null child!");
- album.setShelf(null);
- albums.remove(album);
- }
-
- public int getCountAlbums() {
- return this.getAlbums() != null ? this.getAlbums().size() : 0;
+ public List<Album> getAlbums() {
+ return albums;
+ }
- }
-
- public int getCountImages() {
- int result = 0;
- if(getCountAlbums() > 0){
- for(Album album : getAlbums()){
- result += album.getCountImages();
- }
- }
- return result;
- }
+ public User getOwner() {
+ return owner;
+ }
- /**
- * @return the created
- */
- public Date getCreated() {
- return created;
- }
+ public void setOwner(User owner) {
+ this.owner = owner;
+ }
- /**
- * @param created the created to set
- */
- public void setCreated(Date created) {
- this.created = created;
- }
+ public void addAlbum(Album album) {
+ if (album == null)
+ throw new IllegalArgumentException("Null child!");
+ if (album.getShelf() != null)
+ album.getShelf().getAlbums().remove(album);
+ album.setShelf(this);
+ albums.add(album);
+ }
- public boolean isShared() {
- return shared;
- }
+ public void removeChildAlbum(Album album) {
+ if (album == null)
+ throw new IllegalArgumentException("Null child!");
+ album.setShelf(null);
+ albums.remove(album);
+ }
- public void setShared(boolean shared) {
- this.shared = shared;
- }
+ public int getCountAlbums() {
+ return this.getAlbums() != null ? this.getAlbums().size() : 0;
- public Long getCountUnvisitedImages() {
- return countUnvisitedImages;
- }
+ }
- public void setCountUnvisitedImages(Long countUnvisitedImages) {
- this.countUnvisitedImages = countUnvisitedImages;
- }
+ public int getCountImages() {
+ int result = 0;
+ if (getCountAlbums() > 0) {
+ for (Album album : getAlbums()) {
+ result += album.getCountImages();
+ }
+ }
+ return result;
+ }
- public List<Image> getUnvisitedImages() {
- return unvisitedImages;
- }
+ /**
+ * @return the created
+ */
+ public Date getCreated() {
+ return created;
+ }
- public void setUnvisitedImages(List<Image> unvisitedImages) {
- this.unvisitedImages = unvisitedImages;
- }
+ /**
+ * @param created the created to set
+ */
+ public void setCreated(Date created) {
+ this.created = created;
+ }
- public void visitImage(Image image) {
- if(unvisitedImages.contains(image)){
- unvisitedImages.remove(image);
- countUnvisitedImages--;
- }
- }
+ public boolean isShared() {
+ return shared;
+ }
- public Album getFirstAlbum() {
- if(this.albums.size() > 0){
- return this.albums.get(0);
- }
- return null;
- }
+ public void setShared(boolean shared) {
+ this.shared = shared;
+ }
+
+ public Long getCountUnvisitedImages() {
+ return countUnvisitedImages;
+ }
+
+ public void setCountUnvisitedImages(Long countUnvisitedImages) {
+ this.countUnvisitedImages = countUnvisitedImages;
+ }
+
+ public List<Image> getUnvisitedImages() {
+ return unvisitedImages;
+ }
+
+ public void setUnvisitedImages(List<Image> unvisitedImages) {
+ this.unvisitedImages = unvisitedImages;
+ }
+
+ public void visitImage(Image image) {
+ if (unvisitedImages.contains(image)) {
+ unvisitedImages.remove(image);
+ countUnvisitedImages--;
+ }
+ }
+
+ public Album getFirstAlbum() {
+ if (this.albums.size() > 0) {
+ return this.albums.get(0);
+ }
+ return null;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Shelf shelf = (Shelf) o;
+
+ if (id != null ? !id.equals(shelf.id) : shelf.id != null) return false;
+ if (owner != null ? !owner.equals(shelf.owner) : shelf.owner != null) return
false;
+ if (!name.equals(shelf.name)) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + name.hashCode();
+ result = 31 * result + (owner != null ? owner.hashCode() : 0);
+ return result;
+ }
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -303,4 +303,25 @@
}
return images;
}
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ User user = (User) o;
+
+ if (email != null ? !email.equals(user.email) : user.email != null) return
false;
+ if (id != null ? !id.equals(user.id) : user.id != null) return false;
+ if (login != null ? !login.equals(user.login) : user.login != null) return
false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (email != null ? email.hashCode() : 0);
+ result = 31 * result + (login != null ? login.hashCode() : 0);
+ return result;
+ }
}
\ No newline at end of file
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -41,87 +41,87 @@
@AutoCreate
public class ImageAction implements IImageAction {
- @In(value="entityManager")
- EntityManager em;
-
- public void deleteImage(Image image, boolean isFlushNeeded){
- image.getAlbum().removeImage(image);
- if(isFlushNeeded){
- em.flush();
- }
- }
+ @In(value = "entityManager")
+ EntityManager em;
- public void editImage(Image image, boolean isFlushNeeded) {
- List<MetaTag> removals = new ArrayList<MetaTag>(image.getImageTags());
- String[] tokens = image.getMetaString().split(",");
- Set<String> toks = new HashSet<String>();
- for(String s:tokens){
- toks.add(s.trim());
- }
- for(String s:toks){
- if(!image.containTag(s)){
- MetaTag tag = getTagByName(s);
- if(tag == null){
- tag = new MetaTag();
- tag.setTag(s);
- }
- image.addMetaTag(tag);
- }else{
- MetaTag t = image.getTagByName(s);
- removals.remove(t);
- }
- }
- for(MetaTag tag:removals){
- image.removeMetaTag(tag);
- tag.removeImage(image);
- }
- if(image.isCovering()){
- if(!image.equals(image.getAlbum().getCoveringImage())){
- image.getAlbum().setCoveringImage(image);
- }
- }
- if(isFlushNeeded){
- em.flush();
- }
- }
+ public void deleteImage(Image image, boolean isFlushNeeded) {
+ image.getAlbum().removeImage(image);
+ if (isFlushNeeded) {
+ em.flush();
+ }
+ }
- public void addImage(Image image, boolean isFlushNeeded) {
- em.persist(image);
- image.getAlbum().addImage(image);
- if(isFlushNeeded){
- em.flush();
- }
- }
-
- public void deleteComment(Comment comment, boolean isFlushNeeded){
- comment.getImage().removeComment(comment);
- if(isFlushNeeded){
- em.flush();
- }
- }
-
- public void addComment(Comment comment, boolean isFlushNeeded){
- comment.getImage().addComment(comment);
- if(isFlushNeeded){
- em.flush();
- }
- }
+ public void editImage(Image image, boolean isFlushNeeded) {
+ List<MetaTag> removals = new
ArrayList<MetaTag>(image.getImageTags());
+ String[] tokens = image.getMetaString().split(",");
+ Set<String> toks = new HashSet<String>();
+ for (String s : tokens) {
+ toks.add(s.trim());
+ }
+ for (String s : toks) {
+ if (!image.containTag(s)) {
+ MetaTag tag = getTagByName(s);
+ if (tag == null) {
+ tag = new MetaTag();
+ tag.setTag(s);
+ }
+ image.addMetaTag(tag);
+ } else {
+ MetaTag t = image.getTagByName(s);
+ removals.remove(t);
+ }
+ }
+ for (MetaTag tag : removals) {
+ image.removeMetaTag(tag);
+ tag.removeImage(image);
+ }
+ if (image.isCovering()) {
+ if (!image.equals(image.getAlbum().getCoveringImage())) {
+ image.getAlbum().setCoveringImage(image);
+ }
+ }
+ if (isFlushNeeded) {
+ em.flush();
+ }
+ }
- public MetaTag getTagByName(String tag) {
- MetaTag t;
- try{
- t = (MetaTag)em.createQuery("from MetaTag m where m.tag
=:tag").setParameter("tag", tag).getSingleResult();
- }catch(NoResultException nre){
- return null;
- }
- return t;
- }
+ public void addImage(Image image, boolean isFlushNeeded) {
+ em.persist(image);
+ image.getAlbum().addImage(image);
+ if (isFlushNeeded) {
+ em.flush();
+ }
+ }
- public List<MetaTag> popularTags() {
- return (List<MetaTag>)em.createQuery("select m from MetaTag
m").setMaxResults(20).getResultList();
- }
+ public void deleteComment(Comment comment, boolean isFlushNeeded) {
+ comment.getImage().removeComment(comment);
+ if (isFlushNeeded) {
+ em.flush();
+ }
+ }
- public List<MetaTag> getTagsLikeString(String suggest) {
- return (List<MetaTag>)em.createQuery("select m from MetaTag m where
lower(m.tag) like :tag").setParameter("tag", suggest +
"%").getResultList();
- }
+ public void addComment(Comment comment, boolean isFlushNeeded) {
+ comment.getImage().addComment(comment);
+ if (isFlushNeeded) {
+ em.flush();
+ }
+ }
+
+ public MetaTag getTagByName(String tag) {
+ MetaTag t;
+ try {
+ t = (MetaTag) em.createQuery("from MetaTag m where m.tag
=:tag").setParameter("tag", tag).getSingleResult();
+ } catch (NoResultException nre) {
+ return null;
+ }
+ return t;
+ }
+
+ public List<MetaTag> popularTags() {
+ return em.createQuery("select new MetaTag(m.id, m.tag) from MetaTag m join
m.images img group by m.id, m.tag order by count(img)
desc").setMaxResults(20).getResultList();
+ }
+
+ public List<MetaTag> getTagsLikeString(String suggest) {
+ return (List<MetaTag>) em.createQuery("select m from MetaTag m where
lower(m.tag) like :tag").setParameter("tag", suggest +
"%").getResultList();
+ }
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java 2009-03-25
13:06:42 UTC (rev 13175)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java 2009-03-25
14:33:05 UTC (rev 13176)
@@ -29,6 +29,7 @@
writeFiles(file, "_small80", 80);
writeFiles(file, "_small120", 120);
writeFiles(file, "_small160", 160);
+ writeFiles(file, "_small200", 200);
writeFiles(file, "_mini", 150);
writeFiles(file, "_medium", 600);
}
@@ -40,7 +41,9 @@
}
} else if (file.isFile()) {
final String s = file.getName().toLowerCase();
- if (s.endsWith(".jpg") &&
!s.endsWith("_mini.jpg") && !s.endsWith("_medium.jpg")
&& !s.endsWith("_small80.jpg") &&
!s.endsWith("_small120.jpg") && !s.endsWith("_small160.jpg"))
{
+ if (s.endsWith(".jpg") &&
!s.endsWith("_mini.jpg") && !s.endsWith("_medium.jpg")
+ && !s.endsWith("_small80.jpg") &&
!s.endsWith("_small120.jpg")
+ && !s.endsWith("_small160.jpg") &&
!s.endsWith("_small200.jpg")) {
System.out.println("processing file >> " +
file.getPath());
writeOneImage(file.getParent(), pattern, size, s);
}