1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.api; |
21 |
|
|
22 |
|
import java.util.Calendar; |
23 |
|
import java.util.Date; |
24 |
|
import java.util.Locale; |
25 |
|
|
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.slf4j.LoggerFactory; |
28 |
|
|
29 |
|
import com.xpn.xwiki.XWikiContext; |
30 |
|
import com.xpn.xwiki.XWikiException; |
31 |
|
import com.xpn.xwiki.doc.XWikiDeletedDocument; |
32 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
33 |
|
import com.xpn.xwiki.util.Programming; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
|
|
|
| 56.4% |
Uncovered Elements: 24 (55) |
Complexity: 19 |
Complexity Density: 0.53 |
|
40 |
|
public class DeletedDocument extends Api |
41 |
|
{ |
42 |
|
|
43 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DeletedDocument.class); |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
private final XWikiDeletedDocument deletedDoc; |
49 |
|
|
50 |
|
|
51 |
|
@link |
52 |
|
@link |
53 |
|
|
54 |
|
@param |
55 |
|
@param |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
57 |
19 |
public DeletedDocument(XWikiDeletedDocument deletedDoc, XWikiContext context)... |
58 |
|
{ |
59 |
19 |
super(context); |
60 |
19 |
this.deletedDoc = deletedDoc; |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
@return |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
52 |
public String getFullName()... |
67 |
|
{ |
68 |
52 |
return this.deletedDoc.getFullName(); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
@return |
73 |
|
@deprecated@link |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
@Deprecated... |
76 |
|
public String getLanguage() |
77 |
|
{ |
78 |
0 |
return this.deletedDoc.getLanguage(); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
@return |
83 |
|
@since |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
public Locale getLocale()... |
86 |
|
{ |
87 |
0 |
return this.deletedDoc.getLocale(); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
@return |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
35 |
public Date getDate()... |
94 |
|
{ |
95 |
35 |
return this.deletedDoc.getDate(); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
@return |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
17 |
public String getDeleter()... |
102 |
|
{ |
103 |
17 |
return this.deletedDoc.getDeleter(); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
@return |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
49 |
public long getId()... |
110 |
|
{ |
111 |
49 |
return this.deletedDoc.getId(); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@return |
118 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
119 |
17 |
public boolean canUndelete()... |
120 |
|
{ |
121 |
17 |
try { |
122 |
17 |
return hasAdminRights() || hasAccessLevel("undelete", getFullName()); |
123 |
|
} catch (XWikiException ex) { |
124 |
|
|
125 |
0 |
LOGGER.warn(String.format("Exception while checking if entry [%s] can be restored from the recycle bin", |
126 |
|
getId()), ex); |
127 |
0 |
return false; |
128 |
|
} |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
@return |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 5 |
Complexity Density: 0.31 |
|
138 |
19 |
public boolean canDelete()... |
139 |
|
{ |
140 |
19 |
try { |
141 |
19 |
XWikiDocument doc = new XWikiDocument(); |
142 |
19 |
doc.setFullName(getFullName(), this.context); |
143 |
19 |
if (!hasAdminRights() |
144 |
|
&& !getXWikiContext().getWiki().getRightService().checkAccess("delete", doc, this.context)) { |
145 |
1 |
return false; |
146 |
|
} |
147 |
18 |
String waitdays; |
148 |
18 |
if (hasAdminRights()) { |
149 |
18 |
waitdays = getXWikiContext().getWiki().Param("xwiki.store.recyclebin.adminWaitDays", "0"); |
150 |
|
} else { |
151 |
0 |
waitdays = getXWikiContext().getWiki().Param("xwiki.store.recyclebin.waitDays", "7"); |
152 |
|
} |
153 |
18 |
int seconds = (int) (Double.parseDouble(waitdays) * 24 * 60 * 60 + 0.5); |
154 |
18 |
Calendar cal = Calendar.getInstance(); |
155 |
18 |
cal.setTime(getDate()); |
156 |
18 |
cal.add(Calendar.SECOND, seconds); |
157 |
18 |
return cal.before(Calendar.getInstance()); |
158 |
|
} catch (Exception ex) { |
159 |
|
|
160 |
0 |
LOGGER.warn(String.format("Exception while checking if entry [%s] can be removed from the recycle bin", |
161 |
|
getId()), ex); |
162 |
0 |
return false; |
163 |
|
} |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
@return |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
169 |
0 |
@Programming... |
170 |
|
public XWikiDeletedDocument getDeletedDocument() |
171 |
|
{ |
172 |
0 |
if (hasProgrammingRights()) { |
173 |
0 |
return this.deletedDoc; |
174 |
|
} else { |
175 |
0 |
return null; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
@return |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
182 |
0 |
public Document getDocument()... |
183 |
|
{ |
184 |
0 |
if (hasAdminRights()) { |
185 |
0 |
try { |
186 |
0 |
return new Document(this.deletedDoc.restoreDocument(null, this.context), this.context); |
187 |
|
} catch (XWikiException e) { |
188 |
0 |
LOGGER.warn("Failed to parse deleted document: " + e.getMessage()); |
189 |
|
} |
190 |
|
} |
191 |
|
|
192 |
0 |
return null; |
193 |
|
} |
194 |
|
} |