1
19
20 package com.liferay.portlet.announcements.service.impl;
21
22 import com.liferay.portal.PortalException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.model.User;
25 import com.liferay.portlet.announcements.NoSuchDeliveryException;
26 import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
27 import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryImpl;
28 import com.liferay.portlet.announcements.service.base.AnnouncementsDeliveryLocalServiceBaseImpl;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33
40 public class AnnouncementsDeliveryLocalServiceImpl
41 extends AnnouncementsDeliveryLocalServiceBaseImpl {
42
43 public void deleteDeliveries(long userId) throws SystemException {
44 announcementsDeliveryPersistence.removeByUserId(userId);
45 }
46
47 public void deleteDelivery(long deliveryId)
48 throws PortalException, SystemException {
49
50 announcementsDeliveryPersistence.remove(deliveryId);
51 }
52
53 public void deleteDelivery(long userId, String type)
54 throws SystemException {
55
56 try {
57 announcementsDeliveryPersistence.removeByU_T(userId, type);
58 }
59 catch (NoSuchDeliveryException nsde) {
60 }
61 }
62
63 public AnnouncementsDelivery getDelivery(long deliveryId)
64 throws PortalException, SystemException {
65
66 return announcementsDeliveryPersistence.findByPrimaryKey(deliveryId);
67 }
68
69 public List<AnnouncementsDelivery> getUserDeliveries(long userId)
70 throws PortalException, SystemException {
71
72 List<AnnouncementsDelivery> deliveries =
73 new ArrayList<AnnouncementsDelivery>(
74 AnnouncementsEntryImpl.TYPES.length);
75
76 for (String type : AnnouncementsEntryImpl.TYPES) {
77 deliveries.add(getUserDelivery(userId, type));
78 }
79
80 return deliveries;
81 }
82
83 public AnnouncementsDelivery getUserDelivery(long userId, String type)
84 throws PortalException, SystemException {
85
86 AnnouncementsDelivery delivery =
87 announcementsDeliveryPersistence.fetchByU_T(userId, type);
88
89 if (delivery == null) {
90 User user = userPersistence.findByPrimaryKey(userId);
91
92 long deliveryId = counterLocalService.increment();
93
94 delivery = announcementsDeliveryPersistence.create(deliveryId);
95
96 delivery.setCompanyId(user.getCompanyId());
97 delivery.setUserId(user.getUserId());
98 delivery.setType(type);
99 delivery.setEmail(false);
100 delivery.setSms(false);
101 delivery.setWebsite(true);
102
103 announcementsDeliveryPersistence.update(delivery, false);
104 }
105
106 return delivery;
107 }
108
109 public AnnouncementsDelivery updateDelivery(
110 long userId, String type, boolean email, boolean sms,
111 boolean website)
112 throws PortalException, SystemException {
113
114 AnnouncementsDelivery delivery = getUserDelivery(userId, type);
115
116 delivery.setEmail(email);
117 delivery.setSms(sms);
118 delivery.setWebsite(website);
119
120 announcementsDeliveryPersistence.update(delivery, false);
121
122 return delivery;
123 }
124
125 }