001
014
015 package com.liferay.portal.repository.liferayrepository;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.repository.Repository;
019 import com.liferay.portal.kernel.repository.capabilities.ProcessorCapability;
020 import com.liferay.portal.kernel.repository.model.FileEntry;
021 import com.liferay.portal.kernel.repository.model.FileVersion;
022 import com.liferay.portal.repository.util.RepositoryWrapper;
023 import com.liferay.portal.service.ServiceContext;
024
025 import java.io.File;
026 import java.io.InputStream;
027
028
031 public class LiferayProcessorRepositoryWrapper extends RepositoryWrapper {
032
033 public LiferayProcessorRepositoryWrapper(
034 Repository repository, ProcessorCapability processorCapability) {
035
036 super(repository);
037
038 _processorCapability = processorCapability;
039 }
040
041 @Override
042 public FileEntry addFileEntry(
043 long userId, long folderId, String sourceFileName, String mimeType,
044 String title, String description, String changeLog, File file,
045 ServiceContext serviceContext)
046 throws PortalException {
047
048 FileEntry fileEntry = super.addFileEntry(
049 userId, folderId, sourceFileName, mimeType, title, description,
050 changeLog, file, serviceContext);
051
052 _processorCapability.generateNew(fileEntry);
053
054 return fileEntry;
055 }
056
057 @Override
058 public FileEntry addFileEntry(
059 long userId, long folderId, String sourceFileName, String mimeType,
060 String title, String description, String changeLog, InputStream is,
061 long size, ServiceContext serviceContext)
062 throws PortalException {
063
064 FileEntry fileEntry = super.addFileEntry(
065 userId, folderId, sourceFileName, mimeType, title, description,
066 changeLog, is, size, serviceContext);
067
068 _processorCapability.generateNew(fileEntry);
069
070 return fileEntry;
071 }
072
073 @Override
074 public FileVersion cancelCheckOut(long fileEntryId) throws PortalException {
075 FileEntry fileEntry = getFileEntry(fileEntryId);
076
077 _processorCapability.cleanUp(fileEntry.getLatestFileVersion());
078
079 FileVersion fileVersion = super.cancelCheckOut(fileEntryId);
080
081 _processorCapability.generateNew(fileEntry);
082
083 return fileVersion;
084 }
085
086 @Override
087 public void checkInFileEntry(
088 long userId, long fileEntryId, boolean major, String changeLog,
089 ServiceContext serviceContext)
090 throws PortalException {
091
092 FileEntry fileEntry = getFileEntry(fileEntryId);
093
094 _processorCapability.cleanUp(fileEntry.getLatestFileVersion());
095
096 super.checkInFileEntry(
097 userId, fileEntryId, major, changeLog, serviceContext);
098
099 _processorCapability.copy(fileEntry, fileEntry.getFileVersion());
100 }
101
102 @Override
103 public void checkInFileEntry(
104 long userId, long fileEntryId, String lockUuid,
105 ServiceContext serviceContext)
106 throws PortalException {
107
108 FileEntry fileEntry = getFileEntry(fileEntryId);
109
110 _processorCapability.cleanUp(fileEntry.getLatestFileVersion());
111
112 super.checkInFileEntry(userId, fileEntryId, lockUuid, serviceContext);
113
114 _processorCapability.copy(fileEntry, fileEntry.getFileVersion());
115 }
116
117 @Override
118 public FileEntry checkOutFileEntry(
119 long fileEntryId, ServiceContext serviceContext)
120 throws PortalException {
121
122 FileEntry oldFileEntry = getFileEntry(fileEntryId);
123
124 FileVersion oldFileVersion = oldFileEntry.getFileVersion();
125
126 FileEntry fileEntry = super.checkOutFileEntry(
127 fileEntryId, serviceContext);
128
129 _processorCapability.copy(fileEntry, oldFileVersion);
130
131 return fileEntry;
132 }
133
134 @Override
135 public FileEntry checkOutFileEntry(
136 long fileEntryId, String owner, long expirationTime,
137 ServiceContext serviceContext)
138 throws PortalException {
139
140 FileEntry oldFileEntry = getFileEntry(fileEntryId);
141
142 FileVersion oldFileVersion = oldFileEntry.getFileVersion();
143
144 FileEntry fileEntry = super.checkOutFileEntry(
145 fileEntryId, owner, expirationTime, serviceContext);
146
147 _processorCapability.copy(fileEntry, oldFileVersion);
148
149 return fileEntry;
150 }
151
152 @Override
153 public void deleteFileVersion(long fileEntryId, String version)
154 throws PortalException {
155
156 FileEntry fileEntry = getFileEntry(fileEntryId);
157
158 FileVersion fileVersion = fileEntry.getFileVersion(version);
159
160 super.deleteFileVersion(fileEntryId, version);
161
162 _processorCapability.cleanUp(fileVersion);
163 }
164
165 @Override
166 public void revertFileEntry(
167 long userId, long fileEntryId, String version,
168 ServiceContext serviceContext)
169 throws PortalException {
170
171 super.revertFileEntry(userId, fileEntryId, version, serviceContext);
172
173 FileEntry fileEntry = getFileEntry(fileEntryId);
174
175 _processorCapability.copy(fileEntry, fileEntry.getFileVersion(version));
176 }
177
178 @Override
179 public FileEntry updateFileEntry(
180 long userId, long fileEntryId, String sourceFileName,
181 String mimeType, String title, String description, String changeLog,
182 boolean majorVersion, File file, ServiceContext serviceContext)
183 throws PortalException {
184
185 FileEntry fileEntry = super.updateFileEntry(
186 userId, fileEntryId, sourceFileName, mimeType, title, description,
187 changeLog, majorVersion, file, serviceContext);
188
189 _processorCapability.cleanUp(fileEntry.getLatestFileVersion());
190 _processorCapability.generateNew(fileEntry);
191
192 return fileEntry;
193 }
194
195 @Override
196 public FileEntry updateFileEntry(
197 long userId, long fileEntryId, String sourceFileName,
198 String mimeType, String title, String description, String changeLog,
199 boolean majorVersion, InputStream is, long size,
200 ServiceContext serviceContext)
201 throws PortalException {
202
203 FileEntry oldFileEntry = null;
204 FileVersion oldFileVersion = null;
205
206 if (is == null) {
207 oldFileEntry = getFileEntry(fileEntryId);
208 oldFileVersion = oldFileEntry.getLatestFileVersion(true);
209 }
210
211 FileEntry fileEntry = super.updateFileEntry(
212 userId, fileEntryId, sourceFileName, mimeType, title, description,
213 changeLog, majorVersion, is, size, serviceContext);
214
215 if (is == null) {
216 _processorCapability.copy(fileEntry, oldFileVersion);
217 }
218 else {
219 _processorCapability.cleanUp(fileEntry.getLatestFileVersion());
220 _processorCapability.generateNew(fileEntry);
221 }
222
223 return fileEntry;
224 }
225
226 private final ProcessorCapability _processorCapability;
227
228 }