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