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