001
014
015 package com.liferay.portlet.mobiledevicerules.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.UnicodeProperties;
020 import com.liferay.portal.model.User;
021 import com.liferay.portal.service.ServiceContext;
022 import com.liferay.portlet.mobiledevicerules.model.MDRAction;
023 import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance;
024 import com.liferay.portlet.mobiledevicerules.service.base.MDRActionLocalServiceBaseImpl;
025
026 import java.util.Date;
027 import java.util.List;
028 import java.util.Locale;
029 import java.util.Map;
030
031
034 public class MDRActionLocalServiceImpl extends MDRActionLocalServiceBaseImpl {
035
036 @Override
037 public MDRAction addAction(
038 long ruleGroupInstanceId, Map<Locale, String> nameMap,
039 Map<Locale, String> descriptionMap, String type,
040 String typeSettings, ServiceContext serviceContext)
041 throws PortalException, SystemException {
042
043 User user = userPersistence.findByPrimaryKey(
044 serviceContext.getUserId());
045 MDRRuleGroupInstance ruleGroupInstance =
046 mdrRuleGroupInstancePersistence.findByPrimaryKey(
047 ruleGroupInstanceId);
048 Date now = new Date();
049
050 long actionId = counterLocalService.increment();
051
052 MDRAction action = mdrActionLocalService.createMDRAction(actionId);
053
054 action.setUuid(serviceContext.getUuid());
055 action.setGroupId(ruleGroupInstance.getGroupId());
056 action.setCompanyId(serviceContext.getCompanyId());
057 action.setCreateDate(serviceContext.getCreateDate(now));
058 action.setModifiedDate(serviceContext.getModifiedDate(now));
059 action.setUserId(serviceContext.getUserId());
060 action.setUserName(user.getFullName());
061 action.setClassNameId(ruleGroupInstance.getClassNameId());
062 action.setClassPK(ruleGroupInstance.getClassPK());
063 action.setRuleGroupInstanceId(ruleGroupInstanceId);
064 action.setNameMap(nameMap);
065 action.setDescriptionMap(descriptionMap);
066 action.setType(type);
067 action.setTypeSettings(typeSettings);
068
069 action = updateMDRAction(action, false);
070
071 ruleGroupInstance.setModifiedDate(now);
072
073 mdrRuleGroupInstancePersistence.update(ruleGroupInstance, false);
074
075 return action;
076 }
077
078 @Override
079 public MDRAction addAction(
080 long ruleGroupInstanceId, Map<Locale, String> nameMap,
081 Map<Locale, String> descriptionMap, String type,
082 UnicodeProperties typeSettingsProperties,
083 ServiceContext serviceContext)
084 throws PortalException, SystemException {
085
086 return addAction(
087 ruleGroupInstanceId, nameMap, descriptionMap, type,
088 typeSettingsProperties.toString(), serviceContext);
089 }
090
091 @Override
092 public void deleteAction(long actionId) throws SystemException {
093 MDRAction action = mdrActionPersistence.fetchByPrimaryKey(actionId);
094
095 if (action != null) {
096 deleteAction(action);
097 }
098 }
099
100 @Override
101 public void deleteAction(MDRAction action) throws SystemException {
102 mdrActionPersistence.remove(action);
103
104 MDRRuleGroupInstance ruleGroupInstance =
105 mdrRuleGroupInstancePersistence.fetchByPrimaryKey(
106 action.getRuleGroupInstanceId());
107
108 if (ruleGroupInstance != null) {
109 ruleGroupInstance.setModifiedDate(new Date());
110
111 mdrRuleGroupInstancePersistence.update(ruleGroupInstance, false);
112 }
113 }
114
115 @Override
116 public void deleteActions(long ruleGroupInstanceId) throws SystemException {
117 List<MDRAction> actions =
118 mdrActionPersistence.findByRuleGroupInstanceId(ruleGroupInstanceId);
119
120 for (MDRAction action : actions) {
121 deleteAction(action);
122 }
123 }
124
125 @Override
126 public MDRAction fetchAction(long actionId) throws SystemException {
127 return mdrActionPersistence.fetchByPrimaryKey(actionId);
128 }
129
130 @Override
131 public MDRAction getAction(long actionId)
132 throws PortalException, SystemException {
133
134 return mdrActionPersistence.findByPrimaryKey(actionId);
135 }
136
137 @Override
138 public List<MDRAction> getActions(long ruleGroupInstanceId)
139 throws SystemException {
140
141 return mdrActionPersistence.findByRuleGroupInstanceId(
142 ruleGroupInstanceId);
143 }
144
145 @Override
146 public List<MDRAction> getActions(
147 long ruleGroupInstanceId, int start, int end)
148 throws SystemException {
149
150 return mdrActionPersistence.findByRuleGroupInstanceId(
151 ruleGroupInstanceId, start, end);
152 }
153
154 @Override
155 public int getActionsCount(long ruleGroupInstanceId)
156 throws SystemException {
157
158 return mdrActionPersistence.countByRuleGroupInstanceId(
159 ruleGroupInstanceId);
160 }
161
162 @Override
163 public MDRAction updateAction(
164 long actionId, Map<Locale, String> nameMap,
165 Map<Locale, String> descriptionMap, String type,
166 String typeSettings, ServiceContext serviceContext)
167 throws PortalException, SystemException {
168
169 MDRAction action = mdrActionPersistence.findByPrimaryKey(actionId);
170
171 action.setModifiedDate(serviceContext.getModifiedDate(null));
172 action.setNameMap(nameMap);
173 action.setDescriptionMap(descriptionMap);
174 action.setType(type);
175 action.setTypeSettings(typeSettings);
176
177 mdrActionPersistence.update(action, false);
178
179 MDRRuleGroupInstance ruleGroupInstance =
180 mdrRuleGroupInstancePersistence.findByPrimaryKey(
181 action.getRuleGroupInstanceId());
182
183 ruleGroupInstance.setModifiedDate(serviceContext.getModifiedDate(null));
184
185 mdrRuleGroupInstancePersistence.update(ruleGroupInstance, false);
186
187 return action;
188 }
189
190 @Override
191 public MDRAction updateAction(
192 long actionId, Map<Locale, String> nameMap,
193 Map<Locale, String> descriptionMap, String type,
194 UnicodeProperties typeSettingsProperties,
195 ServiceContext serviceContext)
196 throws PortalException, SystemException {
197
198 return updateAction(
199 actionId, nameMap, descriptionMap, type,
200 typeSettingsProperties.toString(), serviceContext);
201 }
202
203 }