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:com.qcadoo.mes.deviationCausesReporting.DeviationsReportCriteria.java

License:Open Source License

private static DeviationsReportCriteria fromLocalDates(final LocalDate fromDate,
        final Optional<LocalDate> maybeToDate) {
    DateTime rangeBegin = fromDate.toDateTimeAtStartOfDay();
    DateTime rangeEnd = maybeToDate.or(LocalDate.now()).plusDays(1).toDateTimeAtStartOfDay().minusMillis(1);
    Preconditions.checkArgument(rangeBegin.isBefore(rangeEnd), "Passed dates have wrong order.");
    Interval searchInterval = new Interval(rangeBegin, rangeEnd);
    return new DeviationsReportCriteria(searchInterval);
}

From source file:com.qcadoo.mes.deviationCausesReporting.hooks.DeviationReportGeneratorViewHooks.java

License:Open Source License

private void setDefaultDateRange(final ViewDefinitionState view) {
    for (ComponentState dateFromComponent : view
            .tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_FROM).asSet()) {
        Date firstDayOfCurrentMonth = LocalDate.now().withDayOfMonth(1).toDate();
        dateFromComponent.setFieldValue(DateUtils.toDateString(firstDayOfCurrentMonth));
    }//  www .  jav a  2  s .  c  o  m
    Optional<ComponentState> maybeDateFromComponent = view
            .tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_TO);
    for (ComponentState dateFromComponent : maybeDateFromComponent.asSet()) {
        Date today = LocalDate.now().toDate();
        dateFromComponent.setFieldValue(DateUtils.toDateString(today));
    }
}

From source file:com.sg.domain.ar.CatalogItem.java

public void publish() {
    if (!state.equals(CatalogItemState.DRAFT)) {
        throw new IllegalArgumentException();
    }//from   ww  w .  j a v a 2 s .  c  o m
    this.state = CatalogItemState.PUBLISHED;
    this.date = LocalDate.now();
}

From source file:com.tojsq.view.master.VpnViewBean.java

public void search() {
    final List<Vpn> vpnList = vpnService.selectByQQ(this.getQq());
    if (vpnList.size() > 0) {
        final Vpn vpn = vpnList.get(0);
        int days = Days.daysBetween(LocalDate.now(), LocalDate.fromDateFields(vpn.getEndDate())).getDays();
        if (days < 0) {
            this.setResult(String.format("????:%s",
                    LocalDate.fromDateFields(vpn.getEndDate()).toString("yyyy-MM-dd")));
        } else {/*from ww  w.  j  a  va 2 s .c  om*/
            this.setResult(String.format(":%s,%d",
                    LocalDate.fromDateFields(vpn.getEndDate()).toString("yyyy-MM-dd"), days));
        }
    } else {
        this.setResult("?????QQ???~");
    }

}

From source file:com.tsp.controllers.AdminController.java

@RequestMapping(value = "/orders")
ModelAndView orders() {/*from  w ww.j a  v  a2 s. c o m*/
    List<Order> allOrders = orderService.findAllOrders();
    ModelAndView mv = new ModelAndView("orders");
    mv.addObject("orders", allOrders);
    mv.addObject("today", LocalDate.now());
    return mv;
}

From source file:com.tsp.controllers.AdminController.java

@RequestMapping(value = "/createroute")
String createRoute(Model model) {
    model.addAttribute("drivers", driverDao.getAllDrivers());
    model.addAttribute("today", LocalDate.now());
    return "createroute";
}

From source file:com.tysanclan.site.projectewok.beans.impl.DemocracyServiceImpl.java

