📄 editpersonaction.java
字号:
/*
* OPIAM Suite
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package opiam.admin.applis.demo.actions;
import opiam.admin.applis.demo.beans.Person;
import opiam.admin.applis.demo.forms.PersonForm;
import opiam.admin.faare.persistence.javabeans.JBTop;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.service.services.references.ReferenceList;
import opiam.admin.faare.service.services.references.ReferenceService;
import opiam.admin.faare.struts.actions.SecureAction;
import opiam.admin.faare.struts.utils.SessionContext;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/**
* This class allows to show a person entry.
*
* This Action class inherits from SecureAction class.
* The SecureAction class checks that the user is connected before calling
* the action methods.
*/
public class EditPersonAction extends SecureAction
{
/** Instance of the log4j logger.
* Used to generate the execution traces. */
private static Logger _logger = Logger.getLogger(EditPersonAction.class);
/**
* This method is called to execute the action once the checks have been
* performed by the SecureAction class.
*
* @param mapping Struts mapping data.
* @param actionForm FormBean associated with the action.
* @param request HTTP request.
* @param httpServletResponse HTTP response.
*
* @return An ActionForward.
*
* @throws IOException An I/O exception if failed or interrupted I/O operations occurs.
* @throws ServletException A ServletException if the servlet has a problem.
*/
public ActionForward secureExecute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse
) throws IOException, ServletException
{
SessionContext sessionContext = null;
UserContext userContext = null;
ActionMessages msgErrors = new ActionMessages();
// Gets the entry dn from the request.
String dn = request.getParameter("dn");
String name = request.getParameter("name");
try
{
// Gets the session.
HttpSession session = request.getSession();
// Gets the session context.
sessionContext = SessionContext.getInstance(session);
// Gets the user context.
userContext = sessionContext.getUserContext();
// Connected user
Person cuser = (Person) userContext.getJbUser();
boolean selfModify = false;
// Checks if it is a self modify operation
if (name != null)
{
// self modify operation
dn = cuser.getDn();
selfModify = true;
}
// Writes the operation on the output defined in the
// logger_config.properties.
_logger.info("Edit person : " + dn + " by user: " +
sessionContext.getUserContext().getDn()
);
// Calls the StandardService to load the entry corresponding
// to the given dn.
JBTop loadedObj = StandardService.load(dn, userContext);
// Converts the entry in Person entry.
Person person = (Person) loadedObj;
// Clones the entry to allow to do a roolback if an error occurs.
// The clone also allows to manage the concurrent access.
Person pclone = (Person) person.clone();
// Adds the cloned person entry in the formBean.
PersonForm pf = new PersonForm();
pf.setUser(pclone);
pf.setDescription(pclone.getDescription());
String forward = null;
if (selfModify)
{
forward = "success_Self";
}
else
{
// Gets the profile of the user
String profile = cuser.getProfile();
if (profile.equals("Service Manager"))
{
forward = "success_ServiceManager";
// Manages the authorization
pf.setAppAuthRef(person.getVisibleAppAuth());
}
else if (profile.equals("Accounting Manager") ||
profile.equals("HR Manager") ||
profile.equals("PD Manager") ||
profile.equals("QA Manager")
)
{
forward = "success_Manager";
// Manages the departments
ReferenceList depsList =
userContext.findReferenceListByName("departments");
if (depsList == null)
{
depsList =
ReferenceService.getReferenceList("departments",
userContext
);
}
pf.setDepartments(depsList.getReferenceList(),
person.getDepartment()
);
// Manages the sites
ReferenceList sitesList =
userContext.findReferenceListByName("sites");
if (sitesList == null)
{
sitesList =
ReferenceService.getReferenceList("sites",
userContext
);
}
pf.setSites(sitesList.getReferenceList(), person.getSite());
// Manages the title
pf.setTitleRef(person.getTitle());
// Manages the manager
pf.setManagerFromPerson(person.getManager());
}
else if (profile.equals("Directory Administrator"))
{
forward = "success_DirectoryAdministrator";
// Manages the departments
ReferenceList depsList =
userContext.findReferenceListByName("departments");
if (depsList == null)
{
depsList =
ReferenceService.getReferenceList("departments",
userContext
);
}
pf.setDepartments(depsList.getReferenceList(),
person.getDepartment()
);
// Manages the sites
ReferenceList sitesList =
userContext.findReferenceListByName("sites");
if (sitesList == null)
{
sitesList =
ReferenceService.getReferenceList("sites",
userContext
);
}
pf.setSites(sitesList.getReferenceList(), person.getSite());
// Manages the title
pf.setTitleRef(person.getTitle());
// Manages the authorization
pf.setAppAuthRef(person.getVisibleAppAuth());
// Manages the manager
pf.setManagerFromPerson(person.getManager());
}
else
{
forward = "unauthorized_error";
}
}
// Sets the formBean "PersonForm" in the session with the
// "personForm" name.
// This name is used in the jsp page by the Struts tags to
// recover the attributes values of the person entry.
session.setAttribute("personForm", pf);
return mapping.findForward(forward);
}
catch (Exception se)
{
// Writes the error on the standard ouput console.
se.printStackTrace();
// Writes the error on the output defined in the
// logger_config.properties.
_logger.error(se.getMessage());
// Gets the error message from the message-resources file
// defined in the struts-config.xml
msgErrors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("error.service.unknown")
);
// Save the error message in the request to display it in the jsp
// page.
saveErrors(request, msgErrors);
// Returns the URI corresponding to the error.
return (mapping.findForward("error"));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -