001
014
015 package com.liferay.portlet.trash.service.impl;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.util.UnicodeProperties;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.util.PortalUtil;
021 import com.liferay.portlet.trash.model.TrashVersion;
022 import com.liferay.portlet.trash.service.base.TrashVersionLocalServiceBaseImpl;
023
024 import java.util.List;
025
026
029 public class TrashVersionLocalServiceImpl
030 extends TrashVersionLocalServiceBaseImpl {
031
032 @Override
033 public void addTrashVersion(
034 long trashEntryId, String className, long classPK, int status,
035 UnicodeProperties typeSettingsProperties)
036 throws SystemException {
037
038 long versionId = counterLocalService.increment();
039
040 TrashVersion trashVersion = trashVersionPersistence.create(versionId);
041
042 trashVersion.setEntryId(trashEntryId);
043 trashVersion.setClassName(className);
044 trashVersion.setClassPK(classPK);
045
046 if (typeSettingsProperties != null) {
047 trashVersion.setTypeSettingsProperties(typeSettingsProperties);
048 }
049
050 trashVersion.setStatus(status);
051
052 trashVersionPersistence.update(trashVersion);
053 }
054
055 @Override
056 public TrashVersion deleteTrashVersion(
057 long entryId, String className, long classPK)
058 throws SystemException {
059
060 TrashVersion trashVersion = fetchVersion(entryId, className, classPK);
061
062 if (trashVersion != null) {
063 return deleteTrashVersion(trashVersion);
064 }
065
066 return null;
067 }
068
069 @Override
070 public TrashVersion fetchVersion(
071 long entryId, String className, long classPK)
072 throws SystemException {
073
074 List<TrashVersion> trashVersions = getVersions(className, classPK);
075
076 if (trashVersions.isEmpty()) {
077 return null;
078 }
079
080 return trashVersions.get(0);
081 }
082
083 @Override
084 public List<TrashVersion> getVersions(long entryId) throws SystemException {
085 return trashVersionPersistence.findByEntryId(entryId);
086 }
087
088 @Override
089 public List<TrashVersion> getVersions(long entryId, String className)
090 throws SystemException {
091
092 if (Validator.isNull(className)) {
093 return trashVersionPersistence.findByEntryId(entryId);
094 }
095
096 long classNameId = PortalUtil.getClassNameId(className);
097
098 return trashVersionPersistence.findByE_C(entryId, classNameId);
099 }
100
101
109 @Override
110 public List<TrashVersion> getVersions(String className, long classPK)
111 throws SystemException {
112
113 long classNameId = PortalUtil.getClassNameId(className);
114
115 return trashVersionPersistence.findByC_C(classNameId, classPK);
116 }
117
118 }