Example usage for java.util Date equals

List of usage examples for java.util Date equals

Introduction

In this page you can find the example usage for java.util Date equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:org.structr.util.StructrLicenseManager.java

private boolean isValid(final Map<String, String> properties) {

    if (!licensePresent) {
        return false;
    }/*from   www .j a  v  a2 s. c  om*/

    final String src = collectLicenseFieldsForSignature(properties);
    final String name = properties.get(NameKey);
    final String key = properties.get(SignatureKey);
    final String hostId = properties.get(MachineKey);
    final String thisHostId = createHash();
    final String edition = properties.get(EditionKey);
    final String modules = properties.get(ModulesKey);
    final String dateString = properties.get(DateKey);
    final String startDateString = properties.get(StartKey);
    final String endDateString = properties.get(EndKey);
    final String serversString = properties.get(ServersKey);
    final Date now = new Date();

    if (StringUtils.isEmpty(key)) {

        logger.error("Unable to read key from license file.");
        return false;
    }

    try {

        final byte[] data = src.getBytes(CharSet);
        final Signature signer = Signature.getInstance(SignatureAlgorithm);
        final byte[] signature = Hex.decodeHex(key.toCharArray());

        signer.initVerify(certificate);
        signer.update(data);

        if (!signer.verify(signature)) {

            logger.error("License signature verification failed, license is not valid.");
            return false;
        }

    } catch (Throwable t) {

        logger.error("Unable to verify license.", t);
        return false;
    }

    if (StringUtils.isEmpty(name)) {

        logger.error("License file doesn't contain licensee name.");
        return false;
    }

    if (StringUtils.isEmpty(edition)) {

        logger.error("License file doesn't contain edition.");
        return false;
    }

    if (StringUtils.isEmpty(modules)) {

        logger.error("License file doesn't contain modules.");
        return false;
    }

    if (StringUtils.isEmpty(hostId)) {

        logger.error("License file doesn't contain host ID.");
        return false;
    }

    if (StringUtils.isEmpty(dateString)) {

        logger.error("License file doesn't contain license date.");
        return false;
    }

    if (StringUtils.isEmpty(startDateString)) {

        logger.error("License file doesn't contain start date.");
        return false;
    }

    if (StringUtils.isEmpty(endDateString)) {

        logger.error("License file doesn't contain end date.");
        return false;
    }

    // verify host ID
    if (!thisHostId.equals(hostId) && !"*".equals(hostId)) {

        logger.error("Host ID found in license ({}) file does not match current host ID.", hostId);
        return false;
    }

    if ("*".equals(hostId)) {

        // check volume license against server addresses
        if (StringUtils.isNotBlank(serversString)) {

            // send HostID to server
            properties.put(HostIdKey, thisHostId);

            return checkVolumeLicense(properties, serversString);
        }

        final Calendar issuedAtPlusOneMonth = GregorianCalendar.getInstance();
        final Calendar cal = GregorianCalendar.getInstance();

        // set issuedAt to license date plus one month
        issuedAtPlusOneMonth.setTime(parseDate(dateString));
        issuedAtPlusOneMonth.add(Calendar.MONTH, 1);

        // check that the license file was issued not more than one month ago
        if (cal.after(issuedAtPlusOneMonth)) {

            logger.error(
                    "Development license found in license file is not valid any more, license period ended {}.",
                    format.format(issuedAtPlusOneMonth.getTime()));
            return false;
        }
    }

    // verify that the license is valid for the current date
    final Date startDate = parseDate(startDateString);
    if (startDate != null && now.before(startDate) && !now.equals(startDate)) {

        logger.error("License found in license file is not yet valid, license period starts {}.",
                format.format(startDate.getTime()));
        return false;
    }

    // verify that the license is valid for the current date
    final Date endDate = parseDate(endDateString);
    if (endDate != null && now.after(endDate) && !now.equals(endDate)) {

        logger.error("License found in license file is not valid any more, license period ended {}.",
                format.format(endDate.getTime()));
        return false;
    }

    return true;
}

From source file:com.krawler.hrms.hrmsHandler.java

