1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.store.legacy.store.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.xwiki.store.FileSaveTransactionRunnable; |
26 |
|
import org.xwiki.store.StartableTransactionRunnable; |
27 |
|
import org.xwiki.store.StreamProvider; |
28 |
|
import org.xwiki.store.filesystem.internal.DeletedAttachmentFileProvider; |
29 |
|
import org.xwiki.store.filesystem.internal.FilesystemStoreTools; |
30 |
|
import org.xwiki.store.serialization.SerializationStreamProvider; |
31 |
|
import org.xwiki.store.serialization.Serializer; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.XWikiException; |
35 |
|
import com.xpn.xwiki.doc.DeletedAttachment; |
36 |
|
import org.xwiki.store.legacy.doc.internal.DeletedFilesystemAttachment; |
37 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
38 |
|
import com.xpn.xwiki.doc.XWikiAttachmentArchive; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
46 |
|
class SaveTrashAttachmentRunnable extends StartableTransactionRunnable |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
@param |
53 |
|
@param |
54 |
|
@param |
55 |
|
@param |
56 |
|
@param |
57 |
|
@throws |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
59 |
0 |
SaveTrashAttachmentRunnable(final DeletedFilesystemAttachment deleted,... |
60 |
|
final DeletedAttachmentFileProvider provider, |
61 |
|
final FilesystemStoreTools fileTools, |
62 |
|
final Serializer<DeletedAttachment, ? extends DeletedAttachment> deletedAttachmentSerializer, |
63 |
|
final Serializer<List<XWikiAttachment>, List<XWikiAttachment>> versionSerializer, |
64 |
|
final XWikiContext context) |
65 |
|
throws XWikiException |
66 |
|
{ |
67 |
|
|
68 |
0 |
final StreamProvider metaProvider = |
69 |
|
new SerializationStreamProvider<DeletedAttachment>(deletedAttachmentSerializer, deleted); |
70 |
0 |
this.addSaver(metaProvider, fileTools, provider.getDeletedAttachmentMetaFile()); |
71 |
|
|
72 |
0 |
final XWikiAttachment attachment = deleted.getAttachment(); |
73 |
0 |
final XWikiAttachmentArchive archive = attachment.loadArchive(context); |
74 |
0 |
if (archive == null) { |
75 |
0 |
throw new NullPointerException("Failed to load attachment archive, " |
76 |
|
+ "loadArchive() returned null"); |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
0 |
new AttachmentArchiveSaveRunnable(archive, |
81 |
|
fileTools, |
82 |
|
provider, |
83 |
|
versionSerializer, |
84 |
|
context).runIn(this); |
85 |
|
|
86 |
|
|
87 |
0 |
final StreamProvider contentProvider = new AttachmentContentStreamProvider(attachment, context); |
88 |
0 |
this.addSaver(contentProvider, |
89 |
|
fileTools, |
90 |
|
provider.getAttachmentContentFile()); |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
@param |
98 |
|
@param |
99 |
|
@param |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
private void addSaver(final StreamProvider provider,... |
102 |
|
final FilesystemStoreTools fileTools, |
103 |
|
final File saveHere) |
104 |
|
{ |
105 |
0 |
new FileSaveTransactionRunnable(saveHere, |
106 |
|
fileTools.getTempFile(saveHere), |
107 |
|
fileTools.getBackupFile(saveHere), |
108 |
|
fileTools.getLockForFile(saveHere), |
109 |
|
provider).runIn(this); |
110 |
|
} |
111 |
|
} |