License:Open Source License

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void resolveJoinApplication(JoinApplication _application) {
    JoinApplication application = joinApplicationDAO.load(_application.getId());
    if (application != null) {
        int inFavor = 0, total = 0;
        for (JoinVerdict verdict : application.getVerdicts()) {
            if (verdict.isInFavor()) {
                inFavor++;/* ww  w  .  ja  v a  2s.  c om*/
            }
            total++;
        }

        final User mentor = application.getMentor();
        final User applicant = application.getApplicant();
        Date startDate = application.getStartDate();
        LocalDate start = new LocalDate(startDate);
        LocalDate now = LocalDate.now();

        final boolean have3DaysPassed = start.plusDays(3).isBefore(now);

        boolean accepted = false;

        if (have3DaysPassed) {
            if (applicant.getActivations().isEmpty()) {
                // If we managed to let 3 days pass without the member
                // getting
                // accepted,
                // check for mentor is no longer relevant, all we need to
                // know
                // is if a Senator
                // voted against
                if (total == 0) {
                    accepted = true;
                } else {
                    if (inFavor == 0) {
                        accepted = false;
                    } else {
                        accepted = true;
                    }
                }
            } else {
                accepted = false;
            }
        } else {
            // This really shouldn't happen, but don't resolve unactivated
            // users prior to 3 days
            if (!applicant.getActivations().isEmpty()) {
                return;
            }

            // If this method gets invoked earlier, however, then member
            // needs a mentor and 1
            // vote in favor - otherwise do not resolve
            if (inFavor > 0 && mentor != null) {
                accepted = true;
            } else {
                return;
            }
        }

        if (accepted) {
            applicant.setMentor(application.getMentor());
            applicant.setRank(Rank.TRIAL);
            applicant.setJoinDate(new Date());
            applicant.setLoginCount(0);
            applicant.setLastAction(new Date());
            userDAO.update(applicant);

        }

        joinVerdictDAO.deleteForApplication(application);
        joinApplicationDAO.delete(application);

        mailService.sendHTMLMail(applicant.getEMail(), "Result of your Tysan Clan Application",
                mailService.getJoinApplicationMail(application, accepted, inFavor, total));

        logService.logUserAction(applicant, "Membership",
                "User has " + (accepted ? "been" : "not been") + " granted a trial membership");

        if (accepted) {
            notificationService.notifyUser(applicant, "You are now a Trial Member");

            dispatcher.dispatchEvent(new MemberStatusEvent(
                    com.tysanclan.site.projectewok.entities.MembershipStatusChange.ChangeType.TRIAL_GRANTED,
                    applicant));
        } else {
            dispatcher.dispatchEvent(new MemberStatusEvent(
                    com.tysanclan.site.projectewok.entities.MembershipStatusChange.ChangeType.TRIAL_DENIED,
                    applicant));
        }
    }

}

From source file:com.tysanclan.site.projectewok.beans.impl.DemocracyServiceImpl.java

License:Open Source License

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void checkSenatorElections() {
    final SenateElection current = getCurrentSenateElection();

    if (current != null)
        return;// w  w  w .  j  a v a2s. c  om

    LocalDate sixMonthsAgo = LocalDate.now().minusMonths(6);

    SenateElectionFilter electionsMoreThanSixMonthsAgo = new SenateElectionFilter();
    electionsMoreThanSixMonthsAgo.setStartBefore(sixMonthsAgo.toDate());
    electionsMoreThanSixMonthsAgo.addOrderBy("start", false);

    SenateElectionFilter electionsLessThanSixMonthsAgo = new SenateElectionFilter();
    electionsLessThanSixMonthsAgo.setStartAfter(sixMonthsAgo.toDate());
    electionsLessThanSixMonthsAgo.addOrderBy("start", false);

    final boolean thereWasAnElectionMoreThanSixMonthsAgo = senateElectionDAO
            .countByFilter(electionsMoreThanSixMonthsAgo) > 0;
    final boolean thereWasNoElectionLessThanSixMonthsAgo = senateElectionDAO
            .countByFilter(electionsLessThanSixMonthsAgo) == 0;
    final boolean thereHasNeverBeenAnElection = senateElectionDAO.countAll() == 0;
    if (thereHasNeverBeenAnElection
            || (thereWasAnElectionMoreThanSixMonthsAgo && thereWasNoElectionLessThanSixMonthsAgo)) {
        if (thereHasNeverBeenAnElection) {
            logService.logSystemAction("Democracy", "There has never been a Senate election");
        } else {
            logService.logSystemAction("Democracy", "Last Senate election more than six months ago");
        }
        createSenateElection();
    } else {

        SenateElectionFilter lastSenateElectionFilter = new SenateElectionFilter();
        lastSenateElectionFilter.addOrderBy("start", false);
        List<SenateElection> elections = senateElectionDAO.findByFilter(lastSenateElectionFilter, 0, 1);

        final long senators = userDAO.countByRank(Rank.SENATOR);

        if (senators <= 1) {
            logService.logSystemAction("Democracy", "Only one Senator left");
            createSenateElection();
            return;
        }

        for (SenateElection election : elections) {
            final int seats = election.getSeats();

            if (seats > 0) {

                int fraction = (int) ((senators * 100) / seats);

                if (fraction < 40) {
                    logService.logSystemAction("Democracy",
                            "Senate size less than 40% of last election's seats");
                    createSenateElection();
                }
            }
            break;

        }
    }

}

From source file:com.tysanclan.site.projectewok.TysanPage.java

License:Open Source License

