1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.store.legacy.store.internal

File SaveTrashAttachmentRunnable.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
10
2
1
111
56
3
0.3
5
2
1.5

Classes

Class Line # Actions
SaveTrashAttachmentRunnable 46 10 0% 3 14
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * A TransactionRunnable for saving deleted attachments.
42    *
43    * @version $Id: 7b6009bb8ae9ec382d83c62315581589876b331c $
44    * @since 3.0M3
45    */
 
46    class SaveTrashAttachmentRunnable extends StartableTransactionRunnable
47    {
48    /**
49    * The Constructor.
50    *
51    * @param deleted the deleted attachment.
52    * @param provider a means of gettign the files used for storing the attachment.
53    * @param fileTools tools for getting file locks and backup/temporary files.
54    * @param deletedAttachmentSerializer a Serializer to serialize a DeletedAttachment.
55    * @param versionSerializer a Serializer which will serialize a list of XWikiAttachment objects.
56    * @param context the legacy XWikiContext which might be needed to get the attachment archive.
57    * @throws XWikiException if loading the attachment content or archive fails.
58    */
 
59  0 toggle 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    // Save metadata about the deleted attachment.
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    // Save the archive for the deleted attachment.
80  0 new AttachmentArchiveSaveRunnable(archive,
81    fileTools,
82    provider,
83    versionSerializer,
84    context).runIn(this);
85   
86    // Save the attachment's content.
87  0 final StreamProvider contentProvider = new AttachmentContentStreamProvider(attachment, context);
88  0 this.addSaver(contentProvider,
89    fileTools,
90    provider.getAttachmentContentFile());
91    }
92   
93    /**
94    * Save some content safely in this runnable.
95    * TODO This duplicates AttachmentArchiveSaveRunnable, fix.
96    *
97    * @param provider the means to get the content to save.
98    * @param fileTools the means to get the backup file, temporary file, and lock.
99    * @param saveHere the location to save the data.
100    */
 
101  0 toggle 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    }