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.setDestinationMsisdn(null);
smsCommandEntry.setDestinationUser(null);
break;
case 5: // message to user
smsCommandEntry.setDestinationContact(0);
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.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);
smsCommandEntry.setDestinationMsisdn(msisdn);
smsCommandEntry.setDestinationUser(null);
} catch (NumberFormatException e){
throw new BugException("validation of countryCode and mobileNumber failed");
}
break;
default:
throw new BugException("illegal destination selection number");
}
LOGGER.info("User " + req.getUserPrincipal().getName().toLowerCase()
+ ": Created message command entry #" + smsCommandEntry.getId()
+ "; label: " + smsCommandEntry.getSortLabel() + "; with message: " + smsCommandEntry.getTextContent()