Author: amarkhel
Date: 2009-01-06 09:09:03 -0500 (Tue, 06 Jan 2009)
New Revision: 12132
Modified:
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ISearchService.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java
trunk/test-applications/realworld/web/src/main/webapp/includes/image/imageScroller.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/search.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/search/advancedSearch.xhtml
trunk/test-applications/realworld/web/src/main/webapp/main.xhtml
Log:
Modified:
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ISearchService.java
===================================================================
---
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ISearchService.java 2009-01-06
13:50:16 UTC (rev 12131)
+++
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ISearchService.java 2009-01-06
14:09:03 UTC (rev 12132)
@@ -14,4 +14,8 @@
public List<Image> popularImages(String additionalParams, Map<String,
Object> paramMap);
public List<Image> worstImages(String additionalParams, Map<String, Object>
paramMap);
+
+ public abstract List<String> getAllCameras();
+
+ public abstract List<String> getAllMetatags();
}
\ No newline at end of file
Modified:
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java
===================================================================
---
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java 2009-01-06
13:50:16 UTC (rev 12131)
+++
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java 2009-01-06
14:09:03 UTC (rev 12132)
@@ -19,9 +19,19 @@
private static final String PERCENT = "%";
public static final String DATE_NAMED_PARAMETER = ":date";
+ public static final String UPLOAD_NAMED_PARAMETER = ":upload";
+ public static final String WIDTH_NAMED_PARAMETER = ":width";
+ public static final String HEIGHT_NAMED_PARAMETER = ":height";
+ public static final String SIZE_NAMED_PARAMETER = ":size";
+ public static final String CAMERA_NAMED_PARAMETER = ":camera";
public static final String CHOICE_NAMED_PARAMETER = ":choice";
public static final String SPINNER_VALUE_NAMED_PARAMETER = ":spinnerValue";
private static final String DATE_PARAMETER = "date";
+ private static final String UPLOAD_PARAMETER = "upload";
+ private static final String WIDTH_PARAMETER = "width";
+ private static final String HEIGHT_PARAMETER = "height";
+ private static final String SIZE_PARAMETER = "size";
+ private static final String CAMERA_PARAMETER = "camera";
private static final String CHOICE_PARAMETER = "choice";
private static final String SPINNER_VALUE_PARAMETER = "spinnerValue";
private static final String METATAG_PARAMETER = "metatag";
@@ -29,13 +39,27 @@
private static final String SEARCH_POPULAR_QUERY_END = " order by r.total/r.hits
desc";
private static final String SEARCH_RELEVANT_QUERY_BEGIN = "select i from Image i
join i.rank r where i.album.shared=true";
private static final String SEARCH_QUERY_END = " order by i.rank.total/i.rank.hits
desc";
- private static final String SEARCH_QUERY_BEGIN = "select i from MetaTag t join
t.parent i where t.tag like:metatag and i.album.shared=true";
+ private static final String SEARCH_QUERY_BEGIN = "select i from MetaTag t join
t.parent i where upper(t.tag) like:metatag and i.album.shared=true";
+ private static final String SEARCH_SENSITIVE_QUERY_BEGIN = "select i from MetaTag t
join t.parent i where t.tag like:metatag and i.album.shared=true";
private static final long serialVersionUID = -2750591521413940277L;
+ public static final String STRICT_PARAMETER = "STRICT";
+ public static final String CASE_SENSITIVE_PARAMETER = "CASE_SENSITIVE";
@In(value="entityManager")
EntityManager em;
public List<Image> searchImages(String searchPattern, String additionalParams,
Map<String, Object> paramMap){
- String fullQuery = SEARCH_QUERY_BEGIN + additionalParams + SEARCH_QUERY_END;
+ String fullQuery = null;
+ if(searchPattern.equals("")){
+ return null;
+ }
+ if(paramMap != null && paramMap.get(CASE_SENSITIVE_PARAMETER) != null){
+ boolean sensitive = (Boolean)paramMap.get(CASE_SENSITIVE_PARAMETER);
+ if(sensitive){
+ fullQuery = SEARCH_SENSITIVE_QUERY_BEGIN + additionalParams + SEARCH_QUERY_END;
+ }else{
+ fullQuery = SEARCH_QUERY_BEGIN + additionalParams + SEARCH_QUERY_END;
+ }
+ }
Query prepared = prepareQuery(fullQuery, searchPattern, additionalParams, paramMap);
return prepared.getResultList();
}
@@ -56,7 +80,20 @@
Map<String, Object> paramMap) {
Query prepared = em.createQuery(fullQuery);
if(searchPattern != null){
- prepared.setParameter(METATAG_PARAMETER, searchPattern+PERCENT);
+ if(paramMap != null && paramMap.get(STRICT_PARAMETER) != null){
+ String strict = paramMap.get(STRICT_PARAMETER).toString();
+ if(strict.equals("STRICT")){
+ prepared.setParameter(METATAG_PARAMETER, searchPattern.toUpperCase());
+ }else if(strict.equals("START")){
+ prepared.setParameter(METATAG_PARAMETER, searchPattern.toUpperCase()+PERCENT);
+ }else if(strict.equals("END")){
+ prepared.setParameter(METATAG_PARAMETER, PERCENT + searchPattern.toUpperCase());
+ }else if(strict.equals("INCLUDE")){
+ prepared.setParameter(METATAG_PARAMETER, PERCENT +
searchPattern.toUpperCase()+PERCENT);
+ }
+ }else{
+ prepared.setParameter(METATAG_PARAMETER, searchPattern.toUpperCase()+PERCENT);
+ }
}
if(paramMap != null && paramMap.get(SPINNER_VALUE_NAMED_PARAMETER) != null){
prepared.setParameter(SPINNER_VALUE_PARAMETER,
paramMap.get(SPINNER_VALUE_NAMED_PARAMETER));
@@ -67,7 +104,32 @@
if(paramMap != null && paramMap.get(DATE_NAMED_PARAMETER) != null){
prepared.setParameter(DATE_PARAMETER, paramMap.get(DATE_NAMED_PARAMETER));
}
+ if(paramMap != null && paramMap.get(UPLOAD_NAMED_PARAMETER) != null){
+ prepared.setParameter(UPLOAD_PARAMETER, paramMap.get(UPLOAD_NAMED_PARAMETER));
+ }
+ if(paramMap != null && paramMap.get(WIDTH_NAMED_PARAMETER) != null){
+ prepared.setParameter(WIDTH_PARAMETER, paramMap.get(WIDTH_NAMED_PARAMETER));
+ }
+ if(paramMap != null && paramMap.get(HEIGHT_NAMED_PARAMETER) != null){
+ prepared.setParameter(HEIGHT_PARAMETER, paramMap.get(HEIGHT_NAMED_PARAMETER));
+ }
+ if(paramMap != null && paramMap.get(SIZE_NAMED_PARAMETER) != null){
+ prepared.setParameter(SIZE_PARAMETER, paramMap.get(SIZE_NAMED_PARAMETER));
+ }
+ if(paramMap != null && paramMap.get(CAMERA_NAMED_PARAMETER) != null){
+ prepared.setParameter(CAMERA_PARAMETER, paramMap.get(CAMERA_NAMED_PARAMETER));
+ }
prepared.setMaxResults(20);
return prepared;
}
+
+ public List<String> getAllCameras() {
+ Query query = em.createQuery("select distinct i.cameraModel from Image i");
+ return (List<String>)query.getResultList();
+ }
+
+ public List<String> getAllMetatags() {
+ Query query = em.createQuery("select distinct t.tag from Image i join i.tags
t");
+ return (List<String>)query.getResultList();
+ }
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-06
13:50:16 UTC (rev 12131)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-06
14:09:03 UTC (rev 12132)
@@ -88,7 +88,7 @@
image.setUploaded(new Date());
image.setDescription(SAMPLE_DESCRIPTION);
image.setName(SAMPLE_NAME);
- image.setSize(file.getLength());
+ image.setSize(file.getLength() / 1024);
image.setPath(user.getLogin() + "/" +
selectionHelper.getSelectedAlbum().getName() + "/" + item.getFileName());
image.setAlbumName(selectionHelper.getSelectedAlbum().getName());
image.setAlbum(selectionHelper.getSelectedAlbum());
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java 2009-01-06
13:50:16 UTC (rev 12131)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java 2009-01-06
14:09:03 UTC (rev 12132)
@@ -28,12 +28,16 @@
import java.util.Map;
import javax.faces.model.SelectItem;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.service.ISearchService;
import org.richfaces.realworld.service.SearchService;
@@ -46,6 +50,8 @@
@In("#{messages['more']}") private String MORE_CHOICE;
@In("#{messages['nomatter']}") private String NO_MATTER_CHOICE;
+ private boolean collapsed;
+
private static final String EQUALS = "= ";
private static final String LESSTHEN = "< ";
@@ -53,6 +59,16 @@
private static final String GREATTHEN = "> ";
private static final String DATE_ADDON = " and i.created";
+
+ private static final String UPLOAD_ADDON = " and i.upload";
+
+ private static final String HEIGHT_ADDON = " and i.height";
+
+ private static final String SIZE_ADDON = " and i.size";
+
+ private static final String WIDTH_ADDON = " and i.width";
+
+ private static final String CAMERA_ADDON = " and i.cameraModel";
private static final String VOTES_ADDON = " and i.rank.hits";
@@ -60,6 +76,8 @@
private static final long serialVersionUID = 5071655218132021316L;
+ private boolean caseSensitive;
+
@In(required=false)
private SearchBeanHelper helper;
@@ -68,8 +86,18 @@
private String searchPattern;
+ private Long matcherChoice;
+
private Long spinnerChoice;
+ private Long uploadChoice;
+
+ private Long sizeChoice;
+
+ private Long widthChoice;
+
+ private Long heightChoice;
+
private Long dateChoice;
private Long votesChoice;
@@ -78,6 +106,16 @@
private Date date;
+ private String camera;
+
+ private int height;
+
+ private double size;
+
+ private int width;
+
+ private Date uploadDate;
+
private List<Image> findedImages = new ArrayList<Image>();
public List<SelectItem> getItems() {
@@ -89,6 +127,15 @@
return list;
}
+ public List<SelectItem> getMatchItems() {
+ List<SelectItem> list = new ArrayList<SelectItem>(4);
+ list.add(new SelectItem(Long.valueOf(0L), "Strict"));
+ list.add(new SelectItem(Long.valueOf(1L), "Start with"));
+ list.add(new SelectItem(Long.valueOf(2L), "End with"));
+ list.add(new SelectItem(Long.valueOf(3L), "Include"));
+ return list;
+ }
+
private String getAstFromIndex(Long item){
if(item == 1L){
return GREATTHEN;
@@ -100,12 +147,23 @@
return null;
}
+ private String getMatcher(Long item){
+ if(item == 1L){
+ return "START";
+ }else if(item == 2L){
+ return "END";
+ }else if(item == 3L){
+ return "INCLUDE";
+ }else if(item == 0L){
+ return "STRICT";
+ }
+ return null;
+ }
+
public List<Image> searchImages(){
String additionalParams = populateAdditionalParams();
Map<String, Object> paramMap = null;
- if(!additionalParams.equals("")){
- paramMap = populateMap(additionalParams);
- }
+ paramMap = populateMap(additionalParams);
findedImages = searchService.searchImages(this.searchPattern, additionalParams,
paramMap);
return findedImages;
}
@@ -113,9 +171,7 @@
public List<Image> popularImages(){
String additionalParams = populateAdditionalParams();
Map<String, Object> paramMap = null;
- if(!additionalParams.equals("")){
- paramMap = populateMap(additionalParams);
- }
+ paramMap = populateMap(additionalParams);
findedImages = searchService.popularImages(additionalParams, paramMap);
return findedImages;
}
@@ -131,9 +187,32 @@
if(additionalParams.lastIndexOf(SearchService.DATE_NAMED_PARAMETER) != -1){
map.put(SearchService.DATE_NAMED_PARAMETER, date);
}
+ if(additionalParams.lastIndexOf(SearchService.UPLOAD_NAMED_PARAMETER) != -1){
+ map.put(SearchService.UPLOAD_NAMED_PARAMETER, uploadDate);
+ }
+ if(additionalParams.lastIndexOf(SearchService.SIZE_NAMED_PARAMETER) != -1){
+ map.put(SearchService.SIZE_NAMED_PARAMETER, size);
+ }
+ if(additionalParams.lastIndexOf(SearchService.WIDTH_NAMED_PARAMETER) != -1){
+ map.put(SearchService.WIDTH_NAMED_PARAMETER, width);
+ }
+ if(additionalParams.lastIndexOf(SearchService.HEIGHT_NAMED_PARAMETER) != -1){
+ map.put(SearchService.HEIGHT_NAMED_PARAMETER, height);
+ }
+ if(additionalParams.lastIndexOf(SearchService.CAMERA_NAMED_PARAMETER) != -1){
+ map.put(SearchService.CAMERA_NAMED_PARAMETER, camera);
+ }
+ if(matcherChoice != null){
+ map.put(SearchService.STRICT_PARAMETER, getMatcher(matcherChoice));
+ }
+ map.put(SearchService.CASE_SENSITIVE_PARAMETER, caseSensitive);
return map;
}
+ public void collapse(){
+ this.setCollapsed(!collapsed);
+ }
+
private String populateAdditionalParams() {
StringBuilder additionalParams = new StringBuilder("");
if(spinnerChoice != null && spinnerChoice > 0L){
@@ -151,6 +230,31 @@
additionalParams.append(getAstFromIndex(dateChoice));
additionalParams.append(SearchService.DATE_NAMED_PARAMETER);
}
+ if(uploadChoice != null && uploadChoice > 0L && uploadDate !=
null){
+ additionalParams.append(UPLOAD_ADDON);
+ additionalParams.append(getAstFromIndex(uploadChoice));
+ additionalParams.append(SearchService.UPLOAD_NAMED_PARAMETER);
+ }
+ if(widthChoice != null && widthChoice > 0L){
+ additionalParams.append(WIDTH_ADDON);
+ additionalParams.append(getAstFromIndex(widthChoice));
+ additionalParams.append(SearchService.WIDTH_NAMED_PARAMETER);
+ }
+ if(heightChoice != null && heightChoice > 0L){
+ additionalParams.append(HEIGHT_ADDON);
+ additionalParams.append(getAstFromIndex(heightChoice));
+ additionalParams.append(SearchService.HEIGHT_NAMED_PARAMETER);
+ }
+ if(sizeChoice != null && sizeChoice > 0L){
+ additionalParams.append(SIZE_ADDON);
+ additionalParams.append(getAstFromIndex(sizeChoice));
+ additionalParams.append(SearchService.SIZE_NAMED_PARAMETER);
+ }
+ if(camera!= null && !camera.equals("")){
+ additionalParams.append(CAMERA_ADDON);
+ additionalParams.append(EQUALS);
+ additionalParams.append(SearchService.CAMERA_NAMED_PARAMETER);
+ }
return additionalParams.toString();
}
@@ -164,6 +268,18 @@
return findedImages;
}
+ public List<String> getAllCameras(){
+ List<String> cameras = new ArrayList<String>();
+ cameras = searchService.getAllCameras();
+ return cameras;
+ }
+
+ public List<String> getAllMetatags(){
+ List<String> metatags = new ArrayList<String>();
+ metatags = searchService.getAllMetatags();
+ return metatags;
+ }
+
public String getSearchPattern() {
return searchPattern;
}
@@ -219,4 +335,100 @@
public void setFindedImages(List<Image> findedImages) {
this.findedImages = findedImages;
}
+
+ public String getCamera() {
+ return camera;
+ }
+
+ public void setCamera(String camera) {
+ this.camera = camera;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ public double getSize() {
+ return size;
+ }
+
+ public void setSize(double size) {
+ this.size = size;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ public Date getUploadDate() {
+ return uploadDate;
+ }
+
+ public void setUploadDate(Date uploadDate) {
+ this.uploadDate = uploadDate;
+ }
+
+ public Long getUploadChoice() {
+ return uploadChoice;
+ }
+
+ public void setUploadChoice(Long uploadChoice) {
+ this.uploadChoice = uploadChoice;
+ }
+
+ public Long getSizeChoice() {
+ return sizeChoice;
+ }
+
+ public void setSizeChoice(Long sizeChoice) {
+ this.sizeChoice = sizeChoice;
+ }
+
+ public Long getWidthChoice() {
+ return widthChoice;
+ }
+
+ public void setWidthChoice(Long widthChoice) {
+ this.widthChoice = widthChoice;
+ }
+
+ public Long getHeightChoice() {
+ return heightChoice;
+ }
+
+ public void setHeightChoice(Long heightChoice) {
+ this.heightChoice = heightChoice;
+ }
+
+ public boolean isCollapsed() {
+ return collapsed;
+ }
+
+ public void setCollapsed(boolean collapsed) {
+ this.collapsed = collapsed;
+ }
+
+ public boolean isCaseSensitive() {
+ return caseSensitive;
+ }
+
+ public void setCaseSensitive(boolean caseSensitive) {
+ this.caseSensitive = caseSensitive;
+ }
+
+ public Long getMatcherChoice() {
+ return matcherChoice;
+ }
+
+ public void setMatcherChoice(Long matcherChoice) {
+ this.matcherChoice = matcherChoice;
+ }
}
Modified:
trunk/test-applications/realworld/web/src/main/webapp/includes/image/imageScroller.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld/web/src/main/webapp/includes/search/advancedSearch.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/search.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/main.xhtml
===================================================================
(Binary files differ)