Example usage for org.joda.time LocalDate now

List of usage examples for org.joda.time LocalDate now

Introduction

In this page you can find the example usage for org.joda.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:org.esupportail.publisher.domain.AbstractItem.java

License:Apache License

public ItemStatus getStatus() {
    switch (status) {
    case PUBLISHED:
        if (this.startDate.isAfter(LocalDate.now())) {
            status = ItemStatus.SCHEDULED;
            return ItemStatus.SCHEDULED;
        } else if (this.endDate.isBefore(LocalDate.now())) {
            status = ItemStatus.ARCHIVED;
            return ItemStatus.ARCHIVED;
        }/* w w  w . j  a v a2  s .  c  o m*/
        break;
    default:
        break;
    }
    return status;
}

From source file:org.fenixedu.bennu.core.domain.User.java

License:Open Source License

/**
 * Closes any not closed period setting the end day to yesterday (to effectively close, since end date is inclusive).
 *//*from   w w w .  j a v a2s. com*/
public void closeLoginPeriod() {
    closeLoginPeriod(LocalDate.now().minusDays(1));
}

From source file:org.fenixedu.bennu.core.domain.User.java

License:Open Source License

/**
 * Tests whether this user can login or not
 * /*from   w w  w  .j a v  a  2 s .c  o  m*/
 * @return true if login is possible, false otherwise
 */
public boolean isLoginExpired() {
    return getExpiration().map(p -> LocalDate.now().isAfter(p)).orElse(false);
}

From source file:org.fenixedu.learning.api.EventsResource.java

License:Open Source License

@GET
@Path("/executionCourse/{course}/nearestEvent")
@Produces("application/json; charset=utf-8")
public String nearestExecutionCourseEvent(@PathParam("course") ExecutionCourse course) {
    LocalDate date = LocalDate.now();
    if (hasPermissionToViewSchedule(course)) {
        date = nearestEventDate(//w  w  w. j  a v  a  2s.c o m
                ScheduleEventBean.forExecutionCourse(course, course.getAcademicInterval().toInterval()));
    }
    return toJson(date).toString();
}

From source file:org.fenixedu.learning.api.EventsResource.java

License:Open Source License

@GET
@Path("/degree/evaluations/{degree}/nearestEvent")
@Produces("application/json; charset=utf-8")
public String nearestEvaluationEvent(@PathParam("degree") Degree degree) {
    Optional<Interval> interval = degree.getDegreeCurricularPlansExecutionYears().stream()
            .sorted(COMPARATOR_BY_YEAR.reversed()).map(year -> year.getAcademicInterval().toInterval())
            .findFirst();/*  w w w .j a  v  a2 s.c  o m*/
    LocalDate date = interval.isPresent() ? nearestEventDate(allPublicEvaluations(degree, interval.get()))
            : LocalDate.now();
    return toJson(date).toString();
}

From source file:org.fenixedu.learning.api.EventsResource.java

License:Open Source License

private JsonElement toJson(LocalDate localDate) {
    if (localDate == null) {
        return new JsonPrimitive(ISODateTimeFormat.date().print(LocalDate.now()));
    } else {/*from ww w  . ja  v  a 2  s . c  om*/
        return new JsonPrimitive(ISODateTimeFormat.date().print(localDate));
    }
}

From source file:org.fenixedu.learning.api.EventsResource.java

License:Open Source License

private LocalDate nearestEventDate(Collection<ScheduleEventBean> events) {
    LocalDate now = LocalDate.now();
    LocalDate result = events.stream().map(e -> e.begin).map(DateTime::toLocalDate)
            .collect(toCollection(TreeSet::new)).lower(now);
    return Optional.ofNullable(result).orElse(now);
}

From source file:org.gradle.performance.results.BaseCrossBuildResultsStore.java

License:Apache License

