001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.NoSuchUserNotificationDeliveryException;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.model.User;
021 import com.liferay.portal.model.UserNotificationDelivery;
022 import com.liferay.portal.service.base.UserNotificationDeliveryLocalServiceBaseImpl;
023
024
027 public class UserNotificationDeliveryLocalServiceImpl
028 extends UserNotificationDeliveryLocalServiceBaseImpl {
029
030 @Override
031 public UserNotificationDelivery addUserNotificationDelivery(
032 long userId, String portletId, long classNameId,
033 int notificationType, int deliveryType, boolean deliver)
034 throws PortalException, SystemException {
035
036 User user = userPersistence.findByPrimaryKey(userId);
037
038 long userNotificationDeliveryId = counterLocalService.increment();
039
040 UserNotificationDelivery userNotificationDelivery =
041 userNotificationDeliveryPersistence.create(
042 userNotificationDeliveryId);
043
044 userNotificationDelivery.setCompanyId(user.getCompanyId());
045 userNotificationDelivery.setUserId(user.getUserId());
046 userNotificationDelivery.setPortletId(portletId);
047 userNotificationDelivery.setClassNameId(classNameId);
048 userNotificationDelivery.setNotificationType(notificationType);
049 userNotificationDelivery.setDeliveryType(deliveryType);
050 userNotificationDelivery.setDeliver(deliver);
051
052 return userNotificationDeliveryPersistence.update(
053 userNotificationDelivery);
054 }
055
056 @Override
057 public void deleteUserNotificationDeliveries(long userId)
058 throws SystemException {
059
060 userNotificationDeliveryPersistence.removeByUserId(userId);
061 }
062
063 @Override
064 public void deleteUserNotificationDelivery(
065 long userId, String portletId, long classNameId,
066 int notificationType, int deliveryType)
067 throws SystemException {
068
069 try {
070 userNotificationDeliveryPersistence.removeByU_P_C_N_D(
071 userId, portletId, classNameId, notificationType, deliveryType);
072 }
073 catch (NoSuchUserNotificationDeliveryException nsnde) {
074 }
075 }
076
077 @Override
078 public UserNotificationDelivery fetchUserNotificationDelivery(
079 long userId, String portletId, long classNameId,
080 int notificationType, int deliveryType)
081 throws SystemException {
082
083 return userNotificationDeliveryPersistence.fetchByU_P_C_N_D(
084 userId, portletId, classNameId, notificationType, deliveryType);
085 }
086
087 @Override
088 public UserNotificationDelivery getUserNotificationDelivery(
089 long userId, String portletId, long classNameId,
090 int notificationType, int deliveryType, boolean deliver)
091 throws PortalException, SystemException {
092
093 UserNotificationDelivery userNotificationDelivery =
094 userNotificationDeliveryPersistence.fetchByU_P_C_N_D(
095 userId, portletId, classNameId, notificationType, deliveryType);
096
097 if (userNotificationDelivery != null) {
098 return userNotificationDelivery;
099 }
100
101 return userNotificationDeliveryLocalService.addUserNotificationDelivery(
102 userId, portletId, classNameId, notificationType, deliveryType,
103 deliver);
104 }
105
106 @Override
107 public UserNotificationDelivery updateUserNotificationDelivery(
108 long userNotificationDeliveryId, boolean deliver)
109 throws SystemException {
110
111 UserNotificationDelivery userNotificationDelivery =
112 fetchUserNotificationDelivery(userNotificationDeliveryId);
113
114 userNotificationDelivery.setDeliver(deliver);
115
116 return userNotificationDeliveryPersistence.update(
117 userNotificationDelivery);
118 }
119
120 }