Example usage for javax.servlet.http HttpSession getMaxInactiveInterval

List of usage examples for javax.servlet.http HttpSession getMaxInactiveInterval

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getMaxInactiveInterval.

Prototype

public int getMaxInactiveInterval();

Source Link

Document

Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.

Usage

From source file:org.collectionspace.chain.csp.webui.misc.WebLoginStatus.java

public void testlogin(Request in) throws UIException {
    UIRequest request = in.getUIRequest();
    try {/*from w w w. jav a 2  s  .  co  m*/
        Storage storage = in.getStorage();
        JSONObject output = new JSONObject();
        UISession uiSession = request.getSession();
        if (uiSession != null && uiSession.getValue(UISession.USERID) != null) {
            if (uiSession.getValue(UISession.USERID).equals("")) {
                output.put("login", false);
            } else {
                JSONObject perms = null;
                // See if there is a cache of the permissions for this user and tenant.
                String userId = (String) uiSession.getValue(UISession.USERID);
                String tenantId = (String) uiSession.getValue(UISession.TENANT);
                perms = findPermsInCache(userId, tenantId);
                boolean fFoundInCache;
                if (perms != null) {
                    fFoundInCache = true;
                } else {
                    fFoundInCache = false;
                    perms = getPermissions(storage);
                }

                if (perms.has("permissions")) {
                    // Set the cache if did not find it there, and if it has perms
                    // Will only slow down edge case of user with no roles.
                    if (!fFoundInCache) {
                        addPermsToCache(userId, tenantId, perms);
                    }
                    output.put("permissions", perms.getJSONObject("permissions"));
                    output.put("csid", perms.getString("csid"));
                    output.put("screenName", perms.getString("screenName"));
                    output.put("userId", perms.getString("userId"));
                    output.put("login", true);
                    int maxInterval = 0;
                    UIRequest uir = in.getUIRequest();
                    if (uir != null) {
                        HttpSession httpSession = request.getHttpSession();
                        if (httpSession != null) {
                            maxInterval = httpSession.getMaxInactiveInterval();
                        }
                    }
                    // Need to consider the shorter of session timeout and cookie expiry.
                    // cookie life is in minutes, so convert to seconds.
                    int cookieLife = 60 * spec.getAdminData().getCookieLife();
                    if (maxInterval == 0 || maxInterval >= cookieLife) {
                        maxInterval = cookieLife;
                    }
                    output.put("maxInactive", maxInterval);
                } else {
                    output.put("login", false);
                    output.put("message", "no roles associated with this user");
                }
            }
        } else {
            output.put("login", false);
        }
        request.sendJSONResponse(output);
    } catch (JSONException x) {
        throw new UIException("Failed to parse json: " + x.getMessage(), x);
    } catch (ExistException x) {
        //failed login test
        throw new UIException("Existence exception: ", x);
    } catch (UnimplementedException x) {
        throw new UIException("Unimplemented exception: ", x);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.sendJSONResponse(uiexception.getJSON());
    }

}

From source file:org.web4thejob.web.panel.DefaultSessionInfoPanel.java

private void prepareContent() {
    grid.getRows().getChildren().clear();

    Row row = new Row();
    row.setParent(grid.getRows());//from w  w  w.  j  a  v  a 2  s.c o m
    Label label = new Label(L10N_LABEL_USER_LOCALE.toString());
    label.setParent(row);
    label = new Label(CoreUtil.getUserLocale().toString());
    label.setParent(row);

    if (ContextUtil.getSessionContext().getSecurityContext().isAdministrator()) {
        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SERVER_LOCALE.toString());
        label.setParent(row);
        label = new Label(Locale.getDefault().toString());
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SERVER_CHARSET.toString());
        label.setParent(row);
        label = new Label(Charset.defaultCharset().toString());
        label.setParent(row);
    }

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_REMOTE_ADDRESS.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getServerName() + ":" + Executions.getCurrent().getServerPort());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_LOCAL_ADDRESS.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getLocalAddr() + ":" + Executions.getCurrent().getLocalPort());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_CLIENT_TYPE.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getUserAgent());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_DEVICE_TYPE.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getSession().getDeviceType());
    label.setParent(row);

    final ClientInfoEvent info = ContextUtil.getSessionContext().getAttribute(ATTRIB_CLIENT_INFO);
    if (info != null) {
        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SCREEN_RESOLUTION.toString());
        label.setParent(row);
        label = new Label(info.getScreenWidth() + "x" + info.getScreenHeight() + " px");
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_COLOR_DEPTH.toString());
        label.setParent(row);
        label = new Label(String.valueOf(info.getColorDepth()) + "-bit");
        label.setParent(row);
    }

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
            CoreUtil.getUserLocale());

    if (Executions.getCurrent().getSession().getNativeSession() instanceof HttpSession) {
        HttpSession session = (HttpSession) Executions.getCurrent().getSession().getNativeSession();

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_TIMEOUT.toString());
        label.setParent(row);
        label = new Label(String.valueOf(session.getMaxInactiveInterval() / 60) + "'");
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_CREATE_TIME.toString());
        label.setParent(row);
        label = new Label(formatter.format(new Date(session.getCreationTime())));
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_ACCESSED_TIME.toString());
        label.setParent(row);
        label = new Label(formatter.format(new Date(session.getLastAccessedTime())));
        label.setParent(row);
    }

}