public static JSONObject setappraisalcycleFunction(Session session, HttpServletRequest request)
        throws ServiceException, JSONException, ParseException, SessionExpiredException {
    JSONObject jobj = new JSONObject();
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    boolean flag = false;
    boolean initiateFlag = false;
    try {/* w  w  w. ja  va 2  s.  c  o m*/
        Date startdate = (Date) fmt.parse(request.getParameter("startdate"));
        Date enddate = (Date) fmt.parse(request.getParameter("enddate"));
        Date submitstartdate = (Date) fmt.parse(request.getParameter("submitsdate"));
        Date submitenddate = (Date) fmt.parse(request.getParameter("submitedate"));
        String cyclename = request.getParameter("cyclename");
        Appraisalcycle appcycle = null;
        List tabledata = null;
        String hql = "from Appraisalcycle where company.companyID=? and ((? between startdate and enddate) or (? between startdate and enddate))";
        if (request.getParameter("editflag").equals("1")) {
            String cycleid = request.getParameter("cycleid");
            appcycle = (Appraisalcycle) session.get(Appraisalcycle.class, cycleid);
            boolean dateflag = true;
            if (!startdate.equals(appcycle.getStartdate()) || !enddate.equals(appcycle.getEnddate())) {
                dateflag = false;
                //Check for cycle initiated
                hql = "from Appraisalmanagement where appcycle = ?";
                tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { appcycle });
                if (tabledata.size() == 0) {
                    dateflag = true;
                }
            }

            if (dateflag) {
                hql = "from Appraisalcycle where company.companyID=? and id != ? and ((? between startdate and enddate) or (? between startdate and enddate)) ";
                tabledata = HibernateUtil.executeQuery(session, hql,
                        new Object[] { AuthHandler.getCompanyid(request), cycleid, startdate, enddate });
            } else {
                initiateFlag = true;
                jobj.put("msg", MessageSourceProxy.getMessage(
                        "hrms.hrmshandler.msg.youcannoteditcyclestartandenddateasappraisalhasalreadybeeninitiatedfortheselectedappraisalcycle",
                        null,
                        "You can not edit cycle start and end date as appraisal has already been initiated for the selected appraisal cycle.",
                        LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0)));
            }
        } else {
            tabledata = HibernateUtil.executeQuery(session, hql,
                    new Object[] { AuthHandler.getCompanyid(request), startdate, enddate });
            appcycle = new Appraisalcycle();
        }

        if (!initiateFlag && tabledata.isEmpty()) {
            appcycle.setCyclename(cyclename);
            appcycle.setStartdate(startdate);
            appcycle.setEnddate(enddate);
            appcycle.setCreatedby((User) session.get(User.class, AuthHandler.getUserid(request)));
            appcycle.setCompany((Company) session.get(Company.class, AuthHandler.getCompanyid(request)));
            appcycle.setSubmitstartdate(submitstartdate);
            if (request.getParameter("editflag").equals("1")) {
                if (appcycle.getSubmitenddate().before(submitenddate)) {
                    appcycle.setReviewed(false);
                    appcycle.setCycleapproval(false);
                }
            } else {
                appcycle.setReviewed(false);
                appcycle.setCycleapproval(false);
            }

            appcycle.setSubmitenddate(submitenddate);

            session.save(appcycle);
            if (request.getParameter("editflag").equals("1")) {
                //@@ProfileHandler.insertAuditLog(session, AuditAction.CYCLE_EDITED, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has edited appraisal cycle " + appcycle.getCyclename(),request);
            } else {
                //@@ProfileHandler.insertAuditLog(session, AuditAction.CYCLE_ADDED, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has added new appraisal cycle " + appcycle.getCyclename() + " for the period from " + fmt.format(startdate) + " till " + fmt.format(enddate),request);
            }
            flag = true;
        } else if (!initiateFlag && !tabledata.isEmpty()) {
            jobj.put("msg",
                    MessageSourceProxy.getMessage(
                            "hrms.hrmshandler.msg.appraisalcycleaddedisoverlappingotherappraisalcycle.", null,
                            "Appraisal cycle added is overlapping other appraisal cycle.",
                            LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0)));
        }
        jobj.put("success", flag);
    } catch (ParseException e) {
        throw ServiceException.FAILURE("hrmsHandler.setappraisalcycleFunction", e);
    } catch (SessionExpiredException e) {
        throw ServiceException.FAILURE("hrmsHandler.setappraisalcycleFunction", e);
    }
    return jobj;
}

From source file:org.etudes.jforum.view.admin.SpecialAccessAction.java

