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