1   /**
2    * Copyright (c) 2000-2008 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.polls.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.portal.service.permission.PortletPermissionUtil;
29  import com.liferay.portal.util.PortletKeys;
30  import com.liferay.portlet.polls.model.PollsChoice;
31  import com.liferay.portlet.polls.model.PollsQuestion;
32  import com.liferay.portlet.polls.service.base.PollsQuestionServiceBaseImpl;
33  import com.liferay.portlet.polls.service.permission.PollsQuestionPermission;
34  
35  import java.util.List;
36  
37  /**
38   * <a href="PollsQuestionServiceImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   *
42   */
43  public class PollsQuestionServiceImpl extends PollsQuestionServiceBaseImpl {
44  
45      public PollsQuestion addQuestion(
46              long plid, String title, String description,
47              int expirationDateMonth, int expirationDateDay,
48              int expirationDateYear, int expirationDateHour,
49              int expirationDateMinute, boolean neverExpire,
50              List<PollsChoice> choices, boolean addCommunityPermissions,
51              boolean addGuestPermissions)
52          throws PortalException, SystemException {
53  
54          PortletPermissionUtil.check(
55              getPermissionChecker(), plid, PortletKeys.POLLS,
56              ActionKeys.ADD_QUESTION);
57  
58          return pollsQuestionLocalService.addQuestion(
59              getUserId(), plid, title, description, expirationDateMonth,
60              expirationDateDay, expirationDateYear, expirationDateHour,
61              expirationDateMinute, neverExpire, choices,
62              addCommunityPermissions, addGuestPermissions);
63      }
64  
65      public PollsQuestion addQuestion(
66              long plid, String title, String description,
67              int expirationDateMonth, int expirationDateDay,
68              int expirationDateYear, int expirationDateHour,
69              int expirationDateMinute, boolean neverExpire,
70              List<PollsChoice> choices, String[] communityPermissions,
71              String[] guestPermissions)
72          throws PortalException, SystemException {
73  
74          PortletPermissionUtil.check(
75              getPermissionChecker(), plid, PortletKeys.POLLS,
76              ActionKeys.ADD_QUESTION);
77  
78          return pollsQuestionLocalService.addQuestion(
79              getUserId(), plid, title, description, expirationDateMonth,
80              expirationDateDay, expirationDateYear, expirationDateHour,
81              expirationDateMinute, neverExpire, choices, communityPermissions,
82              guestPermissions);
83      }
84  
85      public void deleteQuestion(long questionId)
86          throws PortalException, SystemException {
87  
88          PollsQuestionPermission.check(
89              getPermissionChecker(), questionId, ActionKeys.DELETE);
90  
91          pollsQuestionLocalService.deleteQuestion(questionId);
92      }
93  
94      public PollsQuestion getQuestion(long questionId)
95          throws PortalException, SystemException {
96  
97          PollsQuestionPermission.check(
98              getPermissionChecker(), questionId, ActionKeys.VIEW);
99  
100         return pollsQuestionLocalService.getQuestion(questionId);
101     }
102 
103     public PollsQuestion updateQuestion(
104             long questionId, String title, String description,
105             int expirationDateMonth, int expirationDateDay,
106             int expirationDateYear, int expirationDateHour,
107             int expirationDateMinute, boolean neverExpire,
108             List<PollsChoice> choices)
109         throws PortalException, SystemException {
110 
111         PollsQuestionPermission.check(
112             getPermissionChecker(), questionId, ActionKeys.UPDATE);
113 
114         return pollsQuestionLocalService.updateQuestion(
115             getUserId(), questionId, title, description, expirationDateMonth,
116             expirationDateDay, expirationDateYear, expirationDateHour,
117             expirationDateMinute, neverExpire, choices);
118     }
119 
120 }