Example usage for java.util Date before

List of usage examples for java.util Date before

Introduction

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

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:com.virtusa.akura.reporting.controller.GenerateStudentWiseAttendanceReportController.java

/**
 * Perform the logic of the controller to generate Teacher Wise Attendance Report .
 * /*from  ww w  . jav  a 2s. co  m*/
 * @param studentTemplate of type StudentWiseAttendanceTemplate
 * @param request of type HttpServletRequest
 * @param response of type HttpServletResponse
 * @param errors of type BindingResult
 * @return java.lang.String
 * @param map of type ModelMap
 * @throws AkuraAppException AkuraAppException
 */

@RequestMapping(value = REQ_MAP_STUDENT_ATTENDANCE_REPORT, method = RequestMethod.POST)
public String onSubmit(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute(MODEL_ATT_STUDENT_WISE_ATTENDANCE_TEMPLATE) StudentWiseAttendanceTemplate studentTemplate,
        BindingResult errors, ModelMap map) throws AkuraAppException {

    String selectedClass = request.getParameter(SELECTED_CLASS);
    String reqAddmission = request.getParameter(SELECTED_ADDMISSION);

    String[] noParts = reqAddmission.split(
            AkuraWebConstant.SPACE_STRING + AkuraWebConstant.DASH_STRING + AkuraWebConstant.SPACE_STRING);
    String selectedAddmission = noParts[0];

    ClassGrade classGrade = commonService.findClassGrade(Integer.parseInt(selectedClass));
    studentTemplate.setStudentID(selectedAddmission);

    if (selectedAddmission == null) {

        String message = new ErrorMsgLoader().getErrorMessage(ERROR_MSG_MANDATORY_FIELD_REQUIRED);
        map.addAttribute(MESSAGE, message);
        if (classGrade != null) {
            map.addAttribute(MODEL_ATT_SELECTED_CLASS_GRADE_ID, classGrade.getClassGradeId());
        }

        return VIEW_PAGE;
    }

    String returnString = STRING_EMPTY;
    studentWiseAttendanceValidator.validate(studentTemplate, errors);

    if (errors.hasErrors()) {
        if (classGrade != null) {
            map.addAttribute(MODEL_ATT_SELECTED_CLASS_GRADE_ID, classGrade.getClassGradeId());
        }
        map.addAttribute(MODEL_ATT_SELECTED_ADDMISSION_NO, selectedAddmission);
        return VIEW_PAGE;
    }

    if (selectedClass.equals(AkuraWebConstant.STRING_ZERO)) {

        String message = new ErrorMsgLoader().getErrorMessage(ERROR_MSG_MANDATORY_FIELD_REQUIRED);
        map.addAttribute(MESSAGE, message);
        if (classGrade != null) {
            map.addAttribute(MODEL_ATT_SELECTED_CLASS_GRADE_ID, classGrade.getClassGradeId());
        }
        map.addAttribute(MODEL_ATT_SELECTED_ADDMISSION_NO, selectedAddmission);

        return VIEW_PAGE;
    }

    Map<String, Object> params = new HashMap<String, Object>();

    params.put(REPORT_PARA_TITLE, PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE,
            REPORT_VALUE_STUDENT_WISE_ATTENDANCE_REPORT));
    params.put(REPORT_PARA_STUDENTID,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_VALUE_STUDENT_ID));
    params.put(REPORT_PARA_STUDENTNAME,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_VALUE_STUDENT_NAME));
    params.put(REPORT_PARA_DATE,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_VALUE_DATE));
    params.put(REPORT_PARA_TIMEIN,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_VALUE_TIME_IN));
    params.put(REPORT_PARA_TIMEOUT,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_VALUE_TIME_OUT));
    params.put(REPORT_PARA_STUDENT, studentTemplate.getDateFrom());
    params.put(REPORT_PARA_DATEFROM, studentTemplate.getDateFrom());
    params.put(REPORT_PARA_DATETO, studentTemplate.getDateTo());
    params.put(REPORT_PARA_ATTENDANCE_FROM,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_PARA_ATTENDANCE_FROM_TEXT));
    params.put(REPORT_PARA_ATTENDANCE_TO,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_PARA_ATTENDANCE_TO_TEXT));
    params.put(REPORT_PARA_LOGO_PATH, ReportUtil.getReportLogo());
    params.put(STYLE_TEMPLATE, PropertyReader.getPropertyValue(SYSTEM_CONFIG, APPSERVER_HOME)
            + PropertyReader.getPropertyValue(SYSTEM_CONFIG, STYLE_PATH));
    params.put(REPORT_GENERATED_ON,
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_GENERATED_ON_TEXT));
    params.put(GENERATED_DATE, DateUtil.getReportGeneratedDate(
            PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_GENERATED_DATE_LOCALE)));
    params.put(PAGE, PropertyReader.getPropertyValue(ReportUtil.REPORT_TEMPLATE, REPORT_PAGE));
    params.put(GPL, AkuraWebConstant.REPORT_GPL);

    String todateString = studentTemplate.getDateTo();
    String fromDateString = studentTemplate.getDateFrom();

    Date toDate = DateUtil.getParseDate(todateString);
    Date fromDate = DateUtil.getParseDate(fromDateString);

    int studentId = studentService.findStudentIdForAdmissionNo(selectedAddmission);
    Student student = studentService.findStudent(studentId);
    Date departureDate = student.getDateOfDeparture();

    if (departureDate != null) {
        if (departureDate.before(toDate) && departureDate.after(fromDate)) {
            String depatureDateString = DateUtil.getFormatDate(departureDate);
            studentTemplate.setDateTo(depatureDateString);

        }
    }

    JRBeanCollectionDataSource studentWiseAttendanceSummary = attendanceReportingService
            .getStudentWiseAttendanceSummary(studentTemplate);

    if (studentWiseAttendanceSummary.getRecordCount() != 0) {
        ReportUtil.displayReportInPdfForm(response, studentWiseAttendanceSummary, params,
                REPORT_NAME_STUDENT_WISE_ATTENDANCE);
    } else {
        setErrorMessage(map);
        if (classGrade != null) {
            map.addAttribute(MODEL_ATT_SELECTED_CLASS_GRADE_ID, classGrade.getClassGradeId());
        }
        map.addAttribute(MODEL_ATT_SELECTED_ADDMISSION_NO, selectedAddmission);
        returnString = VIEW_PAGE;
    }

    return returnString;

}