protected void addEditUserTopicSpecialAccess(org.etudes.api.app.jforum.Topic topic,
        org.etudes.api.app.jforum.SpecialAccess specialAccess) throws ParseException {
    // open date//from w ww  .  j ava2 s .co m
    String startDateParam = this.request.getParameter("start_date");
    if (startDateParam != null && startDateParam.trim().length() > 0) {
        Date startDate;
        try {
            startDate = DateUtil.getDateFromString(startDateParam.trim());

            specialAccess.getAccessDates().setOpenDate(startDate);

            // hide until open
            String hideUntilOpen = this.request.getParameter("hide_until_open");

            // check with forum start date
            if (topic.getAccessDates().getOpenDate() == null) {
                specialAccess.setOverrideStartDate(true);
                specialAccess.setOverrideHideUntilOpen(true);
                if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                    specialAccess.getAccessDates().setHideUntilOpen(true);
                } else {
                    specialAccess.getAccessDates().setHideUntilOpen(false);
                }
            } else {
                if (startDate.equals(topic.getAccessDates().getOpenDate())) {
                    specialAccess.getAccessDates().setOpenDate(null);
                    specialAccess.setOverrideStartDate(false);
                } else {
                    specialAccess.setOverrideStartDate(true);
                }

                // hide until open
                if (specialAccess.isOverrideStartDate()) {
                    /*ignore hide until open setting of topic*/
                    //specialAccess.setOverrideStartDate(true);
                    specialAccess.setOverrideHideUntilOpen(true);

                    if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                        specialAccess.getAccessDates().setHideUntilOpen(true);
                    } else {
                        specialAccess.getAccessDates().setHideUntilOpen(false);
                    }
                } else {
                    //consider hide until open setting of topic and override if not selected for special access
                    if (topic.getAccessDates().isHideUntilOpen()) {
                        if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(false);
                        } else {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(true);
                        }
                    } else {
                        if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                            specialAccess.getAccessDates().setHideUntilOpen(true);
                            specialAccess.setOverrideHideUntilOpen(true);
                        } else {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(false);
                        }
                    }
                }
            }

        } catch (ParseException e) {
            throw e;
        }
    } else {
        specialAccess.getAccessDates().setOpenDate(null);
        if (topic.getAccessDates().getOpenDate() != null) {
            specialAccess.setOverrideStartDate(true);
        }
    }

    // due date
    String endDateParam = this.request.getParameter("end_date");
    if (endDateParam != null && endDateParam.trim().length() > 0) {
        Date endDate;
        try {
            endDate = DateUtil.getDateFromString(endDateParam.trim());

            specialAccess.getAccessDates().setDueDate(endDate);

            // check with topic dates
            if (topic.getAccessDates().getDueDate() == null) {
                specialAccess.setOverrideEndDate(true);
                specialAccess.setOverrideLockEndDate(true);
            } else {
                if (endDate.equals(topic.getAccessDates().getDueDate())) {
                    specialAccess.getAccessDates().setDueDate(null);
                    specialAccess.setOverrideEndDate(false);
                } else {
                    specialAccess.setOverrideEndDate(true);
                }
            }
        } catch (ParseException e) {
            throw e;
        }

    } else { /*no special access end date*/

        specialAccess.getAccessDates().setDueDate(null);

        if (topic.getAccessDates().getDueDate() != null) {
            specialAccess.setOverrideEndDate(true);
            specialAccess.setOverrideLockEndDate(true);
        } else {
            specialAccess.setOverrideEndDate(false);
            specialAccess.setOverrideLockEndDate(false);
        }
    }

    // allow until date
    String allowUntilParam = this.request.getParameter("allow_until_date");
    if (allowUntilParam != null && allowUntilParam.trim().length() > 0) {
        Date allowUntilDate;
        try {
            allowUntilDate = DateUtil.getDateFromString(allowUntilParam.trim());

            specialAccess.getAccessDates().setAllowUntilDate(allowUntilDate);

            // check with topic dates
            if (topic.getAccessDates().getAllowUntilDate() == null) {
                specialAccess.setOverrideAllowUntilDate(true);
            } else if (allowUntilDate.equals(topic.getAccessDates().getAllowUntilDate())) {
                specialAccess.setOverrideAllowUntilDate(false);
                specialAccess.getAccessDates().setAllowUntilDate(null);
            } else {
                specialAccess.setOverrideAllowUntilDate(true);
            }
        } catch (ParseException e) {
            throw e;
        }
    } else {
        specialAccess.getAccessDates().setAllowUntilDate(null);
        if (topic.getAccessDates().getAllowUntilDate() != null) {
            specialAccess.setOverrideAllowUntilDate(true);
        }
    }

    int userId = this.request.getIntParameter("user_id");
    List<Integer> specialAccessUser = new ArrayList<Integer>();
    specialAccessUser.add(new Integer(userId));

    specialAccess.setUserIds(specialAccessUser);
}

From source file:org.etudes.jforum.view.admin.SpecialAccessAction.java

/**
 * adds or edits the user forum special access
 * // w  w  w .ja  va 2s  .c o  m
 * @param forum   Forum
 * 
 * @param specialAccess   Special access
 * 
 * @throws ParseException   Date parsing error
 */
