User selectedUser = userManager.getUserDetails(selectedUserId);
if (selectedUser == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SelectedUserNotAvaliableAnymore"),"user #" + selectedUserId + " not found",null,null);
}
checkAccessRights(req,selectedUser.getGroup());
mappingSet.add(new Entry(sourceUser), new Entry(selectedUser));
}
}
// user sets
UserSetManager userSetManager = new UserSetManager(locale,session);
long[] sourceUserSetIds = f.getSourceUserSetIds();
if (sourceUserSetIds != null){
long[] selectedUserSetIds = f.getSelectedUserSetIds();
for (int i = 0; i < sourceUserSetIds.length; i++){
long sourceUserSetId = sourceUserSetIds[i];
UserSet sourceUserSet = userSetManager.getUserSet(sourceUserSetId);
if (sourceUserSet == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SourceUserSetNotAvailableAnymore"),"user set #" + sourceUserSetId + " not found",null,null);
}
checkAccessRights(req,sourceUserSet.getGroup());
long selectedUserSetId = selectedUserSetIds[i];
if (selectedUserSetId >= 1){ // mapping entry => assign; no entry => create
UserSet selectedUserSet = userSetManager.getUserSet(selectedUserSetId);
if (selectedUserSet == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SelectedUserSetNotAvaliableAnymore"),"user set #" + selectedUserSetId + " not found",null,null);
}
checkAccessRights(req,selectedUserSet.getGroup());
mappingSet.add(new Entry(sourceUserSet), new Entry(selectedUserSet));
}
}
}
// senders
SmsSenderManager senderManager = new SmsSenderManager(locale,session);
long[] sourceSenderIds = f.getSourceSenderIds();
if (sourceSenderIds != null){ // at least one mapping
long[] selectedSenderIds = f.getSelectedSenderIds();
for (int i = 0; i < sourceSenderIds.length; i++){
long sourceSenderId = sourceSenderIds[i];
Sender sourceSender = senderManager.getSmsSenderById(sourceSenderId);
if (sourceSender == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SourceSenderNotAvailableAnymore"),"sender #" + sourceSenderId + " not found",null,null);
}
if (!req.isUserInRole(UserManagerBase.ADMINISTRATOR) && !senderManager.isValidForGroup(sourceSender,webUser.getGroup())) {
throw new InputException(getResources(req).getMessage(locale, "smssvc.insufficientRights"));
}
long selectedSenderId = selectedSenderIds[i];
if (selectedSenderId >= 1){ // mapping entry => assign; no entry => add to group
Sender selectedSender = senderManager.getSmsSenderById(selectedSenderId);
if (selectedSender == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SelectedSenderNotAvaliableAnymore"),"sender #" + selectedSenderId + " not found",null,null);
}
if (!req.isUserInRole(UserManagerBase.ADMINISTRATOR) && !senderManager.isValidForGroup(selectedSender,webUser.getGroup())) {
throw new InputException(getResources(req).getMessage(locale, "smssvc.insufficientRights"));
}
mappingSet.add(new Entry(sourceSender), new Entry(selectedSender));
}
}
}
// blogs
BlogManager blogManager = new BlogManager(locale, session);
long[] sourceBlogIds = f.getSourceBlogIds();
if (sourceBlogIds != null) { // at least one mapping
Blog personalBlog = new Blog();
personalBlog.setId(-99);
personalBlog.setName(this.getResources(req).getMessage("smssvc.personalBlog"));
long[] selectedBlogIds = f.getSelectedBlogIds();
for (int i = 0; i < sourceBlogIds.length; i++){
long sourceBlogId = sourceBlogIds[i];
Blog sourceBlog = sourceBlogId == -99 ? personalBlog : blogManager.getBlog(sourceBlogId);
if (sourceBlog == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SourceBlogNotAvailableAnymore"),"blog #" + sourceBlogId + " not found",null,null);
}
if (sourceBlog.getId() != -99) {
checkAccessRights(req, sourceBlog.getGroup());
}
long selectedBlogId = selectedBlogIds[i];
if (selectedBlogId != -99 && selectedBlogId <= 0) {
throw new InputException(getResources(req).getMessage(locale, "smssvc.BlogMappingSelectionMissing"),"sourceBlogId = " + sourceBlogId,null,null);
}
Blog selectedBlog = selectedBlogId == -99 ? personalBlog : blogManager.getBlog(selectedBlogId);
if (selectedBlog == null) {
throw new InputException(getResources(req).getMessage(locale, "smssvc.SelectedBlogNotAvaliableAnymore"),"blog #" + selectedBlogId + " not found",null,null);
}
if (selectedBlogId != -1) {
checkAccessRights(req,selectedBlog.getGroup());
}
mappingSet.add(new Entry(sourceBlog), new Entry(selectedBlog));
}
}
// fragments
SmsDbManager smsDbManager = new SmsDbManager(locale,session);
long[] sourceFragmentIds = f.getSourceFragmentIds();
if (sourceFragmentIds != null){ // at least one mapping
long[] selectedFragmentIds = f.getSelectedFragmentIds();
for (int i = 0; i < sourceFragmentIds.length; i++){
long sourceFragmentId = sourceFragmentIds[i];
Fragment sourceFragment = smsDbManager.getFragment(sourceFragmentId);
if (sourceFragment == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SourceFragmentNotAvailableAnymore"),"fragment #" + sourceFragmentId + " not found",null,null);
}
checkAccessRights(req,sourceFragment.getGroup());
long selectedFragmentId = selectedFragmentIds[i];
if (selectedFragmentId <= 0){
throw new InputException(getResources(req).getMessage(locale, "smssvc.FragmentMappingSelectionMissing"),"sourceFragmentId = " + sourceFragmentId,null,null);
}
Fragment selectedFragment = smsDbManager.getFragment(selectedFragmentId);
if (selectedFragment == null){
throw new InputException(getResources(req).getMessage(locale, "smssvc.SelectedFragmentNotAvaliableAnymore"),"fragment #" + selectedFragmentId + " not found",null,null);
}
checkAccessRights(req,selectedFragment.getGroup());
mappingSet.add(new Entry(sourceFragment), new Entry(selectedFragment));
}
}
req.getSession().setAttribute("mappingSet", mappingSet);
return mapping.findForward("selected");