From source file:com.liferay.journal.util.impl.JournalContentImpl.java

protected JournalArticleDisplay getArticleDisplay(JournalArticle article, String ddmTemplateKey,
        String viewMode, String languageId, int page, PortletRequestModel portletRequestModel,
        ThemeDisplay themeDisplay) {//from  w w  w  . j a v a  2  s  . c  om

    if (article.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        return null;
    }

    Date now = new Date();

    Date displayDate = article.getDisplayDate();
    Date expirationDate = article.getExpirationDate();

    if (((displayDate != null) && displayDate.after(now))
            || ((expirationDate != null) && expirationDate.before(now))) {

        return null;
    }

    try {
        return _journalArticleLocalService.getArticleDisplay(article, ddmTemplateKey, viewMode, languageId,
                page, portletRequestModel, themeDisplay);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(StringBundler.concat("Unable to get display for ", article.toString(), StringPool.SPACE,
                    languageId), e);
        }

        return null;
    }
}

From source file:com.apteligent.ApteligentJavaClient.java

/**
 * Attempt to validate an existing token object
 * Note: this call does not yet check the validity of a token, only if it has not yet expired.
 * @param apiTokenObj/*w  ww .j  a v  a2s  .co  m*/
 * @return true if the client accepted the token, false otherwise
 */
public boolean connect(Token apiTokenObj) {
    boolean success = false;
    if (apiTokenObj != null) {

        // check if the token is still active or expired
        Date today = new Date();

        // setup expiration date object
        Date dateTokenExpires = apiTokenObj.getCreationDate();
        long secondsOffset = apiTokenObj.getExpiresIn();
        dateTokenExpires.setTime(dateTokenExpires.getTime() + 1000 * secondsOffset);

        if (today.before(dateTokenExpires)) {
            this.token = apiTokenObj;
            success = true;
        }
    }
    return success;
}

From source file:com.qcadoo.mes.productionPerShift.hooks.ProductionPerShiftDetailsHooks.java

