1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
public class SubcribeController extends AbstractWizardFormController {
...
public SubcribeController() {
setCommandClass(SubForm.class);
setCommandName(Constants.CMD_SUB_F);
setAllowDirtyBack(true);
setAllowDirtyForward(false);
setSessionForm(true);
setPageAttribute(Constants.ATT_PAGE);
setPages(new String[] {Constants.ACT_ADD_AUDIENCE,
Constants.ACT_ADD_AUDIENCE, Constants.ACT_ADD_AUDIENCE});
}
public void afterPropertiesSet() throws Exception {
...
}
@Override
protected void processFinish(
ActionRequest request, ActionResponse response,
Object command, BindException errors)
throws Exception {
SubForm cmd= (SubForm)command;
this.subService.addSubscribers(cmd.getSubKey(),
cmd.getSubscriber());
response.setRenderParameter(Constants.ATT_CTX_ID,String.valueOf(cmd.getSubscriber().getCtxId()));
response.setRenderParameter(Constants.ACT,
Constants.ACT_VIEW_AUDIENCE+cmd.getSubscriber().getCtxType());
}
@Override
protected void processCancel(
ActionRequest request, ActionResponse response,
Object command, BindException errors)
throws Exception {
SubForm cmd= (SubForm)command;
response.setRenderParameter(Constants.ACT,
Constants.ACT_VIEW_AUDIENCE+cmd.getSubscriber().getCtxType());
response.setRenderParameter(Constants.ATT_CTX_ID,String.valueOf(cmd.getSubscriber().getCtxId()));
}
@Override
protected void validatePage(
Object command, Errors errors, int page, boolean finish) {
SubForm subF = (SubForm)command;
SubValidator subValidator = (SubValidator) getValidator();
if (finish) {
this.getValidator().validate(command, errors);
return;
}
switch (page) {
case 0: subValidator.validateSearch(subF, errors); break;
case 1: subValidator.validateSubscriberKey(subF, errors); break;
}
}
@Override
protected Object formBackingObject(PortletRequest request) throws
Exception {
SubForm subForm = new SubForm();
String ctx = request.getParameter(Constants.ATT_CTX);
subForm.getSubscriber().setCtxType(ctx);
subForm.getSubscriber().setCtxId(PortletRequestUtils.getLongParameter(request,
Constants.ATT_CTX_ID));
return subForm;
}
@Override
protected Map referenceData(PortletRequest request, Object command,
Errors errors, int page) throws Exception {
boolean isGrp = ((SubForm) command).getSubscriber().getIsGroup()
== 1 ? true : false;
Long ctxId = ((SubForm) command).getSubscriber().getCtxId();
String ctx = ((SubForm) command).getSubscriber().getCtxType();
if (!this.um.isUserAdminInCtx(ctxId, ctx,
request.getRemoteUser())) {
log.warn("SubcribeController:: user " +
request.getRemoteUser() + " has no role admin");
throw new PortletSecurityException("you are not authorized
for this action");
}
Map<String, Object> model = new HashMap<String, Object>();
if (ctx.equalsIgnoreCase(NewsConstants.CTX_C)) {
model.put(Constants.CMD_CATEGORY,
this.cm.getCategoryById(ctxId));
} else if (ctx.equalsIgnoreCase(NewsConstants.CTX_T)) {
model.put(Constants.CMD_TOPIC, this.tm.getTopicById(ctxId));
Long cId = this.tm.getTopicById(ctxId).getCategoryId();
model.put(Constants.ATT_CNAME,
this.cm.getCategoryById(cId).getName());
}
model.put(Constants.ATT_PM,
RolePerm.valueOf(this.um.getUserRoleInCtx(ctxId, ctx,
request.getRemoteUser())).getMask());
if (page == 0) {
model.put("subTypeList", SubscribeType.values());
} else if (page == 1) {
model.put(Constants.CMD_SUB_F, (SubForm) command);
if (isGrp) {
groups = this.subService.searchGroups(((SubForm)
command).getToken());
model.put("grps", groups);
} else {
users = this.um.findPersonsByToken(((SubForm)
command).getToken());
model.put(Constants.ATT_USER_LIST, users);
}
model.put(Constants.ATT_LDAP_DISPLAY,
um.getLdapUserService().getSearchDisplayedAttributes());
model.put(Constants.ATT_NB_ITEM_TO_SHOW, this.nbItemsToShow);
model.put(Constants.ERRORS, errors);
} else if (page == 2) {
model.put(Constants.CMD_SUB_F, (SubForm) command);
List<EscoUser> lu = null;
if (((SubForm) command).getSubscriber().getIsGroup() == 0) {
lu = new ArrayList<EscoUser>();
for (String id : ((SubForm) command).getSubKey()) {
for (IEscoUser user : users) {
if (user.getUserId().equalsIgnoreCase(id)) {
lu.add((EscoUser) user);
}
}
}
}
model.put(Constants.ATT_USER_LIST, lu);
model.put(Constants.ATT_LDAP_DISPLAY,
um.getLdapUserService().getSearchDisplayedAttributes());
}
return model;
}
@Override
protected ModelAndView renderInvalidSubmit(RenderRequest request,
RenderResponse response)
throws Exception {
return null;
}
@Override
protected void handleInvalidSubmit(ActionRequest request,
ActionResponse response)
throws Exception {
log.warn("SubcribeController:: handleInvalidSubmit: goto home
page");
response.setRenderParameter(Constants.ACT,
Constants.VIEW_NEWSSTORE);
}
...
@Override
protected boolean isFormSubmission(PortletRequest request) {
for (Enumeration params = request.getParameterNames();
params.hasMoreElements();) {
String paramName = (String) params.nextElement ();
if (paramName.startsWith(PARAM_TARGET) ||
paramName.equals(PARAM_FINISH) || paramName.equals(PARAM_FINISH)) {
return true;
}
}
return super.isFormSubmission (request);
}
} |
Partager