* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
public ActionForward modify(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp) {
SmsInteractionEnterOrEditForm msgForm = (SmsInteractionEnterOrEditForm) form;
long commandEntryId = msgForm.getCommandEntryId();
CommandEntryManager commandEntryManager = new CommandEntryManager(locale,session);
CommandEntry commandEntry = commandEntryManager.getCommandEntry(commandEntryId);
if (commandEntry == null || !(commandEntry instanceof SmsCommandEntry)){
throw new InputException(getResources(req).getMessage(locale, "smssvc.editedInteractionDoesNotExistAnymore")); // may have been deleted
}
SmsCommandEntry smsCommandEntry = (SmsCommandEntry)commandEntry;
Group group = smsCommandEntry.getGroup();
checkAccessRights(req, group);
commandEntryManager.evict(smsCommandEntry); // do not modify in this session yet (might be erroneous)
String messageText = msgForm.getMessage();
if (grossSmsMessageLength(messageText) > MAX_MESSAGE_TEXT_LENGTH){
throw new InputException(getResources(req).getMessage(locale,"smssvc.messageLongerThan450characters"));
}
Sender sender = senderFromMsisdn(req, msgForm.getSendingMsisdn(), group);
SmsTextValidator.checkForValidLatin1AndSmsAllowingPlaceholders(msgForm.getMessage(), locale);
smsCommandEntry.setSender(sender);
smsCommandEntry.setTextContent(messageText);
smsCommandEntry.setDelayInSeconds(msgForm.getDelayInSeconds());
String sortLabel = msgForm.getSortLabel();
smsCommandEntry.setSortLabel(sortLabel);
switch (msgForm.getDestinationSelection().intValue()){
case 1: // message return to sender
smsCommandEntry.setDestinationContact(0);
smsCommandEntry.setDestinationUserSet(null);
smsCommandEntry.setDestinationUser(null);
smsCommandEntry.setDestinationMsisdn(null);
break;
case 2: // contact
smsCommandEntry.setDestinationContact(1);
smsCommandEntry.setDestinationUserSet(null);
smsCommandEntry.setDestinationUser(null);
smsCommandEntry.setDestinationMsisdn(null);
break;
case 4: // message to user set
smsCommandEntry.setDestinationContact(0);
Long userSetId = msgForm.getUserSetId();
if(userSetId.longValue() == -1){
throw new BugException("illegal user set id: " + userSetId);
}
UserSetManager userSetManager = new UserSetManager(locale,session);
UserSet userSet = userSetManager.getUserSet(userSetId);
if (userSet == null && userSetId != -2) {
throw new ConfigurationException("illegal user set id: " + userSetId);
}
smsCommandEntry.setDestinationUserSet(userSet);
smsCommandEntry.setCurrentUserSetAsDestination(userSetId == -2 ? 1 : 0);
smsCommandEntry.setDestinationUser(null);
smsCommandEntry.setDestinationMsisdn(null);
break;
case 5: // message to user
Long userId = msgForm.getUserId();
if (userId.longValue() == -1){
String noUserSelectedString = getResources(req).getMessage(locale,"smssvc.MessageNotSentBecauseNoUserSelected");
throw new InputException(noUserSelectedString);
}
UserManager userManager = new UserManager(locale,session);
User user = userManager.getUserDetails(userId);
if (user == null){
throw new ConfigurationException("illegal user id: " + user);
}
smsCommandEntry.setDestinationContact(0);
smsCommandEntry.setDestinationUser(user);
smsCommandEntry.setDestinationUserSet(null);
smsCommandEntry.setDestinationMsisdn(null);
break;
case 6: // message to msisdn
smsCommandEntry.setDestinationContact(0);
String countryCode = msgForm.getCountryCode();
String mobileNumber = msgForm.getMobileNumber();
try {
long countryCodeNumber = Long.parseLong(countryCode);
long mobileNumberNumber = Long.parseLong(mobileNumber);
long msisdn = Long.parseLong(countryCodeNumber + "" + mobileNumberNumber); // ignores leading zeros
smsCommandEntry.setDestinationUserSet(null);