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.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
27 |
|
import com.xpn.xwiki.doc.XWikiAttachmentArchive; |
28 |
|
import com.xpn.xwiki.XWikiContext; |
29 |
|
import com.xpn.xwiki.XWikiException; |
30 |
|
import com.xpn.xwiki.store.VoidAttachmentVersioningStore; |
31 |
|
|
32 |
|
import org.suigeneris.jrcs.rcs.Version; |
33 |
|
import org.xwiki.store.FileSaveTransactionRunnable; |
34 |
|
import org.xwiki.store.StartableTransactionRunnable; |
35 |
|
import org.xwiki.store.StreamProvider; |
36 |
|
import org.xwiki.store.filesystem.internal.AttachmentFileProvider; |
37 |
|
import org.xwiki.store.filesystem.internal.FilesystemStoreTools; |
38 |
|
import org.xwiki.store.serialization.SerializationStreamProvider; |
39 |
|
import org.xwiki.store.serialization.Serializer; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
|
|
| 80.8% |
Uncovered Elements: 5 (26) |
Complexity: 8 |
Complexity Density: 0.5 |
|
49 |
|
public class AttachmentArchiveSaveRunnable extends StartableTransactionRunnable |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@param |
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
@param |
60 |
|
|
61 |
|
@param |
62 |
|
@throws |
63 |
|
|
|
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 7 |
Complexity Density: 0.47 |
|
64 |
3 |
public AttachmentArchiveSaveRunnable(final XWikiAttachmentArchive archive,... |
65 |
|
final FilesystemStoreTools fileTools, |
66 |
|
final AttachmentFileProvider provider, |
67 |
|
final Serializer<List<XWikiAttachment>, |
68 |
|
List<XWikiAttachment>> serializer, |
69 |
|
final XWikiContext context) |
70 |
|
throws XWikiException |
71 |
|
{ |
72 |
3 |
if (archive instanceof VoidAttachmentVersioningStore.VoidAttachmentArchive) { |
73 |
0 |
return; |
74 |
|
} |
75 |
3 |
if (archive.getVersions().length == 0 && archive.getAttachment() != null) { |
76 |
0 |
archive.updateArchive(context); |
77 |
|
} |
78 |
|
|
79 |
3 |
final Version[] versions = archive.getVersions(); |
80 |
3 |
final List<XWikiAttachment> attachmentVersions = new ArrayList<XWikiAttachment>(versions.length); |
81 |
|
|
82 |
|
|
83 |
12 |
for (int i = 0; i < versions.length; i++) { |
84 |
9 |
final String versionName = versions[i].toString(); |
85 |
9 |
final XWikiAttachment attachVer = |
86 |
|
archive.getRevision(archive.getAttachment(), versionName, context); |
87 |
9 |
attachmentVersions.add(attachVer); |
88 |
|
|
89 |
|
|
90 |
9 |
if (attachVer.isContentDirty() |
91 |
|
|| !provider.getAttachmentVersionContentFile(versionName).exists()) |
92 |
|
{ |
93 |
9 |
final StreamProvider contentProvider = |
94 |
|
new AttachmentContentStreamProvider(attachVer, context); |
95 |
9 |
addSaver(contentProvider, fileTools, provider.getAttachmentVersionContentFile(versionName)); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
3 |
final StreamProvider metaProvider = |
101 |
|
new SerializationStreamProvider<List<XWikiAttachment>>(serializer, attachmentVersions); |
102 |
3 |
addSaver(metaProvider, fileTools, provider.getAttachmentVersioningMetaFile()); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
@param |
110 |
|
@param |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
12 |
private void addSaver(final StreamProvider provider,... |
113 |
|
final FilesystemStoreTools fileTools, |
114 |
|
final File saveHere) |
115 |
|
{ |
116 |
12 |
new FileSaveTransactionRunnable(saveHere, |
117 |
|
fileTools.getTempFile(saveHere), |
118 |
|
fileTools.getBackupFile(saveHere), |
119 |
|
fileTools.getLockForFile(saveHere), |
120 |
|
provider).runIn(this); |
121 |
|
} |
122 |
|
} |