UserGroupEditAction.java
/*
* @ Copyright 2001 FA Software;
* All right reserved. No part of this program may be reproduced or
* transmitted in any form or by any means, electronic or
* mechanical, including photocopying, recording, or by any
* information storage or retrieval system without written
* permission from FA Software, except for inclusion of brief
* quotations in a review.
*/
package com.mycim.webapp.actions.setting.security.user;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.PropertyUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.security.UserGroup;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.CimSetupAction;
import com.mycim.webapp.forms.security.UserGroupInfoForm;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Johnson Wang
**/
public class UserGroupEditAction extends CimSetupAction {
@Override
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (form == null) {
return (mapping.findForward("login"));
}
// Set a transactional control token to prevent double posting
saveToken(request);
UserGroupInfoForm theform = (UserGroupInfoForm) form;
String id = "";
// When from another mapping page,construct new id through valueObject in session
if ((request.getParameter(Constants.MODIFY_KEY) != null) &&
"Y".equals(request.getParameter(Constants.MODIFY_KEY))) {
UserGroup userGroup = (UserGroup) request.getAttribute(SessionNames.USERGROUP_KEY);
if (userGroup == null) {
return (mapping.findForward("login"));
}
id = userGroup.getInstanceId().trim().toUpperCase();
} else {
id = theform.getInstanceId().trim().toUpperCase();
}
// Construct a new value object that stores the id,
// named space(implicit, derived)
// object(hard coded)
UserGroup userGroup = new UserGroup(id, getNamedSpace(ObjectList.USERGROUP_KEY, LocalContext.getFacilityRrn()),
ObjectList.USERGROUP_KEY);
// According to the instance's object, retrieve the value object
userGroup = (UserGroup) getInstance(userGroup);
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, userGroup);
request.setAttribute(SessionNames.USERGROUP_KEY, userGroup);
// if a value object does not exist, its instanceRrn will be set to 0
if (userGroup.getInstanceRrn() == 0) {
theform.setTransId(Constants.CREATE_KEY);
return (mapping.findForward("modify"));
}
userGroup.setUsers(getUsers(userGroup));
theform.setTransId(Constants.MODIFY_KEY);
return (mapping.findForward("modify"));
}
}