protected void addEditUserForumSpecialAccess(org.etudes.api.app.jforum.Forum forum,
        org.etudes.api.app.jforum.SpecialAccess specialAccess) throws ParseException {
    // open date
    String startDateParam = this.request.getParameter("start_date");
    if (startDateParam != null && startDateParam.trim().length() > 0) {
        Date startDate;
        try {
            startDate = DateUtil.getDateFromString(startDateParam.trim());

            specialAccess.getAccessDates().setOpenDate(startDate);

            // hide until open
            String hideUntilOpen = this.request.getParameter("hide_until_open");

            // check with forum start date
            if (forum.getAccessDates().getOpenDate() == null) {
                specialAccess.setOverrideStartDate(true);
                specialAccess.setOverrideHideUntilOpen(true);
                if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                    specialAccess.getAccessDates().setHideUntilOpen(true);
                } else {
                    specialAccess.getAccessDates().setHideUntilOpen(false);
                }
            } else {
                if (startDate.equals(forum.getAccessDates().getOpenDate())) {
                    specialAccess.getAccessDates().setOpenDate(null);
                    specialAccess.setOverrideStartDate(false);
                } else {
                    specialAccess.setOverrideStartDate(true);
                }

                // hide until open
                if (specialAccess.isOverrideStartDate()) {
                    /*ignore hide until open setting of forum*/
                    //specialAccess.setOverrideStartDate(true);
                    specialAccess.setOverrideHideUntilOpen(true);

                    if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                        specialAccess.getAccessDates().setHideUntilOpen(true);
                    } else {
                        specialAccess.getAccessDates().setHideUntilOpen(false);
                    }
                } else {
                    //consider hide until open setting of forum and override if not selected for special access
                    if (forum.getAccessDates().isHideUntilOpen()) {
                        if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(false);
                        } else {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(true);
                        }
                    } else {
                        if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                            specialAccess.getAccessDates().setHideUntilOpen(true);
                            specialAccess.setOverrideHideUntilOpen(true);
                        } else {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(false);
                        }
                    }
                }
            }

        } catch (ParseException e) {
            throw e;
        }
    } else {
        specialAccess.getAccessDates().setOpenDate(null);
        if (forum.getAccessDates().getOpenDate() != null) {
            specialAccess.setOverrideStartDate(true);
        }
    }

    // due date
    String endDateParam = this.request.getParameter("end_date");
    if (endDateParam != null && endDateParam.trim().length() > 0) {
        Date endDate;
        try {
            endDate = DateUtil.getDateFromString(endDateParam.trim());

            specialAccess.getAccessDates().setDueDate(endDate);

            // check with forum dates
            if (forum.getAccessDates().getDueDate() == null) {
                specialAccess.setOverrideEndDate(true);
                specialAccess.setOverrideLockEndDate(true);
            } else {
                if (endDate.equals(forum.getAccessDates().getDueDate())) {
                    specialAccess.getAccessDates().setDueDate(null);
                    specialAccess.setOverrideEndDate(false);
                } else {
                    specialAccess.setOverrideEndDate(true);
                }
            }
        } catch (ParseException e) {
            throw e;
        }

    } else { /*no special access end date*/

        specialAccess.getAccessDates().setDueDate(null);

        if (forum.getAccessDates().getDueDate() != null) {
            specialAccess.setOverrideEndDate(true);
            specialAccess.setOverrideLockEndDate(true);
        } else {
            specialAccess.setOverrideEndDate(false);
            specialAccess.setOverrideLockEndDate(false);
        }
    }

    // allow until date
    String allowUntilParam = this.request.getParameter("allow_until_date");
    if (allowUntilParam != null && allowUntilParam.trim().length() > 0) {
        Date allowUntilDate;
        try {
            allowUntilDate = DateUtil.getDateFromString(allowUntilParam.trim());

            specialAccess.getAccessDates().setAllowUntilDate(allowUntilDate);

            // check with forum dates
            if (forum.getAccessDates().getAllowUntilDate() == null) {
                specialAccess.setOverrideAllowUntilDate(true);
            } else if (allowUntilDate.equals(forum.getAccessDates().getAllowUntilDate())) {
                specialAccess.setOverrideAllowUntilDate(false);
                specialAccess.getAccessDates().setAllowUntilDate(null);
            } else {
                specialAccess.setOverrideAllowUntilDate(true);
            }
        } catch (ParseException e) {
            throw e;
        }
    } else {
        specialAccess.getAccessDates().setAllowUntilDate(null);
        if (forum.getAccessDates().getAllowUntilDate() != null) {
            specialAccess.setOverrideAllowUntilDate(true);
        }
    }

    int userId = this.request.getIntParameter("user_id");
    List<Integer> specialAccessUser = new ArrayList<Integer>();
    specialAccessUser.add(new Integer(userId));

    specialAccess.setUserIds(specialAccessUser);
}

From source file:org.etudes.jforum.view.admin.SpecialAccessAction.java

/**
 * Adds or edits the forum special access
 * /* ww w  . j ava  2s .  c  om*/
 * @param forum      Forum
 * 
 * @param specialAccess      Special access
 * 
 * @throws ParseException   Date parsing error
 */