private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
    Long technologyId = order.getBelongsToField(OrderFields.TECHNOLOGY).getId();
    Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(technologyId);
    DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER,
            ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
    Optional<OrderDates> maybeOrderDates = OrderDates.of(order);
    boolean areDatesCorrect = true;
    if (maybeOrderDates.isPresent()) {
        OrderDates orderDates = maybeOrderDates.get();
        Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
        Date orderEnd = removeTime(orderDates.getEnd().effectiveWithFallback().toDate());
        for (Long id : progressForDayIds) {
            Entity progressForDay = progressForDayDD.get(id);
            Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
            if (progressDate == null) {
                progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
            }//from  ww  w  .j a va  2s .c  o m
            if (progressDate.before(orderStart) || progressDate.after(orderEnd)) {
                areDatesCorrect = false;
            }
        }
    }
    if (!areDatesCorrect) {
        view.addMessage("productionPerShift.info.invalidDates", MessageType.INFO, false);
    }
}

From source file:com.eucalyptus.imaging.backend.ImagingTaskStateManager.java

private boolean shouldPurge(final ImagingTask task) {
    final Date lastUpdated = task.getLastUpdateTimestamp();
    Calendar cal = Calendar.getInstance(); // creates calendar
    cal.setTime(lastUpdated); // sets calendar time/date
    cal.add(Calendar.HOUR_OF_DAY, TASK_PURGE_EXPIRATION_HOURS); // adds one hour
    final Date expirationTime = cal.getTime(); //

    return expirationTime.before(new Date());
}

From source file:com.eucalyptus.imaging.backend.ImagingTaskStateManager.java

private boolean isExpired(final ImagingTask task) {
    final Date expirationTime = task.getExpirationTime();
    return expirationTime.before(new Date());
}

From source file:com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesManager.java

@Override
public DynamicAttributesCache getCacheIfNewer(Date clientCacheDate) {
    if (clientCacheDate == null || this.dynamicAttributesCache == null
            || this.dynamicAttributesCache.getCreationDate() == null
            || clientCacheDate.before(this.dynamicAttributesCache.getCreationDate())) {
        return cache();
    } else {/* w  ww.j  av  a  2  s.com*/
        return null;
    }
}

From source file:com.hp.mqm.atrf.core.configuration.FetchConfiguration.java

