001 /** 002 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 013 */ 014 015 package com.liferay.portlet.documentlibrary.service.impl; 016 017 import com.liferay.portal.kernel.dao.orm.QueryUtil; 018 import com.liferay.portal.kernel.exception.PortalException; 019 import com.liferay.portal.kernel.exception.SystemException; 020 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream; 021 import com.liferay.portal.kernel.log.Log; 022 import com.liferay.portal.kernel.log.LogFactoryUtil; 023 import com.liferay.portal.kernel.repository.Repository; 024 import com.liferay.portal.kernel.repository.model.FileEntry; 025 import com.liferay.portal.kernel.repository.model.FileVersion; 026 import com.liferay.portal.kernel.repository.model.Folder; 027 import com.liferay.portal.kernel.search.Hits; 028 import com.liferay.portal.kernel.search.Query; 029 import com.liferay.portal.kernel.search.SearchContext; 030 import com.liferay.portal.kernel.search.SearchException; 031 import com.liferay.portal.kernel.util.FileUtil; 032 import com.liferay.portal.kernel.util.GetterUtil; 033 import com.liferay.portal.kernel.util.OrderByComparator; 034 import com.liferay.portal.kernel.util.StringBundler; 035 import com.liferay.portal.kernel.util.StringPool; 036 import com.liferay.portal.kernel.util.TempFileUtil; 037 import com.liferay.portal.kernel.workflow.WorkflowConstants; 038 import com.liferay.portal.model.Lock; 039 import com.liferay.portal.security.permission.ActionKeys; 040 import com.liferay.portal.service.ServiceContext; 041 import com.liferay.portal.spring.transaction.TransactionCommitCallbackUtil; 042 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException; 043 import com.liferay.portlet.documentlibrary.model.DLFileShortcut; 044 import com.liferay.portlet.documentlibrary.model.DLFolderConstants; 045 import com.liferay.portlet.documentlibrary.service.base.DLAppServiceBaseImpl; 046 import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission; 047 import com.liferay.portlet.documentlibrary.util.DLAppUtil; 048 import com.liferay.portlet.documentlibrary.util.DLProcessorRegistryUtil; 049 import com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelModifiedDateComparator; 050 051 import java.io.File; 052 import java.io.IOException; 053 import java.io.InputStream; 054 055 import java.util.ArrayList; 056 import java.util.LinkedList; 057 import java.util.List; 058 import java.util.Queue; 059 import java.util.concurrent.Callable; 060 061 /** 062 * The document library remote service. All portlets should interact with the 063 * document library through this class or through {@link DLAppLocalServiceImpl}, 064 * rather than through the individual document library service classes. 065 * 066 * <p> 067 * This class provides a unified interface to all Liferay and third party 068 * repositories. While the method signatures are universal for all repositories. 069 * Additional implementation-specific parameters may be specified in the 070 * serviceContext. 071 * </p> 072 * 073 * <p> 074 * The <code>repositoryId</code> parameter used by most of the methods is the 075 * primary key of the specific repository. If the repository is a default 076 * Liferay repository, the <code>repositoryId</code> is the <code>groupId</code> 077 * or <code>scopeGroupId</code>. Otherwise, the <code>repositoryId</code> will 078 * correspond to values obtained from {@link RepositoryServiceUtil}. 079 * </p> 080 * 081 * @author Alexander Chow 082 * @author Mika Koivisto 083 * @author Shuyang Zhou 084 * @see DLAppLocalServiceImpl 085 */ 086 public class DLAppServiceImpl extends DLAppServiceBaseImpl { 087 088 /** 089 * Adds a file entry and associated metadata. It is created based on a byte 090 * array. 091 * 092 * <p> 093 * This method takes two file names, the <code>sourceFileName</code> and the 094 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 095 * name of the actual file being uploaded. The <code>title</code> 096 * corresponds to a name the client wishes to assign this file after it has 097 * been uploaded to the portal. If it is <code>null</code>, the <code> 098 * sourceFileName</code> will be used. 099 * </p> 100 * 101 * @param repositoryId the primary key of the repository 102 * @param folderId the primary key of the file entry's parent folder 103 * @param sourceFileName the original file's name 104 * @param mimeType the file's MIME type 105 * @param title the name to be assigned to the file (optionally <code>null 106 * </code>) 107 * @param description the file's description 108 * @param changeLog the file's version change log 109 * @param bytes the file's data (optionally <code>null</code>) 110 * @param serviceContext the service context to be applied. Can set the 111 * asset category IDs, asset tag names, and expando bridge 112 * attributes for the file entry. In a Liferay repository, it may 113 * include: <ul> <li> fileEntryTypeId - ID for a custom file entry 114 * type </li> <li> fieldsMap - mapping for fields associated with a 115 * custom file entry type </li> </ul> 116 * @return the file entry 117 * @throws PortalException if the parent folder could not be found or if the 118 * file entry's information was invalid 119 * @throws SystemException if a system exception occurred 120 */ 121 public FileEntry addFileEntry( 122 long repositoryId, long folderId, String sourceFileName, 123 String mimeType, String title, String description, String changeLog, 124 byte[] bytes, ServiceContext serviceContext) 125 throws PortalException, SystemException { 126 127 File file = null; 128 129 try { 130 if ((bytes != null) && (bytes.length > 0)) { 131 file = FileUtil.createTempFile(bytes); 132 } 133 134 return addFileEntry( 135 repositoryId, folderId, sourceFileName, mimeType, title, 136 description, changeLog, file, serviceContext); 137 } 138 catch (IOException ioe) { 139 throw new SystemException("Unable to write temporary file", ioe); 140 } 141 finally { 142 FileUtil.delete(file); 143 } 144 } 145 146 /** 147 * Adds a file entry and associated metadata. It is created based on a 148 * {@link File} object. 149 * 150 * <p> 151 * This method takes two file names, the <code>sourceFileName</code> and the 152 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 153 * name of the actual file being uploaded. The <code>title</code> 154 * corresponds to a name the client wishes to assign this file after it has 155 * been uploaded to the portal. If it is <code>null</code>, the <code> 156 * sourceFileName</code> will be used. 157 * </p> 158 * 159 * @param repositoryId the primary key of the repository 160 * @param folderId the primary key of the file entry's parent folder 161 * @param sourceFileName the original file's name 162 * @param mimeType the file's MIME type 163 * @param title the name to be assigned to the file (optionally <code>null 164 * </code>) 165 * @param description the file's description 166 * @param changeLog the file's version change log 167 * @param file the file's data (optionally <code>null</code>) 168 * @param serviceContext the service context to be applied. Can set the 169 * asset category IDs, asset tag names, and expando bridge 170 * attributes for the file entry. In a Liferay repository, it may 171 * include: <ul> <li> fileEntryTypeId - ID for a custom file entry 172 * type </li> <li> fieldsMap - mapping for fields associated with a 173 * custom file entry type </li> </ul> 174 * @return the file entry 175 * @throws PortalException if the parent folder could not be found or if the 176 * file entry's information was invalid 177 * @throws SystemException if a system exception occurred 178 */ 179 public FileEntry addFileEntry( 180 long repositoryId, long folderId, String sourceFileName, 181 String mimeType, String title, String description, String changeLog, 182 File file, ServiceContext serviceContext) 183 throws PortalException, SystemException { 184 185 if ((file == null) || !file.exists() || (file.length() == 0)) { 186 return addFileEntry( 187 repositoryId, folderId, sourceFileName, mimeType, title, 188 description, changeLog, null, 0, serviceContext); 189 } 190 191 mimeType = DLAppUtil.getMimeType( 192 sourceFileName, mimeType, title, file, null); 193 194 Repository repository = getRepository(repositoryId); 195 196 FileEntry fileEntry = repository.addFileEntry( 197 folderId, sourceFileName, mimeType, title, description, changeLog, 198 file, serviceContext); 199 200 dlAppHelperLocalService.addFileEntry( 201 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 202 203 return fileEntry; 204 } 205 206 /** 207 * Adds a file entry and associated metadata. It is created based on a 208 * {@link InputStream} object. 209 * 210 * <p> 211 * This method takes two file names, the <code>sourceFileName</code> and the 212 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 213 * name of the actual file being uploaded. The <code>title</code> 214 * corresponds to a name the client wishes to assign this file after it has 215 * been uploaded to the portal. If it is <code>null</code>, the <code> 216 * sourceFileName</code> will be used. 217 * </p> 218 * 219 * @param repositoryId the primary key of the repository 220 * @param folderId the primary key of the file entry's parent folder 221 * @param sourceFileName the original file's name 222 * @param mimeType the file's MIME type 223 * @param title the name to be assigned to the file (optionally <code>null 224 * </code>) 225 * @param description the file's description 226 * @param changeLog the file's version change log 227 * @param is the file's data (optionally <code>null</code>) 228 * @param size the file's size (optionally <code>0</code>) 229 * @param serviceContext the service context to be applied. Can set the 230 * asset category IDs, asset tag names, and expando bridge 231 * attributes for the file entry. In a Liferay repository, it may 232 * include: <ul> <li> fileEntryTypeId - ID for a custom file entry 233 * type </li> <li> fieldsMap - mapping for fields associated with a 234 * custom file entry type </li> </ul> 235 * @return the file entry 236 * @throws PortalException if the parent folder could not be found or if the 237 * file entry's information was invalid 238 * @throws SystemException if a system exception occurred 239 */ 240 public FileEntry addFileEntry( 241 long repositoryId, long folderId, String sourceFileName, 242 String mimeType, String title, String description, String changeLog, 243 InputStream is, long size, ServiceContext serviceContext) 244 throws PortalException, SystemException { 245 246 if (is == null) { 247 is = new UnsyncByteArrayInputStream(new byte[0]); 248 size = 0; 249 } 250 251 mimeType = DLAppUtil.getMimeType( 252 sourceFileName, mimeType, title, null, is); 253 254 Repository repository = getRepository(repositoryId); 255 256 FileEntry fileEntry = repository.addFileEntry( 257 folderId, sourceFileName, mimeType, title, description, changeLog, 258 is, size, serviceContext); 259 260 dlAppHelperLocalService.addFileEntry( 261 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 262 263 return fileEntry; 264 } 265 266 /** 267 * Adds a file shortcut to the existing file entry. This method is only 268 * supported by the Liferay repository. 269 * 270 * @param repositoryId the primary key of the repository 271 * @param folderId the primary key of the file shortcut's parent folder 272 * @param toFileEntryId the primary key of the file shortcut's file entry 273 * @param serviceContext the service context to be applied. Can set the 274 * asset category IDs, asset tag names, and expando bridge 275 * attributes for the file entry. 276 * @return the file shortcut 277 * @throws PortalException if the parent folder or file entry could not be 278 * found, or if the file shortcut's information was invalid 279 * @throws SystemException if a system exception occurred 280 */ 281 public DLFileShortcut addFileShortcut( 282 long repositoryId, long folderId, long toFileEntryId, 283 ServiceContext serviceContext) 284 throws PortalException, SystemException { 285 286 return dlFileShortcutService.addFileShortcut( 287 repositoryId, folderId, toFileEntryId, serviceContext); 288 } 289 290 /** 291 * Adds a folder. 292 * 293 * @param repositoryId the primary key of the repository 294 * @param parentFolderId the primary key of the folder's parent folder 295 * @param name the folder's name 296 * @param description the folder's description 297 * @param serviceContext the service context to be applied. In a Liferay 298 * repository, it may include boolean mountPoint specifying whether 299 * folder is a facade for mounting a third-party repository 300 * @return the folder 301 * @throws PortalException if the parent folder could not be found or if the 302 * new folder's information was invalid 303 * @throws SystemException if a system exception occurred 304 */ 305 public Folder addFolder( 306 long repositoryId, long parentFolderId, String name, 307 String description, ServiceContext serviceContext) 308 throws PortalException, SystemException { 309 310 Repository repository = getRepository(repositoryId); 311 312 return repository.addFolder( 313 parentFolderId, name, description, serviceContext); 314 } 315 316 /** 317 * Adds a temporary file entry. 318 * 319 * <p> 320 * This allows a client to upload a file into a temporary location and 321 * manipulate its metadata prior to making it available for public usage. 322 * This is different from checking in and checking out a file entry. 323 * </p> 324 * 325 * @param groupId the primary key of the group 326 * @param folderId the primary key of the folder where the file entry will 327 * eventually reside 328 * @param fileName the file's original name 329 * @param tempFolderName the temporary folder's name 330 * @param file Name the file's original name 331 * @return the file's name 332 * @throws IOException if a problem occurred in the access or storage of the 333 * file 334 * @throws PortalException if the file name was invalid 335 * @throws SystemException if a system exception occurred 336 * @see com.liferay.portal.kernel.util.TempFileUtil 337 */ 338 public String addTempFileEntry( 339 long groupId, long folderId, String fileName, String tempFolderName, 340 File file) 341 throws IOException, PortalException, SystemException { 342 343 DLFolderPermission.check( 344 getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT); 345 346 return TempFileUtil.addTempFile( 347 getUserId(), fileName, tempFolderName, file); 348 } 349 350 public String addTempFileEntry( 351 long groupId, long folderId, String fileName, String tempFolderName, 352 InputStream inputStream) 353 throws PortalException, SystemException { 354 355 DLFolderPermission.check( 356 getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT); 357 358 return TempFileUtil.addTempFile( 359 getUserId(), fileName, tempFolderName, inputStream); 360 } 361 362 /** 363 * Cancels the check out of the file entry. If a user has not checked out 364 * the specified file entry, invoking this method will result in no changes. 365 * 366 * <p> 367 * When a file entry is checked out, a PWC (private working copy) is created 368 * and the original file entry is locked. A client can make as many changes 369 * to the PWC as he desires without those changes being visible to other 370 * users. If the user is satisfied with the changes, he may elect to check 371 * in his changes, resulting in a new file version based on the PWC; the PWC 372 * will be removed and the file entry will be unlocked. If the user is not 373 * satisfied with the changes, he may elect to cancel his check out; this 374 * results in the deletion of the PWC and unlocking of the file entry. 375 * </p> 376 * 377 * @param fileEntryId the primary key of the file entry to cancel the 378 * checkout 379 * @throws PortalException if the file entry could not be found 380 * @throws SystemException if a system exception occurred 381 * @see #checkInFileEntry(long, boolean, String, ServiceContext) 382 * @see #checkOutFileEntry(long) 383 */ 384 public void cancelCheckOut(long fileEntryId) 385 throws PortalException, SystemException { 386 387 Repository repository = getRepository(0, fileEntryId, 0); 388 389 FileEntry fileEntry = repository.getFileEntry(fileEntryId); 390 391 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 392 393 FileVersion draftFileVersion = repository.cancelCheckOut(fileEntryId); 394 395 ServiceContext serviceContext = new ServiceContext(); 396 397 serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); 398 399 dlAppHelperLocalService.cancelCheckOut( 400 getUserId(), fileEntry, fileEntry.getFileVersion(), 401 draftFileVersion, serviceContext); 402 } 403 404 /** 405 * Checks in the file entry. If a user has not checked out the specified 406 * file entry, invoking this method will result in no changes. 407 * 408 * <p> 409 * When a file entry is checked out, a PWC (private working copy) is created 410 * and the original file entry is locked. A client can make as many changes 411 * to the PWC as he desires without those changes being visible to other 412 * users. If the user is satisfied with the changes, he may elect to check 413 * in his changes, resulting in a new file version based on the PWC; the PWC 414 * will be removed and the file entry will be unlocked. If the user is not 415 * satisfied with the changes, he may elect to cancel his check out; this 416 * results in the deletion of the PWC and unlocking of the file entry. 417 * </p> 418 * 419 * @param fileEntryId the primary key of the file entry to check in 420 * @param majorVersion whether the new file version is a major version 421 * @param changeLog the file's version change log 422 * @param serviceContext the service context to be applied 423 * @throws PortalException if the file entry could not be found 424 * @throws SystemException if a system exception occurred 425 * @see #cancelCheckOut(long) 426 * @see #checkOutFileEntry(long) 427 */ 428 public void checkInFileEntry( 429 long fileEntryId, boolean majorVersion, String changeLog, 430 ServiceContext serviceContext) 431 throws PortalException, SystemException { 432 433 Repository repository = getRepository(0, fileEntryId, 0); 434 435 repository.checkInFileEntry( 436 fileEntryId, majorVersion, changeLog, serviceContext); 437 438 FileEntry fileEntry = getFileEntry(fileEntryId); 439 440 FileVersion fileVersion = fileEntry.getLatestFileVersion(); 441 442 dlAppHelperLocalService.updateFileEntry( 443 getUserId(), fileEntry, fileVersion, 444 fileVersion.getFileVersionId()); 445 } 446 447 /** 448 * Checks in the file entry using the lock's UUID. If a user has not checked 449 * out the specified file entry, invoking this method will result in no 450 * changes. This method is primarily used by WebDAV. 451 * 452 * <p> 453 * When a file entry is checked out, a PWC (private working copy) is created 454 * and the original file entry is locked. A client can make as many changes 455 * to the PWC as he desires without those changes being visible to other 456 * users. If the user is satisfied with the changes, he may elect to check 457 * in his changes, resulting in a new file version based on the PWC; the PWC 458 * will be removed and the file entry will be unlocked. If the user is not 459 * satisfied with the changes, he may elect to cancel his check out; this 460 * results in the deletion of the PWC and unlocking of the file entry. 461 * </p> 462 * 463 * @param fileEntryId the primary key of the file entry to check in 464 * @param lockUuid the lock's universally unique identifier 465 * @throws PortalException if the file entry could not be found 466 * @throws SystemException if a system exception occurred 467 * @see #cancelCheckOut(long) 468 * @see #checkOutFileEntry(long, String, long) 469 */ 470 public void checkInFileEntry(long fileEntryId, String lockUuid) 471 throws PortalException, SystemException { 472 473 Repository repository = getRepository(0, fileEntryId, 0); 474 475 repository.checkInFileEntry(fileEntryId, lockUuid); 476 477 FileEntry fileEntry = getFileEntry(fileEntryId); 478 479 FileVersion fileVersion = fileEntry.getLatestFileVersion(); 480 481 dlAppHelperLocalService.updateFileEntry( 482 getUserId(), fileEntry, fileVersion, 483 fileVersion.getFileVersionId()); 484 } 485 486 /** 487 * Check out a file entry. 488 * 489 * <p> 490 * When a file entry is checked out, a PWC (private working copy) is created 491 * and the original file entry is locked. A client can make as many changes 492 * to the PWC as he desires without those changes being visible to other 493 * users. If the user is satisfied with the changes, he may elect to check 494 * in his changes, resulting in a new file version based on the PWC; the PWC 495 * will be removed and the file entry will be unlocked. If the user is not 496 * satisfied with the changes, he may elect to cancel his check out; this 497 * results in the deletion of the PWC and unlocking of the file entry. 498 * </p> 499 * 500 * @param fileEntryId the file entry to check out 501 * @param serviceContext the service context to be applied 502 * @throws PortalException if the file entry could not be found 503 * @throws SystemException if a system exception occurred 504 * @see #cancelCheckOut(long) 505 * @see #checkInFileEntry(long, boolean, String, ServiceContext) 506 */ 507 public void checkOutFileEntry( 508 long fileEntryId, ServiceContext serviceContext) 509 throws PortalException, SystemException { 510 511 Repository repository = getRepository(0, fileEntryId, 0); 512 513 FileEntry fileEntry = repository.checkOutFileEntry( 514 fileEntryId, serviceContext); 515 516 FileVersion fileVersion = fileEntry.getLatestFileVersion(); 517 518 dlAppHelperLocalService.updateFileEntry( 519 getUserId(), fileEntry, fileVersion, fileEntryId); 520 } 521 522 /** 523 * Checks out the file entry. This method is primarily used by WebDAV. 524 * 525 * <p> 526 * When a file entry is checked out, a PWC (private working copy) is created 527 * and the original file entry is locked. A client can make as many changes 528 * to the PWC as he desires without those changes being visible to other 529 * users. If the user is satisfied with the changes, he may elect to check 530 * in his changes, resulting in a new file version based on the PWC; the PWC 531 * will be removed and the file entry will be unlocked. If the user is not 532 * satisfied with the changes, he may elect to cancel his check out; this 533 * results in the deletion of the PWC and unlocking of the file entry. 534 * </p> 535 * 536 * @param fileEntryId the file entry to check out 537 * @param owner the owner string for the checkout (optionally 538 * <code>null</code>) 539 * @param expirationTime the time in milliseconds before the lock expires. 540 * If the value is <code>0</code>, the default expiration time will 541 * be used from <code>portal.properties>. 542 * @param serviceContext the service context to be applied 543 * @return the file entry 544 * @throws PortalException if the file entry could not be found 545 * @throws SystemException if a system exception occurred 546 * @see #cancelCheckOut(long) 547 * @see #checkInFileEntry(long, String) 548 */ 549 public FileEntry checkOutFileEntry( 550 long fileEntryId, String owner, long expirationTime, 551 ServiceContext serviceContext) 552 throws PortalException, SystemException { 553 554 Repository repository = getRepository(0, fileEntryId, 0); 555 556 FileEntry fileEntry = repository.checkOutFileEntry( 557 fileEntryId, owner, expirationTime, serviceContext); 558 559 FileVersion fileVersion = fileEntry.getLatestFileVersion(); 560 561 dlAppHelperLocalService.updateFileEntry( 562 getUserId(), fileEntry, fileVersion, fileEntryId); 563 564 return fileEntry; 565 } 566 567 /** 568 * Performs a deep copy of the folder. 569 * 570 * @param repositoryId the primary key of the repository 571 * @param sourceFolderId the primary key of the folder to copy 572 * @param parentFolderId the primary key of the new folder's parent folder 573 * @param name the new folder's name 574 * @param description the new folder's description 575 * @param serviceContext the service context to be applied 576 * @return the folder 577 * @throws PortalException if the source folder or the new parent folder 578 * could not be found or if the new folder's information was invalid 579 * @throws SystemException if a system exception occurred 580 */ 581 public Folder copyFolder( 582 long repositoryId, long sourceFolderId, long parentFolderId, 583 String name, String description, ServiceContext serviceContext) 584 throws PortalException, SystemException { 585 586 Repository repository = getRepository(repositoryId); 587 588 Folder srcFolder = repository.getFolder(sourceFolderId); 589 590 Folder destFolder = repository.addFolder( 591 parentFolderId, name, description, serviceContext); 592 593 copyFolder(repository, srcFolder, destFolder, serviceContext); 594 595 return destFolder; 596 } 597 598 /** 599 * Deletes the file entry with the primary key. 600 * 601 * @param fileEntryId the primary key of the file entry 602 * @throws PortalException if the file entry could not be found 603 * @throws SystemException if a system exception occurred 604 */ 605 public void deleteFileEntry(long fileEntryId) 606 throws PortalException, SystemException { 607 608 Repository repository = getRepository(0, fileEntryId, 0); 609 610 FileEntry fileEntry = repository.getFileEntry(fileEntryId); 611 612 dlAppHelperLocalService.deleteFileEntry(fileEntry); 613 614 repository.deleteFileEntry(fileEntryId); 615 } 616 617 /** 618 * Deletes the file entry with the title in the folder. 619 * 620 * @param repositoryId the primary key of the repository 621 * @param folderId the primary key of the file entry's parent folder 622 * @param title the file entry's title 623 * @throws PortalException if the file entry could not be found 624 * @throws SystemException if a system exception occurred 625 */ 626 public void deleteFileEntryByTitle( 627 long repositoryId, long folderId, String title) 628 throws PortalException, SystemException { 629 630 Repository repository = getRepository(repositoryId); 631 632 FileEntry fileEntry = repository.getFileEntry(folderId, title); 633 634 dlAppHelperLocalService.deleteFileEntry(fileEntry); 635 636 repository.deleteFileEntry(folderId, title); 637 } 638 639 /** 640 * Deletes the file shortcut with the primary key. This method is only 641 * supported by the Liferay repository. 642 * 643 * @param fileShortcutId the primary key of the file shortcut 644 * @throws PortalException if the file shortcut could not be found 645 * @throws SystemException if a system exception occurred 646 */ 647 public void deleteFileShortcut(long fileShortcutId) 648 throws PortalException, SystemException { 649 650 dlFileShortcutService.deleteFileShortcut(fileShortcutId); 651 } 652 653 /** 654 * Deletes the file version. File versions can only be deleted if it is 655 * approved and there are other approved file versions available. This 656 * method is only supported by the Liferay repository. 657 * 658 * @param fileEntryId the primary key of the file entry 659 * @param version the version label of the file version 660 * @throws PortalException if the file version could not be found or invalid 661 * @throws SystemException if a system exception occurred 662 */ 663 public void deleteFileVersion(long fileEntryId, String version) 664 throws PortalException, SystemException { 665 666 Repository repository = getRepository(0, fileEntryId, 0); 667 668 repository.deleteFileVersion(fileEntryId, version); 669 } 670 671 /** 672 * Deletes the folder with the primary key and all of its subfolders and 673 * file entries. 674 * 675 * @param folderId the primary key of the folder 676 * @throws PortalException if the folder could not be found 677 * @throws SystemException if a system exception occurred 678 */ 679 public void deleteFolder(long folderId) 680 throws PortalException, SystemException { 681 682 Repository repository = getRepository(folderId, 0, 0); 683 684 repository.deleteFolder(folderId); 685 } 686 687 /** 688 * Deletes the folder with the name in the parent folder and all of its 689 * subfolders and file entries. 690 * 691 * @param repositoryId the primary key of the repository 692 * @param parentFolderId the primary key of the folder's parent folder 693 * @param name the folder's name 694 * @throws PortalException if the folder could not be found 695 * @throws SystemException if a system exception occurred 696 */ 697 public void deleteFolder( 698 long repositoryId, long parentFolderId, String name) 699 throws PortalException, SystemException { 700 701 Repository repository = getRepository(repositoryId); 702 703 repository.deleteFolder(parentFolderId, name); 704 } 705 706 /** 707 * Deletes the temporary file entry. 708 * 709 * @param groupId the primary key of the group 710 * @param folderId the primary key of the folder where the file entry was 711 * eventually to reside 712 * @param fileName the file's original name 713 * @param tempFolderName the temporary folder's name 714 * @throws PortalException if the file name was invalid 715 * @throws SystemException if a system exception occurred 716 * @see com.liferay.portal.kernel.util.TempFileUtil 717 */ 718 public void deleteTempFileEntry( 719 long groupId, long folderId, String fileName, String tempFolderName) 720 throws PortalException, SystemException { 721 722 DLFolderPermission.check( 723 getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT); 724 725 TempFileUtil.deleteTempFile(getUserId(), fileName, tempFolderName); 726 } 727 728 /** 729 * Returns all the file entries in the folder. 730 * 731 * @param repositoryId the primary key of the file entry's repository 732 * @param folderId the primary key of the file entry's folder 733 * @return the file entries in the folder 734 * @throws PortalException if the folder could not be found 735 * @throws SystemException if a system exception occurred 736 */ 737 public List<FileEntry> getFileEntries(long repositoryId, long folderId) 738 throws PortalException, SystemException { 739 740 return getFileEntries( 741 repositoryId, folderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 742 } 743 744 /** 745 * Returns a range of all the file entries in the folder. 746 * 747 * <p> 748 * Useful when paginating results. Returns a maximum of <code>end - 749 * start</code> instances. <code>start</code> and <code>end</code> are not 750 * primary keys, they are indexes in the result set. Thus, <code>0</code> 751 * refers to the first result in the set. Setting both <code>start</code> 752 * and <code>end</code> to {@link 753 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 754 * result set. 755 * </p> 756 * 757 * @param repositoryId the primary key of the file entry's repository 758 * @param folderId the primary key of the file entry's folder 759 * @param start the lower bound of the range of results 760 * @param end the upper bound of the range of results (not inclusive) 761 * @return the range of file entries in the folder 762 * @throws PortalException if the folder could not be found 763 * @throws SystemException if a system exception occurred 764 */ 765 public List<FileEntry> getFileEntries( 766 long repositoryId, long folderId, int start, int end) 767 throws PortalException, SystemException { 768 769 return getFileEntries(repositoryId, folderId, start, end, null); 770 } 771 772 /** 773 * Returns an ordered range of all the file entries in the folder. 774 * 775 * <p> 776 * Useful when paginating results. Returns a maximum of <code>end - 777 * start</code> instances. <code>start</code> and <code>end</code> are not 778 * primary keys, they are indexes in the result set. Thus, <code>0</code> 779 * refers to the first result in the set. Setting both <code>start</code> 780 * and <code>end</code> to {@link 781 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 782 * result set. 783 * </p> 784 * 785 * @param repositoryId the primary key of the file entry's repository 786 * @param folderId the primary key of the file entry's folder 787 * @param start the lower bound of the range of results 788 * @param end the upper bound of the range of results (not inclusive) 789 * @param obc the comparator to order the file entries (optionally 790 * <code>null</code>) 791 * @return the range of file entries in the folder ordered by comparator 792 * <code>obc</code> 793 * @throws PortalException if the folder could not be found 794 * @throws SystemException if a system exception occurred 795 */ 796 public List<FileEntry> getFileEntries( 797 long repositoryId, long folderId, int start, int end, 798 OrderByComparator obc) 799 throws PortalException, SystemException { 800 801 Repository repository = getRepository(repositoryId); 802 803 return repository.getFileEntries(folderId, start, end, obc); 804 } 805 806 /** 807 * Returns the file entries with the file entry type in the folder. 808 * 809 * @param repositoryId the primary key of the file entry's repository 810 * @param folderId the primary key of the file entry's folder 811 * @param fileEntryTypeId the primary key of the file entry type 812 * @return the file entries with the file entry type in the folder 813 * @throws PortalException if the folder could not be found 814 * @throws SystemException if a system exception occurred 815 */ 816 public List<FileEntry> getFileEntries( 817 long repositoryId, long folderId, long fileEntryTypeId) 818 throws PortalException, SystemException { 819 820 return getFileEntries( 821 repositoryId, folderId, fileEntryTypeId, QueryUtil.ALL_POS, 822 QueryUtil.ALL_POS); 823 } 824 825 /** 826 * Returns a range of all the file entries with the file entry type in the 827 * folder. 828 * 829 * @param repositoryId the primary key of the file entry's repository 830 * @param folderId the primary key of the file entry's folder 831 * @param fileEntryTypeId the primary key of the file entry type 832 * @param start the lower bound of the range of results 833 * @param end the upper bound of the range of results (not inclusive) 834 * @return the file entries in the folder 835 * @throws PortalException if the folder could not be found 836 * @throws SystemException if a system exception occurred 837 */ 838 public List<FileEntry> getFileEntries( 839 long repositoryId, long folderId, long fileEntryTypeId, int start, 840 int end) 841 throws PortalException, SystemException { 842 843 return getFileEntries( 844 repositoryId, folderId, fileEntryTypeId, start, end, null); 845 } 846 847 /** 848 * Returns an ordered range of all the file entries with the file entry type 849 * in the folder. 850 * 851 * @param repositoryId the primary key of the repository 852 * @param folderId the primary key of the folder 853 * @param fileEntryTypeId the primary key of the file entry type 854 * @param start the lower bound of the range of results 855 * @param end the upper bound of the range of results (not inclusive) 856 * @param obc the comparator to order the results by (optionally 857 * <code>null</code>) 858 * @return the range of file entries with the file entry type in the folder 859 * ordered by <code>null</code> 860 * @throws PortalException if the folder could not be found 861 * @throws SystemException if a system exception occurred 862 */ 863 public List<FileEntry> getFileEntries( 864 long repositoryId, long folderId, long fileEntryTypeId, int start, 865 int end, OrderByComparator obc) 866 throws PortalException, SystemException { 867 868 Repository repository = getRepository(repositoryId); 869 870 return repository.getFileEntries( 871 folderId, fileEntryTypeId, start, end, obc); 872 } 873 874 /** 875 * Returns a range of all the file entries and shortcuts in the folder. 876 * 877 * <p> 878 * Useful when paginating results. Returns a maximum of <code>end - 879 * start</code> instances. <code>start</code> and <code>end</code> are not 880 * primary keys, they are indexes in the result set. Thus, <code>0</code> 881 * refers to the first result in the set. Setting both <code>start</code> 882 * and <code>end</code> to {@link 883 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 884 * result set. 885 * </p> 886 * 887 * @param repositoryId the primary key of the repository 888 * @param folderId the primary key of the folder 889 * @param status the workflow status 890 * @param start the lower bound of the range of results 891 * @param end the upper bound of the range of results (not inclusive) 892 * @return the range of file entries and shortcuts in the folder 893 * @throws PortalException if the folder could not be found 894 * @throws SystemException if a system exception occurred 895 */ 896 public List<Object> getFileEntriesAndFileShortcuts( 897 long repositoryId, long folderId, int status, int start, int end) 898 throws PortalException, SystemException { 899 900 Repository repository = getRepository(repositoryId); 901 902 return repository.getFileEntriesAndFileShortcuts( 903 folderId, status, start, end); 904 } 905 906 /** 907 * Returns the number of file entries and shortcuts in the folder. 908 * 909 * @param repositoryId the primary key of the repository 910 * @param folderId the primary key of the folder 911 * @param status the workflow status 912 * @return the number of file entries and shortcuts in the folder 913 * @throws PortalException if the folder ould not be found 914 * @throws SystemException if a system exception occurred 915 */ 916 public int getFileEntriesAndFileShortcutsCount( 917 long repositoryId, long folderId, int status) 918 throws PortalException, SystemException { 919 920 Repository repository = getRepository(repositoryId); 921 922 return repository.getFileEntriesAndFileShortcutsCount(folderId, status); 923 } 924 925 /** 926 * Returns the number of file entries and shortcuts in the folder. 927 * 928 * @param repositoryId the primary key of the repository 929 * @param folderId the primary key of the folder 930 * @param status the workflow status 931 * @param mimeTypes allowed media types 932 * @return the number of file entries and shortcuts in the folder 933 * @throws PortalException if the folder ould not be found 934 * @throws SystemException if a system exception occurred 935 */ 936 public int getFileEntriesAndFileShortcutsCount( 937 long repositoryId, long folderId, int status, String[] mimeTypes) 938 throws PortalException, SystemException { 939 940 Repository repository = getRepository(repositoryId); 941 942 return repository.getFileEntriesAndFileShortcutsCount( 943 folderId, status, mimeTypes); 944 } 945 946 /** 947 * Returns the number of file entries in the folder. 948 * 949 * @param repositoryId the primary key of the file entry's repository 950 * @param folderId the primary key of the file entry's folder 951 * @return the number of file entries in the folder 952 * @throws PortalException if the folder could not be found 953 * @throws SystemException if a system exception occurred 954 */ 955 public int getFileEntriesCount(long repositoryId, long folderId) 956 throws PortalException, SystemException { 957 958 Repository repository = getRepository(repositoryId); 959 960 return repository.getFileEntriesCount(folderId); 961 } 962 963 /** 964 * Returns the number of file entries with the file entry type in the 965 * folder. 966 * 967 * @param repositoryId the primary key of the file entry's repository 968 * @param folderId the primary key of the file entry's folder 969 * @param fileEntryTypeId the primary key of the file entry type 970 * @return the number of file entries with the file entry type in the folder 971 * @throws PortalException if the folder could not be found 972 * @throws SystemException if a system exception occurred 973 */ 974 public int getFileEntriesCount( 975 long repositoryId, long folderId, long fileEntryTypeId) 976 throws PortalException, SystemException { 977 978 Repository repository = getRepository(repositoryId); 979 980 return repository.getFileEntriesCount(folderId, fileEntryTypeId); 981 } 982 983 /** 984 * Returns the file entry with the primary key. 985 * 986 * @param fileEntryId the primary key of the file entry 987 * @return the file entry with the primary key 988 * @throws PortalException if the file entry could not be found 989 * @throws SystemException if a system exception occurred 990 */ 991 public FileEntry getFileEntry(long fileEntryId) 992 throws PortalException, SystemException { 993 994 Repository repository = getRepository(0, fileEntryId, 0); 995 996 return repository.getFileEntry(fileEntryId); 997 } 998 999 /** 1000 * Returns the file entry with the title in the folder. 1001 * 1002 * @param groupId the primary key of the file entry's group 1003 * @param folderId the primary key of the file entry's folder 1004 * @param title the file entry's title 1005 * @return the file entry with the title in the folder 1006 * @throws PortalException if the file entry could not be found 1007 * @throws SystemException if a system exception occurred 1008 */ 1009 public FileEntry getFileEntry(long groupId, long folderId, String title) 1010 throws PortalException, SystemException { 1011 1012 try { 1013 Repository repository = getRepository(groupId); 1014 1015 return repository.getFileEntry(folderId, title); 1016 } 1017 catch (NoSuchFileEntryException nsfee) { 1018 if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { 1019 Repository repository = getRepository(folderId, 0, 0); 1020 1021 return repository.getFileEntry(folderId, title); 1022 } 1023 else { 1024 throw nsfee; 1025 } 1026 } 1027 } 1028 1029 /** 1030 * Returns the file entry with the UUID and group. 1031 * 1032 * @param uuid the file entry's universally unique identifier 1033 * @param groupId the primary key of the file entry's group 1034 * @return the file entry with the UUID and group 1035 * @throws PortalException if the file entry could not be found 1036 * @throws SystemException if a system exception occurred 1037 */ 1038 public FileEntry getFileEntryByUuidAndGroupId(String uuid, long groupId) 1039 throws PortalException, SystemException { 1040 1041 try { 1042 Repository repository = getRepository(groupId); 1043 1044 return repository.getFileEntryByUuid(uuid); 1045 } 1046 catch (NoSuchFileEntryException nsfee) { 1047 List<com.liferay.portal.model.Repository> repositories = 1048 repositoryPersistence.findByGroupId(groupId); 1049 1050 for (int i = 0; i < repositories.size(); i++) { 1051 try { 1052 long repositoryId = repositories.get(i).getRepositoryId(); 1053 1054 Repository repository = getRepository(repositoryId); 1055 1056 return repository.getFileEntryByUuid(uuid); 1057 } 1058 catch (NoSuchFileEntryException nsfee2) { 1059 } 1060 } 1061 } 1062 1063 StringBundler msg = new StringBundler(6); 1064 1065 msg.append("No DLFileEntry exists with the key {"); 1066 msg.append("uuid="); 1067 msg.append(uuid); 1068 msg.append(", groupId="); 1069 msg.append(groupId); 1070 msg.append(StringPool.CLOSE_CURLY_BRACE); 1071 1072 throw new NoSuchFileEntryException(msg.toString()); 1073 } 1074 1075 /** 1076 * Returns the file shortcut with the primary key. This method is only 1077 * supported by the Liferay repository. 1078 * 1079 * @param fileShortcutId the primary key of the file shortcut 1080 * @return the file shortcut with the primary key 1081 * @throws PortalException if the file shortcut could not be found 1082 * @throws SystemException if a system exception occurred 1083 */ 1084 public DLFileShortcut getFileShortcut(long fileShortcutId) 1085 throws PortalException, SystemException { 1086 1087 return dlFileShortcutService.getFileShortcut(fileShortcutId); 1088 } 1089 1090 /** 1091 * Returns the folder with the primary key. 1092 * 1093 * @param folderId the primary key of the folder 1094 * @return the folder with the primary key 1095 * @throws PortalException if the folder could not be found 1096 * @throws SystemException if a system exception occurred 1097 */ 1098 public Folder getFolder(long folderId) 1099 throws PortalException, SystemException { 1100 1101 Repository repository = getRepository(folderId, 0, 0); 1102 1103 return repository.getFolder(folderId); 1104 } 1105 1106 /** 1107 * Returns the folder with the name in the parent folder. 1108 * 1109 * @param repositoryId the primary key of the folder's repository 1110 * @param parentFolderId the primary key of the folder's parent folder 1111 * @param name the folder's name 1112 * @return the folder with the name in the parent folder 1113 * @throws PortalException if the folder could not be found 1114 * @throws SystemException if a system exception occurred 1115 */ 1116 public Folder getFolder(long repositoryId, long parentFolderId, String name) 1117 throws PortalException, SystemException { 1118 1119 Repository repository = getRepository(repositoryId); 1120 1121 return repository.getFolder(parentFolderId, name); 1122 } 1123 1124 /** 1125 * Returns all immediate subfolders of the parent folder. 1126 * 1127 * @param repositoryId the primary key of the folder's repository 1128 * @param parentFolderId the primary key of the folder's parent folder 1129 * @return the immediate subfolders of the parent folder 1130 * @throws PortalException if the parent folder could not be found 1131 * @throws SystemException if a system exception occurred 1132 */ 1133 public List<Folder> getFolders(long repositoryId, long parentFolderId) 1134 throws PortalException, SystemException { 1135 1136 return getFolders( 1137 repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 1138 } 1139 1140 /** 1141 * Returns all immediate subfolders of the parent folder, optionally 1142 * including mount folders for third-party repositories. 1143 * 1144 * @param repositoryId the primary key of the folder's repository 1145 * @param parentFolderId the primary key of the folder's parent folder 1146 * @param includeMountFolders whether to include mount folders for 1147 * third-party repositories 1148 * @return the immediate subfolders of the parent folder 1149 * @throws PortalException if the parent folder could not be found 1150 * @throws SystemException if a system exception occurred 1151 */ 1152 public List<Folder> getFolders( 1153 long repositoryId, long parentFolderId, boolean includeMountFolders) 1154 throws PortalException, SystemException { 1155 1156 return getFolders( 1157 repositoryId, parentFolderId, includeMountFolders, 1158 QueryUtil.ALL_POS, QueryUtil.ALL_POS); 1159 } 1160 1161 /** 1162 * Returns a range of all the immediate subfolders of the parent folder, 1163 * optionally including mount folders for third-party repositories. 1164 * 1165 * <p> 1166 * Useful when paginating results. Returns a maximum of <code>end - 1167 * start</code> instances. <code>start</code> and <code>end</code> are not 1168 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1169 * refers to the first result in the set. Setting both <code>start</code> 1170 * and <code>end</code> to {@link 1171 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1172 * result set. 1173 * </p> 1174 * 1175 * @param repositoryId the primary key of the folder's repository 1176 * @param parentFolderId the primary key of the folder's parent folder 1177 * @param includeMountFolders whether to include mount folders for 1178 * third-party repositories 1179 * @param start the lower bound of the range of results 1180 * @param end the upper bound of the range of results (not inclusive) 1181 * @return the range of immediate subfolders of the parent folder 1182 * @throws PortalException if the parent folder could not be found 1183 * @throws SystemException if a system exception occurred 1184 */ 1185 public List<Folder> getFolders( 1186 long repositoryId, long parentFolderId, boolean includeMountFolders, 1187 int start, int end) 1188 throws PortalException, SystemException { 1189 1190 return getFolders( 1191 repositoryId, parentFolderId, includeMountFolders, start, end, 1192 null); 1193 } 1194 1195 /** 1196 * Returns an ordered range of all the immediate subfolders of the parent 1197 * folder. 1198 * 1199 * <p> 1200 * Useful when paginating results. Returns a maximum of <code>end - 1201 * start</code> instances. <code>start</code> and <code>end</code> are not 1202 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1203 * refers to the first result in the set. Setting both <code>start</code> 1204 * and <code>end</code> to {@link 1205 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1206 * result set. 1207 * </p> 1208 * 1209 * @param repositoryId the primary key of the folder's repository 1210 * @param parentFolderId the primary key of the folder's parent folder 1211 * @param includeMountFolders whether to include mount folders for 1212 * third-party repositories 1213 * @param start the lower bound of the range of results 1214 * @param end the upper bound of the range of results (not inclusive) 1215 * @param obc the comparator to order the folders (optionally 1216 * <code>null</code>) 1217 * @return the range of immediate subfolders of the parent folder ordered by 1218 * comparator <code>obc</code> 1219 * @throws PortalException if the parent folder could not be found 1220 * @throws SystemException if a system exception occurred 1221 */ 1222 public List<Folder> getFolders( 1223 long repositoryId, long parentFolderId, boolean includeMountFolders, 1224 int start, int end, OrderByComparator obc) 1225 throws PortalException, SystemException { 1226 1227 Repository repository = getRepository(repositoryId); 1228 1229 return repository.getFolders( 1230 parentFolderId, includeMountFolders, start, end, obc); 1231 } 1232 1233 /** 1234 * Returns a range of all the immediate subfolders of the parent folder. 1235 * 1236 * <p> 1237 * Useful when paginating results. Returns a maximum of <code>end - 1238 * start</code> instances. <code>start</code> and <code>end</code> are not 1239 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1240 * refers to the first result in the set. Setting both <code>start</code> 1241 * and <code>end</code> to {@link 1242 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1243 * result set. 1244 * </p> 1245 * 1246 * @param repositoryId the primary key of the folder's repository 1247 * @param parentFolderId the primary key of the folder's parent folder 1248 * @param start the lower bound of the range of results 1249 * @param end the upper bound of the range of results (not inclusive) 1250 * @return the range of immediate subfolders of the parent folder 1251 * @throws PortalException if the parent folder could not be found 1252 * @throws SystemException if a system exception occurred 1253 */ 1254 public List<Folder> getFolders( 1255 long repositoryId, long parentFolderId, int start, int end) 1256 throws PortalException, SystemException { 1257 1258 return getFolders(repositoryId, parentFolderId, start, end, null); 1259 } 1260 1261 /** 1262 * Returns an ordered range of all the immediate subfolders of the parent 1263 * folder. 1264 * 1265 * <p> 1266 * Useful when paginating results. Returns a maximum of <code>end - 1267 * start</code> instances. <code>start</code> and <code>end</code> are not 1268 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1269 * refers to the first result in the set. Setting both <code>start</code> 1270 * and <code>end</code> to {@link 1271 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1272 * result set. 1273 * </p> 1274 * 1275 * @param repositoryId the primary key of the folder's repository 1276 * @param parentFolderId the primary key of the folder's parent folder 1277 * @param start the lower bound of the range of results 1278 * @param end the upper bound of the range of results (not inclusive) 1279 * @param obc the comparator to order the folders (optionally 1280 * <code>null</code>) 1281 * @return the range of immediate subfolders of the parent folder ordered by 1282 * comparator <code>obc</code> 1283 * @throws PortalException if the parent folder could not be found 1284 * @throws SystemException if a system exception occurred 1285 */ 1286 public List<Folder> getFolders( 1287 long repositoryId, long parentFolderId, int start, int end, 1288 OrderByComparator obc) 1289 throws PortalException, SystemException { 1290 1291 Repository repository = getRepository(repositoryId); 1292 1293 return repository.getFolders(parentFolderId, true, start, end, obc); 1294 } 1295 1296 /** 1297 * Returns a range of all the immediate subfolders, file entries, and file 1298 * shortcuts in the parent folder. 1299 * 1300 * <p> 1301 * Useful when paginating results. Returns a maximum of <code>end - 1302 * start</code> instances. <code>start</code> and <code>end</code> are not 1303 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1304 * refers to the first result in the set. Setting both <code>start</code> 1305 * and <code>end</code> to {@link 1306 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1307 * result set. 1308 * </p> 1309 * 1310 * @param repositoryId the primary key of the repository 1311 * @param folderId the primary key of the parent folder 1312 * @param status the workflow status 1313 * @param includeMountFolders whether to include mount folders for 1314 * third-party repositories 1315 * @param start the lower bound of the range of results 1316 * @param end the upper bound of the range of results (not inclusive) 1317 * @return the range of immediate subfolders, file entries, and file 1318 * shortcuts in the parent folder ordered by comparator 1319 * <code>obc</code> 1320 * @throws PortalException if the parent folder could not be found 1321 * @throws SystemException if a system exception occurred 1322 */ 1323 public List<Object> getFoldersAndFileEntriesAndFileShortcuts( 1324 long repositoryId, long folderId, int status, 1325 boolean includeMountFolders, int start, int end) 1326 throws PortalException, SystemException { 1327 1328 return getFoldersAndFileEntriesAndFileShortcuts( 1329 repositoryId, folderId, status, includeMountFolders, start, end, 1330 null); 1331 } 1332 1333 /** 1334 * Returns an ordered range of all the immediate subfolders, file entries, 1335 * and file shortcuts in the parent folder. 1336 * 1337 * <p> 1338 * Useful when paginating results. Returns a maximum of <code>end - 1339 * start</code> instances. <code>start</code> and <code>end</code> are not 1340 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1341 * refers to the first result in the set. Setting both <code>start</code> 1342 * and <code>end</code> to {@link 1343 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1344 * result set. 1345 * </p> 1346 * 1347 * @param repositoryId the primary key of the repository 1348 * @param folderId the primary key of the parent folder 1349 * @param status the workflow status 1350 * @param includeMountFolders whether to include mount folders for 1351 * third-party repositories 1352 * @param start the lower bound of the range of results 1353 * @param end the upper bound of the range of results (not inclusive) 1354 * @param obc the comparator to order the results (optionally 1355 * <code>null</code>) 1356 * @return the range of immediate subfolders, file entries, and file 1357 * shortcuts in the parent folder ordered by comparator 1358 * <code>obc</code> 1359 * @throws PortalException if the parent folder could not be found 1360 * @throws SystemException if a system exception occurred 1361 */ 1362 public List<Object> getFoldersAndFileEntriesAndFileShortcuts( 1363 long repositoryId, long folderId, int status, 1364 boolean includeMountFolders, int start, int end, 1365 OrderByComparator obc) 1366 throws PortalException, SystemException { 1367 1368 return getFoldersAndFileEntriesAndFileShortcuts( 1369 repositoryId, folderId, status, null, includeMountFolders, start, 1370 end, obc); 1371 } 1372 1373 public List<Object> getFoldersAndFileEntriesAndFileShortcuts( 1374 long repositoryId, long folderId, int status, String[] mimeTypes, 1375 boolean includeMountFolders, int start, int end, 1376 OrderByComparator obc) 1377 throws PortalException, SystemException { 1378 1379 Repository repository = getRepository(repositoryId); 1380 1381 return repository.getFoldersAndFileEntriesAndFileShortcuts( 1382 folderId, status, mimeTypes, includeMountFolders, start, end, obc); 1383 } 1384 1385 /** 1386 * Returns the number of immediate subfolders, file entries, and file 1387 * shortcuts in the parent folder. 1388 * 1389 * @param repositoryId the primary key of the repository 1390 * @param folderId the primary key of the parent folder 1391 * @param status the workflow status 1392 * @param includeMountFolders whether to include mount folders for 1393 * third-party repositories 1394 * @return the number of immediate subfolders, file entries, and file 1395 * shortcuts in the parent folder 1396 * @throws PortalException if the folder could not be found 1397 * @throws SystemException if a system exception occurred 1398 */ 1399 public int getFoldersAndFileEntriesAndFileShortcutsCount( 1400 long repositoryId, long folderId, int status, 1401 boolean includeMountFolders) 1402 throws PortalException, SystemException { 1403 1404 return getFoldersAndFileEntriesAndFileShortcutsCount( 1405 repositoryId, folderId, status, null, includeMountFolders); 1406 } 1407 1408 public int getFoldersAndFileEntriesAndFileShortcutsCount( 1409 long repositoryId, long folderId, int status, String[] mimeTypes, 1410 boolean includeMountFolders) 1411 throws PortalException, SystemException { 1412 1413 Repository repository = getRepository(repositoryId); 1414 1415 return repository.getFoldersAndFileEntriesAndFileShortcutsCount( 1416 folderId, status, mimeTypes, includeMountFolders); 1417 } 1418 1419 /** 1420 * Returns the number of immediate subfolders of the parent folder. 1421 * 1422 * @param repositoryId the primary key of the folder's repository 1423 * @param parentFolderId the primary key of the folder's parent folder 1424 * @return the number of immediate subfolders of the parent folder 1425 * @throws PortalException if the parent folder could not be found 1426 * @throws SystemException if a system exception occurred 1427 */ 1428 public int getFoldersCount(long repositoryId, long parentFolderId) 1429 throws PortalException, SystemException { 1430 1431 return getFoldersCount(repositoryId, parentFolderId, true); 1432 } 1433 1434 /** 1435 * Returns the number of immediate subfolders of the parent folder, 1436 * optionally including mount folders for third-party repositories. 1437 * 1438 * @param repositoryId the primary key of the folder's repository 1439 * @param parentFolderId the primary key of the folder's parent folder 1440 * @param includeMountFolders whether to include mount folders for 1441 * third-party repositories 1442 * @return the number of immediate subfolders of the parent folder 1443 * @throws PortalException if the parent folder could not be found 1444 * @throws SystemException if a system exception occurred 1445 */ 1446 public int getFoldersCount( 1447 long repositoryId, long parentFolderId, boolean includeMountFolders) 1448 throws PortalException, SystemException { 1449 1450 Repository repository = getRepository(repositoryId); 1451 1452 return repository.getFoldersCount(parentFolderId, includeMountFolders); 1453 } 1454 1455 /** 1456 * Returns the number of immediate subfolders and file entries across the 1457 * folders. 1458 * 1459 * @param repositoryId the primary key of the repository 1460 * @param folderIds the primary keys of folders from which to count 1461 * immediate subfolders and file entries 1462 * @param status the workflow status 1463 * @return the number of immediate subfolders and file entries across the 1464 * folders 1465 * @throws PortalException if the repository could not be found 1466 * @throws SystemException if a system exception occurred 1467 */ 1468 public int getFoldersFileEntriesCount( 1469 long repositoryId, List<Long> folderIds, int status) 1470 throws PortalException, SystemException { 1471 1472 Repository repository = getRepository(repositoryId); 1473 1474 return repository.getFoldersFileEntriesCount(folderIds, status); 1475 } 1476 1477 /** 1478 * Returns an ordered range of all the file entries in the group starting at 1479 * the repository default parent folder that are stored within the Liferay 1480 * repository. This method is primarily used to search for recently modified 1481 * file entries. It can be limited to the file entries modified by a given 1482 * user. 1483 * 1484 * <p> 1485 * Useful when paginating results. Returns a maximum of <code>end - 1486 * start</code> instances. <code>start</code> and <code>end</code> are not 1487 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1488 * refers to the first result in the set. Setting both <code>start</code> 1489 * and <code>end</code> to {@link 1490 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1491 * result set. 1492 * </p> 1493 * 1494 * @param groupId the primary key of the group 1495 * @param userId the primary key of the user who created the file 1496 * (optionally <code>0</code>) 1497 * @param start the lower bound of the range of results 1498 * @param end the upper bound of the range of results (not inclusive) 1499 * @return the range of matching file entries ordered by date modified 1500 * @throws PortalException if the group could not be found 1501 * @throws SystemException if a system exception occurred 1502 */ 1503 public List<FileEntry> getGroupFileEntries( 1504 long groupId, long userId, int start, int end) 1505 throws PortalException, SystemException { 1506 1507 return getGroupFileEntries( 1508 groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, start, 1509 end, new RepositoryModelModifiedDateComparator()); 1510 } 1511 1512 /** 1513 * Returns an ordered range of all the file entries in the group that are 1514 * stored within the Liferay repository. This method is primarily used to 1515 * search for recently modified file entries. It can be limited to the file 1516 * entries modified by a given user. 1517 * 1518 * <p> 1519 * Useful when paginating results. Returns a maximum of <code>end - 1520 * start</code> instances. <code>start</code> and <code>end</code> are not 1521 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1522 * refers to the first result in the set. Setting both <code>start</code> 1523 * and <code>end</code> to {@link 1524 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1525 * result set. 1526 * </p> 1527 * 1528 * @param groupId the primary key of the group 1529 * @param userId the primary key of the user who created the file 1530 * (optionally <code>0</code>) 1531 * @param start the lower bound of the range of results 1532 * @param end the upper bound of the range of results (not inclusive) 1533 * @param obc the comparator to order the file entries (optionally 1534 * <code>null</code>) 1535 * @return the range of matching file entries ordered by comparator 1536 * <code>obc</code> 1537 * @throws PortalException if the group could not be found 1538 * @throws SystemException if a system exception occurred 1539 */ 1540 public List<FileEntry> getGroupFileEntries( 1541 long groupId, long userId, int start, int end, 1542 OrderByComparator obc) 1543 throws PortalException, SystemException { 1544 1545 return getGroupFileEntries( 1546 groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, start, 1547 end, obc); 1548 } 1549 1550 /** 1551 * Returns an ordered range of all the file entries in the group starting at 1552 * the root folder that are stored within the Liferay repository. This 1553 * method is primarily used to search for recently modified file entries. It 1554 * can be limited to the file entries modified by a given user. 1555 * 1556 * <p> 1557 * Useful when paginating results. Returns a maximum of <code>end - 1558 * start</code> instances. <code>start</code> and <code>end</code> are not 1559 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1560 * refers to the first result in the set. Setting both <code>start</code> 1561 * and <code>end</code> to {@link 1562 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1563 * result set. 1564 * </p> 1565 * 1566 * @param groupId the primary key of the group 1567 * @param userId the primary key of the user who created the file 1568 * (optionally <code>0</code>) 1569 * @param rootFolderId the primary key of the root folder to begin the 1570 * search 1571 * @param start the lower bound of the range of results 1572 * @param end the upper bound of the range of results (not inclusive) 1573 * @return the range of matching file entries ordered by date modified 1574 * @throws PortalException if the group could not be found 1575 * @throws SystemException if a system exception occurred 1576 */ 1577 public List<FileEntry> getGroupFileEntries( 1578 long groupId, long userId, long rootFolderId, int start, int end) 1579 throws PortalException, SystemException { 1580 1581 return getGroupFileEntries( 1582 groupId, userId, rootFolderId, start, end, 1583 new RepositoryModelModifiedDateComparator()); 1584 } 1585 1586 /** 1587 * Returns an ordered range of all the file entries in the group starting at 1588 * the root folder that are stored within the Liferay repository. This 1589 * method is primarily used to search for recently modified file entries. It 1590 * can be limited to the file entries modified by a given user. 1591 * 1592 * <p> 1593 * Useful when paginating results. Returns a maximum of <code>end - 1594 * start</code> instances. <code>start</code> and <code>end</code> are not 1595 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1596 * refers to the first result in the set. Setting both <code>start</code> 1597 * and <code>end</code> to {@link 1598 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1599 * result set. 1600 * </p> 1601 * 1602 * @param groupId the primary key of the group 1603 * @param userId the primary key of the user who created the file 1604 * (optionally <code>0</code>) 1605 * @param rootFolderId the primary key of the root folder to begin the 1606 * search 1607 * @param start the lower bound of the range of results 1608 * @param end the upper bound of the range of results (not inclusive) 1609 * @param obc the comparator to order the file entries (optionally 1610 * <code>null</code>) 1611 * @return the range of matching file entries ordered by comparator 1612 * <code>obc</code> 1613 * @throws PortalException if the group could not be found 1614 * @throws SystemException if a system exception occurred 1615 */ 1616 public List<FileEntry> getGroupFileEntries( 1617 long groupId, long userId, long rootFolderId, int start, int end, 1618 OrderByComparator obc) 1619 throws PortalException, SystemException { 1620 1621 Repository repository = getRepository(groupId); 1622 1623 return repository.getRepositoryFileEntries( 1624 userId, rootFolderId, start, end, obc); 1625 } 1626 1627 public List<FileEntry> getGroupFileEntries( 1628 long groupId, long userId, long rootFolderId, String[] mimeTypes, 1629 int status, int start, int end, OrderByComparator obc) 1630 throws PortalException, SystemException { 1631 1632 Repository repository = getRepository(groupId); 1633 1634 return repository.getRepositoryFileEntries( 1635 userId, rootFolderId, mimeTypes, status, start, end, obc); 1636 } 1637 1638 /** 1639 * Returns the number of file entries in a group starting at the repository 1640 * default parent folder that are stored within the Liferay repository. This 1641 * method is primarily used to search for recently modified file entries. It 1642 * can be limited to the file entries modified by a given user. 1643 * 1644 * @param groupId the primary key of the group 1645 * @param userId the primary key of the user who created the file 1646 * (optionally <code>0</code>) 1647 * @return the number of matching file entries 1648 * @throws PortalException if the group could not be found 1649 * @throws SystemException if a system exception occurred 1650 */ 1651 public int getGroupFileEntriesCount(long groupId, long userId) 1652 throws PortalException, SystemException { 1653 1654 return getGroupFileEntriesCount( 1655 groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID); 1656 } 1657 1658 /** 1659 * Returns the number of file entries in a group starting at the root folder 1660 * that are stored within the Liferay repository. This method is primarily 1661 * used to search for recently modified file entries. It can be limited to 1662 * the file entries modified by a given user. 1663 * 1664 * @param groupId the primary key of the group 1665 * @param userId the primary key of the user who created the file 1666 * (optionally <code>0</code>) 1667 * @param rootFolderId the primary key of the root folder to begin the 1668 * search 1669 * @return the number of matching file entries 1670 * @throws PortalException if the group could not be found 1671 * @throws SystemException if a system exception occurred 1672 */ 1673 public int getGroupFileEntriesCount( 1674 long groupId, long userId, long rootFolderId) 1675 throws PortalException, SystemException { 1676 1677 Repository repository = getRepository(groupId); 1678 1679 return repository.getRepositoryFileEntriesCount(userId, rootFolderId); 1680 } 1681 1682 public int getGroupFileEntriesCount( 1683 long groupId, long userId, long rootFolderId, String[] mimeTypes, 1684 int status) 1685 throws PortalException, SystemException { 1686 1687 Repository repository = getRepository(groupId); 1688 1689 return repository.getRepositoryFileEntriesCount( 1690 userId, rootFolderId, mimeTypes, status); 1691 } 1692 1693 /** 1694 * Returns all immediate subfolders of the parent folder that are used for 1695 * mounting third-party repositories. This method is only supported by the 1696 * Liferay repository. 1697 * 1698 * @param repositoryId the primary key of the folder's repository 1699 * @param parentFolderId the primary key of the folder's parent folder 1700 * @return the immediate subfolders of the parent folder that are used for 1701 * mounting third-party repositories 1702 * @throws PortalException if the repository or parent folder could not be 1703 * found 1704 * @throws SystemException if a system exception occurred 1705 */ 1706 public List<Folder> getMountFolders(long repositoryId, long parentFolderId) 1707 throws PortalException, SystemException { 1708 1709 return getMountFolders( 1710 repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 1711 } 1712 1713 /** 1714 * Returns a range of all the immediate subfolders of the parent folder that 1715 * are used for mounting third-party repositories. This method is only 1716 * supported by the Liferay repository. 1717 * 1718 * <p> 1719 * Useful when paginating results. Returns a maximum of <code>end - 1720 * start</code> instances. <code>start</code> and <code>end</code> are not 1721 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1722 * refers to the first result in the set. Setting both <code>start</code> 1723 * and <code>end</code> to {@link 1724 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1725 * result set. 1726 * </p> 1727 * 1728 * @param repositoryId the primary key of the repository 1729 * @param parentFolderId the primary key of the parent folder 1730 * @param start the lower bound of the range of results 1731 * @param end the upper bound of the range of results (not inclusive) 1732 * @return the range of immediate subfolders of the parent folder that are 1733 * used for mounting third-party repositories 1734 * @throws PortalException if the repository or parent folder could not be 1735 * found 1736 * @throws SystemException if a system exception occurred 1737 */ 1738 public List<Folder> getMountFolders( 1739 long repositoryId, long parentFolderId, int start, int end) 1740 throws PortalException, SystemException { 1741 1742 return getMountFolders(repositoryId, parentFolderId, start, end, null); 1743 } 1744 1745 /** 1746 * Returns an ordered range of all the immediate subfolders of the parent 1747 * folder that are used for mounting third-party repositories. This method 1748 * is only supported by the Liferay repository. 1749 * 1750 * <p> 1751 * Useful when paginating results. Returns a maximum of <code>end - 1752 * start</code> instances. <code>start</code> and <code>end</code> are not 1753 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1754 * refers to the first result in the set. Setting both <code>start</code> 1755 * and <code>end</code> to {@link 1756 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1757 * result set. 1758 * </p> 1759 * 1760 * @param repositoryId the primary key of the folder's repository 1761 * @param parentFolderId the primary key of the folder's parent folder 1762 * @param start the lower bound of the range of results 1763 * @param end the upper bound of the range of results (not inclusive) 1764 * @param obc the comparator to order the folders (optionally 1765 * <code>null</code>) 1766 * @return the range of immediate subfolders of the parent folder that are 1767 * used for mounting third-party repositories ordered by comparator 1768 * <code>obc</code> 1769 * @throws PortalException if the repository or parent folder could not be 1770 * found 1771 * @throws SystemException if a system exception occurred 1772 */ 1773 public List<Folder> getMountFolders( 1774 long repositoryId, long parentFolderId, int start, int end, 1775 OrderByComparator obc) 1776 throws PortalException, SystemException { 1777 1778 Repository repository = getRepository(repositoryId); 1779 1780 return repository.getMountFolders(parentFolderId, start, end, obc); 1781 } 1782 1783 /** 1784 * Returns the number of immediate subfolders of the parent folder that are 1785 * used for mounting third-party repositories. This method is only supported 1786 * by the Liferay repository. 1787 * 1788 * @param repositoryId the primary key of the repository 1789 * @param parentFolderId the primary key of the parent folder 1790 * @return the number of folders of the parent folder that are used for 1791 * mounting third-party repositories 1792 * @throws PortalException if the repository or parent folder could not be 1793 * found 1794 * @throws SystemException if a system exception occurred 1795 */ 1796 public int getMountFoldersCount(long repositoryId, long parentFolderId) 1797 throws PortalException, SystemException { 1798 1799 Repository repository = getRepository(repositoryId); 1800 1801 return repository.getMountFoldersCount(parentFolderId); 1802 } 1803 1804 public void getSubfolderIds( 1805 long repositoryId, List<Long> folderIds, long folderId) 1806 throws PortalException, SystemException { 1807 1808 Repository repository = getRepository(repositoryId); 1809 1810 repository.getSubfolderIds(folderIds, folderId); 1811 } 1812 1813 /** 1814 * Returns all the descendant folders of the folder with the primary key. 1815 * 1816 * @param repositoryId the primary key of the repository 1817 * @param folderId the primary key of the folder 1818 * @return the descendant folders of the folder with the primary key 1819 * @throws PortalException if the repository or parent folder could not be 1820 * found 1821 * @throws SystemException if a system exception occurred 1822 */ 1823 public List<Long> getSubfolderIds(long repositoryId, long folderId) 1824 throws PortalException, SystemException { 1825 1826 return getSubfolderIds(repositoryId, folderId, true); 1827 } 1828 1829 /** 1830 * Returns descendant folders of the folder with the primary key, optionally 1831 * limiting to one level deep. 1832 * 1833 * @param repositoryId the primary key of the repository 1834 * @param folderId the primary key of the folder 1835 * @param recurse whether to recurse through each subfolder 1836 * @return the descendant folders of the folder with the primary key 1837 * @throws PortalException if the repository or parent folder could not be 1838 * found 1839 * @throws SystemException if a system exception occurred 1840 */ 1841 public List<Long> getSubfolderIds( 1842 long repositoryId, long folderId, boolean recurse) 1843 throws PortalException, SystemException { 1844 1845 Repository repository = getRepository(repositoryId); 1846 1847 return repository.getSubfolderIds(folderId, recurse); 1848 } 1849 1850 /** 1851 * Returns all the temporary file entry names. 1852 * 1853 * @param groupId the primary key of the group 1854 * @param folderId the primary key of the folder where the file entry will 1855 * eventually reside 1856 * @param tempFolderName the temporary folder's name 1857 * @return the temporary file entry names 1858 * @throws PortalException if the folder was invalid 1859 * @throws SystemException if a system exception occurred 1860 * @see #addTempFileEntry(long, long, String, String, File) 1861 * @see com.liferay.portal.kernel.util.TempFileUtil 1862 */ 1863 public String[] getTempFileEntryNames( 1864 long groupId, long folderId, String tempFolderName) 1865 throws PortalException, SystemException { 1866 1867 DLFolderPermission.check( 1868 getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT); 1869 1870 return TempFileUtil.getTempFileEntryNames(getUserId(), tempFolderName); 1871 } 1872 1873 /** 1874 * @deprecated {@link #checkOutFileEntry(long, ServiceContext)} 1875 */ 1876 public Lock lockFileEntry(long fileEntryId) 1877 throws PortalException, SystemException { 1878 1879 checkOutFileEntry(fileEntryId, new ServiceContext()); 1880 1881 FileEntry fileEntry = getFileEntry(fileEntryId); 1882 1883 return fileEntry.getLock(); 1884 } 1885 1886 /** 1887 * @deprecated {@link #checkOutFileEntry(long, String, long, 1888 * ServiceContext)} 1889 */ 1890 public Lock lockFileEntry( 1891 long fileEntryId, String owner, long expirationTime) 1892 throws PortalException, SystemException { 1893 1894 FileEntry fileEntry = checkOutFileEntry( 1895 fileEntryId, owner, expirationTime, new ServiceContext()); 1896 1897 return fileEntry.getLock(); 1898 } 1899 1900 /** 1901 * Locks the folder. This method is primarily used by WebDAV. 1902 * 1903 * @param repositoryId the primary key of the repository 1904 * @param folderId the primary key of the folder 1905 * @return the lock object 1906 * @throws PortalException if the repository or folder could not be found 1907 * @throws SystemException if a system exception occurred 1908 */ 1909 public Lock lockFolder(long repositoryId, long folderId) 1910 throws PortalException, SystemException { 1911 1912 Repository repository = getRepository(repositoryId); 1913 1914 return repository.lockFolder(folderId); 1915 } 1916 1917 /** 1918 * Locks the folder. This method is primarily used by WebDAV. 1919 * 1920 * @param repositoryId the primary key of the repository 1921 * @param folderId the primary key of the folder 1922 * @param owner the owner string for the checkout (optionally 1923 * <code>null</code>) 1924 * @param inheritable whether the lock must propagate to descendants 1925 * @param expirationTime the time in milliseconds before the lock expires. 1926 * If the value is <code>0</code>, the default expiration time will 1927 * be used from <code>portal.properties>. 1928 * @return the lock object 1929 * @throws PortalException if the repository or folder could not be found 1930 * @throws SystemException if a system exception occurred 1931 */ 1932 public Lock lockFolder( 1933 long repositoryId, long folderId, String owner, boolean inheritable, 1934 long expirationTime) 1935 throws PortalException, SystemException { 1936 1937 Repository repository = getRepository(repositoryId); 1938 1939 return repository.lockFolder( 1940 folderId, owner, inheritable, expirationTime); 1941 } 1942 1943 /** 1944 * Moves the file entry to the new folder. 1945 * 1946 * @param fileEntryId the primary key of the file entry 1947 * @param newFolderId the primary key of the new folder 1948 * @param serviceContext the service context to be applied 1949 * @return the file entry 1950 * @throws PortalException if the file entry or the new folder could not be 1951 * found 1952 * @throws SystemException if a system exception occurred 1953 */ 1954 public FileEntry moveFileEntry( 1955 long fileEntryId, long newFolderId, ServiceContext serviceContext) 1956 throws PortalException, SystemException { 1957 1958 Repository fromRepository = getRepository(0, fileEntryId, 0); 1959 Repository toRepository = getRepository(newFolderId, serviceContext); 1960 1961 if (newFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { 1962 Folder toFolder = toRepository.getFolder(newFolderId); 1963 1964 if (toFolder.isMountPoint()) { 1965 toRepository = getRepository(toFolder.getRepositoryId()); 1966 } 1967 } 1968 1969 if (fromRepository.getRepositoryId() == 1970 toRepository.getRepositoryId()) { 1971 1972 // Move file entries within repository 1973 1974 FileEntry fileEntry = fromRepository.moveFileEntry( 1975 fileEntryId, newFolderId, serviceContext); 1976 1977 return fileEntry; 1978 } 1979 1980 // Move file entries between repositories 1981 1982 return moveFileEntries( 1983 fileEntryId, newFolderId, fromRepository, toRepository, 1984 serviceContext); 1985 } 1986 1987 /** 1988 * Moves the folder to the new parent folder with the primary key. 1989 * 1990 * @param folderId the primary key of the folder 1991 * @param parentFolderId the primary key of the new parent folder 1992 * @param serviceContext the service context to be applied 1993 * @return the file entry 1994 * @throws PortalException if the folder could not be found 1995 * @throws SystemException if a system exception occurred 1996 */ 1997 public Folder moveFolder( 1998 long folderId, long parentFolderId, ServiceContext serviceContext) 1999 throws PortalException, SystemException { 2000 2001 Repository fromRepository = getRepository(folderId, 0, 0); 2002 Repository toRepository = getRepository(parentFolderId, serviceContext); 2003 2004 if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { 2005 Folder toFolder = toRepository.getFolder(parentFolderId); 2006 2007 if (toFolder.isMountPoint()) { 2008 toRepository = getRepository(toFolder.getRepositoryId()); 2009 } 2010 } 2011 2012 if (fromRepository.getRepositoryId() == 2013 toRepository.getRepositoryId()) { 2014 2015 // Move file entries within repository 2016 2017 Folder folder = fromRepository.moveFolder( 2018 folderId, parentFolderId, serviceContext); 2019 2020 return folder; 2021 } 2022 2023 // Move file entries between repositories 2024 2025 return moveFolders( 2026 folderId, parentFolderId, fromRepository, toRepository, 2027 serviceContext); 2028 } 2029 2030 /** 2031 * Refreshes the lock for the file entry. This method is primarily used by 2032 * WebDAV. 2033 * 2034 * @param lockUuid the lock's universally unique identifier 2035 * @param expirationTime the time in milliseconds before the lock expires. 2036 * If the value is <code>0</code>, the default expiration time will 2037 * be used from <code>portal.properties>. 2038 * @return the lock object 2039 * @throws PortalException if the file entry or lock could not be found 2040 * @throws SystemException if a system exception occurred 2041 */ 2042 public Lock refreshFileEntryLock(String lockUuid, long expirationTime) 2043 throws PortalException, SystemException { 2044 2045 Lock lock = lockLocalService.getLockByUuid(lockUuid); 2046 2047 long fileEntryId = GetterUtil.getLong(lock.getKey()); 2048 2049 Repository repository = getRepository(0, fileEntryId, 0); 2050 2051 return repository.refreshFileEntryLock(lockUuid, expirationTime); 2052 } 2053 2054 /** 2055 * Refreshes the lock for the folder. This method is primarily used by 2056 * WebDAV. 2057 * 2058 * @param lockUuid the lock's universally unique identifier 2059 * @param expirationTime the time in milliseconds before the lock expires. 2060 * If the value is <code>0</code>, the default expiration time will 2061 * be used from <code>portal.properties>. 2062 * @return the lock object 2063 * @throws PortalException if the folder or lock could not be found 2064 * @throws SystemException if a system exception occurred 2065 */ 2066 public Lock refreshFolderLock(String lockUuid, long expirationTime) 2067 throws PortalException, SystemException { 2068 2069 Lock lock = lockLocalService.getLockByUuid(lockUuid); 2070 2071 long folderId = GetterUtil.getLong(lock.getKey()); 2072 2073 Repository repository = getRepository(0, folderId, 0); 2074 2075 return repository.refreshFolderLock(lockUuid, expirationTime); 2076 } 2077 2078 /** 2079 * Reverts the file entry to a previous version. A new version will be 2080 * created based on the previous version and metadata. 2081 * 2082 * @param fileEntryId the primary key of the file entry 2083 * @param version the version to revert back to 2084 * @param serviceContext the service context to be applied 2085 * @throws PortalException if the file entry or version could not be found 2086 * @throws SystemException if a system exception occurred 2087 */ 2088 public void revertFileEntry( 2089 long fileEntryId, String version, ServiceContext serviceContext) 2090 throws PortalException, SystemException { 2091 2092 Repository repository = getRepository(0, fileEntryId, 0); 2093 2094 repository.revertFileEntry(fileEntryId, version, serviceContext); 2095 2096 FileEntry fileEntry = getFileEntry(fileEntryId); 2097 2098 dlAppHelperLocalService.updateFileEntry( 2099 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 2100 } 2101 2102 public Hits search(long repositoryId, SearchContext searchContext) 2103 throws SearchException { 2104 2105 try { 2106 Repository repository = getRepository(repositoryId); 2107 2108 return repository.search(searchContext); 2109 } 2110 catch (Exception e) { 2111 throw new SearchException(e); 2112 } 2113 } 2114 2115 public Hits search( 2116 long repositoryId, SearchContext searchContext, Query query) 2117 throws SearchException { 2118 2119 try { 2120 Repository repository = getRepository(repositoryId); 2121 2122 return repository.search(searchContext, query); 2123 } 2124 catch (Exception e) { 2125 throw new SearchException(e); 2126 } 2127 } 2128 2129 /** 2130 * @deprecated Use {@link #checkInFileEntry(long, boolean, String, 2131 * ServiceContext)}. 2132 */ 2133 public void unlockFileEntry(long fileEntryId) 2134 throws PortalException, SystemException { 2135 2136 checkInFileEntry( 2137 fileEntryId, false, StringPool.BLANK, new ServiceContext()); 2138 } 2139 2140 /** 2141 * @deprecated Use {@link #checkInFileEntry(long, String)}. 2142 */ 2143 public void unlockFileEntry(long fileEntryId, String lockUuid) 2144 throws PortalException, SystemException { 2145 2146 checkInFileEntry(fileEntryId, lockUuid); 2147 } 2148 2149 /** 2150 * Unlocks the folder. This method is primarily used by WebDAV. 2151 * 2152 * @param repositoryId the primary key of the repository 2153 * @param folderId the primary key of the folder 2154 * @param lockUuid the lock's universally unique identifier 2155 * @throws PortalException if the repository or folder could not be found 2156 * @throws SystemException if a system exception occurred 2157 */ 2158 public void unlockFolder(long repositoryId, long folderId, String lockUuid) 2159 throws PortalException, SystemException { 2160 2161 Repository repository = getRepository(repositoryId); 2162 2163 repository.unlockFolder(folderId, lockUuid); 2164 } 2165 2166 /** 2167 * Unlocks the folder. This method is primarily used by WebDAV. 2168 * 2169 * @param repositoryId the primary key of the repository 2170 * @param parentFolderId the primary key of the parent folder 2171 * @param name the folder's name 2172 * @param lockUuid the lock's universally unique identifier 2173 * @throws PortalException if the repository or folder could not be found 2174 * @throws SystemException if a system exception occurred 2175 */ 2176 public void unlockFolder( 2177 long repositoryId, long parentFolderId, String name, 2178 String lockUuid) 2179 throws PortalException, SystemException { 2180 2181 Repository repository = getRepository(repositoryId); 2182 2183 repository.unlockFolder(parentFolderId, name, lockUuid); 2184 } 2185 2186 /** 2187 * Updates a file entry and associated metadata based on a byte array 2188 * object. If the file data is <code>null</code>, then only the associated 2189 * metadata (i.e., <code>title</code>, <code>description</code>, and 2190 * parameters in the <code>serviceContext</code>) will be updated. 2191 * 2192 * <p> 2193 * This method takes two file names, the <code>sourceFileName</code> and the 2194 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 2195 * name of the actual file being uploaded. The <code>title</code> 2196 * corresponds to a name the client wishes to assign this file after it has 2197 * been uploaded to the portal. 2198 * </p> 2199 * 2200 * @param fileEntryId the primary key of the file entry 2201 * @param sourceFileName the original file's name (optionally 2202 * <code>null</code>) 2203 * @param mimeType the file's MIME type (optionally <code>null</code>) 2204 * @param title the new name to be assigned to the file (optionally <code> 2205 * <code>null</code></code>) 2206 * @param description the file's new description 2207 * @param changeLog the file's version change log (optionally 2208 * <code>null</code>) 2209 * @param majorVersion whether the new file version is a major version 2210 * @param bytes the file's data (optionally <code>null</code>) 2211 * @param serviceContext the service context to be applied. Can set the 2212 * asset category IDs, asset tag names, and expando bridge 2213 * attributes for the file entry. In a Liferay repository, it may 2214 * include: <ul> <li> fileEntryTypeId - ID for a custom file entry 2215 * type </li> <li> fieldsMap - mapping for fields associated with a 2216 * custom file entry type </li> </ul> 2217 * @return the file entry 2218 * @throws PortalException if the file entry could not be found 2219 * @throws SystemException if a system exception occurred 2220 */ 2221 public FileEntry updateFileEntry( 2222 long fileEntryId, String sourceFileName, String mimeType, 2223 String title, String description, String changeLog, 2224 boolean majorVersion, byte[] bytes, ServiceContext serviceContext) 2225 throws PortalException, SystemException { 2226 2227 File file = null; 2228 2229 try { 2230 if ((bytes != null) && (bytes.length > 0)) { 2231 file = FileUtil.createTempFile(bytes); 2232 } 2233 2234 return updateFileEntry( 2235 fileEntryId, sourceFileName, mimeType, title, description, 2236 changeLog, majorVersion, file, serviceContext); 2237 } 2238 catch (IOException ioe) { 2239 throw new SystemException("Unable to write temporary file", ioe); 2240 } 2241 finally { 2242 FileUtil.delete(file); 2243 } 2244 } 2245 2246 /** 2247 * Updates a file entry and associated metadata based on a {@link File} 2248 * object. If the file data is <code>null</code>, then only the associated 2249 * metadata (i.e., <code>title</code>, <code>description</code>, and 2250 * parameters in the <code>serviceContext</code>) will be updated. 2251 * 2252 * <p> 2253 * This method takes two file names, the <code>sourceFileName</code> and the 2254 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 2255 * name of the actual file being uploaded. The <code>title</code> 2256 * corresponds to a name the client wishes to assign this file after it has 2257 * been uploaded to the portal. 2258 * </p> 2259 * 2260 * @param fileEntryId the primary key of the file entry 2261 * @param sourceFileName the original file's name (optionally 2262 * <code>null</code>) 2263 * @param mimeType the file's MIME type (optionally <code>null</code>) 2264 * @param title the new name to be assigned to the file (optionally <code> 2265 * <code>null</code></code>) 2266 * @param description the file's new description 2267 * @param changeLog the file's version change log (optionally 2268 * <code>null</code>) 2269 * @param majorVersion whether the new file version is a major version 2270 * @param file EntryId the primary key of the file entry 2271 * @param serviceContext the service context to be applied. Can set the 2272 * asset category IDs, asset tag names, and expando bridge 2273 * attributes for the file entry. In a Liferay repository, it may 2274 * include: <ul> <li> fileEntryTypeId - ID for a custom file entry 2275 * type </li> <li> fieldsMap - mapping for fields associated with a 2276 * custom file entry type </li> </ul> 2277 * @return the file entry 2278 * @throws PortalException if the file entry could not be found 2279 * @throws SystemException if a system exception occurred 2280 */ 2281 public FileEntry updateFileEntry( 2282 long fileEntryId, String sourceFileName, String mimeType, 2283 String title, String description, String changeLog, 2284 boolean majorVersion, File file, ServiceContext serviceContext) 2285 throws PortalException, SystemException { 2286 2287 if ((file == null) || !file.exists() || (file.length() == 0)) { 2288 return updateFileEntry( 2289 fileEntryId, sourceFileName, mimeType, title, description, 2290 changeLog, majorVersion, null, 0, serviceContext); 2291 } 2292 2293 mimeType = DLAppUtil.getMimeType( 2294 sourceFileName, mimeType, title, file, null); 2295 2296 Repository repository = getRepository(0, fileEntryId, 0); 2297 2298 FileEntry fileEntry = repository.updateFileEntry( 2299 fileEntryId, sourceFileName, mimeType, title, description, 2300 changeLog, majorVersion, file, serviceContext); 2301 2302 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 2303 2304 dlAppHelperLocalService.updateFileEntry( 2305 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 2306 2307 return fileEntry; 2308 } 2309 2310 /** 2311 * Updates a file entry and associated metadata based on an {@link 2312 * InputStream} object. If the file data is <code>null</code>, then only the 2313 * associated metadata (i.e., <code>title</code>, <code>description</code>, 2314 * and parameters in the <code>serviceContext</code>) will be updated. 2315 * 2316 * <p> 2317 * This method takes two file names, the <code>sourceFileName</code> and the 2318 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 2319 * name of the actual file being uploaded. The <code>title</code> 2320 * corresponds to a name the client wishes to assign this file after it has 2321 * been uploaded to the portal. 2322 * </p> 2323 * 2324 * @param fileEntryId the primary key of the file entry 2325 * @param sourceFileName the original file's name (optionally 2326 * <code>null</code>) 2327 * @param mimeType the file's MIME type (optionally <code>null</code>) 2328 * @param title the new name to be assigned to the file (optionally <code> 2329 * <code>null</code></code>) 2330 * @param description the file's new description 2331 * @param changeLog the file's version change log (optionally 2332 * <code>null</code>) 2333 * @param majorVersion whether the new file version is a major version 2334 * @param is the file's data (optionally <code>null</code>) 2335 * @param size the file's size (optionally <code>0</code>) 2336 * @param serviceContext the service context to be applied. Can set the 2337 * asset category IDs, asset tag names, and expando bridge 2338 * attributes for the file entry. In a Liferay repository, it may 2339 * include: <ul> <li> fileEntryTypeId - ID for a custom file entry 2340 * type </li> <li> fieldsMap - mapping for fields associated with a 2341 * custom file entry type </li> </ul> 2342 * @return the file entry 2343 * @throws PortalException if the file entry could not be found 2344 * @throws SystemException if a system exception occurred 2345 */ 2346 public FileEntry updateFileEntry( 2347 long fileEntryId, String sourceFileName, String mimeType, 2348 String title, String description, String changeLog, 2349 boolean majorVersion, InputStream is, long size, 2350 ServiceContext serviceContext) 2351 throws PortalException, SystemException { 2352 2353 mimeType = DLAppUtil.getMimeType( 2354 sourceFileName, mimeType, title, null, is); 2355 2356 Repository repository = getRepository(0, fileEntryId, 0); 2357 2358 FileEntry fileEntry = repository.updateFileEntry( 2359 fileEntryId, sourceFileName, mimeType, title, description, 2360 changeLog, majorVersion, is, size, serviceContext); 2361 2362 if (is != null) { 2363 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 2364 } 2365 2366 dlAppHelperLocalService.updateFileEntry( 2367 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 2368 2369 return fileEntry; 2370 } 2371 2372 public FileEntry updateFileEntryAndCheckIn( 2373 long fileEntryId, String sourceFileName, String mimeType, 2374 String title, String description, String changeLog, 2375 boolean majorVersion, File file, ServiceContext serviceContext) 2376 throws PortalException, SystemException { 2377 2378 if ((file == null) || !file.exists() || (file.length() == 0)) { 2379 return updateFileEntryAndCheckIn( 2380 fileEntryId, sourceFileName, mimeType, title, description, 2381 changeLog, majorVersion, null, 0, serviceContext); 2382 } 2383 2384 Repository repository = getRepository(0, fileEntryId, 0); 2385 2386 FileEntry fileEntry = repository.updateFileEntry( 2387 fileEntryId, sourceFileName, mimeType, title, description, 2388 changeLog, majorVersion, file, serviceContext); 2389 2390 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 2391 2392 repository.checkInFileEntry( 2393 fileEntryId, majorVersion, changeLog, serviceContext); 2394 2395 dlAppHelperLocalService.updateFileEntry( 2396 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 2397 2398 return fileEntry; 2399 } 2400 2401 public FileEntry updateFileEntryAndCheckIn( 2402 long fileEntryId, String sourceFileName, String mimeType, 2403 String title, String description, String changeLog, 2404 boolean majorVersion, InputStream is, long size, 2405 ServiceContext serviceContext) 2406 throws PortalException, SystemException { 2407 2408 Repository repository = getRepository(0, fileEntryId, 0); 2409 2410 FileEntry fileEntry = repository.updateFileEntry( 2411 fileEntryId, sourceFileName, mimeType, title, description, 2412 changeLog, majorVersion, is, size, serviceContext); 2413 2414 if (is != null) { 2415 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 2416 } 2417 2418 repository.checkInFileEntry( 2419 fileEntryId, majorVersion, changeLog, serviceContext); 2420 2421 dlAppHelperLocalService.updateFileEntry( 2422 getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext); 2423 2424 return fileEntry; 2425 } 2426 2427 /** 2428 * Updates a file shortcut to the existing file entry. This method is only 2429 * supported by the Liferay repository. 2430 * 2431 * @param fileShortcutId the primary key of the file shortcut 2432 * @param folderId the primary key of the file shortcut's parent folder 2433 * @param toFileEntryId the primary key of the file shortcut's file entry 2434 * @param serviceContext the service context to be applied. Can set the 2435 * asset category IDs, asset tag names, and expando bridge 2436 * attributes for the file entry. 2437 * @return the file shortcut 2438 * @throws PortalException if the file shortcut, folder, or file entry could 2439 * not be found 2440 * @throws SystemException if a system exception occurred 2441 */ 2442 public DLFileShortcut updateFileShortcut( 2443 long fileShortcutId, long folderId, long toFileEntryId, 2444 ServiceContext serviceContext) 2445 throws PortalException, SystemException { 2446 2447 return dlFileShortcutService.updateFileShortcut( 2448 fileShortcutId, folderId, toFileEntryId, serviceContext); 2449 } 2450 2451 /** 2452 * Updates the folder. 2453 * 2454 * @param folderId the primary key of the folder 2455 * @param name the folder's new name 2456 * @param description the folder's new description 2457 * @param serviceContext the service context to be applied. In a Liferay 2458 * repository, it may include: <ul> <li> defaultFileEntryTypeId - 2459 * the file entry type to default all Liferay file entries to </li> 2460 * <li> dlFileEntryTypesSearchContainerPrimaryKeys - a 2461 * comma-delimited list of file entry type primary keys allowed in 2462 * the given folder and all descendants </li> <li> 2463 * overrideFileEntryTypes - boolean specifying whether to override 2464 * ancestral folder's restriction of file entry types allowed </li> 2465 * <li> workflowDefinitionXYZ - the workflow definition name 2466 * specified per file entry type. The parameter name must be the 2467 * string <code>workflowDefinition</code> appended by the <code> 2468 * fileEntryTypeId</code> (optionally <code>0</code>). </li> </ul> 2469 * @return the folder 2470 * @throws PortalException if the current or new parent folder could not be 2471 * found or if the new parent folder's information was invalid 2472 * @throws SystemException if a system exception occurred 2473 */ 2474 public Folder updateFolder( 2475 long folderId, String name, String description, 2476 ServiceContext serviceContext) 2477 throws PortalException, SystemException { 2478 2479 Repository repository = null; 2480 2481 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { 2482 repository = getRepository(serviceContext.getScopeGroupId()); 2483 } 2484 else { 2485 repository = getRepository(folderId, 0, 0); 2486 } 2487 2488 return repository.updateFolder( 2489 folderId, name, description, serviceContext); 2490 } 2491 2492 /** 2493 * Returns <code>true</code> if the file entry is checked out. This method 2494 * is primarily used by WebDAV. 2495 * 2496 * @param repositoryId the primary key for the repository 2497 * @param fileEntryId the primary key for the file entry 2498 * @param lockUuid the lock's universally unique identifier 2499 * @return <code>true</code> if the file entry is checked out; 2500 * <code>false</code> otherwise 2501 * @throws PortalException if the file entry could not be found 2502 * @throws SystemException if a system exception occurred 2503 */ 2504 public boolean verifyFileEntryCheckOut( 2505 long repositoryId, long fileEntryId, String lockUuid) 2506 throws PortalException, SystemException { 2507 2508 Repository repository = getRepository(repositoryId); 2509 2510 return repository.verifyFileEntryCheckOut(fileEntryId, lockUuid); 2511 } 2512 2513 public boolean verifyFileEntryLock( 2514 long repositoryId, long fileEntryId, String lockUuid) 2515 throws PortalException, SystemException { 2516 2517 Repository repository = getRepository(repositoryId); 2518 2519 return repository.verifyFileEntryLock(fileEntryId, lockUuid); 2520 } 2521 2522 /** 2523 * Returns <code>true</code> if the inheritable lock exists. This method is 2524 * primarily used by WebDAV. 2525 * 2526 * @param repositoryId the primary key for the repository 2527 * @param folderId the primary key for the folder 2528 * @param lockUuid the lock's universally unique identifier 2529 * @return <code>true</code> if the inheritable lock exists; 2530 * <code>false</code> otherwise 2531 * @throws PortalException if the folder could not be found 2532 * @throws SystemException if a system exception occurred 2533 */ 2534 public boolean verifyInheritableLock( 2535 long repositoryId, long folderId, String lockUuid) 2536 throws PortalException, SystemException { 2537 2538 Repository repository = getRepository(repositoryId); 2539 2540 return repository.verifyInheritableLock(folderId, lockUuid); 2541 } 2542 2543 protected FileEntry copyFileEntry( 2544 Repository toRepository, FileEntry fileEntry, long newFolderId, 2545 ServiceContext serviceContext) 2546 throws PortalException, SystemException { 2547 2548 List<FileVersion> fileVersions = fileEntry.getFileVersions( 2549 WorkflowConstants.STATUS_ANY); 2550 2551 FileVersion latestFileVersion = fileVersions.get( 2552 fileVersions.size() - 1); 2553 2554 FileEntry destinationFileEntry = toRepository.addFileEntry( 2555 newFolderId, fileEntry.getTitle(), latestFileVersion.getMimeType(), 2556 latestFileVersion.getTitle(), latestFileVersion.getDescription(), 2557 StringPool.BLANK, latestFileVersion.getContentStream(false), 2558 latestFileVersion.getSize(), serviceContext); 2559 2560 for (int i = fileVersions.size() - 2; i >= 0 ; i--) { 2561 FileVersion fileVersion = fileVersions.get(i); 2562 2563 FileVersion previousFileVersion = fileVersions.get(i + 1); 2564 2565 try { 2566 destinationFileEntry = toRepository.updateFileEntry( 2567 destinationFileEntry.getFileEntryId(), fileEntry.getTitle(), 2568 destinationFileEntry.getMimeType(), 2569 destinationFileEntry.getTitle(), 2570 destinationFileEntry.getDescription(), StringPool.BLANK, 2571 DLAppUtil.isMajorVersion(previousFileVersion, fileVersion), 2572 fileVersion.getContentStream(false), fileVersion.getSize(), 2573 serviceContext); 2574 } 2575 catch (PortalException pe) { 2576 toRepository.deleteFileEntry( 2577 destinationFileEntry.getFileEntryId()); 2578 2579 throw pe; 2580 } 2581 } 2582 2583 dlAppHelperLocalService.addFileEntry( 2584 getUserId(), destinationFileEntry, 2585 destinationFileEntry.getFileVersion(), serviceContext); 2586 2587 return destinationFileEntry; 2588 } 2589 2590 protected void copyFolder( 2591 Repository repository, Folder srcFolder, Folder destFolder, 2592 ServiceContext serviceContext) 2593 throws PortalException, SystemException { 2594 2595 Queue<Folder[]> folders = new LinkedList<Folder[]>(); 2596 final List<FileEntry> fileEntries = new ArrayList<FileEntry>(); 2597 2598 Folder curSrcFolder = srcFolder; 2599 Folder curDestFolder = destFolder; 2600 2601 while (true) { 2602 List<FileEntry> srcFileEntries = repository.getFileEntries( 2603 curSrcFolder.getFolderId(), QueryUtil.ALL_POS, 2604 QueryUtil.ALL_POS, null); 2605 2606 for (FileEntry srcFileEntry : srcFileEntries) { 2607 try { 2608 FileEntry fileEntry = repository.copyFileEntry( 2609 curDestFolder.getGroupId(), 2610 srcFileEntry.getFileEntryId(), 2611 curDestFolder.getFolderId(), serviceContext); 2612 2613 dlAppHelperLocalService.addFileEntry( 2614 getUserId(), fileEntry, fileEntry.getFileVersion(), 2615 serviceContext); 2616 2617 fileEntries.add(fileEntry); 2618 } 2619 catch (Exception e) { 2620 _log.error(e, e); 2621 2622 continue; 2623 } 2624 } 2625 2626 List<Folder> srcSubfolders = repository.getFolders( 2627 curSrcFolder.getFolderId(), false, QueryUtil.ALL_POS, 2628 QueryUtil.ALL_POS, null); 2629 2630 for (Folder srcSubfolder : srcSubfolders) { 2631 Folder destSubfolder = repository.addFolder( 2632 curDestFolder.getFolderId(), srcSubfolder.getName(), 2633 srcSubfolder.getDescription(), serviceContext); 2634 2635 folders.offer(new Folder[] {srcSubfolder, destSubfolder}); 2636 } 2637 2638 Folder[] next = folders.poll(); 2639 2640 if (next == null) { 2641 break; 2642 } 2643 else { 2644 curSrcFolder = next[0]; 2645 curDestFolder = next[1]; 2646 } 2647 } 2648 2649 TransactionCommitCallbackUtil.registerCallback( 2650 new Callable<Void>() { 2651 2652 public Void call() throws Exception { 2653 for (FileEntry fileEntry : fileEntries) { 2654 DLProcessorRegistryUtil.trigger(fileEntry); 2655 } 2656 2657 return null; 2658 } 2659 2660 }); 2661 } 2662 2663 protected void deleteFileEntry( 2664 long oldFileEntryId, long newFileEntryId, Repository fromRepository, 2665 Repository toRepository) 2666 throws PortalException, SystemException { 2667 2668 try { 2669 FileEntry fileEntry = fromRepository.getFileEntry(oldFileEntryId); 2670 2671 dlAppHelperLocalService.deleteFileEntry(fileEntry); 2672 2673 fromRepository.deleteFileEntry(oldFileEntryId); 2674 } 2675 catch (PortalException pe) { 2676 FileEntry fileEntry = toRepository.getFileEntry(newFileEntryId); 2677 2678 toRepository.deleteFileEntry(newFileEntryId); 2679 2680 dlAppHelperLocalService.deleteFileEntry(fileEntry); 2681 2682 throw pe; 2683 } 2684 } 2685 2686 protected Repository getRepository(long repositoryId) 2687 throws PortalException, SystemException { 2688 2689 return repositoryService.getRepositoryImpl(repositoryId); 2690 } 2691 2692 protected Repository getRepository( 2693 long folderId, long fileEntryId, long fileVersionId) 2694 throws PortalException, SystemException { 2695 2696 return repositoryService.getRepositoryImpl( 2697 folderId, fileEntryId, fileVersionId); 2698 } 2699 2700 protected Repository getRepository( 2701 long folderId, ServiceContext serviceContext) 2702 throws PortalException, SystemException { 2703 2704 Repository repository = null; 2705 2706 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { 2707 repository = getRepository(serviceContext.getScopeGroupId()); 2708 } 2709 else { 2710 repository = getRepository(folderId, 0, 0); 2711 } 2712 2713 return repository; 2714 } 2715 2716 protected FileEntry moveFileEntries( 2717 long fileEntryId, long newFolderId, Repository fromRepository, 2718 Repository toRepository, ServiceContext serviceContext) 2719 throws PortalException, SystemException { 2720 2721 FileEntry sourceFileEntry = fromRepository.getFileEntry(fileEntryId); 2722 2723 FileEntry destinationFileEntry = copyFileEntry( 2724 toRepository, sourceFileEntry, newFolderId, serviceContext); 2725 2726 deleteFileEntry( 2727 fileEntryId, destinationFileEntry.getFileEntryId(), fromRepository, 2728 toRepository); 2729 2730 return destinationFileEntry; 2731 } 2732 2733 protected Folder moveFolders( 2734 long folderId, long parentFolderId, Repository fromRepository, 2735 Repository toRepository, ServiceContext serviceContext) 2736 throws PortalException, SystemException { 2737 2738 Folder folder = fromRepository.getFolder(folderId); 2739 2740 Folder newFolder = toRepository.addFolder( 2741 parentFolderId, folder.getName(), folder.getDescription(), 2742 serviceContext); 2743 2744 List<Object> foldersAndFileEntriesAndFileShortcuts = 2745 getFoldersAndFileEntriesAndFileShortcuts( 2746 fromRepository.getRepositoryId(), folderId, 2747 WorkflowConstants.STATUS_ANY, true, QueryUtil.ALL_POS, 2748 QueryUtil.ALL_POS); 2749 2750 try { 2751 for (Object folderAndFileEntryAndFileShortcut : 2752 foldersAndFileEntriesAndFileShortcuts) { 2753 2754 if (folderAndFileEntryAndFileShortcut instanceof FileEntry) { 2755 FileEntry fileEntry = 2756 (FileEntry)folderAndFileEntryAndFileShortcut; 2757 2758 copyFileEntry( 2759 toRepository, fileEntry, newFolder.getFolderId(), 2760 serviceContext); 2761 } 2762 else if (folderAndFileEntryAndFileShortcut instanceof Folder) { 2763 Folder currentFolder = 2764 (Folder)folderAndFileEntryAndFileShortcut; 2765 2766 moveFolders( 2767 currentFolder.getFolderId(), newFolder.getFolderId(), 2768 fromRepository, toRepository, serviceContext); 2769 2770 } 2771 else if (folderAndFileEntryAndFileShortcut 2772 instanceof DLFileShortcut) { 2773 2774 if (newFolder.isSupportsShortcuts()) { 2775 DLFileShortcut dlFileShorcut = 2776 (DLFileShortcut)folderAndFileEntryAndFileShortcut; 2777 2778 dlFileShortcutService.addFileShortcut( 2779 dlFileShorcut.getGroupId(), newFolder.getFolderId(), 2780 dlFileShorcut.getToFileEntryId(), serviceContext); 2781 } 2782 } 2783 } 2784 } 2785 catch (PortalException pe) { 2786 toRepository.deleteFolder(newFolder.getFolderId()); 2787 2788 throw pe; 2789 } 2790 2791 try { 2792 fromRepository.deleteFolder(folderId); 2793 } 2794 catch (PortalException pe) { 2795 toRepository.deleteFolder(newFolder.getFolderId()); 2796 2797 throw pe; 2798 } 2799 2800 return newFolder; 2801 } 2802 2803 private static Log _log = LogFactoryUtil.getLog(DLAppServiceImpl.class); 2804 2805 }