protected void addEditSpecialAccess(org.etudes.api.app.jforum.Forum forum,
        org.etudes.api.app.jforum.SpecialAccess specialAccess) throws ParseException {
    // open date
    String startDateParam = this.request.getParameter("start_date");
    if (startDateParam != null && startDateParam.trim().length() > 0) {
        Date startDate;
        try {
            startDate = DateUtil.getDateFromString(startDateParam.trim());

            specialAccess.getAccessDates().setOpenDate(startDate);

            // hide until open
            String hideUntilOpen = this.request.getParameter("hide_until_open");

            // check with forum start date
            if (forum.getAccessDates().getOpenDate() == null) {
                specialAccess.setOverrideStartDate(true);
                specialAccess.setOverrideHideUntilOpen(true);
                if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                    specialAccess.getAccessDates().setHideUntilOpen(true);
                } else {
                    specialAccess.getAccessDates().setHideUntilOpen(false);
                }
            } else {
                if (startDate.equals(forum.getAccessDates().getOpenDate())) {
                    specialAccess.getAccessDates().setOpenDate(null);
                    specialAccess.setOverrideStartDate(false);
                } else {
                    specialAccess.setOverrideStartDate(true);
                }

                // hide until open
                if (specialAccess.isOverrideStartDate()) {
                    /*ignore hide until open setting of forum*/
                    //specialAccess.setOverrideStartDate(true);
                    specialAccess.setOverrideHideUntilOpen(true);

                    if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                        specialAccess.getAccessDates().setHideUntilOpen(true);
                    } else {
                        specialAccess.getAccessDates().setHideUntilOpen(false);
                    }
                } else {
                    //consider hide until open setting of forum and override if not selected for special access
                    if (forum.getAccessDates().isHideUntilOpen()) {
                        if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(false);
                        } else {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(true);
                        }
                    } else {
                        if (hideUntilOpen != null && "1".equals(hideUntilOpen)) {
                            specialAccess.getAccessDates().setHideUntilOpen(true);
                            specialAccess.setOverrideHideUntilOpen(true);
                        } else {
                            specialAccess.getAccessDates().setHideUntilOpen(false);
                            specialAccess.setOverrideHideUntilOpen(false);
                        }
                    }
                }
            }

        } catch (ParseException e) {
            throw e;
        }
    } else {
        specialAccess.getAccessDates().setOpenDate(null);
        if (forum.getAccessDates().getOpenDate() != null) {
            specialAccess.setOverrideStartDate(true);
        }
    }

    // due date
    String endDateParam = this.request.getParameter("end_date");
    if (endDateParam != null && endDateParam.trim().length() > 0) {
        Date endDate;
        try {
            endDate = DateUtil.getDateFromString(endDateParam.trim());

            specialAccess.getAccessDates().setDueDate(endDate);

            // check with forum dates
            if (forum.getAccessDates().getDueDate() == null) {
                specialAccess.setOverrideEndDate(true);
                specialAccess.setOverrideLockEndDate(true);
            } else {
                if (endDate.equals(forum.getAccessDates().getDueDate())) {
                    specialAccess.getAccessDates().setDueDate(null);
                    specialAccess.setOverrideEndDate(false);
                } else {
                    specialAccess.setOverrideEndDate(true);
                }
            }
        } catch (ParseException e) {
            throw e;
        }

    } else { /*no special access end date*/

        specialAccess.getAccessDates().setDueDate(null);

        if (forum.getAccessDates().getDueDate() != null) {
            specialAccess.setOverrideEndDate(true);
            specialAccess.setOverrideLockEndDate(true);
        } else {
            specialAccess.setOverrideEndDate(false);
            specialAccess.setOverrideLockEndDate(false);
        }
    }

    // allow until date
    String allowUntilParam = this.request.getParameter("allow_until");
    if (allowUntilParam != null && allowUntilParam.trim().length() > 0) {
        Date allowUntilDate;
        try {
            allowUntilDate = DateUtil.getDateFromString(allowUntilParam.trim());

            specialAccess.getAccessDates().setAllowUntilDate(allowUntilDate);

            // check with forum dates
            if (forum.getAccessDates().getAllowUntilDate() == null) {
                specialAccess.setOverrideAllowUntilDate(true);
            } else if (allowUntilDate.equals(forum.getAccessDates().getAllowUntilDate())) {
                specialAccess.setOverrideAllowUntilDate(false);
                specialAccess.getAccessDates().setAllowUntilDate(null);
            } else {
                specialAccess.setOverrideAllowUntilDate(true);
            }
        } catch (ParseException e) {
            throw e;
        }
    } else {
        specialAccess.getAccessDates().setAllowUntilDate(null);
        if (forum.getAccessDates().getAllowUntilDate() != null) {
            specialAccess.setOverrideAllowUntilDate(true);
        }
    }

    List<Integer> users = new ArrayList<Integer>();
    String userIds[] = (String[]) this.request.getObjectParameter("toUsername" + "ParamValues");
    if (userIds != null) {

        for (int i = 0; i < userIds.length; i++) {
            if (userIds[i] != null && userIds[i].trim().length() > 0) {
                int userId;
                try {
                    userId = Integer.parseInt(userIds[i]);
                    users.add(new Integer(userId));
                } catch (NumberFormatException e) {
                    if (logger.isWarnEnabled())
                        logger.warn(this.getClass().getName()
                                + ".editForumSpecialAccess() : Error while parsing the userId.", e);
                }
            }
        }
    } else {
        try {
            int userId = Integer.parseInt(this.request.getParameter("toUsername"));
            users.add(new Integer(userId));
        } catch (NumberFormatException e) {
            if (logger.isWarnEnabled())
                logger.warn(this.getClass().getName()
                        + ".editForumSpecialAccess() : Error while parsing the userId.", e);
        }
    }

    specialAccess.setUserIds(users);
}

From source file:tds.dll.mssql.ProctorDLL.java

/**
 * @param connection/*from   w w  w .ja  v a2  s  . c o m*/
 * @param clientName
 * @param browserKey
 * @param sessionName
 * @param proctorKey
 * @param procId
 * @param procName
 * @param dateBegin
 * @param dateEnd
 * @param sessionType
 * @return
 * @throws ReturnStatusException
 */