public TysanPage(String title, IModel<?> model) {
    super(model);

    notificationWindow = new Dialog("notificationWindow");
    notificationWindow.setTitle("Urgent Message");
    notificationWindow.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true);

    notificationWindow.add(new ComponentFeedbackPanel("messages", notificationWindow).setOutputMarkupId(true)
            .setOutputMarkupPlaceholderTag(true));
    notificationWindow.setAutoOpen(false);
    notificationWindow.setVisible(false);

    add(notificationWindow);/* w w w  .j  av  a 2 s  . c  o m*/

    headerLabel = new Label("header", title);
    titleLabel = new Label("title", title + getTitleSuffix());

    headerLabel.setEscapeModelStrings(false);
    titleLabel.setEscapeModelStrings(false);

    add(headerLabel);
    add(titleLabel);
    add(new FeedbackPanel("feedback").setOutputMarkupId(true));

    Dialog window = new Dialog("debugWindow");
    window.setTitle("Debug Information");
    window.add(new DebugWindow("debugPanel", this.getPageClass()));
    window.setWidth(600);
    window.setHeight(300);
    window.setResizable(false);

    window.add(new AjaxLink<Void>("magicpushbutton") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

        }

    }.setVisible(ENABLE_MAGIC_PUSHTBUTTON));

    add(window);

    add(new AjaxLink<Dialog>("debugLink", new Model<Dialog>(window)) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Dialog _window = getModelObject();
            target.appendJavaScript(_window.open().render().toString());

        }

    }.setVisible(Application.get().getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT));

    User u = getTysanSession().getUser();
    WebMarkupContainer subMenu = new WebMarkupContainer("topMenu");
    if (u != null) {
        if (MemberUtil.isMember(u)) {
            topPanel = new WebMarkupContainer("topbar");
            subMenu = new TysanMemberPanel("topMenu", u);
        } else {
            topPanel = new WebMarkupContainer("topbar");
            subMenu = new TysanUserPanel("topMenu", u);
        }
    } else {
        topPanel = new TysanLoginPanel("topbar");
    }
    add(new TysanMenu("menu", u != null));
    add(subMenu);

    add(topPanel);

    add(new Label("version", TysanApplication.getApplicationVersion()));

    if (u != null) {
        get("version").add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(30)) {
            private static final long serialVersionUID = 1L;

            /**
             * @see org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior#onPostProcessTarget(org.apache.wicket.ajax.AjaxRequestTarget)
             */
            @Override
            protected void onPostProcessTarget(AjaxRequestTarget target) {
                Dialog d = getNotificationWindow();
                TysanSession t = TysanSession.get();
                int i = 0;

                for (SiteWideNotification swn : TysanApplication.get().getActiveNotifications()) {
                    if (t != null && !t.notificationSeen(swn)) {
                        swn.display(d);
                        i++;
                    }
                }

                if (i > 0) {
                    d.setAutoOpen(true);
                    d.setVisible(true);
                    target.add(d);
                    getNotificationWindow().open(target);
                }
            }
        });

    }
    addAnimalPanel();

    add(new Label("year", LocalDate.now().getYear()).setRenderBodyOnly(true));
    add(new WebMarkupContainer("texas").setVisible(isAprilFoolsDay(2017)));
}

From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSCostStatsService.java

License:Open Source License

protected void scheduleDownload(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) {
    //Starting creation of cost stats for current month

    String accountId = statsData.computeDesc.customProperties.getOrDefault(AWSConstants.AWS_ACCOUNT_ID_KEY,
            null);//  ww  w .ja  v  a  2  s . c o  m
    if (accountId == null) {
        logWarning("Account ID is not set for account '%s'. Not collecting cost stats.",
                statsData.computeDesc.documentSelfLink);
        return;
    }

    String billsBucketName = statsData.computeDesc.customProperties
            .getOrDefault(AWSConstants.AWS_BILLS_S3_BUCKET_NAME_KEY, null);
    if (billsBucketName == null) {
        billsBucketName = AWSUtils.autoDiscoverBillsBucketName(statsData.s3Client.getAmazonS3Client(),
                accountId);
        if (billsBucketName == null) {
            logWarning("Bills Bucket name is not configured for account '%s'. Not collecting cost stats.",
                    statsData.computeDesc.documentSelfLink);
            return;
        } else {
            setBillsBucketNameInAccount(statsData, billsBucketName);
        }
    }
    try {
        downloadAndParse(statsData, billsBucketName, LocalDate.now().getYear(),
                LocalDate.now().getMonthOfYear(), next);
    } catch (IOException e) {
        logSevere(e);
        AdapterUtils.sendFailurePatchToProvisioningTask(this, statsData.statsRequest.taskReference, e);
    }
}