001
014
015 package com.liferay.portal.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.repository.InvalidRepositoryIdException;
019 import com.liferay.portal.kernel.repository.LocalRepository;
020 import com.liferay.portal.kernel.repository.RepositoryException;
021 import com.liferay.portal.kernel.repository.RepositoryProviderUtil;
022 import com.liferay.portal.kernel.repository.capabilities.RepositoryEventTriggerCapability;
023 import com.liferay.portal.kernel.repository.event.RepositoryEventTrigger;
024 import com.liferay.portal.kernel.repository.event.RepositoryEventType;
025
026
029 public class RepositoryUtil {
030
031 public static RepositoryEventTrigger getFolderRepositoryEventTrigger(
032 long folderId)
033 throws PortalException {
034
035 LocalRepository localRepository =
036 RepositoryProviderUtil.getFolderLocalRepository(folderId);
037
038 return getRepositoryEventTrigger(localRepository);
039 }
040
041 public static long getRepositoryEntryId(
042 long folderId, long fileEntryId, long fileVersionId)
043 throws RepositoryException {
044
045 long repositoryEntryId = 0;
046
047 if (folderId != 0) {
048 repositoryEntryId = folderId;
049 }
050 else if (fileEntryId != 0) {
051 repositoryEntryId = fileEntryId;
052 }
053 else if (fileVersionId != 0) {
054 repositoryEntryId = fileVersionId;
055 }
056
057 if (repositoryEntryId == 0) {
058 throw new InvalidRepositoryIdException(
059 "Missing a valid ID for folder, file entry, or file version");
060 }
061
062 return repositoryEntryId;
063 }
064
065 public static RepositoryEventTrigger getRepositoryEventTrigger(
066 long repositoryId)
067 throws PortalException {
068
069 LocalRepository localRepository =
070 RepositoryProviderUtil.getLocalRepository(repositoryId);
071
072 return getRepositoryEventTrigger(localRepository);
073 }
074
075 protected static RepositoryEventTrigger getRepositoryEventTrigger(
076 LocalRepository localRepository) {
077
078 if (localRepository.isCapabilityProvided(
079 RepositoryEventTriggerCapability.class)) {
080
081 return localRepository.getCapability(
082 RepositoryEventTriggerCapability.class);
083 }
084
085 return _dummyRepositoryEventTrigger;
086 }
087
088 private static final RepositoryEventTrigger _dummyRepositoryEventTrigger =
089 new RepositoryEventTrigger() {
090
091 @Override
092 public <S extends RepositoryEventType, T> void trigger(
093 Class<S> repositoryEventTypeClass, Class<T> modelClass,
094 T model) {
095 }
096
097 };
098
099 }