1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.store.hibernate; |
21 |
|
|
22 |
|
import java.util.Date; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.hibernate.Criteria; |
30 |
|
import org.hibernate.HibernateException; |
31 |
|
import org.hibernate.Session; |
32 |
|
import org.hibernate.criterion.Order; |
33 |
|
import org.hibernate.criterion.Restrictions; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.DeletedAttachment; |
39 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
40 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
41 |
|
import com.xpn.xwiki.store.AttachmentRecycleBinStore; |
42 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore; |
43 |
|
|
44 |
|
|
45 |
|
@link |
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
50 |
|
@Component |
51 |
|
@Named("hibernate") |
52 |
|
@Singleton |
|
|
| 17% |
Uncovered Elements: 39 (47) |
Complexity: 19 |
Complexity Density: 0.7 |
|
53 |
|
public class HibernateAttachmentRecycleBinStore extends XWikiHibernateBaseStore implements AttachmentRecycleBinStore |
54 |
|
{ |
55 |
|
|
56 |
|
private static final String ANOTATE_UNCHECKED = "unchecked"; |
57 |
|
|
58 |
|
|
59 |
|
private static final String DOC_ID = "docId"; |
60 |
|
|
61 |
|
|
62 |
|
private static final String DATE = "date"; |
63 |
|
|
64 |
|
|
65 |
|
@link |
66 |
|
|
67 |
|
@param |
68 |
|
@deprecated |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@Deprecated... |
71 |
|
public HibernateAttachmentRecycleBinStore(XWikiContext context) |
72 |
|
{ |
73 |
0 |
super(context.getWiki(), context); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
79 |
87 |
public HibernateAttachmentRecycleBinStore()... |
80 |
|
{ |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
83 |
5 |
@Override... |
84 |
|
public void saveToRecycleBin(XWikiAttachment attachment, String deleter, Date date, XWikiContext inputxcontext, |
85 |
|
boolean bTransaction) throws XWikiException |
86 |
|
{ |
87 |
5 |
XWikiContext context = getXWikiContext(inputxcontext); |
88 |
|
|
89 |
5 |
final DeletedAttachment trashAtachment = new DeletedAttachment(attachment, deleter, date, context); |
90 |
5 |
executeWrite(context, bTransaction, new HibernateCallback<Object>() |
91 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
92 |
5 |
@Override... |
93 |
|
public Object doInHibernate(Session session) throws HibernateException |
94 |
|
{ |
95 |
5 |
session.save(trashAtachment); |
96 |
5 |
return null; |
97 |
|
} |
98 |
|
}); |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
101 |
0 |
@Override... |
102 |
|
public XWikiAttachment restoreFromRecycleBin(final XWikiAttachment attachment, final long index, |
103 |
|
final XWikiContext inputxcontext, boolean bTransaction) throws XWikiException |
104 |
|
{ |
105 |
0 |
XWikiContext context = getXWikiContext(inputxcontext); |
106 |
|
|
107 |
0 |
return executeRead(context, bTransaction, new HibernateCallback<XWikiAttachment>() |
108 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
109 |
0 |
@Override... |
110 |
|
public XWikiAttachment doInHibernate(Session session) throws HibernateException, XWikiException |
111 |
|
{ |
112 |
0 |
try { |
113 |
0 |
DeletedAttachment trashAttachment = |
114 |
|
(DeletedAttachment) session.load(DeletedAttachment.class, Long.valueOf(index)); |
115 |
0 |
return trashAttachment.restoreAttachment(attachment, context); |
116 |
|
} catch (Exception ex) { |
117 |
|
|
118 |
0 |
return null; |
119 |
|
} |
120 |
|
} |
121 |
|
}); |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0 |
@Override... |
125 |
|
public DeletedAttachment getDeletedAttachment(final long index, XWikiContext context, boolean bTransaction) |
126 |
|
throws XWikiException |
127 |
|
{ |
128 |
0 |
return executeRead(context, bTransaction, new HibernateCallback<DeletedAttachment>() |
129 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
@Override... |
131 |
|
public DeletedAttachment doInHibernate(Session session) throws HibernateException, XWikiException |
132 |
|
{ |
133 |
0 |
return (DeletedAttachment) session.get(DeletedAttachment.class, Long.valueOf(index)); |
134 |
|
} |
135 |
|
}); |
136 |
|
} |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
@Override... |
139 |
|
public List<DeletedAttachment> getAllDeletedAttachments(final XWikiAttachment attachment, XWikiContext context, |
140 |
|
boolean bTransaction) throws XWikiException |
141 |
|
{ |
142 |
0 |
return executeRead(context, bTransaction, new HibernateCallback<List<DeletedAttachment>>() |
143 |
|
{ |
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
144 |
0 |
@SuppressWarnings(ANOTATE_UNCHECKED)... |
145 |
|
@Override |
146 |
|
public List<DeletedAttachment> doInHibernate(Session session) throws HibernateException, XWikiException |
147 |
|
{ |
148 |
0 |
Criteria c = session.createCriteria(DeletedAttachment.class); |
149 |
0 |
if (attachment != null) { |
150 |
0 |
c.add(Restrictions.eq(DOC_ID, attachment.getDocId())); |
151 |
0 |
if (!StringUtils.isBlank(attachment.getFilename())) { |
152 |
0 |
c.add(Restrictions.eq("filename", attachment.getFilename())); |
153 |
|
} |
154 |
|
} |
155 |
0 |
return c.addOrder(Order.desc(DATE)).list(); |
156 |
|
} |
157 |
|
}); |
158 |
|
} |
159 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
0 |
@Override... |
161 |
|
public List<DeletedAttachment> getAllDeletedAttachments(final XWikiDocument doc, XWikiContext context, |
162 |
|
boolean bTransaction) throws XWikiException |
163 |
|
{ |
164 |
0 |
return executeRead(context, bTransaction, new HibernateCallback<List<DeletedAttachment>>() |
165 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
166 |
0 |
@SuppressWarnings(ANOTATE_UNCHECKED)... |
167 |
|
@Override |
168 |
|
public List<DeletedAttachment> doInHibernate(Session session) throws HibernateException, XWikiException |
169 |
|
{ |
170 |
0 |
assert doc != null; |
171 |
0 |
return session.createCriteria(DeletedAttachment.class).add(Restrictions.eq(DOC_ID, doc.getId())) |
172 |
|
.addOrder(Order.desc(DATE)).list(); |
173 |
|
} |
174 |
|
}); |
175 |
|
} |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
0 |
@Override... |
178 |
|
public void deleteFromRecycleBin(final long index, XWikiContext context, boolean bTransaction) |
179 |
|
throws XWikiException |
180 |
|
{ |
181 |
0 |
executeWrite(context, bTransaction, new HibernateCallback<Object>() |
182 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
183 |
0 |
@Override... |
184 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
185 |
|
{ |
186 |
0 |
try { |
187 |
0 |
session.createQuery("delete from " + DeletedAttachment.class.getName() + " where id=?") |
188 |
|
.setLong(0, index).executeUpdate(); |
189 |
|
} catch (Exception ex) { |
190 |
|
|
191 |
|
} |
192 |
0 |
return null; |
193 |
|
} |
194 |
|
}); |
195 |
|
} |
196 |
|
} |