public void validateProperties() {

    //MUST PARAMETERS
    validateMustParameter(ALM_USER_PARAM);
    validateMustParameter(ALM_PROJECT_PARAM);
    validateMustParameter(ALM_DOMAIN_PARAM);
    validateMustParameter(ALM_SERVER_URL_PARAM);

    if (StringUtils.isEmpty(getOutputFile())) {
        //MUST//from   w w w  .j  a v a2 s.  c o m
        validateMustParameter(OCTANE_USER_PARAM);
        validateMustParameter(OCTANE_WORKSPACE_ID_PARAM);
        validateMustParameter(OCTANE_SHAREDSPACE_ID_PARAM);
        validateMustParameter(OCTANE_SERVER_URL_PARAM);

        //INTEGER
        validateIntegerParameter(OCTANE_WORKSPACE_ID_PARAM);
        validateIntegerParameter(OCTANE_SHAREDSPACE_ID_PARAM);
    }

    //INTEGER
    validateIntegerParameter(SYNC_BULK_SIZE_PARAM);
    validateIntegerParameter(SYNC_SLEEP_BETWEEN_POSTS_PARAM);
    validateIntegerParameter(PROXY_PORT_PARAM);

    //CUSTOM VALIDATIONS
    //ALM_RUN_FILTER_START_FROM_ID
    String startFromIdValue = getAlmRunFilterStartFromId();
    if (StringUtils.isNotEmpty(startFromIdValue)) {
        boolean isValid = false;
        if (ALM_RUN_FILTER_START_FROM_ID_LAST_SENT.equalsIgnoreCase(startFromIdValue)) {
            isValid = true;
        } else {
            try {
                Integer.parseInt(startFromIdValue);
                isValid = true;
            } catch (NumberFormatException e) {
                isValid = false;
            }
        }

        if (!isValid) {
            throw new RuntimeException(String.format(
                    "Configuration parameter '%s' can hold integer value or '%s' string, but contains '%s'",
                    ALM_RUN_FILTER_START_FROM_ID_PARAM, ALM_RUN_FILTER_START_FROM_ID_LAST_SENT,
                    startFromIdValue));
        }
    }

    //ALM_RUN_FILTER_START_FROM_DATE
    String startFromDateValue = getAlmRunFilterStartFromDate();
    if (StringUtils.isNotEmpty(startFromDateValue)) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
        try {
            Date d = dateFormat.parse(startFromDateValue);
            if (d.after(dateFormat.parse("2099-12-31")) || d.before(dateFormat.parse("1900-01-01"))) {
                throw new RuntimeException(
                        String.format("Configuration parameter '%s' should be in range of 1900-2100",
                                ALM_RUN_FILTER_START_FROM_DATE_PARAM));
            }
            //The date 2017-12-06 is out of <1900-2100> range"
        } catch (ParseException e) {
            throw new RuntimeException(String.format(
                    "Configuration parameter '%s' should contain date in the following format '%s'",
                    ALM_RUN_FILTER_START_FROM_DATE_PARAM, DATE_FORMAT));
        }

    }

    //ALM_RUN_FILTER_RELATED_ENTITY_ENTITY_ID_PARAM
    String relatedEntityType = getAlmRunFilterRelatedEntityType();
    String relatedEntityId = getAlmRunFilterRelatedEntityId();
    if (StringUtils.isNotEmpty(relatedEntityType) && StringUtils.isEmpty(relatedEntityId)) {
        throw new RuntimeException(String.format(
                "Configuration contains value for parameter '%s', but missing value for parameter '%s'",
                ALM_RUN_FILTER_RELATED_ENTITY_TYPE_PARAM, ALM_RUN_FILTER_RELATED_ENTITY_ID_PARAM));
    }
    if (StringUtils.isNotEmpty(relatedEntityId) && StringUtils.isEmpty(relatedEntityType)) {
        throw new RuntimeException(String.format(
                "Configuration contains value for parameter '%s', but missing value for parameter '%s'",
                ALM_RUN_FILTER_RELATED_ENTITY_ID_PARAM, ALM_RUN_FILTER_RELATED_ENTITY_TYPE_PARAM));
    }
    if (StringUtils.isNotEmpty(relatedEntityType)) {
        relatedEntityType = relatedEntityType.toLowerCase();
        List<String> allowedEntityTypes = Arrays.asList("test", "testset", "sprint", "release");
        if (!allowedEntityTypes.contains(relatedEntityType)) {
            throw new RuntimeException(String.format(
                    "Configuration contains illegal value for parameter '%s', allowed values are %s",
                    ALM_RUN_FILTER_RELATED_ENTITY_TYPE_PARAM, allowedEntityTypes.toString()));
        }
    }

    //FETCH LIMIT
    String fetchLimitStr = getProperty(ALM_RUN_FILTER_FETCH_LIMIT_PARAM);
    int fetchLimit = ALM_RUN_FILTER_FETCH_LIMIT_DEFAULT;
    if (StringUtils.isNotEmpty(fetchLimitStr)) {
        try {
            fetchLimit = Integer.parseInt(fetchLimitStr);
        } catch (Exception e) {
            throw new RuntimeException(String.format(
                    "Configuration contains illegal value for parameter '%s', the value should be integer in range of  1-200000",
                    ALM_RUN_FILTER_FETCH_LIMIT_PARAM));
        }
        if (fetchLimit > ALM_RUN_FILTER_FETCH_LIMIT_MAX || fetchLimit < ALM_RUN_FILTER_FETCH_LIMIT_MIN) {
            throw new RuntimeException(String.format(
                    "Configuration contains illegal value for parameter '%s', the value should be integer in range of  1-200000",
                    ALM_RUN_FILTER_FETCH_LIMIT_PARAM));
        }
    } else {
        fetchLimit = ALM_RUN_FILTER_FETCH_LIMIT_DEFAULT;
    }
    setProperty(ALM_RUN_FILTER_FETCH_LIMIT_PARAM, Integer.toString(fetchLimit));

    //BULK SIZE
    String bulkSizeStr = getProperty(SYNC_BULK_SIZE_PARAM);
    int bulkSize = SYNC_BULK_SIZE_DEFAULT;
    if (StringUtils.isNotEmpty(bulkSizeStr)) {
        try {
            bulkSize = Integer.parseInt(bulkSizeStr);
            if (bulkSize < SYNC_BULK_SIZE_MIN || bulkSize > SYNC_BULK_SIZE_MAX) {
                bulkSize = SYNC_BULK_SIZE_DEFAULT;
            }
        } catch (Exception e) {
            bulkSize = SYNC_BULK_SIZE_DEFAULT;
        }
    }
    setProperty(SYNC_BULK_SIZE_PARAM, Integer.toString(bulkSize));

    //SLEEP
    String sleepBetweenPostsStr = getProperty(SYNC_SLEEP_BETWEEN_POSTS_PARAM);
    int sleepBetweenPosts = SYNC_SLEEP_BETWEEN_POSTS_DEFAULT;
    if (StringUtils.isNotEmpty(sleepBetweenPostsStr)) {
        try {
            sleepBetweenPosts = Integer.parseInt(sleepBetweenPostsStr);
            if (sleepBetweenPosts < SYNC_SLEEP_BETWEEN_POSTS_MIN
                    || sleepBetweenPosts > SYNC_SLEEP_BETWEEN_POSTS_MAX) {
                sleepBetweenPosts = SYNC_SLEEP_BETWEEN_POSTS_DEFAULT;
            }
        } catch (Exception e) {
            sleepBetweenPosts = SYNC_SLEEP_BETWEEN_POSTS_DEFAULT;
        }
    }
    setProperty(SYNC_SLEEP_BETWEEN_POSTS_PARAM, Integer.toString(sleepBetweenPosts));

}