From source file:org.dihedron.webmvc.ActionContext.java

/**
 * Returns whether the session is still valid.
 * //from w  ww .  jav a  2 s .  c  o  m
 * @return 
 *   whether the session is still valid.
 */
public static boolean isSessionValid() {
    HttpSession session = getContext().request.getSession();
    long elapsed = System.currentTimeMillis() - session.getLastAccessedTime();
    return (elapsed < session.getMaxInactiveInterval() * MILLISECONDS_PER_SECOND);
}

From source file:it.cnr.icar.eric.client.ui.thin.SearchPanelBean.java

public String getInactivityLength() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
            .getSession(false);/*from www. ja va  2  s  . co m*/
    int inactiveInterval = session.getMaxInactiveInterval();
    // convert seconds to minutes
    inactiveInterval = inactiveInterval / 60;
    return String.valueOf(inactiveInterval);
}

From source file:org.dihedron.webmvc.ActionContext.java

/**
 * Returns the number of seconds left before the session gets invalidated by
 * the container.//from  w w  w . j a va  2 s. c  om
 * 
 * @return 
 *   the number of seconds left before the session gets invalidated by the 
 *   container.
 */
public static long getSecondsToSessionInvalid() {
    HttpSession session = getContext().request.getSession();
    long elapsed = System.currentTimeMillis() - session.getLastAccessedTime();
    return (long) ((elapsed - session.getMaxInactiveInterval() * MILLISECONDS_PER_SECOND)
            / MILLISECONDS_PER_SECOND);
}

From source file:org.openmrs.module.cccgenerator.web.controller.CCCGeneratorFormController.java

