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