001
014
015 package com.liferay.portlet.announcements.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.model.Group;
020 import com.liferay.portal.model.Organization;
021 import com.liferay.portal.model.Role;
022 import com.liferay.portal.model.UserGroup;
023 import com.liferay.portal.security.auth.PrincipalException;
024 import com.liferay.portal.security.permission.ActionKeys;
025 import com.liferay.portal.security.permission.PermissionChecker;
026 import com.liferay.portal.service.permission.GroupPermissionUtil;
027 import com.liferay.portal.service.permission.OrganizationPermissionUtil;
028 import com.liferay.portal.service.permission.PortletPermissionUtil;
029 import com.liferay.portal.service.permission.RolePermissionUtil;
030 import com.liferay.portal.service.permission.UserGroupPermissionUtil;
031 import com.liferay.portal.util.PortalUtil;
032 import com.liferay.portal.util.PortletKeys;
033 import com.liferay.portlet.announcements.model.AnnouncementsEntry;
034 import com.liferay.portlet.announcements.service.base.AnnouncementsEntryServiceBaseImpl;
035 import com.liferay.portlet.announcements.service.permission.AnnouncementsEntryPermission;
036
037
040 public class AnnouncementsEntryServiceImpl
041 extends AnnouncementsEntryServiceBaseImpl {
042
043 public AnnouncementsEntry addEntry(
044 long plid, long classNameId, long classPK, String title,
045 String content, String url, String type, int displayDateMonth,
046 int displayDateDay, int displayDateYear, int displayDateHour,
047 int displayDateMinute, int expirationDateMonth,
048 int expirationDateDay, int expirationDateYear,
049 int expirationDateHour, int expirationDateMinute, int priority,
050 boolean alert)
051 throws PortalException, SystemException {
052
053 PermissionChecker permissionChecker = getPermissionChecker();
054
055 PortletPermissionUtil.check(
056 permissionChecker, plid, PortletKeys.ANNOUNCEMENTS,
057 ActionKeys.ADD_ENTRY);
058
059 if (classNameId == 0) {
060 if (!permissionChecker.isOmniadmin()) {
061 throw new PrincipalException();
062 }
063 }
064 else {
065 String className = PortalUtil.getClassName(classNameId);
066
067 if (className.equals(Group.class.getName()) &&
068 !GroupPermissionUtil.contains(
069 permissionChecker, classPK,
070 ActionKeys.MANAGE_ANNOUNCEMENTS)) {
071
072 throw new PrincipalException();
073 }
074
075 if (className.equals(Organization.class.getName()) &&
076 !OrganizationPermissionUtil.contains(
077 permissionChecker, classPK,
078 ActionKeys.MANAGE_ANNOUNCEMENTS)) {
079
080 throw new PrincipalException();
081 }
082
083 if (className.equals(Role.class.getName()) &&
084 !RolePermissionUtil.contains(
085 permissionChecker, classPK,
086 ActionKeys.MANAGE_ANNOUNCEMENTS)) {
087
088 throw new PrincipalException();
089 }
090
091 if (className.equals(UserGroup.class.getName()) &&
092 !UserGroupPermissionUtil.contains(
093 permissionChecker, classPK,
094 ActionKeys.MANAGE_ANNOUNCEMENTS)) {
095
096 throw new PrincipalException();
097 }
098 }
099
100 return announcementsEntryLocalService.addEntry(
101 getUserId(), classNameId, classPK, title, content, url, type,
102 displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
103 displayDateMinute, expirationDateMonth, expirationDateDay,
104 expirationDateYear, expirationDateHour, expirationDateMinute,
105 priority, alert);
106 }
107
108 public void deleteEntry(long entryId)
109 throws PortalException, SystemException {
110
111 AnnouncementsEntryPermission.check(
112 getPermissionChecker(), entryId, ActionKeys.DELETE);
113
114 announcementsEntryLocalService.deleteEntry(entryId);
115 }
116
117 public AnnouncementsEntry updateEntry(
118 long entryId, String title, String content, String url,
119 String type, int displayDateMonth, int displayDateDay,
120 int displayDateYear, int displayDateHour, int displayDateMinute,
121 int expirationDateMonth, int expirationDateDay,
122 int expirationDateYear, int expirationDateHour,
123 int expirationDateMinute, int priority)
124 throws PortalException, SystemException {
125
126 AnnouncementsEntryPermission.check(
127 getPermissionChecker(), entryId, ActionKeys.UPDATE);
128
129 return announcementsEntryLocalService.updateEntry(
130 getUserId(), entryId, title, content, url, type, displayDateMonth,
131 displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
132 expirationDateMonth, expirationDateDay, expirationDateYear,
133 expirationDateHour, expirationDateMinute, priority);
134 }
135
136 }