@RequestMapping(value = "/module/cccgenerator/csvdownload")
public void downloadCSV(HttpServletResponse response, HttpServletRequest request,
        @RequestParam(required = true, value = "sitelocationToDownload") String location,
        @RequestParam(required = true, value = "additionalNumbers") String additional) throws IOException {

    //get the location based on the location name
    Location cccLocation = Context.getLocationService().getLocation(location);
    ///////////from  w  w  w  .  j  a  v a 2  s .  c  om
    //lengthen the session to make sure generation is complete
    HttpSession httpSession = request.getSession();
    Integer httpSessionvalue = httpSession.getMaxInactiveInterval();
    httpSession.setMaxInactiveInterval(-1);

    //create a temporary file that will be destroyed after completion
    File file = File.createTempFile(cccLocation.getName(), ".csv");
    ///////find the patients to be added on the file

    LocationService locationService = Context.getLocationService();
    PatientService patientService = Context.getPatientService();

    // List<Location> siteLocation=locationService.getAllLocations(false);

    String glbccc = Context.getAdministrationService().getGlobalProperty("cccgenerator.CCC");
    PatientIdentifierType patientIdentifier = patientService.getPatientIdentifierTypeByName(glbccc);
    //get all the location and related ones
    Set<Integer> setOfIdsLocsAndSubLocs = Context.getService(CCCGeneratorService.class)
            .getIdsOfLocationsParentAndChildren(cccLocation.getLocationId());
    //log.info("This are all the locations and sub sites "+setOfIdsLocsAndSubLocs);
    //get patientIds based on patientIdentifiers and location
    //loop through all the locations as we pick all the patient ids
    Set<Integer> setOfPatientsWithIdentifierAndLocation = new HashSet<Integer>();

    for (Integer j : setOfIdsLocsAndSubLocs) {
        Cohort listOfPatientsWithCCCandLocation = Context.getService(CCCGeneratorService.class)
                .getPatientByIdentifierAndLocation(patientIdentifier.getPatientIdentifierTypeId(), j);
        setOfPatientsWithIdentifierAndLocation.addAll(listOfPatientsWithCCCandLocation.getMemberIds());
    }
    List<Patient> patientsFromSet = new ArrayList<Patient>();
    //find all the patients using patient ids found

    for (Integer i : setOfPatientsWithIdentifierAndLocation) {

        patientsFromSet.add(Context.getPatientService().getPatient(i));
    }

    Location l = Context.getLocationService().getLocation(location.trim());

    Collections.sort(patientsFromSet, new SortCCC());

    StringBuilder stringBuilderColumnsHeaders = new StringBuilder();
    StringBuilder stringBuilderContents;
    StringBuilder additionalCCC;
    StringBuilder stringBuilderContentsAdditionals = new StringBuilder();
    StringBuilder reportHeader = new StringBuilder();

    reportHeader.append("\"" + l.getName() + "\"" + "," + "\"" + " and Other Related Sites" + "\"" + "," + "\""
            + "CCC Number Registar" + "\"" + ",");

    stringBuilderColumnsHeaders.append("\"CCC Number\"").append(",").append("\"Names\"").append(",")
            .append("\"AMRS ID\"").append(",").append("\"D.O.B\"").append(",");

    FileWriter fstream = new FileWriter(file, true);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(reportHeader.toString() + "\n");
    out.write(stringBuilderColumnsHeaders.toString() + "\n");

    for (Patient p : patientsFromSet) {
        stringBuilderContents = new StringBuilder();
        stringBuilderContents.append("\"" + p.getPatientIdentifier(patientIdentifier.getName()) + "\"")
                .append(",").append("\"" + namesFormated(p.getNames().toString()) + "\"").append(",")
                .append("\"" + p.getPatientIdentifier(getAMRSID(p)) + "\"").append(",")
                .append("\"" + formatDate(p.getBirthdate()) + "\"").append(",");
        out.write(stringBuilderContents.toString());
        out.write("\n");

    }
    //pick the last count of the ccc number location
    CCCGeneratorService service = Context.getService(CCCGeneratorService.class);
    CCCLocation ml = service.getCCCLocationByLocation(cccLocation);

    //we pick the unique number for every facility
    Integer CCC = ml.getCCC();

    //using CCC above we check for the last count
    CCCCount mc = service.getCCCCountByCCC(CCC);
    Integer lastcount = mc.getLastCount();
    Integer counttogetto = Integer.parseInt(additional) + lastcount;
    for (int h = lastcount; h < counttogetto; h++) {
        additionalCCC = new StringBuilder();
        lastcount++;
        String lcount = lastcount.toString();
        String cccNumber;
        if (lcount.length() < 5) {
            int x = 5 - lcount.length();
            String y = "";
            for (int k = 0; k < x; k++)
                y += "0";
            lcount = y + lcount;
        }
        cccNumber = CCC + "-" + lcount;

        additionalCCC.append("\"" + cccNumber + "\"").append(",").append("\"" + "\"").append(",")
                .append("\"" + "\"").append(",").append("\"" + "\"").append(",");
        out.write(additionalCCC.toString());
        out.write("\n");

    }

    out.close();

    //////////////////////////////////////////////////////////////////////

    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=" + file);
    response.setContentLength((int) file.length());

    FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream());
    file.delete();
    httpSession.setMaxInactiveInterval(httpSessionvalue);
}

From source file:password.pwm.http.filter.RequestInitializationFilter.java

