001    /**
002     * Copyright (c) 2000-present 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.util.UnicodeProperties;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portlet.trash.model.TrashVersion;
020    import com.liferay.portlet.trash.service.base.TrashVersionLocalServiceBaseImpl;
021    
022    import java.util.List;
023    
024    /**
025     * @author Zsolt Berentey
026     */
027    public class TrashVersionLocalServiceImpl
028            extends TrashVersionLocalServiceBaseImpl {
029    
030            @Override
031            public TrashVersion addTrashVersion(
032                    long trashEntryId, String className, long classPK, int status,
033                    UnicodeProperties typeSettingsProperties) {
034    
035                    long versionId = counterLocalService.increment();
036    
037                    TrashVersion trashVersion = trashVersionPersistence.create(versionId);
038    
039                    trashVersion.setEntryId(trashEntryId);
040                    trashVersion.setClassName(className);
041                    trashVersion.setClassPK(classPK);
042    
043                    if (typeSettingsProperties != null) {
044                            trashVersion.setTypeSettingsProperties(typeSettingsProperties);
045                    }
046    
047                    trashVersion.setStatus(status);
048    
049                    return trashVersionPersistence.update(trashVersion);
050            }
051    
052            @Override
053            public TrashVersion deleteTrashVersion(String className, long classPK) {
054                    long classNameId = classNameLocalService.getClassNameId(className);
055    
056                    TrashVersion trashVersion = trashVersionPersistence.fetchByC_C(
057                            classNameId, classPK);
058    
059                    if (trashVersion != null) {
060                            return deleteTrashVersion(trashVersion);
061                    }
062    
063                    return null;
064            }
065    
066            /**
067             * @deprecated As of 7.0.0, replaced by {@link #fetchVersion(String, long)}
068             */
069            @Deprecated
070            @Override
071            public TrashVersion fetchVersion(
072                    long entryId, String className, long classPK) {
073    
074                    return fetchVersion(className, classPK);
075            }
076    
077            @Override
078            public TrashVersion fetchVersion(String className, long classPK) {
079                    long classNameId = classNameLocalService.getClassNameId(className);
080    
081                    return trashVersionPersistence.fetchByC_C(classNameId, classPK);
082            }
083    
084            @Override
085            public List<TrashVersion> getVersions(long entryId) {
086                    return trashVersionPersistence.findByEntryId(entryId);
087            }
088    
089            @Override
090            public List<TrashVersion> getVersions(long entryId, String className) {
091                    if (Validator.isNull(className)) {
092                            return trashVersionPersistence.findByEntryId(entryId);
093                    }
094    
095                    long classNameId = classNameLocalService.getClassNameId(className);
096    
097                    return trashVersionPersistence.findByE_C(entryId, classNameId);
098            }
099    
100    }