1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.softwarecatalog.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.security.permission.ActionKeys;
28  import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
29  import com.liferay.portlet.softwarecatalog.service.base.SCProductVersionServiceBaseImpl;
30  import com.liferay.portlet.softwarecatalog.service.permission.SCProductEntryPermission;
31  
32  import java.util.List;
33  
34  /**
35   * <a href="SCProductVersionServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Jorge Ferrer
38   * @author Brian Wing Shun Chan
39   */
40  public class SCProductVersionServiceImpl
41      extends SCProductVersionServiceBaseImpl {
42  
43      public SCProductVersion addProductVersion(
44              long productEntryId, String version, String changeLog,
45              String downloadPageURL, String directDownloadURL,
46              boolean testDirectDownloadURL, boolean repoStoreArtifact,
47              long[] frameworkVersionIds, boolean addCommunityPermissions,
48              boolean addGuestPermissions)
49          throws PortalException, SystemException {
50  
51          SCProductEntryPermission.check(
52              getPermissionChecker(), productEntryId, ActionKeys.UPDATE);
53  
54          return scProductVersionLocalService.addProductVersion(
55              getUserId(), productEntryId, version, changeLog, downloadPageURL,
56              directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
57              frameworkVersionIds, addCommunityPermissions, addGuestPermissions);
58      }
59  
60      public SCProductVersion addProductVersion(
61              long productEntryId, String version, String changeLog,
62              String downloadPageURL, String directDownloadURL,
63              boolean testDirectDownloadURL, boolean repoStoreArtifact,
64              long[] frameworkVersionIds, String[] communityPermissions,
65              String[] guestPermissions)
66          throws PortalException, SystemException {
67  
68          SCProductEntryPermission.check(
69              getPermissionChecker(), productEntryId, ActionKeys.UPDATE);
70  
71          return scProductVersionLocalService.addProductVersion(
72              getUserId(), productEntryId, version, changeLog, downloadPageURL,
73              directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
74              frameworkVersionIds, communityPermissions, guestPermissions);
75      }
76  
77      public void deleteProductVersion(long productVersionId)
78          throws PortalException, SystemException {
79  
80          SCProductVersion productVersion =
81              scProductVersionLocalService.getProductVersion(productVersionId);
82  
83          SCProductEntryPermission.check(
84              getPermissionChecker(), productVersion.getProductEntryId(),
85              ActionKeys.UPDATE);
86  
87          scProductVersionLocalService.deleteProductVersion(productVersionId);
88      }
89  
90      public SCProductVersion getProductVersion(long productVersionId)
91          throws PortalException, SystemException {
92  
93          SCProductVersion productVersion =
94              scProductVersionLocalService.getProductVersion(productVersionId);
95  
96          SCProductEntryPermission.check(
97              getPermissionChecker(), productVersion.getProductEntryId(),
98              ActionKeys.VIEW);
99  
100         return productVersion;
101     }
102 
103     public List<SCProductVersion> getProductVersions(
104             long productEntryId, int start, int end)
105         throws SystemException, PortalException {
106 
107         SCProductEntryPermission.check(
108             getPermissionChecker(), productEntryId, ActionKeys.VIEW);
109 
110         return scProductVersionLocalService.getProductVersions(
111             productEntryId, start, end);
112     }
113 
114     public int getProductVersionsCount(long productEntryId)
115         throws SystemException, PortalException {
116 
117         SCProductEntryPermission.check(
118             getPermissionChecker(), productEntryId, ActionKeys.VIEW);
119 
120         return scProductVersionLocalService.getProductVersionsCount(
121             productEntryId);
122     }
123 
124     public SCProductVersion updateProductVersion(
125             long productVersionId, String version, String changeLog,
126             String downloadPageURL, String directDownloadURL,
127             boolean testDirectDownloadURL, boolean repoStoreArtifact,
128             long[] frameworkVersionIds)
129         throws PortalException, SystemException {
130 
131         SCProductVersion productVersion =
132             scProductVersionLocalService.getProductVersion(productVersionId);
133 
134         SCProductEntryPermission.check(
135             getPermissionChecker(), productVersion.getProductEntryId(),
136             ActionKeys.UPDATE);
137 
138         return scProductVersionLocalService.updateProductVersion(
139             productVersionId, version, changeLog, downloadPageURL,
140             directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
141             frameworkVersionIds);
142     }
143 
144 }