private void checkIfSessionRecycleNeeded(final PwmRequest pwmRequest) throws IOException, ServletException {
    if (!pwmRequest.getPwmSession().getSessionStateBean().isSessionIdRecycleNeeded()) {
        return;/*from ww w  .j  a va  2  s .  c  o  m*/
    }

    final boolean recycleEnabled = Boolean
            .parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_SESSION_RECYCLE_AT_AUTH));

    if (!recycleEnabled) {
        return;
    }
    LOGGER.debug(pwmRequest, "forcing new http session due to authentication");

    final HttpServletRequest req = pwmRequest.getHttpServletRequest();

    // read the old session data
    final HttpSession oldSession = req.getSession(true);
    final int oldMaxInactiveInterval = oldSession.getMaxInactiveInterval();
    final Map<String, Object> sessionAttributes = new HashMap<>();
    final Enumeration oldSessionAttrNames = oldSession.getAttributeNames();
    while (oldSessionAttrNames.hasMoreElements()) {
        final String attrName = (String) oldSessionAttrNames.nextElement();
        sessionAttributes.put(attrName, oldSession.getAttribute(attrName));
    }

    for (final String attrName : sessionAttributes.keySet()) {
        oldSession.removeAttribute(attrName);
    }

    //invalidate the old session
    oldSession.invalidate();

    // make a new session
    final HttpSession newSession = req.getSession(true);

    // write back all the session data
    for (final String attrName : sessionAttributes.keySet()) {
        newSession.setAttribute(attrName, sessionAttributes.get(attrName));
    }

    newSession.setMaxInactiveInterval(oldMaxInactiveInterval);

    pwmRequest.getPwmSession().getSessionStateBean().setSessionIdRecycleNeeded(false);
}

From source file:SessionTracker.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    HttpSession session = req.getSession(true);

    Integer count = (Integer) session.getAttribute("count");

    if (count == null) {
        count = new Integer(1);
    } else {/*from  w  ww  .jav  a 2s  .  co  m*/
        count = new Integer(count.intValue() + 1);
    }

    session.setAttribute("count", count);
    out.println("<html><head><title>SessionSnoop</title></head>");
    out.println("<body><h1>Session Details</h1>");
    out.println(
            "You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.") + "<br/>");
    out.println("<h3>Details of this session:</h3>");
    out.println("Session id: " + session.getId() + "<br/>");
    out.println("New session: " + session.isNew() + "<br/>");
    out.println("Timeout: " + session.getMaxInactiveInterval() + "<br/>");
    out.println("Creation time: " + new Date(session.getCreationTime()) + "<br/>");
    out.println("Last access time: " + new Date(session.getLastAccessedTime()) + "<br/>");
    out.println("</body></html>");
}

From source file:org.openmrs.module.cccgenerator.web.controller.CCCGeneratorFormController.java