public SingleDataResultSet P_CreateSession_SP(SQLConnection connection, String clientName, UUID browserKey,
        String sessionName, Long proctorKey, String procId, String procName, Date dateBegin, Date dateEnd,
        Integer sessionType) throws ReturnStatusException {

    SingleDataResultSet result = null;
    UUID sessionKey = null;
    _Ref<String> sessionId = new _Ref<>();
    String environment = null;
    String prefix = null;
    String status = "closed";
    String errMsg = null;
    Date now = _dateUtil.getDateWRetStatus(connection);
    Integer audit = null;
    audit = _commonDll.AuditSessions_FN(connection, clientName);

    final String SQL_QUERY1 = "select environment from _externs where clientname = ${clientname};";
    SqlParametersMaps parms1 = (new SqlParametersMaps()).put("clientname", clientName);
    result = executeStatement(connection, SQL_QUERY1, parms1, false).getResultSets().next();
    DbResultRecord record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        environment = record.<String>get("environment");
    }
    if (environment == null) {
        errMsg = String.format("Unknown client: %s", clientName);
        return _commonDll._ReturnError_SP(connection, clientName, "P_CreateSession", errMsg);
    }
    final String SQL_QUERY2 = "select top 1 _Key from session S where clientname = ${clientname} and _efk_Proctor = ${proctorKey} and ${now} between S.DateBegin and S.DateEnd and sessiontype = ${sessiontype}";
    SqlParametersMaps parms2 = (new SqlParametersMaps()).put("clientname", clientName)
            .put("proctorKey", proctorKey).put("now", now).put("sessiontype", sessionType);
    if (exists(executeStatement(connection, SQL_QUERY2, parms2, true))) {
        return _commonDll._ReturnError_SP(connection, clientName, "P_CreateSession",
                "There already is an active session for this user.");
    }
    prefix = _commonDll._CoreSessName_FN(connection, clientName, procName);
    sessionKey = UUID.randomUUID();
    if (dateBegin == null) {
        dateBegin = now;
    }
    if (dateEnd == null) {
        dateEnd = adjustDateHours(dateBegin, 8);
    } else if (DbComparator.lessOrEqual(dateEnd, dateBegin)) {
        dateEnd = adjustDateHours(dateBegin, 8);
    }
    if ((now.equals(dateBegin) || now.after(dateBegin)) && (now.equals(dateEnd) || now.before(dateEnd))) {
        status = "open";
    }
    _commonDll._CreateClientSessionID_SP(connection, clientName, prefix, sessionId);
    if (sessionId.get() == null) {
        return _commonDll._ReturnError_SP(connection, clientName, "P_CreateSession",
                "Failed to insert new session into database");
    }
    try {
        final String SQL_INSERT = "insert into Session (_Key, [Name], _efk_Proctor, ProctorID, ProctorName, [status], DateBegin, DateEnd, SessionID, _fk_browser, clientname, environment, dateVisited, sessiontype) "
                + " values (${sessionKey}, ${sessionName}, ${proctorKey}, ${procID}, ${procName}, ${status}, ${dateBegin}, ${dateEnd}, ${sessionID}, ${browserKey}, ${clientname}, ${environment}, ${now}, ${sessiontype});";
        SqlParametersMaps parms3 = new SqlParametersMaps();
        parms3.put("sessionKey", sessionKey);
        parms3.put("sessionName", sessionName);
        parms3.put("proctorKey", proctorKey);
        parms3.put("procID", procId);
        parms3.put("procName", procName);
        parms3.put("status", status);
        parms3.put("dateBegin", dateBegin);
        parms3.put("dateEnd", dateEnd);
        parms3.put("sessionID", sessionId.toString());
        parms3.put("browserKey", browserKey);
        parms3.put("clientname", clientName);
        parms3.put("environment", environment);
        parms3.put("now", now);
        parms3.put("sessiontype", sessionType);
        int insertedCnt = executeStatement(connection, SQL_INSERT, parms3, false).getUpdateCount();
        // //_logger.info (insertedCnt); // for testing

    } catch (Exception e) {
        String err = e.getMessage();
        _commonDll._LogDBError_SP(connection, "P_CreateSession", err, null, null, null, null, clientName, null);
        _commonDll._LogDBLatency_SP(connection, "P_CreateSession", now, proctorKey, true, null, null, null,
                clientName, null);
        return _commonDll._ReturnError_SP(connection, clientName, "P_CreateSession",
                "Failed to insert new session into database");
    }
    String localhostname = _commonDll.getLocalhostName();
    if (DbComparator.notEqual(audit, 0)) {
        final String SQL_INSERT1 = "insert into SessionAudit (_fk_session, DateAccessed, AccessType, hostname, browserKey) values (${sessionKey}, ${now}, ${status}, ${hostname}, ${browserKey});";
        SqlParametersMaps parms4 = new SqlParametersMaps().put("sessionKey", sessionKey).put("now", now)
                .put("status", status).put("hostname", localhostname).put("browserKey", browserKey);
        int insertedCnt = executeStatement(connection, SQL_INSERT1, parms4, false).getUpdateCount();
        // //_logger.info (insertedCnt); // for testing
    }
    List<CaseInsensitiveMap<Object>> resultlist = new ArrayList<CaseInsensitiveMap<Object>>();
    CaseInsensitiveMap<Object> rcrd = new CaseInsensitiveMap<Object>();
    rcrd.put("sessionKey", sessionKey.toString());
    rcrd.put("sessionID", sessionId.get());
    rcrd.put("Name", sessionName);
    rcrd.put("sessionStatus", status);
    resultlist.add(rcrd);

    result = new SingleDataResultSet();
    result.addColumn("sessionKey", SQL_TYPE_To_JAVA_TYPE.UNIQUEIDENTIFIER);
    result.addColumn("sessionID", SQL_TYPE_To_JAVA_TYPE.VARCHAR);
    result.addColumn("Name", SQL_TYPE_To_JAVA_TYPE.VARCHAR);
    result.addColumn("sessionStatus", SQL_TYPE_To_JAVA_TYPE.VARCHAR);
    result.addRecords(resultlist);

    _commonDll._LogDBLatency_SP(connection, "P_CreateSession", now, proctorKey, true, null, null, sessionKey,
            clientName, null);
    return result;
}

