001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.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    /**
027     * @author Zsolt Berentey
028     */
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                    long classNameId = PortalUtil.getClassNameId(className);
075    
076                    return trashVersionPersistence.fetchByE_C_C(
077                            entryId, classNameId, classPK);
078            }
079    
080            @Override
081            public List<TrashVersion> getVersions(long entryId) throws SystemException {
082                    return trashVersionPersistence.findByEntryId(entryId);
083            }
084    
085            @Override
086            public List<TrashVersion> getVersions(long entryId, String className)
087                    throws SystemException {
088    
089                    if (Validator.isNull(className)) {
090                            return trashVersionPersistence.findByEntryId(entryId);
091                    }
092    
093                    long classNameId = PortalUtil.getClassNameId(className);
094    
095                    return trashVersionPersistence.findByE_C(entryId, classNameId);
096            }
097    
098            /**
099             * Returns all the trash versions associated with the trash entry.
100             *
101             * @param  className the class name of the trash entity
102             * @param  classPK the primary key of the trash entity
103             * @return all the trash versions associated with the trash entry
104             * @throws SystemException if a system exception occurred
105             */
106            @Override
107            public List<TrashVersion> getVersions(String className, long classPK)
108                    throws SystemException {
109    
110                    long classNameId = PortalUtil.getClassNameId(className);
111    
112                    return trashVersionPersistence.findByC_C(classNameId, classPK);
113            }
114    
115    }