BrightSide Workbench Full Report + Source Code
AttachHeadlessResults.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.attach.search;
19 
20 
21 import org.turro.attach.db.AttachPU;
22 import org.turro.attach.entity.Attachment;
23 import org.turro.elephant.db.SQLHelper;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.jpa.Dao;
26 import org.zkoss.lang.Strings;
27 
32 public class AttachHeadlessResults {
33 
34  private boolean ckNonValidated = false, ckExactPath;
35  private String attachValue = "*", attachPath;
36 
38  }
39 
40  public void markAll() {
41  attachValue = "*";
42  ckNonValidated = false;
43  }
44 
45  public java.util.List<Attachment> getAttachmentList() {
46  Dao dao = new AttachPU();
47  WhereClause wc = new WhereClause();
48  wc.addClause("select distinct attachment from Attachment as attachment");
49  wc.addClause("where 1=1");
50  addCriteria(wc);
51  wc.addClause("order by attachment.fileName, attachment.modification DESC");
52  return new AttachmentList(dao.getResultList(wc), true);
53  }
54 
55  public java.util.Set<String> getPathList(String currPath) {
56  Dao dao = new AttachPU();
57  WhereClause wc = new WhereClause();
58  wc.addClause("select distinct attachment.path from Attachment as attachment");
59  wc.addClause("where 1=1");
60  addCriteria(wc);
61  wc.addClause("order by attachment.path");
62  return new PathSet(dao.getResultList(wc), currPath, true);
63  }
64 
65  public void addCriteria(WhereClause wc) {
66 
67  if(Strings.isEmpty(attachValue)) {
68  return;
69  }
70 
71  wc = SQLHelper.getWhereClause(wc, new String[] {
72  "attachment.fileName"
73  }, (attachValue == null ? "" : attachValue.replaceAll("\\*", "%")));
74 
75  if(ckNonValidated) {
76  wc.addClause("and attachment.validated = false");
77  }
78 
79  if(attachPath != null) {
80  wc.addClause("and UCASE(attachment.path) " +
81  (ckExactPath ? "=" : "like") +
82  " UCASE(:path)");
83  wc.addNamedValue("path", attachPath);
84  }
85 
86  }
87 
88  public String getAttachPath() {
89  return attachPath;
90  }
91 
92  public void setAttachPath(String attachPath) {
93  this.attachPath = attachPath;
94  }
95 
96  public String getAttachValue() {
97  return attachValue;
98  }
99 
100  public void setAttachValue(String attachValue) {
101  this.attachValue = attachValue;
102  }
103 
104  public boolean isCkExactPath() {
105  return ckExactPath;
106  }
107 
108  public void setCkExactPath(boolean ckExactPath) {
109  this.ckExactPath = ckExactPath;
110  }
111 
112  public boolean isCkNonValidated() {
113  return ckNonValidated;
114  }
115 
116  public void setCkNonValidated(boolean ckNonValidated) {
117  this.ckNonValidated = ckNonValidated;
118  }
119 
120  public static long getCountAttachments(String root) {
121  Dao dao = new AttachPU();
122  return (Long) dao.getSingleResult(
123  " select count(attachment) " +
124  " from Attachment as attachment" +
125  " where attachment.path like '" + root + "/%'");
126  }
127 
128 }
java.util.Set< String > getPathList(String currPath)
static WhereClause getWhereClause(String[] fields, String value)
Definition: SQLHelper.java:64
void addNamedValue(String name, Object value)
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380