001 /** 002 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 013 */ 014 015 package com.liferay.portlet.documentlibrary.service.impl; 016 017 import com.liferay.portal.kernel.dao.orm.QueryUtil; 018 import com.liferay.portal.kernel.exception.PortalException; 019 import com.liferay.portal.kernel.exception.SystemException; 020 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream; 021 import com.liferay.portal.kernel.repository.LocalRepository; 022 import com.liferay.portal.kernel.repository.model.FileEntry; 023 import com.liferay.portal.kernel.repository.model.FileVersion; 024 import com.liferay.portal.kernel.repository.model.Folder; 025 import com.liferay.portal.kernel.util.FileUtil; 026 import com.liferay.portal.kernel.util.GetterUtil; 027 import com.liferay.portal.kernel.util.OrderByComparator; 028 import com.liferay.portal.kernel.util.StringBundler; 029 import com.liferay.portal.kernel.util.StringPool; 030 import com.liferay.portal.kernel.workflow.WorkflowConstants; 031 import com.liferay.portal.repository.liferayrepository.model.LiferayFolder; 032 import com.liferay.portal.service.ServiceContext; 033 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException; 034 import com.liferay.portlet.documentlibrary.model.DLFileRank; 035 import com.liferay.portlet.documentlibrary.model.DLFileShortcut; 036 import com.liferay.portlet.documentlibrary.model.DLFolder; 037 import com.liferay.portlet.documentlibrary.model.DLFolderConstants; 038 import com.liferay.portlet.documentlibrary.service.base.DLAppLocalServiceBaseImpl; 039 import com.liferay.portlet.documentlibrary.util.DLProcessorRegistryUtil; 040 041 import java.io.File; 042 import java.io.IOException; 043 import java.io.InputStream; 044 045 import java.util.List; 046 047 /** 048 * The document library local service. All portlets should interact with the 049 * document library through this class or through {@link DLAppServiceImpl}, 050 * rather than through the individual document library service classes. 051 * 052 * <p> 053 * This class provides a unified interface to all Liferay and third party 054 * repositories. While the method signatures are universal for all repositories. 055 * Additional implementation-specific parameters may be specified in the 056 * serviceContext. 057 * </p> 058 * 059 * <p> 060 * The <code>repositoryId</code> parameter used by most of the methods is the 061 * primary key of the specific repository. If the repository is a default 062 * Liferay repository, the <code>repositoryId</code> is the <code>groupId</code> 063 * or <code>scopeGroupId</code>. Otherwise, the <code>repositoryId</code> will 064 * correspond to values obtained from {@link RepositoryServiceUtil}. 065 * </p> 066 * 067 * @author Alexander Chow 068 * @author Mika Koivisto 069 * @see DLAppServiceImpl 070 */ 071 public class DLAppLocalServiceImpl extends DLAppLocalServiceBaseImpl { 072 073 /** 074 * Adds a file entry and associated metadata based on a byte array. 075 * 076 * <p> 077 * This method takes two file names, the <code>sourceFileName</code> and the 078 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 079 * name of the actual file being uploaded. The <code>title</code> 080 * corresponds to a name the client wishes to assign this file after it has 081 * been uploaded to the portal. If it is <code>null</code>, the <code> 082 * sourceFileName</code> will be used. 083 * </p> 084 * 085 * @param userId the primary key of the file entry's creator/owner 086 * @param repositoryId the primary key of the file entry's repository 087 * @param folderId the primary key of the file entry's parent folder 088 * @param sourceFileName the original file's name 089 * @param mimeType the file's MIME type 090 * @param title the name to be assigned to the file (optionally <code>null 091 * </code>) 092 * @param description the file's description 093 * @param changeLog the file's version change log 094 * @param bytes the file's data (optionally <code>null</code>) 095 * @param serviceContext the service context to be applied. Can specify the 096 * file entry's asset category IDs, asset tag names, and expando 097 * bridge attributes. In a Liferay repository, it may include: 098 * 099 * <ul> 100 * <li> 101 * fileEntryTypeId - ID for a custom file entry type 102 * </li> 103 * <li> 104 * fieldsMap - mapping for fields associated with a custom file 105 * entry type 106 * </li> 107 * </ul> 108 * 109 * @return the file entry 110 * @throws PortalException if the parent folder could not be 111 * found or if the file entry's information was invalid 112 * @throws SystemException if a system exception occurred 113 */ 114 public FileEntry addFileEntry( 115 long userId, long repositoryId, long folderId, 116 String sourceFileName, String mimeType, String title, 117 String description, String changeLog, byte[] bytes, 118 ServiceContext serviceContext) 119 throws PortalException, SystemException { 120 121 File file = null; 122 123 try { 124 if ((bytes != null) && (bytes.length > 0)) { 125 file = FileUtil.createTempFile(bytes); 126 } 127 128 return addFileEntry( 129 userId, repositoryId, folderId, sourceFileName, mimeType, title, 130 description, changeLog, file, serviceContext); 131 } 132 catch (IOException ioe) { 133 throw new SystemException("Unable to write temporary file", ioe); 134 } 135 finally { 136 FileUtil.delete(file); 137 } 138 } 139 140 /** 141 * Adds a file entry and associated metadata based on a {@link File} object. 142 * 143 * <p> 144 * This method takes two file names, the <code>sourceFileName</code> and the 145 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 146 * name of the actual file being uploaded. The <code>title</code> 147 * corresponds to a name the client wishes to assign this file after it has 148 * been uploaded to the portal. If it is <code>null</code>, the <code> 149 * sourceFileName</code> will be used. 150 * </p> 151 * 152 * @param userId the primary key of the file entry's creator/owner 153 * @param repositoryId the primary key of the repository 154 * @param folderId the primary key of the file entry's parent folder 155 * @param sourceFileName the original file's name 156 * @param mimeType the file's MIME type 157 * @param title the name to be assigned to the file (optionally <code>null 158 * </code>) 159 * @param description the file's description 160 * @param changeLog the file's version change log 161 * @param file the file's data (optionally <code>null</code>) 162 * @param serviceContext the service context to be applied. Can specify the 163 * file entry's asset category IDs, asset tag names, and expando 164 * bridge attributes. In a Liferay repository, it may include: 165 * 166 * <ul> 167 * <li> 168 * fileEntryTypeId - ID for a custom file entry type 169 * </li> 170 * <li> 171 * fieldsMap - mapping for fields associated with a custom file 172 * entry type 173 * </li> 174 * </ul> 175 * 176 * @return the file entry 177 * @throws PortalException if the parent folder could not be 178 * found or if the file entry's information was invalid 179 * @throws SystemException if a system exception occurred 180 */ 181 public FileEntry addFileEntry( 182 long userId, long repositoryId, long folderId, 183 String sourceFileName, String mimeType, String title, 184 String description, String changeLog, File file, 185 ServiceContext serviceContext) 186 throws PortalException, SystemException { 187 188 if (file == null || !file.exists() || (file.length() == 0)) { 189 return addFileEntry( 190 userId, repositoryId, folderId, sourceFileName, mimeType, title, 191 description, changeLog, null, 0, serviceContext); 192 } 193 194 LocalRepository localRepository = getLocalRepository(repositoryId); 195 196 FileEntry fileEntry = localRepository.addFileEntry( 197 userId, folderId, sourceFileName, mimeType, title, description, 198 changeLog, file, serviceContext); 199 200 dlAppHelperLocalService.addFileEntry( 201 userId, fileEntry, fileEntry.getFileVersion(), serviceContext); 202 203 return fileEntry; 204 } 205 206 /** 207 * Adds a file entry and associated metadata based on an {@link InputStream} 208 * object. 209 * 210 * <p> 211 * This method takes two file names, the <code>sourceFileName</code> and the 212 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 213 * name of the actual file being uploaded. The <code>title</code> 214 * corresponds to a name the client wishes to assign this file after it has 215 * been uploaded to the portal. If it is <code>null</code>, the <code> 216 * sourceFileName</code> will be used. 217 * </p> 218 * 219 * @param userId the primary key of the file entry's creator/owner 220 * @param repositoryId the primary key of the repository 221 * @param folderId the primary key of the file entry's parent folder 222 * @param sourceFileName the original file's name 223 * @param mimeType the file's MIME type 224 * @param title the name to be assigned to the file (optionally <code>null 225 * </code>) 226 * @param description the file's description 227 * @param changeLog the file's version change log 228 * @param is the file's data (optionally <code>null</code>) 229 * @param size the file's size (optionally <code>0</code>) 230 * @param serviceContext the service context to be applied. Can specify the 231 * file entry's asset category IDs, asset tag names, and expando 232 * bridge attributes. In a Liferay repository, it may include: 233 * 234 * <ul> 235 * <li> 236 * fileEntryTypeId - ID for a custom file entry type 237 * </li> 238 * <li> 239 * fieldsMap - mapping for fields associated with a custom file 240 * entry type 241 * </li> 242 * </ul> 243 * 244 * @return the file entry 245 * @throws PortalException if the parent folder could not 246 * be found or if the file entry's information was invalid 247 * @throws SystemException if a system exception occurred 248 */ 249 public FileEntry addFileEntry( 250 long userId, long repositoryId, long folderId, 251 String sourceFileName, String mimeType, String title, 252 String description, String changeLog, InputStream is, long size, 253 ServiceContext serviceContext) 254 throws PortalException, SystemException { 255 256 if (is == null) { 257 is = new UnsyncByteArrayInputStream(new byte[0]); 258 size = 0; 259 } 260 261 LocalRepository localRepository = getLocalRepository(repositoryId); 262 263 FileEntry fileEntry = localRepository.addFileEntry( 264 userId, folderId, sourceFileName, mimeType, title, description, 265 changeLog, is, size, serviceContext); 266 267 dlAppHelperLocalService.addFileEntry( 268 userId, fileEntry, fileEntry.getFileVersion(), serviceContext); 269 270 return fileEntry; 271 } 272 273 /** 274 * Adds the file rank to the existing file entry. This method is only 275 * supported by the Liferay repository. 276 * 277 * @param repositoryId the primary key of the repository 278 * @param companyId the primary key of the company 279 * @param userId the primary key of the file rank's creator/owner 280 * @param fileEntryId the primary key of the file entry 281 * @param serviceContext the service context to be applied 282 * @return the file rank 283 * @throws SystemException if a system exception occurred 284 */ 285 public DLFileRank addFileRank( 286 long repositoryId, long companyId, long userId, long fileEntryId, 287 ServiceContext serviceContext) 288 throws SystemException { 289 290 return dlFileRankLocalService.addFileRank( 291 repositoryId, companyId, userId, fileEntryId, serviceContext); 292 } 293 294 /** 295 * Adds the file shortcut to the existing file entry. This method is only 296 * supported by the Liferay repository. 297 * 298 * @param userId the primary key of the file shortcut's creator/owner 299 * @param repositoryId the primary key of the repository 300 * @param folderId the primary key of the file shortcut's parent folder 301 * @param toFileEntryId the primary key of the file entry to point to 302 * @param serviceContext the service context to be applied. Can specify the 303 * file entry's asset category IDs, asset tag names, and expando 304 * bridge attributes. 305 * @return the file shortcut 306 * @throws PortalException if the parent folder or file entry could not be 307 * found, or if the file shortcut's information was invalid 308 * @throws SystemException if a system exception occurred 309 */ 310 public DLFileShortcut addFileShortcut( 311 long userId, long repositoryId, long folderId, long toFileEntryId, 312 ServiceContext serviceContext) 313 throws PortalException, SystemException { 314 315 return dlFileShortcutLocalService.addFileShortcut( 316 userId, repositoryId, folderId, toFileEntryId, serviceContext); 317 } 318 319 /** 320 * Adds a folder. 321 * 322 * @param userId the primary key of the folder's creator/owner 323 * @param repositoryId the primary key of the repository 324 * @param parentFolderId the primary key of the folder's parent folder 325 * @param name the folder's name 326 * @param description the folder's description 327 * @param serviceContext the service context to be applied. In a Liferay 328 * repository, it may include mountPoint which is a boolean 329 * specifying whether the folder is a facade for mounting a 330 * third-party repository 331 * @return the folder 332 * @throws PortalException if the parent folder could not 333 * be found or if the new folder's information was invalid 334 * @throws SystemException if a system exception occurred 335 */ 336 public Folder addFolder( 337 long userId, long repositoryId, long parentFolderId, String name, 338 String description, ServiceContext serviceContext) 339 throws PortalException, SystemException { 340 341 LocalRepository localRepository = getLocalRepository(repositoryId); 342 343 return localRepository.addFolder( 344 userId, parentFolderId, name, description, serviceContext); 345 } 346 347 /** 348 * Delete all data associated to the given repository. This method is only 349 * supported by the Liferay repository. 350 * 351 * @param repositoryId the primary key of the data's repository 352 * @throws PortalException if the repository could not be 353 * found 354 * @throws SystemException if a system exception occurred 355 */ 356 public void deleteAll(long repositoryId) 357 throws PortalException, SystemException { 358 359 LocalRepository localRepository = getLocalRepository(repositoryId); 360 361 localRepository.deleteAll(); 362 } 363 364 /** 365 * Deletes the file entry. 366 * 367 * @param fileEntryId the primary key of the file entry 368 * @throws PortalException if the file entry could not be 369 * found 370 * @throws SystemException if a system exception occurred 371 */ 372 public void deleteFileEntry(long fileEntryId) 373 throws PortalException, SystemException { 374 375 LocalRepository localRepository = getLocalRepository(0, fileEntryId, 0); 376 377 FileEntry fileEntry = localRepository.getFileEntry(fileEntryId); 378 379 localRepository.deleteFileEntry(fileEntryId); 380 381 dlAppHelperLocalService.deleteFileEntry(fileEntry); 382 } 383 384 /** 385 * Deletes the file ranks associated to a given file entry. This method is 386 * only supported by the Liferay repository. 387 * 388 * @param fileEntryId the primary key of the file entry 389 * @throws SystemException if a system exception occurred 390 */ 391 public void deleteFileRanksByFileEntryId(long fileEntryId) 392 throws SystemException { 393 394 dlFileRankLocalService.deleteFileRanksByFileEntryId(fileEntryId); 395 } 396 397 /** 398 * Deletes the file ranks associated to a given user. This method is only 399 * supported by the Liferay repository. 400 * 401 * @param userId the primary key of the user 402 * @throws SystemException if a system exception occurred 403 */ 404 public void deleteFileRanksByUserId(long userId) throws SystemException { 405 dlFileRankLocalService.deleteFileRanksByUserId(userId); 406 } 407 408 /** 409 * Deletes the file shortcut. This method is only supported by the Liferay 410 * repository. 411 * 412 * @param dlFileShortcut the file shortcut 413 * @throws PortalException if the file shortcut could not be found 414 * @throws SystemException if a system exception occurred 415 */ 416 public void deleteFileShortcut(DLFileShortcut dlFileShortcut) 417 throws PortalException, SystemException { 418 419 dlFileShortcutLocalService.deleteFileShortcut(dlFileShortcut); 420 } 421 422 /** 423 * Deletes the file shortcut. This method is only supported by the Liferay 424 * repository. 425 * 426 * @param fileShortcutId the primary key of the file shortcut 427 * @throws PortalException if the file shortcut could not 428 * be found 429 * @throws SystemException if a system exception occurred 430 */ 431 public void deleteFileShortcut(long fileShortcutId) 432 throws PortalException, SystemException { 433 434 dlFileShortcutLocalService.deleteDLFileShortcut(fileShortcutId); 435 } 436 437 /** 438 * Deletes all file shortcuts associated to the file entry. This method is 439 * only supported by the Liferay repository. 440 * 441 * @param toFileEntryId the primary key of the associated file entry 442 * @throws PortalException if the file shortcut for the file entry could not be found 443 * @throws SystemException if a system exception occurred 444 */ 445 public void deleteFileShortcuts(long toFileEntryId) 446 throws PortalException, SystemException { 447 448 dlFileShortcutLocalService.deleteFileShortcuts(toFileEntryId); 449 } 450 451 /** 452 * Deletes the folder and all of its subfolders and file entries. 453 * 454 * @param folderId the primary key of the folder 455 * @throws PortalException if the folder could not be 456 * found 457 * @throws SystemException if a system exception occurred 458 */ 459 public void deleteFolder(long folderId) 460 throws PortalException, SystemException { 461 462 LocalRepository localRepository = getLocalRepository(folderId, 0, 0); 463 464 localRepository.deleteFolder(folderId); 465 } 466 467 /** 468 * Returns the file entries in the folder. 469 * 470 * @param repositoryId the primary key of the file entry's repository 471 * @param folderId the primary key of the file entry's folder 472 * @return the file entries in the folder 473 * @throws PortalException if the folder could not be 474 * found 475 * @throws SystemException if a system exception occurred 476 */ 477 public List<FileEntry> getFileEntries(long repositoryId, long folderId) 478 throws PortalException, SystemException { 479 480 return getFileEntries( 481 repositoryId, folderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 482 } 483 484 /** 485 * Returns a range of all the file entries in the folder. 486 * 487 * <p> 488 * Useful when paginating results. Returns a maximum of <code>end - 489 * start</code> instances. <code>start</code> and <code>end</code> are not 490 * primary keys, they are indexes in the result set. Thus, <code>0</code> 491 * refers to the first result in the set. Setting both <code>start</code> 492 * and <code>end</code> to {@link 493 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 494 * result set. 495 * </p> 496 * 497 * @param repositoryId the primary key of the file entry's repository 498 * @param folderId the primary key of the file entry's folder 499 * @param start the lower bound of the range of results 500 * @param end the upper bound of the range of results (not inclusive) 501 * @return the range of file entries in the folder 502 * @throws PortalException if the folder could not be 503 * found 504 * @throws SystemException if a system exception occurred 505 */ 506 public List<FileEntry> getFileEntries( 507 long repositoryId, long folderId, int start, int end) 508 throws PortalException, SystemException { 509 510 return getFileEntries(repositoryId, folderId, start, end, null); 511 } 512 513 /** 514 * Returns an ordered range of all the file entries in the folder. 515 * 516 * <p> 517 * Useful when paginating results. Returns a maximum of <code>end - 518 * start</code> instances. <code>start</code> and <code>end</code> are not 519 * primary keys, they are indexes in the result set. Thus, <code>0</code> 520 * refers to the first result in the set. Setting both <code>start</code> 521 * and <code>end</code> to {@link 522 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 523 * result set. 524 * </p> 525 * 526 * @param repositoryId the primary key of the file entry's repository 527 * @param folderId the primary key of the file entry's folder 528 * @param start the lower bound of the range of results 529 * @param end the upper bound of the range of results (not inclusive) 530 * @param obc the comparator to order the file entries (optionally 531 * <code>null</code>) 532 * @return the range of file entries in the folder ordered by comparator 533 * <code>obc</code> 534 * @throws PortalException if the folder could not be 535 * found 536 * @throws SystemException if a system exception occurred 537 */ 538 public List<FileEntry> getFileEntries( 539 long repositoryId, long folderId, int start, int end, 540 OrderByComparator obc) 541 throws PortalException, SystemException { 542 543 LocalRepository localRepository = getLocalRepository(repositoryId); 544 545 return localRepository.getFileEntries(folderId, start, end, obc); 546 } 547 548 /** 549 * Returns a range of all the file entries and shortcuts in the folder. 550 * 551 * <p> 552 * Useful when paginating results. Returns a maximum of <code>end - 553 * start</code> instances. <code>start</code> and <code>end</code> are not 554 * primary keys, they are indexes in the result set. Thus, <code>0</code> 555 * refers to the first result in the set. Setting both <code>start</code> 556 * and <code>end</code> to {@link 557 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 558 * result set. 559 * </p> 560 * 561 * @param repositoryId the primary key of the repository 562 * @param folderId the primary key of the folder 563 * @param status the workflow status 564 * @param start the lower bound of the range of results 565 * @param end the upper bound of the range of results (not inclusive) 566 * @return the range of file entries and shortcuts in the folder 567 * @throws PortalException if the folder could not be 568 * found 569 * @throws SystemException if a system exception occurred 570 */ 571 public List<Object> getFileEntriesAndFileShortcuts( 572 long repositoryId, long folderId, int status, int start, 573 int end) 574 throws PortalException, SystemException { 575 576 LocalRepository localRepository = getLocalRepository(repositoryId); 577 578 return localRepository.getFileEntriesAndFileShortcuts( 579 folderId, status, start, end); 580 } 581 582 /** 583 * Returns the number of file entries and shortcuts in the folder. 584 * 585 * @param repositoryId the primary key of the repository 586 * @param folderId the primary key of the folder 587 * @param status the workflow status 588 * @return the number of file entries and shortcuts in the folder 589 * @throws PortalException if the folder could not be 590 * found 591 * @throws SystemException if a system exception occurred 592 */ 593 public int getFileEntriesAndFileShortcutsCount( 594 long repositoryId, long folderId, int status) 595 throws PortalException, SystemException { 596 597 LocalRepository localRepository = getLocalRepository(repositoryId); 598 599 return localRepository.getFileEntriesAndFileShortcutsCount( 600 folderId, status); 601 } 602 603 /** 604 * Returns the number of file entries in the folder. 605 * 606 * @param repositoryId the primary key of the file entry's repository 607 * @param folderId the primary key of the file entry's folder 608 * @return the number of file entries in the folder 609 * @throws PortalException if the folder could not be 610 * found 611 * @throws SystemException if a system exception occurred 612 */ 613 public int getFileEntriesCount(long repositoryId, long folderId) 614 throws PortalException, SystemException { 615 616 LocalRepository localRepository = getLocalRepository(repositoryId); 617 618 return localRepository.getFileEntriesCount(folderId); 619 } 620 621 /** 622 * Returns the file entry with the primary key. 623 * 624 * @param fileEntryId the primary key of the file entry 625 * @return the file entry with the primary key 626 * @throws PortalException if the file entry could not be 627 * found 628 * @throws SystemException if a system exception occurred 629 */ 630 public FileEntry getFileEntry(long fileEntryId) 631 throws PortalException, SystemException { 632 633 LocalRepository localRepository = getLocalRepository(0, fileEntryId, 0); 634 635 return localRepository.getFileEntry(fileEntryId); 636 } 637 638 /** 639 * Returns the file entry with the title in the folder. 640 * 641 * @param groupId the primary key of the file entry's group 642 * @param folderId the primary key of the file entry's folder 643 * @param title the file entry's title 644 * @return the file entry with the title in the folder 645 * @throws PortalException if the file entry could not be found 646 * @throws SystemException if a system exception occurred 647 */ 648 public FileEntry getFileEntry(long groupId, long folderId, String title) 649 throws PortalException, SystemException { 650 651 try { 652 LocalRepository localRepository = getLocalRepository(groupId); 653 654 return localRepository.getFileEntry(folderId, title); 655 } 656 catch (NoSuchFileEntryException nsfee) { 657 } 658 659 LocalRepository localRepository = getLocalRepository(folderId, 0, 0); 660 661 return localRepository.getFileEntry(folderId, title); 662 } 663 664 /** 665 * Returns the file entry with the UUID and group. 666 * 667 * @param uuid the file entry's universally unique identifier 668 * @param groupId the primary key of the file entry's group 669 * @return the file entry with the UUID and group 670 * @throws PortalException if the file entry could not be found 671 * @throws SystemException if a system exception occurred 672 */ 673 public FileEntry getFileEntryByUuidAndGroupId(String uuid, long groupId) 674 throws PortalException, SystemException { 675 676 try { 677 LocalRepository localRepository = getLocalRepository(groupId); 678 679 return localRepository.getFileEntryByUuid(uuid); 680 } 681 catch (NoSuchFileEntryException nsfee) { 682 List<com.liferay.portal.model.Repository> repositories = 683 repositoryPersistence.findByGroupId(groupId); 684 685 for (int i = 0; i < repositories.size(); i++) { 686 try { 687 long repositoryId = repositories.get(i).getRepositoryId(); 688 689 LocalRepository localRepository = getLocalRepository( 690 repositoryId); 691 692 return localRepository.getFileEntryByUuid(uuid); 693 } 694 catch (NoSuchFileEntryException nsfee2) { 695 } 696 } 697 } 698 699 StringBundler msg = new StringBundler(6); 700 701 msg.append("No DLFileEntry exists with the key {"); 702 msg.append("uuid="); 703 msg.append(uuid); 704 msg.append(", groupId="); 705 msg.append(groupId); 706 msg.append(StringPool.CLOSE_CURLY_BRACE); 707 708 throw new NoSuchFileEntryException(msg.toString()); 709 } 710 711 /** 712 * Returns the file ranks from the user. This method is only supported by 713 * the Liferay repository. 714 * 715 * @param repositoryId the primary key of the repository 716 * @param userId the primary key of the user 717 * @return the file ranks from the user 718 * @throws SystemException if a system exception occurred 719 */ 720 public List<DLFileRank> getFileRanks(long repositoryId, long userId) 721 throws SystemException { 722 723 return dlFileRankLocalService.getFileRanks(repositoryId, userId); 724 } 725 726 /** 727 * Returns the file shortcut with the primary key. This method is only 728 * supported by the Liferay repository. 729 * 730 * @param fileShortcutId the primary key of the file shortcut 731 * @return the file shortcut with the primary key 732 * @throws PortalException if the file shortcut could not 733 * be found 734 * @throws SystemException if a system exception occurred 735 */ 736 public DLFileShortcut getFileShortcut(long fileShortcutId) 737 throws PortalException, SystemException { 738 739 return dlFileShortcutLocalService.getFileShortcut(fileShortcutId); 740 } 741 742 /** 743 * Returns the file version with the primary key. 744 * 745 * @param fileVersionId the primary key of the file version 746 * @return the file version with the primary key 747 * @throws PortalException if the file version could not 748 * be found 749 * @throws SystemException if a system exception occurred 750 */ 751 public FileVersion getFileVersion(long fileVersionId) 752 throws PortalException, SystemException { 753 754 LocalRepository localRepository = getLocalRepository( 755 0, 0, fileVersionId); 756 757 return localRepository.getFileVersion(fileVersionId); 758 } 759 760 /** 761 * Returns the folder with the primary key. 762 * 763 * @param folderId the primary key of the folder 764 * @return the folder with the primary key 765 * @throws PortalException if the folder could not be 766 * found 767 * @throws SystemException if a system exception occurred 768 */ 769 public Folder getFolder(long folderId) 770 throws PortalException, SystemException { 771 772 LocalRepository localRepository = getLocalRepository(folderId, 0, 0); 773 774 return localRepository.getFolder(folderId); 775 } 776 777 /** 778 * Returns the folder with the name in the parent folder. 779 * 780 * @param repositoryId the primary key of the folder's repository 781 * @param parentFolderId the primary key of the folder's parent folder 782 * @param name the folder's name 783 * @return the folder with the name in the parent folder 784 * @throws PortalException if the folder could not be found 785 * @throws SystemException if a system exception occurred 786 */ 787 public Folder getFolder( 788 long repositoryId, long parentFolderId, String name) 789 throws PortalException, SystemException { 790 791 LocalRepository localRepository = getLocalRepository(repositoryId); 792 793 return localRepository.getFolder(parentFolderId, name); 794 } 795 796 /** 797 * Returns all immediate subfolders of the parent folder. 798 * 799 * @param repositoryId the primary key of the folder's repository 800 * @param parentFolderId the primary key of the folder's parent folder 801 * @return the immediate subfolders of the parent folder 802 * @throws PortalException if the parent folder could not be found 803 * @throws SystemException if a system exception occurred 804 */ 805 public List<Folder> getFolders(long repositoryId, long parentFolderId) 806 throws PortalException, SystemException { 807 808 return getFolders(repositoryId, parentFolderId, true); 809 } 810 811 /** 812 * Returns all immediate subfolders of the parent folder, optionally 813 * including mount folders for third-party repositories. 814 * 815 * @param repositoryId the primary key of the folder's repository 816 * @param parentFolderId the primary key of the folder's parent folder 817 * @param includeMountFolders whether to include mount folders for 818 * third-party repositories 819 * @return the immediate subfolders of the parent folder 820 * @throws PortalException if the parent folder could not be found 821 * @throws SystemException if a system exception occurred 822 */ 823 public List<Folder> getFolders( 824 long repositoryId, long parentFolderId, boolean includeMountFolders) 825 throws PortalException, SystemException { 826 827 return getFolders( 828 repositoryId, parentFolderId, includeMountFolders, 829 QueryUtil.ALL_POS, QueryUtil.ALL_POS); 830 } 831 832 /** 833 * Returns a range of all the immediate subfolders of the parent folder, 834 * optionally including mount folders for third-party repositories. 835 * 836 * <p> 837 * Useful when paginating results. Returns a maximum of <code>end - 838 * start</code> instances. <code>start</code> and <code>end</code> are not 839 * primary keys, they are indexes in the result set. Thus, <code>0</code> 840 * refers to the first result in the set. Setting both <code>start</code> 841 * and <code>end</code> to {@link 842 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 843 * result set. 844 * </p> 845 * 846 * @param repositoryId the primary key of the folder's repository 847 * @param parentFolderId the primary key of the folder's parent folder 848 * @param includeMountFolders whether to include mount folders for 849 * third-party repositories 850 * @param start the lower bound of the range of results 851 * @param end the upper bound of the range of results (not inclusive) 852 * @return the range of immediate subfolders of the parent folder 853 * @throws PortalException if the parent folder could not be 854 * found 855 * @throws SystemException if a system exception occurred 856 */ 857 public List<Folder> getFolders( 858 long repositoryId, long parentFolderId, boolean includeMountFolders, 859 int start, int end) 860 throws PortalException, SystemException { 861 862 return getFolders( 863 repositoryId, parentFolderId, includeMountFolders, 864 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); 865 } 866 867 /** 868 * Returns an ordered range of all the immediate subfolders of the parent 869 * folder. 870 * 871 * <p> 872 * Useful when paginating results. Returns a maximum of <code>end - 873 * start</code> instances. <code>start</code> and <code>end</code> are not 874 * primary keys, they are indexes in the result set. Thus, <code>0</code> 875 * refers to the first result in the set. Setting both <code>start</code> 876 * and <code>end</code> to {@link 877 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 878 * result set. 879 * </p> 880 * 881 * @param repositoryId the primary key of the folder's repository 882 * @param parentFolderId the primary key of the folder's parent folder 883 * @param includeMountFolders whether to include mount folders for 884 * third-party repositories 885 * @param start the lower bound of the range of results 886 * @param end the upper bound of the range of results (not inclusive) 887 * @param obc the comparator to order the folders (optionally 888 * <code>null</code>) 889 * @return the range of immediate subfolders of the parent folder ordered by 890 * comparator <code>obc</code> 891 * @throws PortalException if the parent folder could not be 892 * found 893 * @throws SystemException if a system exception occurred 894 */ 895 public List<Folder> getFolders( 896 long repositoryId, long parentFolderId, boolean includeMountFolders, 897 int start, int end, OrderByComparator obc) 898 throws PortalException, SystemException { 899 900 LocalRepository localRepository = getLocalRepository(repositoryId); 901 902 return localRepository.getFolders( 903 parentFolderId, includeMountFolders, start, end, obc); 904 } 905 906 /** 907 * Returns a range of all the immediate subfolders of the parent 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 folder's repository 920 * @param parentFolderId the primary key of the folder's parent folder 921 * @param start the lower bound of the range of results 922 * @param end the upper bound of the range of results (not inclusive) 923 * @return the range of immediate subfolders of the parent folder 924 * @throws PortalException if the parent folder could not be 925 * found 926 * @throws SystemException if a system exception occurred 927 */ 928 public List<Folder> getFolders( 929 long repositoryId, long parentFolderId, int start, int end) 930 throws PortalException, SystemException { 931 932 return getFolders(repositoryId, parentFolderId, true, start, end); 933 } 934 935 /** 936 * Returns an ordered range of all the immediate subfolders of the parent 937 * folder. 938 * 939 * <p> 940 * Useful when paginating results. Returns a maximum of <code>end - 941 * start</code> instances. <code>start</code> and <code>end</code> are not 942 * primary keys, they are indexes in the result set. Thus, <code>0</code> 943 * refers to the first result in the set. Setting both <code>start</code> 944 * and <code>end</code> to {@link 945 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 946 * result set. 947 * </p> 948 * 949 * @param repositoryId the primary key of the folder's repository 950 * @param parentFolderId the primary key of the folder's parent folder 951 * @param start the lower bound of the range of results 952 * @param end the upper bound of the range of results (not inclusive) 953 * @param obc the comparator to order the folders (optionally 954 * <code>null</code>) 955 * @return the range of immediate subfolders of the parent folder ordered by 956 * comparator <code>obc</code> 957 * @throws PortalException if the parent folder could not be 958 * found 959 * @throws SystemException if a system exception occurred 960 */ 961 public List<Folder> getFolders( 962 long repositoryId, long parentFolderId, int start, int end, 963 OrderByComparator obc) 964 throws PortalException, SystemException { 965 966 return getFolders(repositoryId, parentFolderId, true, start, end, obc); 967 } 968 969 /** 970 * Returns an ordered range of all the immediate subfolders, file entries, 971 * and file shortcuts in the parent folder. 972 * 973 * <p> 974 * Useful when paginating results. Returns a maximum of <code>end - 975 * start</code> instances. <code>start</code> and <code>end</code> are not 976 * primary keys, they are indexes in the result set. Thus, <code>0</code> 977 * refers to the first result in the set. Setting both <code>start</code> 978 * and <code>end</code> to {@link 979 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 980 * result set. 981 * </p> 982 * 983 * @param repositoryId the primary key of the repository 984 * @param folderId the primary key of the parent folder 985 * @param status the workflow status 986 * @param includeMountFolders whether to include mount folders for 987 * third-party repositories 988 * @param start the lower bound of the range of results 989 * @param end the upper bound of the range of results (not inclusive) 990 * @param obc the comparator to order the results (optionally 991 * <code>null</code>) 992 * @return the range of immediate subfolders, file entries, and file 993 * shortcuts in the parent folder ordered by comparator 994 * <code>obc</code> 995 * @throws PortalException if the folder could not be 996 * found 997 * @throws SystemException if a system exception occurred 998 */ 999 public List<Object> getFoldersAndFileEntriesAndFileShortcuts( 1000 long repositoryId, long folderId, int status, 1001 boolean includeMountFolders, int start, int end, 1002 OrderByComparator obc) 1003 throws PortalException, SystemException { 1004 1005 return getFoldersAndFileEntriesAndFileShortcuts( 1006 repositoryId, folderId, status, null, includeMountFolders, start, 1007 end, obc); 1008 } 1009 1010 public List<Object> getFoldersAndFileEntriesAndFileShortcuts( 1011 long repositoryId, long folderId, int status, String[] mimeTypes, 1012 boolean includeMountFolders, int start, int end, 1013 OrderByComparator obc) 1014 throws PortalException, SystemException { 1015 1016 LocalRepository localRepository = getLocalRepository(repositoryId); 1017 1018 return localRepository.getFoldersAndFileEntriesAndFileShortcuts( 1019 folderId, status, mimeTypes, includeMountFolders, start, end, obc); 1020 } 1021 1022 /** 1023 * Returns the number of immediate subfolders, file entries, and file 1024 * shortcuts in the parent folder. 1025 * 1026 * @param repositoryId the primary key of the repository 1027 * @param folderId the primary key of the parent folder 1028 * @param status the workflow status 1029 * @param includeMountFolders whether to include mount folders for 1030 * third-party repositories 1031 * @return the number of immediate subfolders, file entries, and file 1032 * shortcuts in the parent folder 1033 * @throws PortalException if the folder could not be 1034 * found 1035 * @throws SystemException if a system exception occurred 1036 */ 1037 public int getFoldersAndFileEntriesAndFileShortcutsCount( 1038 long repositoryId, long folderId, int status, 1039 boolean includeMountFolders) 1040 throws PortalException, SystemException { 1041 1042 return getFoldersAndFileEntriesAndFileShortcutsCount( 1043 repositoryId, folderId, status, null, includeMountFolders); 1044 } 1045 1046 public int getFoldersAndFileEntriesAndFileShortcutsCount( 1047 long repositoryId, long folderId, int status, String[] mimeTypes, 1048 boolean includeMountFolders) 1049 throws PortalException, SystemException { 1050 1051 LocalRepository localRepository = getLocalRepository(repositoryId); 1052 1053 return localRepository.getFoldersAndFileEntriesAndFileShortcutsCount( 1054 folderId, status, mimeTypes, includeMountFolders); 1055 } 1056 1057 /** 1058 * Returns the number of immediate subfolders of the parent folder. 1059 * 1060 * @param repositoryId the primary key of the folder's repository 1061 * @param parentFolderId the primary key of the folder's parent folder 1062 * @return the number of immediate subfolders of the parent folder 1063 * @throws PortalException if the parent folder could not 1064 * be found 1065 * @throws SystemException if a system exception occurred 1066 */ 1067 public int getFoldersCount(long repositoryId, long parentFolderId) 1068 throws PortalException, SystemException { 1069 1070 return getFoldersCount(repositoryId, parentFolderId, true); 1071 } 1072 1073 /** 1074 * Returns the number of immediate subfolders of the parent folder, 1075 * optionally including mount folders for third-party repositories. 1076 * 1077 * @param repositoryId the primary key of the folder's repository 1078 * @param parentFolderId the primary key of the folder's parent folder 1079 * @param includeMountFolders whether to include mount folders for 1080 * third-party repositories 1081 * @return the number of immediate subfolders of the parent folder 1082 * @throws PortalException if the parent folder could not 1083 * be found 1084 * @throws SystemException if a system exception occurred 1085 */ 1086 public int getFoldersCount( 1087 long repositoryId, long parentFolderId, boolean includeMountFolders) 1088 throws PortalException, SystemException { 1089 1090 LocalRepository localRepository = getLocalRepository(repositoryId); 1091 1092 return localRepository.getFoldersCount( 1093 parentFolderId, includeMountFolders); 1094 } 1095 1096 /** 1097 * Returns the number of immediate subfolders and file entries across the 1098 * folders. 1099 * 1100 * @param repositoryId the primary key of the repository 1101 * @param folderIds the primary keys of folders from which to count 1102 * immediate subfolders and file entries 1103 * @param status the workflow status 1104 * @return the number of immediate subfolders and file entries across the 1105 * folders 1106 * @throws PortalException if the repository could not be 1107 * found 1108 * @throws SystemException if a system exception occurred 1109 */ 1110 public int getFoldersFileEntriesCount( 1111 long repositoryId, List<Long> folderIds, int status) 1112 throws PortalException, SystemException { 1113 1114 LocalRepository localRepository = getLocalRepository(repositoryId); 1115 1116 return localRepository.getFoldersFileEntriesCount(folderIds, status); 1117 } 1118 1119 /** 1120 * Returns the mount folder of the repository with the primary key. This 1121 * method is only supported by the Liferay repository. 1122 * 1123 * @param repositoryId the primary key of the repository 1124 * @return the folder used for mounting third-party repositories 1125 * @throws PortalException if the repository or mount folder could not be found 1126 * @throws SystemException if a system exception occurred 1127 */ 1128 public Folder getMountFolder(long repositoryId) 1129 throws PortalException, SystemException { 1130 1131 DLFolder dlFolder = dlFolderLocalService.getMountFolder(repositoryId); 1132 1133 return new LiferayFolder(dlFolder); 1134 } 1135 1136 /** 1137 * Returns all immediate subfolders of the parent folder that are used for 1138 * mounting third-party repositories. This method is only supported by the 1139 * Liferay repository. 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 * @return the immediate subfolders of the parent folder that are used for 1144 * mounting third-party repositories 1145 * @throws PortalException if the repository or parent 1146 * folder could not be found 1147 * @throws SystemException if a system exception occurred 1148 */ 1149 public List<Folder> getMountFolders(long repositoryId, long parentFolderId) 1150 throws PortalException, SystemException { 1151 1152 return getMountFolders( 1153 repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 1154 } 1155 1156 /** 1157 * Returns a range of all the immediate subfolders of the parent folder that 1158 * are used for mounting third-party repositories. This method is only 1159 * supported by the Liferay repository. 1160 * 1161 * <p> 1162 * Useful when paginating results. Returns a maximum of <code>end - 1163 * start</code> instances. <code>start</code> and <code>end</code> are not 1164 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1165 * refers to the first result in the set. Setting both <code>start</code> 1166 * and <code>end</code> to {@link 1167 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1168 * result set. 1169 * </p> 1170 * 1171 * @param repositoryId the primary key of the repository 1172 * @param parentFolderId the primary key of the parent folder 1173 * @param start the lower bound of the range of results 1174 * @param end the upper bound of the range of results (not inclusive) 1175 * @return the range of immediate subfolders of the parent folder that are 1176 * used for mounting third-party repositories 1177 * @throws PortalException if the repository or parent 1178 * folder could not be found 1179 * @throws SystemException if a system exception occurred 1180 */ 1181 public List<Folder> getMountFolders( 1182 long repositoryId, long parentFolderId, int start, int end) 1183 throws PortalException, SystemException { 1184 1185 return getMountFolders(repositoryId, parentFolderId, start, end, null); 1186 } 1187 1188 /** 1189 * Returns an ordered range of all the immediate subfolders of the parent 1190 * folder that are used for mounting third-party repositories. This method 1191 * is only supported by the Liferay repository. 1192 * 1193 * <p> 1194 * Useful when paginating results. Returns a maximum of <code>end - 1195 * start</code> instances. <code>start</code> and <code>end</code> are not 1196 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1197 * refers to the first result in the set. Setting both <code>start</code> 1198 * and <code>end</code> to {@link 1199 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1200 * result set. 1201 * </p> 1202 * 1203 * @param repositoryId the primary key of the folder's repository 1204 * @param parentFolderId the primary key of the folder's parent folder 1205 * @param start the lower bound of the range of results 1206 * @param end the upper bound of the range of results (not inclusive) 1207 * @param obc the comparator to order the folders (optionally 1208 * <code>null</code>) 1209 * @return the range of immediate subfolders of the parent folder that are 1210 * used for mounting third-party repositories ordered by comparator 1211 * <code>obc</code> 1212 * @throws PortalException if the repository or parent 1213 * folder could not be found 1214 * @throws SystemException if a system exception occurred 1215 */ 1216 public List<Folder> getMountFolders( 1217 long repositoryId, long parentFolderId, int start, int end, 1218 OrderByComparator obc) 1219 throws PortalException, SystemException { 1220 1221 LocalRepository localRepository = getLocalRepository(repositoryId); 1222 1223 return localRepository.getMountFolders(parentFolderId, start, end, obc); 1224 } 1225 1226 /** 1227 * Returns the number of immediate subfolders of the parent folder that are 1228 * used for mounting third-party repositories. This method is only supported 1229 * by the Liferay repository. 1230 * 1231 * @param repositoryId the primary key of the repository 1232 * @param parentFolderId the primary key of the parent folder 1233 * @return the number of folders of the parent folder that are used for 1234 * mounting third-party repositories 1235 * @throws PortalException if the repository or parent 1236 * folder could not be found 1237 * @throws SystemException if a system exception occurred 1238 */ 1239 public int getMountFoldersCount(long repositoryId, long parentFolderId) 1240 throws PortalException, SystemException { 1241 1242 LocalRepository localRepository = getLocalRepository(repositoryId); 1243 1244 return localRepository.getMountFoldersCount(parentFolderId); 1245 } 1246 1247 /** 1248 * Moves the file entry to the new folder. 1249 * 1250 * @param userId the primary key of the user 1251 * @param fileEntryId the primary key of the file entry 1252 * @param newFolderId the primary key of the new folder 1253 * @param serviceContext the service context to be applied 1254 * @return the file entry 1255 * @throws PortalException if the file entry or the new folder could not be 1256 * found 1257 * @throws SystemException if a system exception occurred 1258 */ 1259 public FileEntry moveFileEntry( 1260 long userId, long fileEntryId, long newFolderId, 1261 ServiceContext serviceContext) 1262 throws PortalException, SystemException { 1263 1264 LocalRepository fromLocalRepository = getLocalRepository( 1265 0, fileEntryId, 0); 1266 LocalRepository toLocalRepository = getLocalRepository( 1267 newFolderId, serviceContext); 1268 1269 if (fromLocalRepository.getRepositoryId() == 1270 toLocalRepository.getRepositoryId()) { 1271 1272 // Move file entries within repository 1273 1274 return fromLocalRepository.moveFileEntry( 1275 userId, fileEntryId, newFolderId, serviceContext); 1276 } 1277 1278 // Move file entries between repositories 1279 1280 return moveFileEntries( 1281 userId, fileEntryId, newFolderId, fromLocalRepository, 1282 toLocalRepository, serviceContext); 1283 } 1284 1285 /** 1286 * Updates the file entry's asset replacing its asset categories, tags, and 1287 * links. 1288 * 1289 * @param userId the primary key of the user 1290 * @param fileEntry the file entry to update 1291 * @param fileVersion the file version to update 1292 * @param assetCategoryIds the primary keys of the new asset categories 1293 * @param assetTagNames the new asset tag names 1294 * @param assetLinkEntryIds the primary keys of the new asset link entries 1295 * @throws PortalException if the file entry or version could not be found 1296 * @throws SystemException if a system exception occurred 1297 */ 1298 public void updateAsset( 1299 long userId, FileEntry fileEntry, FileVersion fileVersion, 1300 long[] assetCategoryIds, String[] assetTagNames, 1301 long[] assetLinkEntryIds) 1302 throws PortalException, SystemException { 1303 1304 LocalRepository localRepository = getLocalRepository( 1305 0, fileEntry.getFileEntryId(), 0); 1306 1307 localRepository.updateAsset( 1308 userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames, 1309 assetLinkEntryIds); 1310 } 1311 1312 /** 1313 * Updates a file entry and associated metadata based on a byte array 1314 * object. If the file data is <code>null</code>, then only the associated 1315 * metadata (i.e., <code>title</code>, <code>description</code>, and 1316 * parameters in the <code>serviceContext</code>) will be updated. 1317 * 1318 * <p> 1319 * This method takes two file names, the <code>sourceFileName</code> and the 1320 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 1321 * name of the actual file being uploaded. The <code>title</code> 1322 * corresponds to a name the client wishes to assign this file after it has 1323 * been uploaded to the portal. 1324 * </p> 1325 * 1326 * @param userId the primary key of the user 1327 * @param fileEntryId the primary key of the file entry 1328 * @param sourceFileName the original file's name (optionally 1329 * <code>null</code>) 1330 * @param mimeType the file's MIME type (optionally <code>null</code>) 1331 * @param title the new name to be assigned to the file (optionally <code> 1332 * null</code>) 1333 * @param description the file's new description 1334 * @param changeLog the file's version change log (optionally 1335 * <code>null</code>) 1336 * @param majorVersion whether the new file version is a major version 1337 * @param bytes the file's data (optionally <code>null</code>) 1338 * @param serviceContext the service context to be applied. Can specify the 1339 * file entry's asset category IDs, asset tag names, and expando 1340 * bridge attributes. In a Liferay repository, it may include: 1341 * 1342 * <ul> 1343 * <li> 1344 * fileEntryTypeId - ID for a custom file entry type 1345 * </li> 1346 * <li> 1347 * fieldsMap - mapping for fields associated with a custom file 1348 * entry type 1349 * </li> 1350 * </ul> 1351 * 1352 * @return the file entry 1353 * @throws PortalException if the file entry could not be 1354 * found 1355 * @throws SystemException if a system exception occurred 1356 */ 1357 public FileEntry updateFileEntry( 1358 long userId, long fileEntryId, String sourceFileName, 1359 String mimeType, String title, String description, String changeLog, 1360 boolean majorVersion, byte[] bytes, ServiceContext serviceContext) 1361 throws PortalException, SystemException { 1362 1363 File file = null; 1364 1365 try { 1366 if ((bytes != null) && (bytes.length > 0)) { 1367 file = FileUtil.createTempFile(bytes); 1368 } 1369 1370 return updateFileEntry( 1371 userId, fileEntryId, sourceFileName, mimeType, title, 1372 description, changeLog, majorVersion, file, serviceContext); 1373 } 1374 catch (IOException ioe) { 1375 throw new SystemException("Unable to write temporary file", ioe); 1376 } 1377 finally { 1378 FileUtil.delete(file); 1379 } 1380 } 1381 1382 /** 1383 * Updates a file entry and associated metadata based on a {@link File} 1384 * object. If the file data is <code>null</code>, then only the associated 1385 * metadata (i.e., <code>title</code>, <code>description</code>, and 1386 * parameters in the <code>serviceContext</code>) will be updated. 1387 * 1388 * <p> 1389 * This method takes two file names, the <code>sourceFileName</code> and the 1390 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 1391 * name of the actual file being uploaded. The <code>title</code> 1392 * corresponds to a name the client wishes to assign this file after it has 1393 * been uploaded to the portal. 1394 * </p> 1395 * 1396 * @param userId the primary key of the user 1397 * @param fileEntryId the primary key of the file entry 1398 * @param sourceFileName the original file's name (optionally 1399 * <code>null</code>) 1400 * @param mimeType the file's MIME type (optionally <code>null</code>) 1401 * @param title the new name to be assigned to the file (optionally <code> 1402 * null</code>) 1403 * @param description the file's new description 1404 * @param changeLog the file's version change log (optionally 1405 * <code>null</code>) 1406 * @param majorVersion whether the new file version is a major version 1407 * @param file EntryId the primary key of the file entry 1408 * @param serviceContext the service context to be applied. Can specify the 1409 * file entry's asset category IDs, asset tag names, and expando 1410 * bridge attributes. In a Liferay repository, it may include: 1411 * 1412 * <ul> 1413 * <li> 1414 * fileEntryTypeId - ID for a custom file entry type 1415 * </li> 1416 * <li> 1417 * fieldsMap - mapping for fields associated with a custom file 1418 * entry type 1419 * </li> 1420 * </ul> 1421 * 1422 * @return the file entry 1423 * @throws PortalException if the file entry could not be 1424 * found 1425 * @throws SystemException if a system exception occurred 1426 */ 1427 public FileEntry updateFileEntry( 1428 long userId, long fileEntryId, String sourceFileName, 1429 String mimeType, String title, String description, String changeLog, 1430 boolean majorVersion, File file, ServiceContext serviceContext) 1431 throws PortalException, SystemException { 1432 1433 if (file == null || !file.exists() || file.length() == 0) { 1434 return updateFileEntry( 1435 userId, fileEntryId, sourceFileName, mimeType, title, 1436 description, changeLog, majorVersion, null, 0, serviceContext); 1437 } 1438 1439 LocalRepository localRepository = getLocalRepository(0, fileEntryId, 0); 1440 1441 FileEntry fileEntry = localRepository.updateFileEntry( 1442 userId, fileEntryId, sourceFileName, mimeType, title, description, 1443 changeLog, majorVersion, file, serviceContext); 1444 1445 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 1446 1447 dlAppHelperLocalService.updateFileEntry( 1448 userId, fileEntry, fileEntry.getFileVersion(), serviceContext); 1449 1450 return fileEntry; 1451 } 1452 1453 /** 1454 * Updates a file entry and associated metadata based on an {@link 1455 * InputStream} object. If the file data is <code>null</code>, then only the 1456 * associated metadata (i.e., <code>title</code>, <code>description</code>, 1457 * and parameters in the <code>serviceContext</code>) will be updated. 1458 * 1459 * <p> 1460 * This method takes two file names, the <code>sourceFileName</code> and the 1461 * <code>title</code>. The <code>sourceFileName</code> corresponds to the 1462 * name of the actual file being uploaded. The <code>title</code> 1463 * corresponds to a name the client wishes to assign this file after it has 1464 * been uploaded to the portal. 1465 * </p> 1466 * 1467 * @param userId the primary key of the user 1468 * @param fileEntryId the primary key of the file entry 1469 * @param sourceFileName the original file's name (optionally 1470 * <code>null</code>) 1471 * @param mimeType the file's MIME type (optionally <code>null</code>) 1472 * @param title the new name to be assigned to the file (optionally <code> 1473 * null</code>) 1474 * @param description the file's new description 1475 * @param changeLog the file's version change log (optionally 1476 * <code>null</code>) 1477 * @param majorVersion whether the new file version is a major version 1478 * @param is the file's data (optionally <code>null</code>) 1479 * @param size the file's size (optionally <code>0</code>) 1480 * @param serviceContext the service context to be applied. Can specify the 1481 * file entry's asset category IDs, asset tag names, and expando 1482 * bridge attributes. In a Liferay repository, it may include: 1483 * 1484 * <ul> 1485 * <li> 1486 * fileEntryTypeId - ID for a custom file entry type 1487 * </li> 1488 * <li> 1489 * fieldsMap - mapping for fields associated with a custom file 1490 * entry type 1491 * </li> 1492 * </ul> 1493 * 1494 * @return the file entry 1495 * @throws PortalException if the file entry could not be 1496 * found 1497 * @throws SystemException if a system exception occurred 1498 */ 1499 public FileEntry updateFileEntry( 1500 long userId, long fileEntryId, String sourceFileName, 1501 String mimeType, String title, String description, String changeLog, 1502 boolean majorVersion, InputStream is, long size, 1503 ServiceContext serviceContext) 1504 throws PortalException, SystemException { 1505 1506 LocalRepository localRepository = getLocalRepository(0, fileEntryId, 0); 1507 1508 FileEntry fileEntry = localRepository.updateFileEntry( 1509 userId, fileEntryId, sourceFileName, mimeType, title, description, 1510 changeLog, majorVersion, is, size, serviceContext); 1511 1512 if (is != null) { 1513 DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion()); 1514 } 1515 1516 dlAppHelperLocalService.updateFileEntry( 1517 userId, fileEntry, fileEntry.getFileVersion(), serviceContext); 1518 1519 return fileEntry; 1520 } 1521 1522 /** 1523 * Updates a file rank to the existing file entry. This method is only 1524 * supported by the Liferay repository. 1525 * 1526 * @param repositoryId the primary key of the file rank's repository 1527 * @param companyId the primary key of the file rank's company 1528 * @param userId the primary key of the file rank's creator/owner 1529 * @param fileEntryId the primary key of the file rank's file entry 1530 * @param serviceContext the service context to be applied 1531 * @return the file rank 1532 * @throws SystemException if a system exception occurred 1533 */ 1534 public DLFileRank updateFileRank( 1535 long repositoryId, long companyId, long userId, long fileEntryId, 1536 ServiceContext serviceContext) 1537 throws SystemException { 1538 1539 return dlFileRankLocalService.updateFileRank( 1540 repositoryId, companyId, userId, fileEntryId, serviceContext); 1541 } 1542 1543 /** 1544 * Updates a file shortcut to the existing file entry. This method is only 1545 * supported by the Liferay repository. 1546 * 1547 * @param userId the primary key of the file shortcut's creator/owner 1548 * @param fileShortcutId the primary key of the file shortcut 1549 * @param folderId the primary key of the file shortcut's parent folder 1550 * @param toFileEntryId the primary key of the file shortcut's file entry 1551 * @param serviceContext the service context to be applied. Can specify the 1552 * file entry's asset category IDs, asset tag names, and expando 1553 * bridge attributes. 1554 * @return the file shortcut 1555 * @throws PortalException if the file shortcut, folder, or file entry could 1556 * not be found 1557 * @throws SystemException if a system exception occurred 1558 */ 1559 public DLFileShortcut updateFileShortcut( 1560 long userId, long fileShortcutId, long folderId, long toFileEntryId, 1561 ServiceContext serviceContext) 1562 throws PortalException, SystemException { 1563 1564 return dlFileShortcutLocalService.updateFileShortcut( 1565 userId, fileShortcutId, folderId, toFileEntryId, serviceContext); 1566 } 1567 1568 /** 1569 * Updates all file shortcuts to the existing file entry to the new file 1570 * entry. This method is only supported by the Liferay repository. 1571 * 1572 * @param toRepositoryId the primary key of the repository 1573 * @param oldToFileEntryId the primary key of the old file entry pointed to 1574 * @param newToFileEntryId the primary key of the new file entry to point 1575 * to 1576 * @throws SystemException if a system exception occurred 1577 */ 1578 public void updateFileShortcuts( 1579 long toRepositoryId, long oldToFileEntryId, long newToFileEntryId) 1580 throws SystemException { 1581 1582 dlFileShortcutLocalService.updateFileShortcuts( 1583 oldToFileEntryId, newToFileEntryId); 1584 } 1585 1586 /** 1587 * Updates the folder. 1588 * 1589 * @param folderId the primary key of the folder 1590 * @param parentFolderId the primary key of the folder's new parent folder 1591 * @param name the folder's new name 1592 * @param description the folder's new description 1593 * @param serviceContext the service context to be applied. In a Liferay 1594 * repository, it may include: 1595 * 1596 * <ul> 1597 * <li> 1598 * defaultFileEntryTypeId - the file entry type to default all 1599 * Liferay file entries to 1600 * </li> 1601 * <li> 1602 * fileEntryTypeSearchContainerPrimaryKeys - a comma-delimited list 1603 * of file entry type primary keys allowed in the given folder and 1604 * all descendants 1605 * </li> 1606 * <li> 1607 * mountPoint - boolean specifying whether folder is a facade for 1608 * mounting a third-party repository 1609 * </li> 1610 * <li> 1611 * overrideFileEntryTypes - boolean specifying whether to override 1612 * ancestral folder's restriction of file entry types allowed 1613 * </li> 1614 * <li> 1615 * workflowDefinitionXYZ - the workflow definition name specified 1616 * per file entry type. The parameter name must be the string 1617 * <code>workflowDefinition</code> appended by the 1618 * <code>fileEntryTypeId</code> (optionally <code>0</code>). 1619 * </li> 1620 * </ul> 1621 * 1622 * @return the folder 1623 * @throws PortalException if the current or new parent folder could not be 1624 * found, or if the new parent folder's information was invalid 1625 * @throws SystemException if a system exception occurred 1626 */ 1627 public Folder updateFolder( 1628 long folderId, long parentFolderId, String name, String description, 1629 ServiceContext serviceContext) 1630 throws PortalException, SystemException { 1631 1632 LocalRepository localRepository = getLocalRepository(folderId, 0, 0); 1633 1634 return localRepository.updateFolder( 1635 folderId, parentFolderId, name, description, serviceContext); 1636 } 1637 1638 protected FileEntry copyFileEntry( 1639 long userId, LocalRepository toLocalRepository, FileEntry fileEntry, 1640 long newFolderId, ServiceContext serviceContext) 1641 throws PortalException, SystemException { 1642 1643 List<FileVersion> fileVersions = fileEntry.getFileVersions( 1644 WorkflowConstants.STATUS_ANY); 1645 1646 FileVersion latestFileVersion = fileVersions.get( 1647 fileVersions.size() - 1); 1648 1649 FileEntry destinationFileEntry = toLocalRepository.addFileEntry( 1650 userId, newFolderId, fileEntry.getTitle(), 1651 latestFileVersion.getMimeType(), latestFileVersion.getTitle(), 1652 latestFileVersion.getDescription(), StringPool.BLANK, 1653 latestFileVersion.getContentStream(false), 1654 latestFileVersion.getSize(), serviceContext); 1655 1656 for (int i = fileVersions.size() - 2; i >= 0 ; i--) { 1657 FileVersion fileVersion = fileVersions.get(i); 1658 1659 FileVersion previousFileVersion = fileVersions.get(i + 1); 1660 1661 try { 1662 destinationFileEntry = toLocalRepository.updateFileEntry( 1663 userId, destinationFileEntry.getFileEntryId(), 1664 fileEntry.getTitle(), destinationFileEntry.getMimeType(), 1665 destinationFileEntry.getTitle(), 1666 destinationFileEntry.getDescription(), StringPool.BLANK, 1667 isMajorVersion(fileVersion, previousFileVersion), 1668 fileVersion.getContentStream(false), fileVersion.getSize(), 1669 serviceContext); 1670 } 1671 catch (PortalException pe) { 1672 toLocalRepository.deleteFileEntry( 1673 destinationFileEntry.getFileEntryId()); 1674 1675 throw pe; 1676 } 1677 } 1678 1679 dlAppHelperLocalService.addFileEntry( 1680 userId, destinationFileEntry, destinationFileEntry.getFileVersion(), 1681 serviceContext); 1682 1683 return destinationFileEntry; 1684 } 1685 1686 protected void deleteFileEntry( 1687 long oldFileEntryId, long newFileEntryId, 1688 LocalRepository fromLocalRepository, 1689 LocalRepository toLocalRepository) 1690 throws PortalException, SystemException { 1691 1692 try { 1693 FileEntry fileEntry = fromLocalRepository.getFileEntry( 1694 oldFileEntryId); 1695 1696 fromLocalRepository.deleteFileEntry(oldFileEntryId); 1697 1698 dlAppHelperLocalService.deleteFileEntry(fileEntry); 1699 } 1700 catch (PortalException pe) { 1701 FileEntry fileEntry = toLocalRepository.getFileEntry( 1702 newFileEntryId); 1703 1704 toLocalRepository.deleteFileEntry(newFileEntryId); 1705 1706 dlAppHelperLocalService.deleteFileEntry(fileEntry); 1707 1708 throw pe; 1709 } 1710 } 1711 1712 protected LocalRepository getLocalRepository(long repositoryId) 1713 throws PortalException, SystemException { 1714 1715 return repositoryService.getLocalRepositoryImpl(repositoryId); 1716 } 1717 1718 protected LocalRepository getLocalRepository( 1719 long folderId, long fileEntryId, long fileVersionId) 1720 throws PortalException, SystemException { 1721 1722 return repositoryService.getLocalRepositoryImpl( 1723 folderId, fileEntryId, fileVersionId); 1724 } 1725 1726 protected LocalRepository getLocalRepository( 1727 long folderId, ServiceContext serviceContext) 1728 throws PortalException, SystemException { 1729 1730 LocalRepository localRepository = null; 1731 1732 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { 1733 localRepository = 1734 getLocalRepository(serviceContext.getScopeGroupId()); 1735 } 1736 else { 1737 localRepository = getLocalRepository(folderId, 0, 0); 1738 } 1739 1740 return localRepository; 1741 } 1742 1743 protected boolean isMajorVersion( 1744 FileVersion previousFileVersion, FileVersion currentFileVersion) { 1745 1746 long currentVersion = GetterUtil.getLong( 1747 currentFileVersion.getVersion()); 1748 long previousVersion = GetterUtil.getLong( 1749 previousFileVersion.getVersion()); 1750 1751 return (currentVersion - previousVersion) >= 1; 1752 } 1753 1754 protected FileEntry moveFileEntries( 1755 long userId, long fileEntryId, long newFolderId, 1756 LocalRepository fromLocalRepository, 1757 LocalRepository toLocalRepository, ServiceContext serviceContext) 1758 throws SystemException, PortalException { 1759 1760 FileEntry sourceFileEntry = fromLocalRepository.getFileEntry( 1761 fileEntryId); 1762 1763 FileEntry destinationFileEntry = copyFileEntry( 1764 userId, toLocalRepository, sourceFileEntry, newFolderId, 1765 serviceContext); 1766 1767 deleteFileEntry( 1768 fileEntryId, destinationFileEntry.getFileEntryId(), 1769 fromLocalRepository, toLocalRepository); 1770 1771 return destinationFileEntry; 1772 } 1773 1774 }