Author: amarkhel
Date: 2009-04-06 10:31:27 -0400 (Mon, 06 Apr 2009)
New Revision: 13391
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/User.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
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/ShelfAction.java
trunk/test-applications/realworld2/ejb/src/main/resources/import.sql
Log:
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-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Album.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -33,8 +33,6 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@@ -48,7 +46,6 @@
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Role;
import org.jboss.seam.annotations.Scope;
/**
@@ -171,7 +168,6 @@
return;
}
if (image.getAlbum() != null && !this.equals(image.getAlbum())) {
- //TODO nick - use removeImage()
image.getAlbum().removeImage(image);
}if(!image.isVisited()){
this.getShelf().getUnvisitedImages().add(image);
@@ -191,7 +187,6 @@
if (image == null) {
throw new IllegalArgumentException("Null image");
}
- //TODO nick - check if image is in the current album
if(image.getAlbum().equals(this)){
if(image.getAlbum().getUnvisitedImages().contains(image)){
image.getAlbum().getUnvisitedImages().remove(image);
@@ -224,9 +219,10 @@
}
public int getIndex(Image image) {
- //TODO nick - use indexOf
- //TODO nick - check images == null?
- return this.images.indexOf(image);
+ if(this.images.size() > 0){
+ return this.images.indexOf(image);
+ }
+ return -1;
}
public Image getCoveringImage() {
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-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -59,7 +59,6 @@
@ManyToOne(optional=false)
@JoinColumn(name = "IMAGE_ID", referencedColumnName =
"IMAGE_ID")
- //TODO nick - add @NotNull
private Image image;
@ManyToOne(fetch = FetchType.LAZY)
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-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -241,7 +241,6 @@
if (comment == null) {
throw new IllegalArgumentException("Null comment");
}
- //TODO nick - check that comments belongs to "this" image
if(comment.getImage().equals(this)){
comment.setImage(null);
comments.remove(comment);
@@ -267,8 +266,6 @@
for (MetaTag tag : this.imageTags) {
s.append(tag.getTag()).append(", ");
}
-
- //TODO nick - changed by nick
if (s.length() >= 2) {
s.delete(s.length() - 2, s.length());
}
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-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/MetaTag.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -30,6 +30,7 @@
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
@@ -40,7 +41,9 @@
@Entity
@Name("metaTag")
-@Table(name = "metatags")
+@Table(name = "metatags", uniqueConstraints = {
+ @UniqueConstraint(columnNames = "tag"),
+ })
@Scope(ScopeType.EVENT)
public class MetaTag implements Serializable {
@@ -55,7 +58,6 @@
@NotNull
@NotEmpty
@Length(min = 3, max=50)
- //TODO nick - meta tags should not contain ',', add constraint
private String tag;
@ManyToMany(mappedBy = "imageTags")
@@ -67,6 +69,11 @@
public MetaTag(Long id) {
this.id = id;
}
+
+ public MetaTag(Long id, String tag) {
+ this.id = id;
+ this.tag = tag;
+ }
public Long getId() {
return id;
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-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/User.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -204,8 +204,7 @@
public void removeShelf(Shelf shelf) {
if (shelf == null) {
throw new IllegalArgumentException("Null shelf");
- }
- //TODO nick - check if owner is current user?
+ }
if(shelf.getOwner().getLogin().equals(this.getLogin())){
shelf.setOwner(null);
shelfs.remove(shelf);
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java 2009-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -20,10 +20,6 @@
*/
package org.richfaces.realworld.service;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.List;
import javax.ejb.Stateless;
@@ -32,10 +28,8 @@
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Out;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.domain.User;
@Name("albumAction")
@Stateless
@@ -73,15 +67,6 @@
}
public List<Image> getUnvisitedImages(Album album){
- //TODO nick - use Shelf/Album.unvisitedImages
- return (List<Image>)em.createQuery("from Image i where i.album=:album and
i.uploaded > :date").setParameter("album",
album).setParameter("date", getDate()).getResultList();
+ return (List<Image>)em.createQuery("from Image i where i.album=:album and
i.uploaded > :date").setParameter("album",
album).setParameter("date", ActionTools.getRecentlyDate()).getResultList();
}
-
- private Date getDate() {
- //TODO nick - use Calendar.getInstance()
- Calendar c = Calendar.getInstance();
- c.add(Calendar.DAY_OF_YEAR, -15);
- //TODO nick - return c.getTime()
- return c.getTime();
- }
}
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-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -70,14 +70,18 @@
//TODO nick - how about concurrent creation of meta tags with the same
name?
removals.remove(t);
} else {
- t = new MetaTag();
- t.setTag(s);
- image.addMetaTag(t);
- }
+ t = getTagByName(s);
+ if(t != null){
+ image.addMetaTag(t);
+ }else{
+ t = new MetaTag();
+ t.setTag(s);
+ image.addMetaTag(t);
+ }
+ }
}
for (MetaTag tag : removals) {
image.removeMetaTag(tag);
- tag.removeImage(image);
}
if (image.isCovering()) {
if (!image.equals(image.getAlbum().getCoveringImage())) {
@@ -85,7 +89,12 @@
}
}
if (flushStrategy.isDatabaseStoreStrategy()) {
- em.flush();
+ try{
+ em.flush();
+ }catch(Exception e){
+ editImage(image);
+ }
+
}
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java 2009-04-06
14:31:17 UTC (rev 13390)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java 2009-04-06
14:31:27 UTC (rev 13391)
@@ -20,13 +20,7 @@
*/
package org.richfaces.realworld.service;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
Modified: trunk/test-applications/realworld2/ejb/src/main/resources/import.sql
===================================================================
--- trunk/test-applications/realworld2/ejb/src/main/resources/import.sql 2009-04-06
14:31:17 UTC (rev 13390)
+++ trunk/test-applications/realworld2/ejb/src/main/resources/import.sql 2009-04-06
14:31:27 UTC (rev 13391)
@@ -3,7 +3,7 @@
INSERT INTO Users(user_id, firstname, secondname, email, login, passwordHash, birthdate,
sex, hasAvatar) VALUES (3, 'John', 'Smith',
'jsmith(a)jboss.com', 'Noname',
'8cb2237d0679ca88db6464eac60da96345513964', '1970-01-08', 1, 0);
INSERT INTO shelves(shelf_id, name, description, user_id, created, shared) VALUES (1,
'Nature', 'Nature pictures', 1, '2009-12-18', true);
-INSERT INTO shelves(shelf_id, name, description, user_id, created, shared) VALUES (2,
'Sport', 'Nature pictures', 1, '2009-12-18', false);
+INSERT INTO shelves(shelf_id, name, description, user_id, created, shared) VALUES (2,
'Sport', 'Nature pictures', 1, '2009-12-18', true);
INSERT INTO shelves(shelf_id, name, description, user_id, created, shared) VALUES (3,
'Water', 'Nature pictures', 2, '2009-12-18', true);
INSERT INTO shelves(shelf_id, name, description, user_id, created, shared) VALUES (4,
'Flowers', 'Nature pictures', 3, '2009-12-18', true);