@RequestMapping(method = RequestMethod.POST, value = "module/cccgenerator/cccgeneratorForm.form")
public void whenPageIsPosted(ModelMap map, HttpServletRequest request,
        @RequestParam(required = false, value = "site") String siteId,
        @RequestParam(required = true, value = "cohort") String cohortdefuuid) {
    //lengthen the session to make sure generation is complete
    HttpSession httpSession = request.getSession();
    Integer httpSessionvalue = httpSession.getMaxInactiveInterval();
    httpSession.setMaxInactiveInterval(-1);

    CCCGeneratorService service = Context.getService(CCCGeneratorService.class);
    EncounterService encounterservice = Context.getEncounterService();
    AdministrationService adminservice = Context.getAdministrationService();
    PatientService pService = Context.getPatientService();
    LocationService locservice = Context.getLocationService();
    List<Patient> listOfHIVPatientsPerSite = new ArrayList<Patient>();
    Set<Integer> patientIdsFromCohort = null;
    ///////try to find all the required ids for patient

    CohortDefinitionService cohortDefinitionService = Context.getService(CohortDefinitionService.class);
    List<CohortDefinition> listOfCohorts = cohortDefinitionService.getAllDefinitions(false);

    List<Location> listOfLocations = Context.getLocationService().getAllLocations(false);

    map.addAttribute("listOfCohort", listOfCohorts);

    CohortDefinition cohortDefinition = Context.getService(CohortDefinitionService.class)
            .getDefinitionByUuid(cohortdefuuid);
    try {/* w  w w .ja v a2 s. c o m*/
        EvaluationContext evaluationContext = new EvaluationContext();

        //add loctation to be displayed here
        ///evaluationContext.addParameterValue("locationList",Arrays.asList(Context.getLocationService().getLocation(Integer.parseInt(siteId))));

        //evaluation
        Cohort cohort = cohortDefinitionService.evaluate(cohortDefinition, evaluationContext);
        patientIdsFromCohort = new HashSet<Integer>();
        patientIdsFromCohort.addAll(cohort.getMemberIds());

    } catch (Exception e) {
        e.printStackTrace();
    }
    //////////////////////////////////////////////////

    //get the location from the jsp interface
    Location siteLocation = locservice.getLocation(Integer.parseInt(siteId));

    map.addAttribute("location1", siteLocation.getName());
    Integer CCC = 0;
    Integer lastcount = 0;
    String CCCIdentifier = "";
    String glbCCC = "";
    int number_of_hiv_patients_affected = 0;
    int number_of_hiv_patients_affected_generated = 0;

    //cohort to return all patient ids

    log.info("Get all patients who are  HIV positive " + patientIdsFromCohort.size());

    //get cohort of all the patient ids in the database
    Cohort allpatientscohort = Context.getPatientSetService().getAllPatients();

    Set<Integer> allpatientscohortset = allpatientscohort.getMemberIds();

    log.info("All patients in the databse are " + allpatientscohortset.size());

    //get all patients to exclude from the set
    Set<Integer> toExclude = new HashSet<Integer>(
            Context.getService(CCCGeneratorService.class).excludeDiscontinued().getMemberIds());
    log.info("The number of patients discontinued from care " + toExclude.size());

    //remove the above from the patientIdsFromCohort to get only true matches

    patientIdsFromCohort.removeAll(toExclude);
    //get the intersection of only the patients who are present no empty slots

    Set<Integer> uniqueSetids = new HashSet<Integer>(
            CollectionUtils.intersection(allpatientscohortset, patientIdsFromCohort));

    log.info("Only unique numbers selected " + uniqueSetids.size());

    //get aready generated members
    Cohort listOfHIVPatientIdAlreadygenerated = service.getAllHIVPatients();
    Set<Integer> listOfHIVPatientIdAlreadygeneratedpatientsIds = new HashSet<Integer>(
            listOfHIVPatientIdAlreadygenerated.getMemberIds());

    log.info("Already generated ones are " + listOfHIVPatientIdAlreadygeneratedpatientsIds.size());

    //get the difference in number of HIV patients

    uniqueSetids.removeAll(listOfHIVPatientIdAlreadygeneratedpatientsIds);

    log.info("Difference comes in here excluding already generated ones " + uniqueSetids.size());

    Patient patients;

    int count = 0;

    for (Integer patientId : uniqueSetids) {
        count++;
        log.info("This patient Number " + patientId + " and this number " + count + " Remaining "
                + (uniqueSetids.size() - count));
        cleanupafterCount(count);
        patients = pService.getPatient(patientId);

        List<Encounter> listOfEncounters = encounterservice.getEncountersByPatientId(patientId);

        Collections.sort(listOfEncounters, new SortEncountersByDateComparator());

        for (Encounter encounters : listOfEncounters) {

            log.info("Got in the encounters loop");

            if (encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_ADULT_INITIAL)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_ADULT_RETURN)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_PEDS_INITIAL)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_PEDS_RETURN)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_BASELINE_INVESTIGATION)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_PMTCTANC)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_PMTCTPOSTNATAL)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_ECPeds)
                    || encounters.getEncounterType().getName().equals(ENCOUNTER_TYPE_ECSTABLE)) {

                // log.info("Found a patient having HIV encounters");
                // log.info("Locations are seen here if equal is when we enter the loop ");
                log.info(encounters.getLocation() + "==" + locservice.getLocation(Integer.parseInt(siteId)));
                //starts here
                //get all the related locations in the database

                Set<Integer> getAllLocations = Context.getService(CCCGeneratorService.class)
                        .getIdsOfLocationsParentAndChildren(Integer.parseInt(siteId));
                log.info("All locations and their sub sites " + getAllLocations.size());
                for (Integer i : getAllLocations) {
                    if (encounters.getLocation() == locservice.getLocation(i)) {

                        log.info("Checking for provided location from the encounters");

                        CCCLocation ml = service
                                .getCCCLocationByLocation(locservice.getLocation(Integer.parseInt(siteId)));

                        //we pick the unique number for every facility
                        CCC = ml.getCCC();

                        //using CCC above we check for the last count
                        CCCCount mc = service.getCCCCountByCCC(CCC);
                        lastcount = mc.getLastCount();
                        log.info("This the last count per the location and CCC " + lastcount);

                        //we increament the count by one

                        lastcount++;
                        String pCCCIdentifier = "" + lastcount;

                        //check for the number of digits required to be concatnated to facility number
                        if (pCCCIdentifier.length() < 5) {
                            int x = 5 - pCCCIdentifier.length();
                            String y = "";
                            for (int k = 0; k < x; k++)
                                y += "0";
                            pCCCIdentifier = y + pCCCIdentifier;
                        }
                        CCCIdentifier = CCC + "-" + pCCCIdentifier;

                        glbCCC = adminservice.getGlobalProperty("cccgenerator.CCC");

                        PatientIdentifierType patientIdentifierType = pService
                                .getPatientIdentifierTypeByName(glbCCC);

                        List<PatientIdentifier> listOfCCCIdentifier = pService.getPatientIdentifiers(null,
                                Arrays.asList(patientIdentifierType), Arrays.asList(locservice.getLocation(i)),
                                Arrays.asList(patients), false);

                        log.info("Already patients ids per CCC " + listOfCCCIdentifier.size());
                        if (listOfCCCIdentifier.size() == 0) {

                            //}

                            PatientIdentifier patientIdentifier = new PatientIdentifier();

                            patientIdentifier.setPatient(patients);
                            patientIdentifier.setIdentifier(CCCIdentifier);
                            patientIdentifier.setIdentifierType(patientIdentifierType);
                            patientIdentifier.setLocation(locservice.getLocation(i));
                            patientIdentifier.setPreferred(false);

                            mc.setLastCount(lastcount);
                            //save the count thereby rewriting the previous one
                            service.saveCCCCount(mc);
                            Integer thecountLast = null;
                            Integer CCCcount = null;
                            CCCCount thecount = service.getCCCCountByCCC(CCC);
                            thecountLast = thecount.getCCC();
                            CCCcount = thecount.getLastCount();

                            //log.info("This is the count  "+CCCcount+" and CCC is "+thecountLast);

                            //add and save patient identserifier
                            pService.savePatientIdentifier(patientIdentifier);

                            number_of_hiv_patients_affected += 1;

                            number_of_hiv_patients_affected_generated += number_of_hiv_patients_affected;
                            //add the patients to the list so that we can use in the jsp
                            listOfHIVPatientsPerSite.add(patients);
                            ////////////////////////////////////////////////////////////////////////

                            //CCCCount allCCC=new CCCCount();
                            //update all other related sites
                            List<CCCCount> allCCC = service.getAllRelatedSites(thecountLast);
                            //log.info("uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu "+allCCC.size());
                            //log.info("This is the CCC sizes "+allCCC.getLocation());
                            for (CCCCount m : allCCC) {
                                m.setLastCount(CCCcount);
                                service.saveCCCCount(m);
                            }

                            // log.info("After the count has been changed ");
                            ////////////////////////////////////////////////////////////////////////

                            cleanupaftersaving(number_of_hiv_patients_affected);
                        } else {
                            continue;
                        }

                    }

                }

            }

            break;

        }

    }
    List<Location> locations = locservice.getAllLocations(false);
    map.addAttribute("siteLocations", locations);
    map.addAttribute("totalcccnumbersgenerated", listOfHIVPatientsPerSite.size());
    httpSession.setMaxInactiveInterval(httpSessionvalue);

}

