List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java
private void formInternalFrameActivated(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameActivated txtIP.setText(Preferences.userRoot().node("MG").get("DatabaseIP", "127.0.0.1")); txtDatadir.setText(Preferences.userRoot().node("MG").get("Datadir", "C:\\javadb")); rbServidor.setSelected(Boolean.parseBoolean(Preferences.userRoot().node("MG").get("isServer", "true"))); cboModoImpresion.setSelectedItem(Preferences.userRoot().node("MG").get("modoImpresion", "Normal")); cboFormatoFactura// w ww . j av a 2s. c o m .setSelectedItem(Preferences.userRoot().node("MG").get("formatoFactura", "Preimpreso sin rejilla")); rbCobrarACPorMes .setSelected(Boolean.parseBoolean(Preferences.userRoot().node("MG").get("cobrarAC", "true"))); jspAnoActivo.setValue(Integer.parseInt( Preferences.userRoot().node("MG").get("anoActivo", String.valueOf(LocalDate.now().getYear())))); }
From source file:eu.clarin.cmdi.vlo.importer.MetadataImporter.java
/** * Update "days since last import" field for all Solr records of dataRoot. * Notice that it will not touch records that have a "last seen" value newer * than today. Therefore this should be called <em>after</em> normal * processing of data root!//from w w w .ja va2 s. co m * * @param dataRoot * @throws SolrServerException * @throws IOException */ private void updateDaysSinceLastImport(DataRoot dataRoot) throws SolrServerException, IOException { LOG.info("Updating \"days since last import\" in Solr for: {}", dataRoot.getOriginName()); SolrQuery query = new SolrQuery(); query.setQuery( //we're going to process all records in the current data root... FacetConstants.FIELD_DATA_PROVIDER + ":" + ClientUtils.escapeQueryChars(dataRoot.getOriginName()) + " AND " // ...that have a "last seen" value _older_ than today (on update/initialisation all records get 0 so we can skip the rest) + FacetConstants.FIELD_LAST_SEEN + ":[* TO NOW-1DAY]"); query.setFields(FacetConstants.FIELD_ID, FacetConstants.FIELD_LAST_SEEN); int fetchSize = 1000; query.setRows(fetchSize); QueryResponse rsp = solrServer.query(query); final long totalResults = rsp.getResults().getNumFound(); final LocalDate nowDate = LocalDate.now(); final int docsListSize = config.getMaxDocsInList(); List<SolrInputDocument> updateDocs = new ArrayList<>(docsListSize); Boolean updatedDocs = false; int offset = 0; while (offset < totalResults) { query.setStart(offset); query.setRows(fetchSize); for (SolrDocument doc : solrServer.query(query).getResults()) { updatedDocs = true; String recordId = (String) doc.getFieldValue(FacetConstants.FIELD_ID); Date lastImportDate = (Date) doc.getFieldValue(FacetConstants.FIELD_LAST_SEEN); LocalDate oldDate = lastImportDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); long daysSinceLastSeen = DAYS.between(oldDate, nowDate); SolrInputDocument updateDoc = new SolrInputDocument(); updateDoc.setField(FacetConstants.FIELD_ID, recordId); Map<String, Long> partialUpdateMap = new HashMap<>(); partialUpdateMap.put("set", daysSinceLastSeen); updateDoc.setField(FacetConstants.FIELD_DAYS_SINCE_LAST_SEEN, partialUpdateMap); updateDocs.add(updateDoc); if (updateDocs.size() == docsListSize) { solrServer.add(updateDocs); if (serverError != null) { throw new SolrServerException(serverError); } updateDocs = new ArrayList<>(docsListSize); } } offset += fetchSize; LOG.info("Updating \"days since last import\": {} out of {} records updated", offset, totalResults); } if (!updateDocs.isEmpty()) { solrServer.add(updateDocs); if (serverError != null) { throw new SolrServerException(serverError); } } if (updatedDocs) { solrServer.commit(); } LOG.info("Updating \"days since last import\" done."); }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testValidationBoundedFailedRestrictedFlag() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, true, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);// w ww. j a va 2 s. c o m Event event = pair.getLeft(); String username = pair.getRight(); TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0); Map<String, String> categoryDescription = ticketCategoryDescriptionRepository .descriptionForTicketCategory(category.getId()); TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 10, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", false, null, null, null, null, null); Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username); assertFalse(result.isSuccess()); }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java
/** * /* w w w . j a v a 2 s. co m*/ * @param path int of the path to get the Time Options for * @param storedTimePref Long of anytime during the specific day that we want to return times for * @return populates the "times" TreeSet (time longs truncated at the "the seconds" position) * which populates Time Combo box, the truncTimeToFullTimeMap which maps the truncated times * im times TreeSet to each times full Long value. The truncTimeToFullTimeMap chooses each time * up to the second and maps it to the greatest equivalent time up to the milliseconds. * */ protected void setTimeOptions(int path, Long storedTimePref) { try { timeSelectCombo.getItems().clear(); overrideTimestamp = null; Date startDate = null, finishDate = null; if (storedTimePref != null) { StampBdb stampDb = Bdb.getStampDb(); NidSet nidSet = new NidSet(); nidSet.add(path); NidSetBI stamps = null; if (!storedTimePref.equals(getDefaultTime())) { startDate = getStartOfDay(new Date(storedTimePref)); finishDate = getEndOfDay(new Date(storedTimePref)); stamps = stampDb.getSpecifiedStamps(nidSet, startDate.getTime(), finishDate.getTime()); } else { stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); } truncTimeToFullTimeMap.clear(); times.clear(); HashSet<Integer> stampSet = stamps.getAsSet(); Date d = new Date(storedTimePref); if (dateIsLocalDate(d)) { // Get stamps of day Date todayStartDate = getStartOfDay(new Date()); Date todayFinishDate = getEndOfDay(new Date()); NidSetBI todayStamps = stampDb.getSpecifiedStamps(nidSet, todayStartDate.getTime(), todayFinishDate.getTime()); // If have stamps, no action, if not, show Latest and set stamps to latest stamp we have in stampset if (todayStamps.size() == 0) { // timeSelectCombo.getItems().add(Long.MAX_VALUE); NidSetBI allStamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); HashSet<Integer> allStampSet = allStamps.getAsSet(); SortedSet<Integer> s = new TreeSet<Integer>(allStampSet); if (!s.isEmpty()) { Integer stampToSet = s.last(); overrideTimestamp = stampDb.getPosition(stampToSet).getTime(); timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); } } } this.pathDatesList.add(LocalDate.now()); if (overrideTimestamp == null) { if (!stampSet.isEmpty()) { enableTimeCombo(true); for (Integer thisStamp : stampSet) { Long fullTime = null; Date stampDate; LocalDate stampInstant = null; try { fullTime = stampDb.getPosition(thisStamp).getTime(); stampDate = new Date(fullTime); stampInstant = stampDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(new Date(fullTime)); cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds Long truncTime = cal.getTimeInMillis(); this.pathDatesList.add(stampInstant); //Build DatePicker times.add(truncTime); //This can probably go, we don't populate hashmap like this at initialization timeSelectCombo.getItems().add(truncTime); if (truncTimeToFullTimeMap.containsKey(truncTime)) { //Build Truncated Time to Full Time HashMap //If truncTimeToFullTimeMap has this key, is the value the newest time in milliseconds? if (new Date(truncTimeToFullTimeMap.get(truncTime)).before(new Date(fullTime))) { truncTimeToFullTimeMap.put(truncTime, fullTime); } } else { truncTimeToFullTimeMap.put(truncTime, fullTime); } } } else { // disableTimeCombo(true); // timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); enableTimeCombo(true); // logger.error("Could not retreive any Stamps"); } } } } catch (Exception e) { logger.error("Error setting the default Time Dropdown"); e.printStackTrace(); } }
From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java
private void makeActions() { exportAction = new Action() { @Override// w w w. j a v a 2 s. c om public void run() { ExportToClipboard export = new ExportToClipboard(); export.copyWeekAsHTML(contentProvider.getFirstDayOfWeek()); } }; exportAction.setText("Export to clipboard"); exportAction.setImageDescriptor(Activator.getImageDescriptor("icons/full/elcl16/export.gif")); previousWeekAction = new Action() { @Override public void run() { contentProvider.setFirstDayOfWeek(contentProvider.getFirstDayOfWeek().minusDays(7)); viewer.setInput(getViewSite()); } }; previousWeekAction.setText("Previous Week"); previousWeekAction.setToolTipText("Show previous week"); previousWeekAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK)); currentWeekAction = new Action() { @Override public void run() { contentProvider.setFirstDayOfWeek(calculateFirstDayOfWeek(LocalDate.now())); viewer.setInput(getViewSite()); } }; currentWeekAction.setText("Current Week"); currentWeekAction.setToolTipText("Show current week"); currentWeekAction.setImageDescriptor(Activator.getImageDescriptor("icons/full/elcl16/cur_nav.png")); nextWeekAction = new Action() { @Override public void run() { contentProvider.setFirstDayOfWeek(contentProvider.getFirstDayOfWeek().plusDays(7)); viewer.setInput(getViewSite()); } }; nextWeekAction.setText("Next Week"); nextWeekAction.setToolTipText("Show next week"); nextWeekAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD)); doubleClickAction = new Action() { @Override public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj instanceof ITask) { TasksUiUtil.openTask((ITask) obj); } } }; deactivateAction = new Action("Deactivate") { @Override public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj instanceof ITask) { TasksUi.getTaskActivityManager().deactivateTask((ITask) obj); } } }; activateAction = new Action("Activate") { @Override public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj instanceof ITask) { TasksUi.getTaskActivityManager().activateTask((ITask) obj); } } }; projectFieldMenu = new MenuManager("Set Grouping Field", null); projectFieldMenu.setRemoveAllWhenShown(true); projectFieldMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection) { Object firstElement = ((IStructuredSelection) selection).getFirstElement(); if (firstElement instanceof AbstractTask) { AbstractTask task = (AbstractTask) firstElement; // No way to change project on local tasks if (task instanceof LocalTask) { return; } String url = task.getRepositoryUrl(); TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(url); try { TaskData taskData = TasksUi.getTaskDataManager().getTaskData(task); List<TaskAttribute> attributesByType = taskData.getAttributeMapper() .getAttributesByType(taskData, TaskAttribute.TYPE_SINGLE_SELECT); // customfield_10410 = subproject for (TaskAttribute taskAttribute : attributesByType) { final String label = taskAttribute.getMetaData().getLabel(); if (label != null) { final String id = taskAttribute.getId(); Action a = new Action(label.replaceAll(":", "")) { @Override public void run() { setProjectField(repository, id); } }; manager.add(a); } } manager.add(new Separator()); Action a = new Action("Default") { @Override public void run() { setProjectField(repository, null); } }; manager.add(a); } catch (CoreException e) { e.printStackTrace(); } } } } }); }
From source file:ui.Analyze.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel( new String[] { "Nama Barang", "Jumlah" }, 0); tblMinta.setModel(m);/*w w w. j av a 2s . co m*/ LocalDate ld1 = LocalDate.now(), ld2 = ld1.minusWeeks(1); fillPermintaanTgl(ld1, ld2); fillURTgl(ld1, ld2); fillLabaTgl(ld1, ld2); }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testValidationBoundedFailedPendingTickets() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/*w w w . j av a2 s . c o m*/ Event event = pair.getLeft(); String username = pair.getRight(); TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0); Map<String, String> categoryDescription = ticketCategoryDescriptionRepository .descriptionForTicketCategory(category.getId()); List<Integer> tickets = ticketRepository.selectTicketInCategoryForUpdate(event.getId(), category.getId(), 1, Collections.singletonList(Ticket.TicketStatus.FREE.name())); String reservationId = "12345678"; ticketReservationRepository.createNewReservation(reservationId, DateUtils.addDays(new Date(), 1), null, "en", event.getId(), event.getVat(), event.isVatIncluded()); ticketRepository.reserveTickets(reservationId, tickets, category.getId(), "en", 100); TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 10, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), false, "", false, null, null, null, null, null); Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username); assertFalse(result.isSuccess()); }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java
private boolean dateIsLocalDate(Date d) { Month ldMonth = LocalDate.now().atStartOfDay().getMonth(); int ldDate = LocalDate.now().atStartOfDay().getDayOfMonth(); int ldYear = LocalDate.now().atStartOfDay().getYear(); Calendar cal = Calendar.getInstance(); cal.setTime(d);/*from w w w .j a v a 2 s . c om*/ if (cal.get(Calendar.YEAR) == ldYear && cal.get(Calendar.DAY_OF_MONTH) == ldDate && cal.get(Calendar.MONTH) == (ldMonth.getValue() - 1)) { return true; } return false; }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testIncreaseRestrictedCategory() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, true, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/* w w w. j a v a 2s . c o m*/ Event event = pair.getLeft(); String username = pair.getRight(); TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0); Map<String, String> categoryDescription = ticketCategoryDescriptionRepository .descriptionForTicketCategory(category.getId()); TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 11, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", true, null, null, null, null, null); Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username); assertTrue(result.isSuccess()); assertEquals(11, ticketRepository.countFreeTickets(event.getId(), category.getId()).intValue()); }
From source file:ch.algotrader.service.LookupServiceTest.java
@Test public void testGetSubscribedFutures() { SecurityFamily family1 = new SecurityFamilyImpl(); family1.setName("Forex1"); family1.setTickSizePattern("0<0.1"); family1.setCurrency(Currency.USD); Strategy strategy1 = new StrategyImpl(); strategy1.setName("Strategy1"); LocalDate today = LocalDate.now(); Future future1 = new FutureImpl(); future1.setSecurityFamily(family1);/*from w w w . j a va2s . co m*/ future1.setExpiration(DateTimeLegacy.toLocalDate(today)); future1.setMonthYear(DateTimePatterns.MONTH_YEAR.format(today)); LocalDate nextMonth = today.plusMonths(1); Future future2 = new FutureImpl(); future2.setSecurityFamily(family1); future2.setExpiration(DateTimeLegacy.toLocalDate(nextMonth)); future2.setMonthYear(DateTimePatterns.MONTH_YEAR.format(nextMonth)); this.session.save(family1); this.session.save(future1); this.session.save(future2); this.session.flush(); List<Future> futures1 = lookupService.getSubscribedFutures(); Assert.assertEquals(0, futures1.size()); Subscription subscription1 = new SubscriptionImpl(); subscription1.setFeedType(FeedType.SIM.name()); subscription1.setSecurity(future1); subscription1.setStrategy(strategy1); this.session.save(strategy1); this.session.save(subscription1); this.session.flush(); List<Future> futures2 = lookupService.getSubscribedFutures(); Assert.assertEquals(1, futures2.size()); Assert.assertSame(future1, futures2.get(0)); Assert.assertSame(family1, futures2.get(0).getSecurityFamily()); Subscription subscription2 = new SubscriptionImpl(); subscription2.setFeedType(FeedType.BB.name()); subscription2.setSecurity(future2); subscription2.setStrategy(strategy1); this.session.save(subscription2); this.session.flush(); List<Future> futures3 = lookupService.getSubscribedFutures(); Assert.assertEquals(2, futures3.size()); Assert.assertSame(future1, futures3.get(0)); Assert.assertSame(family1, futures3.get(0).getSecurityFamily()); Assert.assertSame(future2, futures3.get(1)); Assert.assertSame(family1, futures3.get(1).getSecurityFamily()); }