From source file:info.rmapproject.auth.service.ApiKeyServiceImpl.java

/**
 * Validate an API key/secret combination to ensure the user has access to write to RMap.
 *
 * @param accessKey the access key/*ww w  .  j  a v  a2 s.c  o  m*/
 * @param secret the secret
 * @throws RMapAuthException the RMap Auth exception
 */
public void validateApiKey(String accessKey, String secret) throws RMapAuthException {

    ApiKey apiKey = getApiKeyByKeySecret(accessKey, secret);

    if (apiKey != null) {
        KeyStatus keyStatus = apiKey.getKeyStatus();
        Date keyStartDate = apiKey.getStartDate();
        Date keyEndDate = apiKey.getEndDate();

        Calendar now = Calendar.getInstance();
        now.set(Calendar.HOUR_OF_DAY, 0);
        now.set(Calendar.MINUTE, 0);
        now.set(Calendar.SECOND, 0);
        Date today = now.getTime();
        now.add(Calendar.DATE, -1);
        Date yesterday = now.getTime();

        if (keyStatus != KeyStatus.ACTIVE || (keyStartDate != null && keyStartDate.after(today))
                || (keyEndDate != null && keyEndDate.before(yesterday))) {
            //key not valid! throw exception
            throw new RMapAuthException(ErrorCode.ER_KEY_INACTIVE.getMessage());
        }
    } else {
        throw new RMapAuthException(ErrorCode.ER_ACCESSCODE_SECRET_NOT_FOUND.getMessage());
    }

}

From source file:de.micromata.genome.chronos.spi.ram.RamJobStore.java

@Override
public synchronized List<TriggerJobDO> getNextJobs(long lookForward) {
    final ArrayList<TriggerJobDO> jobsToStart = new ArrayList<TriggerJobDO>();
    Date vnow = new Date(System.currentTimeMillis() + lookForward);

    for (Map<Long, TriggerJobDO> tjobs : allJobs.values()) {

        for (final TriggerJobDO job : tjobs.values()) {
            if (job.getState() != State.WAIT) {
                continue;
            }// w ww  .j av a2s. c  om
            final Trigger trigger = job.getTrigger();
            final Date nextFireTime = job.getNextFireTime();
            if (nextFireTime != null && nextFireTime.before(vnow)) {
                if (log.isDebugEnabled() == true) {
                    log.debug("Found trigger: " + trigger);
                }
                jobsToStart.add(job);
            } else {
                if (log.isDebugEnabled() == true) {
                    log.debug("Job in future: " + nextFireTime);
                }
            }

        }
    }
    return jobsToStart;
}