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