From source file:org.sakaiproject.tool.assessment.facade.AssessmentGradingFacadeQueries.java

/**
 * @author Mustansar Mehmood mustansar@rice.edu
 * *//*  ww w  .ja v  a2s . c  o m*/
public HashMap getAverageAssessmentGradingByPublishedItem(final Long publishedAssessmentId) {
    HashMap h = new HashMap();
    final String query = "select new AssessmentGradingData(" + " a.assessmentGradingId, p.itemId, "
            + " a.agentId, a.finalScore, a.submittedDate) "
            + " from ItemGradingData i, AssessmentGradingData a," + " PublishedItemData p where "
            + " i.assessmentGradingId = a.assessmentGradingId and i.publishedItemId = p.itemId and "
            + " a.publishedAssessmentId=? " + " order by a.agentId asc, a.submittedDate desc";

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setLong(0, publishedAssessmentId.longValue());
            return q.list();
        };
    };

    List assessmentGradings = getHibernateTemplate().executeFind(hcb);

    String currentAgent = "";
    Date submittedDate = null;
    for (int i = 0; i < assessmentGradings.size(); i++) {
        AssessmentGradingData g = (AssessmentGradingData) assessmentGradings.get(i);
        Long itemId = g.getPublishedItemId();
        Long gradingId = g.getAssessmentGradingId();
        if (i == 0) {
            currentAgent = g.getAgentId();
            submittedDate = g.getSubmittedDate();
        }
        if (currentAgent.equals(g.getAgentId()) && ((submittedDate == null && g.getSubmittedDate() == null)
                || (submittedDate != null && submittedDate.equals(g.getSubmittedDate())))) {
            Object o = h.get(itemId);
            if (o != null)
                ((ArrayList) o).add(gradingId);
            else {
                ArrayList gradingIds = new ArrayList();
                gradingIds.add(gradingId);
                h.put(itemId, gradingIds);
            }
        }
        if (!currentAgent.equals(g.getAgentId())) {
            currentAgent = g.getAgentId();
            submittedDate = g.getSubmittedDate();
        }
    }
    return h;
}

From source file:org.sakaiproject.tool.assessment.facade.AssessmentGradingFacadeQueries.java

public HashMap getLastAssessmentGradingByPublishedItem(final Long publishedAssessmentId) {
    HashMap h = new HashMap();
    final String query = "select new AssessmentGradingData(" + " a.assessmentGradingId, p.itemId, "
            + " a.agentId, a.finalScore, a.submittedDate) "
            + " from ItemGradingData i, AssessmentGradingData a," + " PublishedItemData p where "
            + " i.assessmentGradingId = a.assessmentGradingId and i.publishedItemId = p.itemId and "
            + " a.publishedAssessmentId=? " + " order by a.agentId asc, a.submittedDate desc";

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setLong(0, publishedAssessmentId.longValue());
            return q.list();
        };/*from ww w .j av  a2s  . c om*/
    };
    List assessmentGradings = getHibernateTemplate().executeFind(hcb);

    //    List assessmentGradings = getHibernateTemplate().find(query,
    //         new Object[] { publishedAssessmentId },
    //         new org.hibernate.type.Type[] { Hibernate.LONG });

    //    ArrayList l = new ArrayList();
    String currentAgent = "";
    Date submittedDate = null;
    for (int i = 0; i < assessmentGradings.size(); i++) {
        AssessmentGradingData g = (AssessmentGradingData) assessmentGradings.get(i);
        Long itemId = g.getPublishedItemId();
        Long gradingId = g.getAssessmentGradingId();
        log.debug("**** itemId=" + itemId + ", gradingId=" + gradingId + ", agentId=" + g.getAgentId()
                + ", score=" + g.getFinalScore());
        if (i == 0) {
            currentAgent = g.getAgentId();
            submittedDate = g.getSubmittedDate();
        }
        if (currentAgent.equals(g.getAgentId()) && ((submittedDate == null && g.getSubmittedDate() == null)
                || (submittedDate != null && submittedDate.equals(g.getSubmittedDate())))) {
            Object o = h.get(itemId);
            if (o != null)
                ((ArrayList) o).add(gradingId);
            else {
                ArrayList gradingIds = new ArrayList();
                gradingIds.add(gradingId);
                h.put(itemId, gradingIds);
            }
        }
        if (!currentAgent.equals(g.getAgentId())) {
            currentAgent = g.getAgentId();
            submittedDate = g.getSubmittedDate();
        }
    }
    return h;
}

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

