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.Validator;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portlet.trash.model.TrashVersion;
021    import com.liferay.portlet.trash.service.base.TrashVersionLocalServiceBaseImpl;
022    
023    import java.util.List;
024    
025    /**
026     * @author Zsolt Berentey
027     */
028    public class TrashVersionLocalServiceImpl
029            extends TrashVersionLocalServiceBaseImpl {
030    
031            @Override
032            public void addTrashVersion(
033                            long trashEntryId, String className, long classPK, int status)
034                    throws SystemException {
035    
036                    long versionId = counterLocalService.increment();
037    
038                    TrashVersion trashVersion = trashVersionPersistence.create(versionId);
039    
040                    trashVersion.setEntryId(trashEntryId);
041                    trashVersion.setClassName(className);
042                    trashVersion.setClassPK(classPK);
043                    trashVersion.setStatus(status);
044    
045                    trashVersionPersistence.update(trashVersion);
046            }
047    
048            @Override
049            public TrashVersion fetchVersion(
050                            long entryId, String className, long classPK)
051                    throws SystemException {
052    
053                    long classNameId = PortalUtil.getClassNameId(className);
054    
055                    TrashVersion version = trashVersionPersistence.fetchByE_C_C(
056                            entryId, classNameId, classPK);
057    
058                    return version;
059            }
060    
061            @Override
062            public List<TrashVersion> getVersions(long entryId) throws SystemException {
063                    return trashVersionPersistence.findByEntryId(entryId);
064            }
065    
066            @Override
067            public List<TrashVersion> getVersions(long entryId, String className)
068                    throws SystemException {
069    
070                    if (Validator.isNull(className)) {
071                            return trashVersionPersistence.findByEntryId(entryId);
072                    }
073    
074                    long classNameId = PortalUtil.getClassNameId(className);
075    
076                    return trashVersionPersistence.findByE_C(entryId, classNameId);
077            }
078    
079            /**
080             * Returns all the trash versions associated with the trash entry.
081             *
082             * @param  className the class name of the trash entity
083             * @param  classPK the primary key of the trash entity
084             * @return all the trash versions associated with the trash entry
085             * @throws SystemException if a system exception occurred
086             */
087            @Override
088            public List<TrashVersion> getVersions(String className, long classPK)
089                    throws SystemException {
090    
091                    long classNameId = PortalUtil.getClassNameId(className);
092    
093                    return trashVersionPersistence.findByC_C(classNameId, classPK);
094            }
095    
096    }