Search in sources :

Example 1 with LoggedUserDto

use of org.mifos.application.admin.servicefacade.LoggedUserDto 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;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) PersonnelInfo(org.mifos.application.admin.system.PersonnelInfo) ShutdownManager(org.mifos.application.admin.system.ShutdownManager) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoggedUserDto(org.mifos.application.admin.servicefacade.LoggedUserDto) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

ArrayList (java.util.ArrayList)1 HttpSession (javax.servlet.http.HttpSession)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 LoggedUserDto (org.mifos.application.admin.servicefacade.LoggedUserDto)1 PersonnelInfo (org.mifos.application.admin.system.PersonnelInfo)1 ShutdownManager (org.mifos.application.admin.system.ShutdownManager)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)1 ServiceException (org.mifos.framework.exceptions.ServiceException)1 ActivityContext (org.mifos.security.util.ActivityContext)1 UserContext (org.mifos.security.util.UserContext)1