public CrossBuildPerformanceTestHistory getTestResults(final String testName, final int mostRecentN,
        final int maxDaysOld, final String channel) {
    try {//from w ww.  j  a  v a2 s . co m
        return db.withConnection(new ConnectionAction<CrossBuildPerformanceTestHistory>() {
            public CrossBuildPerformanceTestHistory execute(Connection connection) throws SQLException {
                List<CrossBuildPerformanceResults> results = Lists.newArrayList();
                Set<BuildDisplayInfo> builds = Sets.newTreeSet(new Comparator<BuildDisplayInfo>() {
                    @Override
                    public int compare(BuildDisplayInfo o1, BuildDisplayInfo o2) {
                        return o1.getDisplayName().compareTo(o2.getDisplayName());
                    }
                });
                PreparedStatement executionsForName = connection.prepareStatement(
                        "select top ? id, startTime, endTime, versionUnderTest, operatingSystem, jvm, vcsBranch, vcsCommit, testGroup, channel from testExecution where testId = ? and startTime >= ? and channel = ? order by startTime desc");
                PreparedStatement operationsForExecution = connection.prepareStatement(
                        "select testProject, displayName, tasks, args, gradleOpts, daemon, totalTime, configurationTime, executionTime, heapUsageBytes, totalHeapUsageBytes, maxHeapUsageBytes, maxUncollectedHeapBytes, maxCommittedHeapBytes, compileTotalTime, gcTotalTime from testOperation where testExecution = ?");
                executionsForName.setInt(1, mostRecentN);
                executionsForName.setString(2, testName);
                Timestamp minDate = new Timestamp(LocalDate.now().minusDays(maxDaysOld).toDate().getTime());
                executionsForName.setTimestamp(3, minDate);
                executionsForName.setString(4, channel);
                ResultSet testExecutions = executionsForName.executeQuery();
                while (testExecutions.next()) {
                    long id = testExecutions.getLong(1);
                    CrossBuildPerformanceResults performanceResults = new CrossBuildPerformanceResults();
                    performanceResults.setTestId(testName);
                    performanceResults.setStartTime(testExecutions.getTimestamp(2).getTime());
                    performanceResults.setEndTime(testExecutions.getTimestamp(3).getTime());
                    performanceResults.setVersionUnderTest(testExecutions.getString(4));
                    performanceResults.setOperatingSystem(testExecutions.getString(5));
                    performanceResults.setJvm(testExecutions.getString(6));
                    performanceResults.setVcsBranch(testExecutions.getString(7).trim());
                    performanceResults.setVcsCommits(split(testExecutions.getString(8)));
                    performanceResults.setTestGroup(testExecutions.getString(9));
                    performanceResults.setChannel(testExecutions.getString(10));

                    if (ignore(performanceResults)) {
                        continue;
                    }

                    results.add(performanceResults);

                    operationsForExecution.setLong(1, id);
                    ResultSet resultSet = operationsForExecution.executeQuery();
                    while (resultSet.next()) {
                        BuildDisplayInfo displayInfo = new BuildDisplayInfo(resultSet.getString(1),
                                resultSet.getString(2), toList(resultSet.getObject(3)),
                                toList(resultSet.getObject(4)), toList(resultSet.getObject(5)),
                                (Boolean) resultSet.getObject(6));

                        MeasuredOperation operation = new MeasuredOperation();
                        operation.setTotalTime(Duration.millis(resultSet.getBigDecimal(7)));
                        operation.setConfigurationTime(Duration.millis(resultSet.getBigDecimal(8)));
                        operation.setExecutionTime(Duration.millis(resultSet.getBigDecimal(9)));
                        operation.setTotalMemoryUsed(DataAmount.bytes(resultSet.getBigDecimal(10)));
                        operation.setTotalHeapUsage(DataAmount.bytes(resultSet.getBigDecimal(11)));
                        operation.setMaxHeapUsage(DataAmount.bytes(resultSet.getBigDecimal(12)));
                        operation.setMaxUncollectedHeap(DataAmount.bytes(resultSet.getBigDecimal(13)));
                        operation.setMaxCommittedHeap(DataAmount.bytes(resultSet.getBigDecimal(14)));
                        BigDecimal compileTotalTime = resultSet.getBigDecimal(15);
                        if (compileTotalTime != null) {
                            operation.setCompileTotalTime(Duration.millis(compileTotalTime));
                        }
                        BigDecimal gcTotalTime = resultSet.getBigDecimal(16);
                        if (gcTotalTime != null) {
                            operation.setGcTotalTime(Duration.millis(gcTotalTime));
                        }
                        performanceResults.buildResult(displayInfo).add(operation);
                        builds.add(displayInfo);
                    }
                    resultSet.close();
                }
                testExecutions.close();
                operationsForExecution.close();
                executionsForName.close();

                return new CrossBuildPerformanceTestHistory(testName, ImmutableList.copyOf(builds), results);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(String.format("Could not load results from datastore '%s'.", db.getUrl()),
                e);
    }
}

From source file:org.gradle.performance.results.CrossVersionResultsStore.java

License:Apache License

@Override
public CrossVersionPerformanceTestHistory getTestResults(final String testName, final int mostRecentN,
        final int maxDaysOld, final String channel) {
    try {/*from   w  w  w  .j  ava  2 s  . c  o  m*/
        return db.withConnection(new ConnectionAction<CrossVersionPerformanceTestHistory>() {
            public CrossVersionPerformanceTestHistory execute(Connection connection) throws SQLException {
                Map<Long, CrossVersionPerformanceResults> results = Maps.newLinkedHashMap();
                Set<String> allVersions = new TreeSet<String>(new Comparator<String>() {
                    public int compare(String o1, String o2) {
                        return GradleVersion.version(o1).compareTo(GradleVersion.version(o2));
                    }
                });
                Set<String> allBranches = new TreeSet<String>();

                PreparedStatement executionsForName = null;
                PreparedStatement operationsForExecution = null;
                ResultSet testExecutions = null;
                ResultSet operations = null;

                try {
                    executionsForName = connection.prepareStatement(
                            "select top ? id, startTime, endTime, targetVersion, testProject, tasks, args, gradleOpts, daemon, operatingSystem, jvm, vcsBranch, vcsCommit, channel from testExecution where testId = ? and startTime >= ? and channel = ? order by startTime desc");
                    executionsForName.setFetchSize(mostRecentN);
                    executionsForName.setInt(1, mostRecentN);
                    executionsForName.setString(2, testName);
                    Timestamp minDate = new Timestamp(LocalDate.now().minusDays(maxDaysOld).toDate().getTime());
                    executionsForName.setTimestamp(3, minDate);
                    executionsForName.setString(4, channel);

                    testExecutions = executionsForName.executeQuery();
                    while (testExecutions.next()) {
                        long id = testExecutions.getLong(1);
                        CrossVersionPerformanceResults performanceResults = new CrossVersionPerformanceResults();
                        performanceResults.setTestId(testName);
                        performanceResults.setStartTime(testExecutions.getTimestamp(2).getTime());
                        performanceResults.setEndTime(testExecutions.getTimestamp(3).getTime());
                        performanceResults.setVersionUnderTest(testExecutions.getString(4));
                        performanceResults.setTestProject(testExecutions.getString(5));
                        performanceResults.setTasks(ResultsStoreHelper.toList(testExecutions.getObject(6)));
                        performanceResults.setArgs(ResultsStoreHelper.toList(testExecutions.getObject(7)));
                        performanceResults
                                .setGradleOpts(ResultsStoreHelper.toList(testExecutions.getObject(8)));
                        performanceResults.setDaemon((Boolean) testExecutions.getObject(9));
                        performanceResults.setOperatingSystem(testExecutions.getString(10));
                        performanceResults.setJvm(testExecutions.getString(11));
                        performanceResults.setVcsBranch(testExecutions.getString(12).trim());
                        performanceResults
                                .setVcsCommits(ResultsStoreHelper.split(testExecutions.getString(13)));
                        performanceResults.setChannel(testExecutions.getString(14));
                        results.put(id, performanceResults);
                        allBranches.add(performanceResults.getVcsBranch());
                    }

                    operationsForExecution = connection.prepareStatement(
                            "select version, testExecution, totalTime, configurationTime, executionTime, heapUsageBytes, totalHeapUsageBytes, maxHeapUsageBytes, maxUncollectedHeapBytes, maxCommittedHeapBytes, compileTotalTime, gcTotalTime from testOperation where testExecution in (select * from table(x int = ?))");
                    operationsForExecution.setFetchSize(10 * results.size());
                    operationsForExecution.setObject(1, results.keySet().toArray());

                    operations = operationsForExecution.executeQuery();
                    while (operations.next()) {
                        CrossVersionPerformanceResults result = results.get(operations.getLong(2));
                        String version = operations.getString(1);
                        if ("1.7".equals(version) && result.getStartTime() <= ignoreV17Before) {
                            // Ignore some broken samples
                            continue;
                        }
                        MeasuredOperation operation = new MeasuredOperation();
                        operation.setTotalTime(Duration.millis(operations.getBigDecimal(3)));
                        operation.setConfigurationTime(Duration.millis(operations.getBigDecimal(4)));
                        operation.setExecutionTime(Duration.millis(operations.getBigDecimal(5)));
                        operation.setTotalMemoryUsed(DataAmount.bytes(operations.getBigDecimal(6)));
                        operation.setTotalHeapUsage(DataAmount.bytes(operations.getBigDecimal(7)));
                        operation.setMaxHeapUsage(DataAmount.bytes(operations.getBigDecimal(8)));
                        operation.setMaxUncollectedHeap(DataAmount.bytes(operations.getBigDecimal(9)));
                        operation.setMaxCommittedHeap(DataAmount.bytes(operations.getBigDecimal(10)));
                        BigDecimal compileTotalTime = operations.getBigDecimal(11);
                        if (compileTotalTime != null) {
                            operation.setCompileTotalTime(Duration.millis(compileTotalTime));
                        }
                        BigDecimal gcTotalTime = operations.getBigDecimal(12);
                        if (gcTotalTime != null) {
                            operation.setGcTotalTime(Duration.millis(gcTotalTime));
                        }

                        if (version == null) {
                            result.getCurrent().add(operation);
                        } else {
                            BaselineVersion baselineVersion = result.baseline(version);
                            baselineVersion.getResults().add(operation);
                            allVersions.add(version);
                        }
                    }

                } finally {
                    closeResultSet(operations);
                    closeStatement(operationsForExecution);
                    closeResultSet(testExecutions);
                    closeStatement(executionsForName);
                }

                return new CrossVersionPerformanceTestHistory(testName, new ArrayList<String>(allVersions),
                        new ArrayList<String>(allBranches), Lists.newArrayList(results.values()));
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(String.format("Could not load results from datastore '%s'.", db.getUrl()),
                e);
    }
}

From source file:org.icgc.dcc.storage.client.ssl.ClientKeyTool.java

License:Open Source License

@SneakyThrows
private Certificate createCertificate(KeyPair keyPair) {
    LocalDate today = LocalDate.now();
    X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(x500Name,
            BigInteger.valueOf(sr.nextInt(Integer.MAX_VALUE)), today.minusDays(1).toDate(),
            today.plusYears(3).toDate(), x500Name, keyPair.getPublic());
    ContentSigner sigGen = new JcaContentSignerBuilder(SHA256_WITH_RSA_ENCRYPTION).setProvider(BC)
            .build(keyPair.getPrivate());
    X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC)
            .getCertificate(certGen.build(sigGen));
    return cert;/*  w w  w.  j  a  v  a  2 s.  c  o  m*/
}