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.softwarecatalog.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.security.permission.ActionKeys;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
021    import com.liferay.portlet.softwarecatalog.service.base.SCProductVersionServiceBaseImpl;
022    import com.liferay.portlet.softwarecatalog.service.permission.SCProductEntryPermission;
023    
024    import java.util.List;
025    
026    /**
027     * @author Jorge Ferrer
028     * @author Brian Wing Shun Chan
029     */
030    public class SCProductVersionServiceImpl
031            extends SCProductVersionServiceBaseImpl {
032    
033            @Override
034            public SCProductVersion addProductVersion(
035                            long productEntryId, String version, String changeLog,
036                            String downloadPageURL, String directDownloadURL,
037                            boolean testDirectDownloadURL, boolean repoStoreArtifact,
038                            long[] frameworkVersionIds, ServiceContext serviceContext)
039                    throws PortalException {
040    
041                    SCProductEntryPermission.check(
042                            getPermissionChecker(), productEntryId, ActionKeys.UPDATE);
043    
044                    return scProductVersionLocalService.addProductVersion(
045                            getUserId(), productEntryId, version, changeLog, downloadPageURL,
046                            directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
047                            frameworkVersionIds, serviceContext);
048            }
049    
050            @Override
051            public void deleteProductVersion(long productVersionId)
052                    throws PortalException {
053    
054                    SCProductVersion productVersion =
055                            scProductVersionLocalService.getProductVersion(productVersionId);
056    
057                    SCProductEntryPermission.check(
058                            getPermissionChecker(), productVersion.getProductEntryId(),
059                            ActionKeys.UPDATE);
060    
061                    scProductVersionLocalService.deleteProductVersion(productVersionId);
062            }
063    
064            @Override
065            public SCProductVersion getProductVersion(long productVersionId)
066                    throws PortalException {
067    
068                    SCProductVersion productVersion =
069                            scProductVersionLocalService.getProductVersion(productVersionId);
070    
071                    SCProductEntryPermission.check(
072                            getPermissionChecker(), productVersion.getProductEntryId(),
073                            ActionKeys.VIEW);
074    
075                    return productVersion;
076            }
077    
078            @Override
079            public List<SCProductVersion> getProductVersions(
080                            long productEntryId, int start, int end)
081                    throws PortalException {
082    
083                    SCProductEntryPermission.check(
084                            getPermissionChecker(), productEntryId, ActionKeys.VIEW);
085    
086                    return scProductVersionLocalService.getProductVersions(
087                            productEntryId, start, end);
088            }
089    
090            @Override
091            public int getProductVersionsCount(long productEntryId)
092                    throws PortalException {
093    
094                    SCProductEntryPermission.check(
095                            getPermissionChecker(), productEntryId, ActionKeys.VIEW);
096    
097                    return scProductVersionLocalService.getProductVersionsCount(
098                            productEntryId);
099            }
100    
101            @Override
102            public SCProductVersion updateProductVersion(
103                            long productVersionId, String version, String changeLog,
104                            String downloadPageURL, String directDownloadURL,
105                            boolean testDirectDownloadURL, boolean repoStoreArtifact,
106                            long[] frameworkVersionIds)
107                    throws PortalException {
108    
109                    SCProductVersion productVersion =
110                            scProductVersionLocalService.getProductVersion(productVersionId);
111    
112                    SCProductEntryPermission.check(
113                            getPermissionChecker(), productVersion.getProductEntryId(),
114                            ActionKeys.UPDATE);
115    
116                    return scProductVersionLocalService.updateProductVersion(
117                            productVersionId, version, changeLog, downloadPageURL,
118                            directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
119                            frameworkVersionIds);
120            }
121    
122    }