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