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.portal.service.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.model.LayoutBranch;
021    import com.liferay.portal.model.RecentLayoutBranch;
022    import com.liferay.portal.service.base.RecentLayoutBranchLocalServiceBaseImpl;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Preston Crary
027     */
028    @ProviderType
029    public class RecentLayoutBranchLocalServiceImpl
030            extends RecentLayoutBranchLocalServiceBaseImpl {
031    
032            @Override
033            public RecentLayoutBranch addRecentLayoutBranch(
034                            long userId, long layoutBranchId, long layoutSetBranchId, long plid)
035                    throws PortalException {
036    
037                    LayoutBranch layoutBranch = layoutBranchPersistence.findByPrimaryKey(
038                            layoutBranchId);
039    
040                    RecentLayoutBranch recentLayoutBranch =
041                            recentLayoutBranchPersistence.create(
042                                    counterLocalService.increment());
043    
044                    recentLayoutBranch.setGroupId(layoutBranch.getGroupId());
045                    recentLayoutBranch.setCompanyId(layoutBranch.getCompanyId());
046                    recentLayoutBranch.setUserId(userId);
047                    recentLayoutBranch.setLayoutBranchId(layoutBranchId);
048                    recentLayoutBranch.setLayoutSetBranchId(layoutSetBranchId);
049                    recentLayoutBranch.setPlid(plid);
050    
051                    return recentLayoutBranchPersistence.update(recentLayoutBranch);
052            }
053    
054            @Override
055            public void deleteRecentLayoutBranches(long layoutBranchId) {
056                    recentLayoutBranchPersistence.removeByLayoutBranchId(layoutBranchId);
057            }
058    
059            @Override
060            public void deleteUserRecentLayoutBranches(long userId) {
061                    recentLayoutBranchPersistence.removeByUserId(userId);
062            }
063    
064            @Override
065            public RecentLayoutBranch fetchRecentLayoutBranch(
066                    long userId, long layoutSetBranchId, long plid) {
067    
068                    return recentLayoutBranchPersistence.fetchByU_L_P(
069                            userId, layoutSetBranchId, plid);
070            }
071    
072    }