BrightSide Workbench Full Report + Source Code
PublicationResults.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.publication.zul.www;
19 
20 import java.util.List;
21 import org.turro.string.Strings;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.publication.db.PublicationPU;
24 import org.turro.publication.entity.Publication;
25 
30 public class PublicationResults {
31 
32  private PublicationOrdering ordering;
33  private String author;
34  private List<String> pathList;
35  private long group, category;
36 
37  public String getAuthor() {
38  return author;
39  }
40 
41  public void setAuthor(String author) {
42  this.author = author;
43  }
44 
45  public long getCategory() {
46  return category;
47  }
48 
49  public void setCategory(long category) {
50  this.category = category;
51  }
52 
53  public long getGroup() {
54  return group;
55  }
56 
57  public void setGroup(long group) {
58  this.group = group;
59  }
60 
62  return ordering;
63  }
64 
65  public void setOrdering(PublicationOrdering ordering) {
66  this.ordering = ordering;
67  }
68 
69  public List<String> getPathList() {
70  return pathList;
71  }
72 
73  public void setPathList(List<String> pathList) {
74  this.pathList = pathList;
75  }
76 
77  public List<Publication> getPublications(int max) {
78  WhereClause wc = new WhereClause();
79  wc.addClause("select publication from Publication publication");
80  wc.addClause("where publication.accepted = true");
81  wc.addClause("and publication.publicationGroup.publishable = true");
82  wc.addClause("and publication.publicationCategory.publishable = true");
83  if(group != 0) {
84  wc.addClause("and publication.publicationGroup.id = :group");
85  wc.addNamedValue("group", group);
86  }
87  if(category != 0) {
88  wc.addClause("and publication.publicationCategory.id = :category");
89  wc.addNamedValue("category", category);
90  }
91  if(!Strings.isBlank(author)) {
92  wc.addClause("and publication.author = :author");
93  wc.addNamedValue("author", author);
94  }
95  if(pathList != null && !pathList.isEmpty()) {
96  wc.addClause("and publication.id in (" + convertToIn(pathList) + ")");
97  }
98  wc.addClause(ordering.getOrderStr());
99  return new PublicationPU().getResultList(wc, max);
100  }
101 
102  public String convertToIn(List<String> paths) {
103  String result = null;
104  for(String s : paths) {
105  result = (String) ((result == null) ? s.substring(13) : (result + "," + s.substring(13))); // "/publication/n"
106  }
107  return result;
108  }
109 
110 }
void addNamedValue(String name, Object value)
void setOrdering(PublicationOrdering ordering)