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.LayoutSetBranch;
021    import com.liferay.portal.model.RecentLayoutSetBranch;
022    import com.liferay.portal.service.base.RecentLayoutSetBranchLocalServiceBaseImpl;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Preston Crary
027     */
028    @ProviderType
029    public class RecentLayoutSetBranchLocalServiceImpl
030            extends RecentLayoutSetBranchLocalServiceBaseImpl {
031    
032            @Override
033            public RecentLayoutSetBranch addRecentLayoutSetBranch(
034                            long userId, long layoutSetBranchId, long layoutSetId)
035                    throws PortalException {
036    
037                    LayoutSetBranch layoutSetBranch =
038                            layoutSetBranchPersistence.findByPrimaryKey(layoutSetBranchId);
039    
040                    RecentLayoutSetBranch recentLayoutSetBranch =
041                            recentLayoutSetBranchPersistence.create(
042                                    counterLocalService.increment());
043    
044                    recentLayoutSetBranch.setGroupId(layoutSetBranch.getGroupId());
045                    recentLayoutSetBranch.setCompanyId(layoutSetBranch.getCompanyId());
046                    recentLayoutSetBranch.setUserId(userId);
047                    recentLayoutSetBranch.setLayoutSetBranchId(layoutSetBranchId);
048                    recentLayoutSetBranch.setLayoutSetId(layoutSetId);
049    
050                    return recentLayoutSetBranchPersistence.update(recentLayoutSetBranch);
051            }
052    
053            @Override
054            public void deleteRecentLayoutSetBranches(long layoutSetBranchId) {
055                    recentLayoutSetBranchPersistence.removeByLayoutSetBranchId(
056                            layoutSetBranchId);
057            }
058    
059            @Override
060            public void deleteUserRecentLayoutSetBranches(long userId) {
061                    recentLayoutSetBranchPersistence.removeByUserId(userId);
062            }
063    
064            @Override
065            public RecentLayoutSetBranch fetchRecentLayoutSetBranch(
066                    long userId, long layoutSetId) {
067    
068                    return recentLayoutSetBranchPersistence.fetchByU_L(userId, layoutSetId);
069            }
070    
071    }