use of org.mifos.security.util.ActivityContext in project head by mifos.
the class MifosRequestProcessor method processActionPerform.
/**
* This method is overridden because in case of exception we need to
* populate the request with the old values so that when the user goes back
* to the previous page it has all the values in the request.For this we
* create an object which will store the values of previous request in case
* the request is successful and if there is an exception it reads values
* from that object and context and dups all in the request.
*/
@Override
protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
ActivityContext activityContext = null;
ActionForward forward = null;
HttpSession session = request.getSession();
// gets the object where we will store values from request.
PreviousRequestValues previousRequestValues = (PreviousRequestValues) session.getAttribute(Constants.PREVIOUS_REQUEST);
if (null == previousRequestValues) {
previousRequestValues = new PreviousRequestValues();
session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues);
}
// getting the activity context from the session
activityContext = (ActivityContext) session.getAttribute("ActivityContext");
try {
String currentFlowKey = request.getParameter(Constants.CURRENTFLOWKEY);
if (currentFlowKey != null) {
previousRequestValues.getPreviousRequestValueMap().put(Constants.CURRENTFLOWKEY, currentFlowKey);
}
forward = (action.execute(mapping, form, request, response));
String method = request.getParameter("method");
if (method.equals(ClientConstants.METHOD_RETRIEVE_PICTURE)) {
forward = mapping.findForward("get_success");
}
// set the last forward in the activity context
if (activityContext != null) {
activityContext.setLastForward(forward);
}
// read the request and add the values to the PreviousRequestValues
// object. this will set every thing in the request apart from
// context and value object.
Enumeration requestAttributes = request.getAttributeNames();
while (requestAttributes.hasMoreElements()) {
String nextName = (String) requestAttributes.nextElement();
if (nextName.startsWith(Constants.STORE_ATTRIBUTE) || nextName.equalsIgnoreCase(Constants.CURRENTFLOWKEY)) {
logger.debug(nextName + "=" + request.getAttribute(nextName));
previousRequestValues.getPreviousRequestValueMap().put(nextName, request.getAttribute(nextName));
}
}
} catch (Exception e) {
// processException logs an error (see MifosExceptionHandler)
forward = (processException(request, response, e, form, mapping));
// set the last forward in the activity context
if (activityContext != null) {
activityContext.setLastForward(forward);
}
populateTheRequestFromPreviousValues(request, previousRequestValues);
} finally {
try {
session.removeAttribute(SecurityConstants.SECURITY_PARAM);
} catch (Exception e) {
// FIXME: yikes, what is being swallowed here?
}
}
if (null != forward) {
logger.info("forward.path=" + forward.getPath());
}
return forward;
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class MifosRequestProcessor method setActivityContextFromRequest.
private ActivityContext setActivityContextFromRequest(HttpServletRequest request, Short activityId) {
HttpSession session = request.getSession();
ActivityContext activityContext = (ActivityContext) session.getAttribute("ActivityContext");
if (activityContext != null) {
// get the values from the request
String recordOfficeId = request.getParameter("recordOfficeId");
String recordLoanOfficerId = request.getParameter("recordLoanOfficerId");
short recordOffId = -1;
short recordLoOffId = -1;
try {
/*
* The null case is if one or both parameters was omitted.
* What's the difference between supplying these as parameters
* versus the UserContext, versus just using what is in the
* ActivityContext?
*/
if (recordOfficeId != null) {
recordOffId = Short.valueOf(recordOfficeId).shortValue();
}
if (recordLoanOfficerId != null) {
recordLoOffId = Short.valueOf(recordLoanOfficerId).shortValue();
}
} catch (NumberFormatException e) {
throw new RuntimeException(e);
}
if (recordOffId > 0 && recordLoOffId > 0) {
activityContext.setRecordOfficeId(recordOffId);
activityContext.setRecordLoanOfficer(recordLoOffId);
} else if (recordOffId == 0 && recordLoOffId == 0) {
if (session.getAttribute("UserContext") != null) {
UserContext uc = (UserContext) session.getAttribute("UserContext");
activityContext.setRecordOfficeId(uc.getBranchId());
activityContext.setRecordLoanOfficer(uc.getId());
}
}
activityContext.setActivityId(activityId);
return activityContext;
} else {
// TODO: Can this happen? Why? Is null right?
return null;
}
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class FeeActionStrutsTest method setUp.
@Before
public void setUp() throws Exception {
UserContext userContext = TestUtils.makeUser();
request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
addRequestParameter("recordLoanOfficerId", "1");
addRequestParameter("recordOfficeId", "1");
ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
request.getSession(false).setAttribute("ActivityContext", ac);
flowKey = createFlow(request, FeeAction.class);
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class ShutdownServiceFacadeWebTier method getLoggedUsers.
@Override
public List<LoggedUserDto> getLoggedUsers(HttpServletRequest request) {
ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class.getName());
Collection<HttpSession> sessions = shutdownManager.getActiveSessions();
List<PersonnelInfo> personnelInfos = new ArrayList<PersonnelInfo>();
UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
if (ActivityMapper.getInstance().isViewActiveSessionsPermitted(userContext, userContext.getBranchId())) {
PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
for (HttpSession session : sessions) {
UserContext userContextFromSession = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
if (userContextFromSession == null) {
continue;
}
PersonnelBO personnel;
try {
personnel = personnelBusinessService.getPersonnel(userContextFromSession.getId());
} catch (ServiceException e) {
continue;
}
String offices = generateOfficeChain(personnel.getOffice());
String names = personnel.getPersonnelDetails().getName().getFirstName() + " " + personnel.getPersonnelDetails().getName().getLastName();
DateTimeFormatter formatter = DateTimeFormat.shortDateTime().withOffsetParsed().withLocale(userContext.getCurrentLocale());
String activityTime = formatter.print(session.getLastAccessedTime());
ActivityContext activityContext = (ActivityContext) session.getAttribute(LoginConstants.ACTIVITYCONTEXT);
String activityDesc = "[" + activityContext.getLastForward().getName() + "] " + activityContext.getLastForward().getPath();
personnelInfos.add(new PersonnelInfo(offices, names, activityTime, activityDesc));
}
}
Collections.sort(personnelInfos);
List<LoggedUserDto> loggedUsers = new ArrayList<LoggedUserDto>();
for (PersonnelInfo personnelInfo : personnelInfos) {
loggedUsers.add(new LoggedUserDto(personnelInfo.getOffices(), personnelInfo.getNames(), personnelInfo.getActivityTime(), personnelInfo.getActivityContext()));
}
return loggedUsers;
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class BulkEntryActionStrutsTest method setUp.
@Before
public void setUp() throws Exception {
enableCustomWorkingDays();
userContext = TestUtils.makeUser();
request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
addRequestParameter("recordLoanOfficerId", "1");
addRequestParameter("recordOfficeId", "1");
ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
request.getSession(false).setAttribute("ActivityContext", ac);
flowKey = createFlow(request, CollectionSheetEntryAction.class);
}
Aggregations