From source file:org.carewebframework.ui.sessiontracker.MainRowRenderer.java

/**
 * @see AbstractRowRenderer#renderRow/*from w  w w. j  a va  2 s  .com*/
 */
@Override
protected Component renderRow(final Row row, final SessionInfo sInfo) {
    final Session session = sInfo == null ? null : sInfo.getSession();
    final HttpSession nativeSession = session == null ? null : (HttpSession) session.getNativeSession();
    //Because it's possible that the session could be invalidated but yet still in the list
    String sessionId = null;
    String institution = StrUtil.formatMessage("@cwf.sessiontracker.msg.unknown");
    Date creationTime = null;
    Date lastAccessedTime = null;
    int maxInactiveInterval = 0;
    String clientAddress = null;

    try {
        if (nativeSession != null) {
            sessionId = nativeSession.getId();
            creationTime = new Date(nativeSession.getCreationTime());
            lastAccessedTime = new Date(nativeSession.getLastAccessedTime());
            maxInactiveInterval = nativeSession.getMaxInactiveInterval();
            clientAddress = session.getRemoteAddr();
        }
    } catch (final IllegalStateException e) {
        log.warn("The following session was still in the list of activeSessions yet was invalidated: "
                + session);
        return null;
    }

    createCell(row, sessionId);
    createCell(row, clientAddress);
    createCell(row, institution);
    createCell(row, creationTime);
    createCell(row, lastAccessedTime);
    createCell(row, String.valueOf(maxInactiveInterval));
    return sInfo == null || sInfo.getDesktops().isEmpty() ? null : row;
}