public static String getMsgDate(EipTSchedule schedule) {
    Calendar start_cal = Calendar.getInstance();
    start_cal.setTime(schedule.getStartDate());
    Calendar end_cal = Calendar.getInstance();
    end_cal.setTime(schedule.getEndDate());

    StringBuffer result = new StringBuffer();
    // DN ->  (A = N -> ??? A = L -> ??)
    // WnnnnnnnN W01111110 -> ()
    // MnnN M25 -> 25
    // YnnmmN Y0825N ->825
    // S -> ??
    String ptn = schedule.getRepeatPattern();
    int count = 0;
    boolean is_repeat = true;
    boolean is_span = false;
    // //  www . j  a v a2  s.c o m
    if (ptn.charAt(0) == 'D') {
        result.append(ALLocalizationUtils.getl10n("SCHEDULE_EVERY_DAY"));
        count = 1;
        // 
    } else if (ptn.charAt(0) == 'W') {
        result.append(new StringBuffer().append(ALLocalizationUtils.getl10n("SCHEDULE_EVERY_WEEK"))
                .append(ptn.charAt(1) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_SUNDAY") : "")
                .append(ptn.charAt(2) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_MONDAY") : "")
                .append(ptn.charAt(3) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_TUSEDAY") : "")
                .append(ptn.charAt(4) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_WEDNESDAY") : "")
                .append(ptn.charAt(5) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_THURSDAY") : "")
                .append(ptn.charAt(6) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_FRIDAY") : "")
                .append(ptn.charAt(7) != '0' ? ALLocalizationUtils.getl10n("SCHEDULE_SATURDAY") : "")
                .append(ALLocalizationUtils.getl10n("SCHEDULE_A_DAY_OF_THE_WEEK")).toString());
        count = 8;
        // 
    } else if (ptn.charAt(0) == 'M') {
        if (ptn.substring(1, 3).equals("XX")) {
            result.append(ALLocalizationUtils.getl10n("SCHEDULE_EVERY_MONTH_SPACE"))
                    .append(ALLocalizationUtils.getl10n("SCHEDULE_END_OF_MONTH"))
                    .append(ALLocalizationUtils.getl10n("SCHEDULE_DAY")).toString();
        } else {
            result.append(ALLocalizationUtils.getl10n("SCHEDULE_EVERY_MONTH_SPACE"))
                    .append(Integer.parseInt(ptn.substring(1, 3)))
                    .append(ALLocalizationUtils.getl10n("SCHEDULE_DAY")).toString();
        }
        count = 3;
        // 
    } else if (ptn.charAt(0) == 'Y') {
        result.append(ALLocalizationUtils.getl10n("SCHEDULE_EVERY_YEAR_SPACE"))
                .append(Integer.parseInt(ptn.substring(1, 3)))
                .append(ALLocalizationUtils.getl10n("SCHEDULE_MONTH"))
                .append(Integer.parseInt(ptn.substring(3, 5)))
                .append(ALLocalizationUtils.getl10n("SCHEDULE_DAY")).toString();
        count = 5;
        // 
    } else if (ptn.charAt(0) == 'S') {// ?S
        is_span = true;
        is_repeat = false;
    } else {
        is_repeat = false;
    }

    ALDateTimeField date_field = new ALDateTimeField("yyyy/MM/dd");
    ALDateTimeField time_field = new ALDateTimeField("HH:mm");

    if (!is_span) {
        if (!is_repeat) {
            date_field.setValue(schedule.getStartDate());
            result.append(date_field.toString());
        }
        time_field.setValue(schedule.getStartDate());
        // ?????? - ?
        result.append(" ").append(time_field.toString()).append(" - ");
        time_field.setValue(schedule.getEndDate());
        result.append(time_field.toString()).append(" ");
    } else {
        Date start = schedule.getStartDate();
        Date end = schedule.getEndDate();
        date_field.setValue(start);
        result.append(date_field.toString());
        if (!start.equals(end)) {
            result.append(" - ");
            date_field.setValue(end);
            result.append(date_field.toString());
        }
    }

    if (is_repeat) {
        if (ptn.charAt(count) == 'N') {
            // schedule.setLimit(false);
        } else {
            // schedule.setLimit(true);
            // ?
            date_field.setValue(schedule.getStartDate());
            result.append(" ").append(date_field.toString()).append(" - ");
            date_field.setValue(schedule.getEndDate());
            result.append(date_field.toString()).append("").toString();
        }
    }
    return result.toString();
}