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   */
41  public class SCProductVersionServiceImpl
42      extends SCProductVersionServiceBaseImpl {
43  
44      public SCProductVersion addProductVersion(
45              long productEntryId, String version, String changeLog,
46              String downloadPageURL, String directDownloadURL,
47              boolean testDirectDownloadURL, boolean repoStoreArtifact,
48              long[] frameworkVersionIds, boolean addCommunityPermissions,
49              boolean addGuestPermissions)
50          throws PortalException, SystemException {
51  
52          SCProductEntryPermission.check(
53              getPermissionChecker(), productEntryId, ActionKeys.UPDATE);
54  
55          return scProductVersionLocalService.addProductVersion(
56              getUserId(), productEntryId, version, changeLog, downloadPageURL,
57              directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
58              frameworkVersionIds, addCommunityPermissions, addGuestPermissions);
59      }
60  
61      public SCProductVersion addProductVersion(
62              long productEntryId, String version, String changeLog,
63              String downloadPageURL, String directDownloadURL,
64              boolean testDirectDownloadURL, boolean repoStoreArtifact,
65              long[] frameworkVersionIds, String[] communityPermissions,
66              String[] guestPermissions)
67          throws PortalException, SystemException {
68  
69          SCProductEntryPermission.check(
70              getPermissionChecker(), productEntryId, ActionKeys.UPDATE);
71  
72          return scProductVersionLocalService.addProductVersion(
73              getUserId(), productEntryId, version, changeLog, downloadPageURL,
74              directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
75              frameworkVersionIds, communityPermissions, guestPermissions);
76      }
77  
78      public void deleteProductVersion(long productVersionId)
79          throws PortalException, SystemException {
80  
81          SCProductVersion productVersion =
82              scProductVersionLocalService.getProductVersion(productVersionId);
83  
84          SCProductEntryPermission.check(
85              getPermissionChecker(), productVersion.getProductEntryId(),
86              ActionKeys.UPDATE);
87  
88          scProductVersionLocalService.deleteProductVersion(productVersionId);
89      }
90  
91      public SCProductVersion getProductVersion(long productVersionId)
92          throws PortalException, SystemException {
93  
94          SCProductVersion productVersion =
95              scProductVersionLocalService.getProductVersion(productVersionId);
96  
97          SCProductEntryPermission.check(
98              getPermissionChecker(), productVersion.getProductEntryId(),
99              ActionKeys.VIEW);
100 
101         return productVersion;
102     }
103 
104     public List<SCProductVersion> getProductVersions(
105             long productEntryId, int start, int end)
106         throws SystemException, PortalException {
107 
108         SCProductEntryPermission.check(
109             getPermissionChecker(), productEntryId, ActionKeys.VIEW);
110 
111         return scProductVersionLocalService.getProductVersions(
112             productEntryId, start, end);
113     }
114 
115     public int getProductVersionsCount(long productEntryId)
116         throws SystemException, PortalException {
117 
118         SCProductEntryPermission.check(
119             getPermissionChecker(), productEntryId, ActionKeys.VIEW);
120 
121         return scProductVersionLocalService.getProductVersionsCount(
122             productEntryId);
123     }
124 
125     public SCProductVersion updateProductVersion(
126             long productVersionId, String version, String changeLog,
127             String downloadPageURL, String directDownloadURL,
128             boolean testDirectDownloadURL, boolean repoStoreArtifact,
129             long[] frameworkVersionIds)
130         throws PortalException, SystemException {
131 
132         SCProductVersion productVersion =
133             scProductVersionLocalService.getProductVersion(productVersionId);
134 
135         SCProductEntryPermission.check(
136             getPermissionChecker(), productVersion.getProductEntryId(),
137             ActionKeys.UPDATE);
138 
139         return scProductVersionLocalService.updateProductVersion(
140             productVersionId, version, changeLog, downloadPageURL,
141             directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
142             frameworkVersionIds);
143     }
144 
145 }