List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testUpdateTicketReservation() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventUsername = initEvent(categories); Event event = eventUsername.getKey(); try {/* w w w. j ava 2 s . com*/ TicketReservationModification trm = new TicketReservationModification(); trm.setAmount(1); trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId()); TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty()); Date expiration = DateUtils.addDays(new Date(), 1); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), expiration, Optional.empty(), Optional.empty(), Locale.ENGLISH, false); dataMigrator.fillReservationsLanguage(); TicketReservation ticketReservation = ticketReservationManager.findById(reservationId).get(); assertEquals("en", ticketReservation.getUserLanguage()); } finally { eventManager.deleteEvent(event.getId(), eventUsername.getValue()); } }
From source file:alfio.manager.TicketReservationManagerIntegrationTest.java
@Test public void testTicketWithDiscount() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository) .getKey();// w ww. java 2 s . c o m TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).stream() .filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new); //promo code at event level eventManager.addPromoCode("MYPROMOCODE", event.getId(), null, event.getBegin(), event.getEnd(), 10, PromoCodeDiscount.DiscountType.PERCENTAGE, null); //promo code at organization level eventManager.addPromoCode("MYFIXEDPROMO", null, event.getOrganizationId(), event.getBegin(), event.getEnd(), 5, PromoCodeDiscount.DiscountType.FIXED_AMOUNT, null); TicketReservationModification tr = new TicketReservationModification(); tr.setAmount(3); tr.setTicketCategoryId(unbounded.getId()); TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty()); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.of("MYPROMOCODE"), Locale.ENGLISH, false); TotalPrice totalPrice = ticketReservationManager.totalReservationCostWithVAT(reservationId); // 3 * 10 chf is the normal price, 10% discount -> 300 discount Assert.assertEquals(2700, totalPrice.getPriceWithVAT()); Assert.assertEquals(27, totalPrice.getVAT()); Assert.assertEquals(-300, totalPrice.getDiscount()); Assert.assertEquals(1, totalPrice.getDiscountAppliedCount()); OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event, Locale.ENGLISH); Assert.assertEquals("27.00", orderSummary.getTotalPrice()); Assert.assertEquals("0.27", orderSummary.getTotalVAT()); Assert.assertEquals(3, orderSummary.getTicketAmount()); TicketReservationModification trFixed = new TicketReservationModification(); trFixed.setAmount(3); trFixed.setTicketCategoryId(unbounded.getId()); TicketReservationWithOptionalCodeModification modFixed = new TicketReservationWithOptionalCodeModification( trFixed, Optional.empty()); String reservationIdFixed = ticketReservationManager.createTicketReservation(event, Collections.singletonList(modFixed), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.of("MYFIXEDPROMO"), Locale.ENGLISH, false); TotalPrice totalPriceFixed = ticketReservationManager.totalReservationCostWithVAT(reservationIdFixed); // 3 * 10 chf is the normal price, 3 * 5 is the discount Assert.assertEquals(2985, totalPriceFixed.getPriceWithVAT()); Assert.assertEquals(30, totalPriceFixed.getVAT()); Assert.assertEquals(-15, totalPriceFixed.getDiscount()); Assert.assertEquals(3, totalPriceFixed.getDiscountAppliedCount()); OrderSummary orderSummaryFixed = ticketReservationManager.orderSummaryForReservationId(reservationIdFixed, event, Locale.ENGLISH); Assert.assertEquals("29.85", orderSummaryFixed.getTotalPrice()); Assert.assertEquals("0.30", orderSummaryFixed.getTotalVAT()); Assert.assertEquals(3, orderSummaryFixed.getTicketAmount()); }
From source file:alfio.manager.WaitingQueueProcessorIntegrationTest.java
private Pair<String, Event> initSoldOutEvent(boolean withUnboundedCategory) throws InterruptedException { int boundedCategorySize = AVAILABLE_SEATS - (withUnboundedCategory ? 1 : 0); List<TicketCategoryModification> categories = new ArrayList<>(); categories.add(new TicketCategoryModification(null, "default", boundedCategorySize, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", true, null, null, null, null, null)); if (withUnboundedCategory) { categories.add(new TicketCategoryModification(null, "unbounded", 0, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", false, null, null, null, null, null)); }//from ww w.ja va 2 s .c om Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository); Event event = pair.getKey(); List<TicketCategory> ticketCategories = eventManager.loadTicketCategories(event); TicketCategory bounded = ticketCategories.stream().filter(t -> t.getName().equals("default")).findFirst() .orElseThrow(IllegalStateException::new); List<Integer> boundedReserved = ticketRepository.selectFreeTicketsForPreReservation(event.getId(), 20, bounded.getId()); assertEquals(boundedCategorySize, boundedReserved.size()); List<Integer> reserved = new ArrayList<>(boundedReserved); String reservationId = UUID.randomUUID().toString(); ticketReservationRepository.createNewReservation(reservationId, DateUtils.addHours(new Date(), 1), null, Locale.ITALIAN.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded()); List<Integer> reservedForUpdate = withUnboundedCategory ? reserved.subList(0, 19) : reserved; ticketRepository.reserveTickets(reservationId, reservedForUpdate, bounded.getId(), Locale.ITALIAN.getLanguage(), 0); if (withUnboundedCategory) { TicketCategory unbounded = ticketCategories.stream().filter(t -> t.getName().equals("unbounded")) .findFirst().orElseThrow(IllegalStateException::new); List<Integer> unboundedReserved = ticketRepository .selectNotAllocatedFreeTicketsForPreReservation(event.getId(), 20); assertEquals(1, unboundedReserved.size()); reserved.addAll(unboundedReserved); ticketRepository.reserveTickets(reservationId, reserved.subList(19, 20), unbounded.getId(), Locale.ITALIAN.getLanguage(), 0); } ticketRepository.updateTicketsStatusWithReservationId(reservationId, Ticket.TicketStatus.ACQUIRED.name()); //sold-out waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH); Thread.sleep(100L);//we are testing ordering, not concurrency... waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN); List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId()); assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2); assertTrue(subscriptions.stream() .allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.SOLD_OUT))); //the following call shouldn't have any effect waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2); return Pair.of(reservationId, event); }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java
@Override public Region getContent() { if (hBox == null) { VBox statedInferredToggleGroupVBox = new VBox(); statedInferredToggleGroupVBox.setSpacing(4.0); //Instantiate Everything pathComboBox = new ComboBox<>(); //Path statedInferredToggleGroup = new ToggleGroup(); //Stated / Inferred List<RadioButton> statedInferredOptionButtons = new ArrayList<>(); datePicker = new DatePicker(); //Date timeSelectCombo = new ComboBox<Long>(); //Time //Radio buttons for (StatedInferredOptions option : StatedInferredOptions.values()) { RadioButton optionButton = new RadioButton(); if (option == StatedInferredOptions.STATED) { optionButton.setText("Stated"); } else if (option == StatedInferredOptions.INFERRED_THEN_STATED) { optionButton.setText("Inferred Then Stated"); } else if (option == StatedInferredOptions.INFERRED) { optionButton.setText("Inferred"); } else { throw new RuntimeException("oops"); }/* w w w . ja va 2 s. c om*/ optionButton.setUserData(option); optionButton.setTooltip( new Tooltip("Default StatedInferredOption is " + getDefaultStatedInferredOption())); statedInferredToggleGroup.getToggles().add(optionButton); statedInferredToggleGroupVBox.getChildren().add(optionButton); statedInferredOptionButtons.add(optionButton); } statedInferredToggleGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { @Override public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) { currentStatedInferredOptionProperty.set((StatedInferredOptions) newValue.getUserData()); } }); //Path Combo Box pathComboBox.setCellFactory(new Callback<ListView<UUID>, ListCell<UUID>>() { @Override public ListCell<UUID> call(ListView<UUID> param) { final ListCell<UUID> cell = new ListCell<UUID>() { @Override protected void updateItem(UUID c, boolean emptyRow) { super.updateItem(c, emptyRow); if (c == null) { setText(null); } else { String desc = OTFUtility.getDescription(c); setText(desc); } } }; return cell; } }); pathComboBox.setButtonCell(new ListCell<UUID>() { // Don't know why this should be necessary, but without this the UUID itself is displayed @Override protected void updateItem(UUID c, boolean emptyRow) { super.updateItem(c, emptyRow); if (emptyRow) { setText(""); } else { String desc = OTFUtility.getDescription(c); setText(desc); } } }); pathComboBox.setOnAction((event) -> { if (!pathComboFirstRun) { UUID selectedPath = pathComboBox.getSelectionModel().getSelectedItem(); if (selectedPath != null) { int path = OTFUtility.getConceptVersion(selectedPath).getPathNid(); StampBdb stampDb = Bdb.getStampDb(); NidSet nidSet = new NidSet(); nidSet.add(path); //TODO: Make this multi-threaded and possibly implement setTimeOptions() here also NidSetBI stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); pathDatesList.clear(); // disableTimeCombo(true); timeSelectCombo.setValue(Long.MAX_VALUE); for (Integer thisStamp : stamps.getAsSet()) { try { Position stampPosition = stampDb.getPosition(thisStamp); this.stampDate = new Date(stampPosition.getTime()); stampDateInstant = stampDate.toInstant().atZone(ZoneId.systemDefault()) .toLocalDate(); this.pathDatesList.add(stampDateInstant); //Build DatePicker } catch (Exception e) { e.printStackTrace(); } } datePicker.setValue(LocalDate.now()); } } else { pathComboFirstRun = false; } }); pathComboBox.setTooltip( new Tooltip("Default path is \"" + OTFUtility.getDescription(getDefaultPath()) + "\"")); //Calendar Date Picker final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() { @Override public DateCell call(final DatePicker datePicker) { return new DateCell() { @Override public void updateItem(LocalDate thisDate, boolean empty) { super.updateItem(thisDate, empty); if (pathDatesList != null) { if (pathDatesList.contains(thisDate)) { setDisable(false); } else { setDisable(true); } } } }; } }; datePicker.setDayCellFactory(dayCellFactory); datePicker.setOnAction((event) -> { if (!datePickerFirstRun) { UUID selectedPath = pathComboBox.getSelectionModel().getSelectedItem(); Instant instant = Instant.from(datePicker.getValue().atStartOfDay(ZoneId.systemDefault())); Long dateSelected = Date.from(instant).getTime(); if (selectedPath != null && dateSelected != 0) { int path = OTFUtility.getConceptVersion(selectedPath).getPathNid(); setTimeOptions(path, dateSelected); try { timeSelectCombo.setValue(times.first()); //Default Dropdown Value } catch (Exception e) { // Eat it.. like a sandwich! TODO: Create Read Only Property Conditional for checking if Time Combo is disabled // Right now, Sometimes Time Combo is disabled, so we catch this and eat it // Otherwise make a conditional from the Read Only Boolean Property to check first } } else { disableTimeCombo(false); logger.debug("The path isn't set or the date isn't set. Both are needed right now"); } } else { datePickerFirstRun = false; } }); //Commit-Time ComboBox timeSelectCombo.setMinWidth(200); timeSelectCombo.setCellFactory(new Callback<ListView<Long>, ListCell<Long>>() { @Override public ListCell<Long> call(ListView<Long> param) { final ListCell<Long> cell = new ListCell<Long>() { @Override protected void updateItem(Long item, boolean emptyRow) { super.updateItem(item, emptyRow); if (item == null) { setText(""); } else { if (item == Long.MAX_VALUE) { setText("LATEST TIME"); } else { setText(timeFormatter.format(new Date(item))); } } } }; return cell; } }); timeSelectCombo.setButtonCell(new ListCell<Long>() { @Override protected void updateItem(Long item, boolean emptyRow) { super.updateItem(item, emptyRow); if (item == null) { setText(""); } else { if (item == Long.MAX_VALUE) { setText("LATEST TIME"); } else { setText(timeFormatter.format(new Date(item))); } } } }); try { currentPathProperty.bind(pathComboBox.getSelectionModel().selectedItemProperty()); //Set Path Property currentTimeProperty.bind(timeSelectCombo.getSelectionModel().selectedItemProperty()); } catch (Exception e) { e.printStackTrace(); } // DEFAULT VALUES UserProfile loggedIn = ExtendedAppContext.getCurrentlyLoggedInUserProfile(); storedTimePref = loggedIn.getViewCoordinateTime(); storedPathPref = loggedIn.getViewCoordinatePath(); if (storedPathPref != null) { pathComboBox.getItems().clear(); //Set the path Dates by default pathComboBox.getItems().addAll(getPathOptions()); final UUID storedPath = getStoredPath(); if (storedPath != null) { pathComboBox.getSelectionModel().select(storedPath); } if (storedTimePref != null) { final Long storedTime = loggedIn.getViewCoordinateTime(); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(storedTime)); cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds Long storedTruncTime = cal.getTimeInMillis(); if (!storedTime.equals(Long.MAX_VALUE)) { //***** FIX THIS, not checking default vc time value int path = OTFUtility.getConceptVersion(storedPathPref).getPathNid(); setTimeOptions(path, storedTimePref); timeSelectCombo.setValue(storedTruncTime); // timeSelectCombo.getItems().addAll(getTimeOptions()); //The correct way, but doesen't work Date storedDate = new Date(storedTime); datePicker.setValue(storedDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); } else { datePicker.setValue(LocalDate.now()); timeSelectCombo.getItems().addAll(Long.MAX_VALUE); //The correct way, but doesen't work timeSelectCombo.setValue(Long.MAX_VALUE); // disableTimeCombo(false); } } else { //Stored Time Pref == null logger.error("ERROR: Stored Time Preference = null"); } } else { //Stored Path Pref == null logger.error("We could not load a stored path, ISAAC cannot run"); throw new Error("No stored PATH could be found. ISAAC can't run without a path"); } GridPane gridPane = new GridPane(); gridPane.setHgap(10); gridPane.setVgap(10); Label pathLabel = new Label("View Coordinate Path"); gridPane.add(pathLabel, 0, 0); //Path Label - Row 0 GridPane.setHalignment(pathLabel, HPos.LEFT); gridPane.add(statedInferredToggleGroupVBox, 1, 0, 1, 2); //--Row 0, span 2 gridPane.add(pathComboBox, 0, 1); //Path Combo box - Row 2 GridPane.setValignment(pathComboBox, VPos.TOP); Label datePickerLabel = new Label("View Coordinate Dates"); gridPane.add(datePickerLabel, 0, 2); //Row 3 GridPane.setHalignment(datePickerLabel, HPos.LEFT); gridPane.add(datePicker, 0, 3); //Row 4 Label timeSelectLabel = new Label("View Coordinate Times"); gridPane.add(timeSelectLabel, 1, 2); //Row 3 GridPane.setHalignment(timeSelectLabel, HPos.LEFT); gridPane.add(timeSelectCombo, 1, 3); //Row 4 // FOR DEBUGGING CURRENTLY SELECTED PATH, TIME AND POLICY /* UserProfile userProfile = ExtendedAppContext.getCurrentlyLoggedInUserProfile(); StatedInferredOptions chosenPolicy = userProfile.getStatedInferredPolicy(); UUID chosenPathUuid = userProfile.getViewCoordinatePath(); Long chosenTime = userProfile.getViewCoordinateTime(); Label printSelectedPathLabel = new Label("Path: " + OTFUtility.getDescription(chosenPathUuid)); gridPane.add(printSelectedPathLabel, 0, 4); GridPane.setHalignment(printSelectedPathLabel, HPos.LEFT); Label printSelectedTimeLabel = null; if(chosenTime != getDefaultTime()) { printSelectedTimeLabel = new Label("Time: " + dateFormat.format(new Date(chosenTime))); } else { printSelectedTimeLabel = new Label("Time: LONG MAX VALUE"); } gridPane.add(printSelectedTimeLabel, 1, 4); GridPane.setHalignment(printSelectedTimeLabel, HPos.LEFT); Label printSelectedPolicyLabel = new Label("Policy: " + chosenPolicy); gridPane.add(printSelectedPolicyLabel, 2, 4); GridPane.setHalignment(printSelectedPolicyLabel, HPos.LEFT); */ hBox = new HBox(); hBox.getChildren().addAll(gridPane); allValid_ = new ValidBooleanBinding() { { bind(currentStatedInferredOptionProperty, currentPathProperty, currentTimeProperty); setComputeOnInvalidate(true); } @Override protected boolean computeValue() { if (currentStatedInferredOptionProperty.get() == null) { this.setInvalidReason("Null/unset/unselected StatedInferredOption"); for (RadioButton button : statedInferredOptionButtons) { TextErrorColorHelper.setTextErrorColor(button); } return false; } else { for (RadioButton button : statedInferredOptionButtons) { TextErrorColorHelper.clearTextErrorColor(button); } } if (currentPathProperty.get() == null) { this.setInvalidReason("Null/unset/unselected path"); TextErrorColorHelper.setTextErrorColor(pathComboBox); return false; } else { TextErrorColorHelper.clearTextErrorColor(pathComboBox); } if (OTFUtility.getConceptVersion(currentPathProperty.get()) == null) { this.setInvalidReason("Invalid path"); TextErrorColorHelper.setTextErrorColor(pathComboBox); return false; } else { TextErrorColorHelper.clearTextErrorColor(pathComboBox); } // if(currentTimeProperty.get() == null && currentTimeProperty.get() != Long.MAX_VALUE) // { // this.setInvalidReason("View Coordinate Time is unselected"); // TextErrorColorHelper.setTextErrorColor(timeSelectCombo); // return false; // } this.clearInvalidReason(); return true; } }; } // createButton.disableProperty().bind(saveButtonValid.not())); // Reload persisted values every time final StatedInferredOptions storedStatedInferredOption = getStoredStatedInferredOption(); for (Toggle toggle : statedInferredToggleGroup.getToggles()) { if (toggle.getUserData() == storedStatedInferredOption) { toggle.setSelected(true); } } // pathComboBox.setButtonCell(new ListCell<UUID>() { // @Override // protected void updateItem(UUID c, boolean emptyRow) { // super.updateItem(c, emptyRow); // if (emptyRow) { // setText(""); // } else { // String desc = OTFUtility.getDescription(c); // setText(desc); // } // } // }); // timeSelectCombo.setButtonCell(new ListCell<Long>() { // @Override // protected void updateItem(Long item, boolean emptyRow) { // super.updateItem(item, emptyRow); // if (emptyRow) { // setText(""); // } else { // setText(timeFormatter.format(new Date(item))); // } // } // }); // datePickerFirstRun = false; // pathComboFirstRun = false; return hBox; }
From source file:com.github.drbookings.ui.controller.MainController.java
private Callback<TableView<DateBean>, TableRow<DateBean>> getRowFactory() { return param -> { final TableRow<DateBean> row = new TableRow<DateBean>() { @Override/*from w w w.j av a 2s . c o m*/ protected void updateItem(final DateBean item, final boolean empty) { super.updateItem(item, empty); getStyleClass().removeAll("now", "end-of-month"); if (empty || item == null) { } else { if (item.getDate().isEqual(LocalDate.now())) { getStyleClass().add("now"); } else if (item.getDate().equals( item.getDate().with(java.time.temporal.TemporalAdjusters.lastDayOfMonth()))) { getStyleClass().add("end-of-month"); } else { } } } }; // final PseudoClass rowContainsSelectedCell = // PseudoClass.getPseudoClass("contains-selection"); // final BooleanBinding containsSelection = // Bindings.createBooleanBinding( // () -> rowsWithSelectedCells.contains(row.getIndex()), // rowsWithSelectedCells, row.indexProperty()); // containsSelection.addListener((obs, didContainSelection, // nowContainsSelection) -> row // .pseudoClassStateChanged(rowContainsSelectedCell, // nowContainsSelection)); return row; }; }
From source file:org.silverpeas.core.calendar.CalendarSynchronizationIT.java
private CalendarEvent addExternalEventIn(final Calendar calendar) throws SQLException { CalendarEvent event = CalendarEvent.on(LocalDate.now().minusMonths(2)) .withExternalId(UUID.randomUUID().toString()).withTitle("next deleted event") .withDescription("This event will be deleted at the next synchronization"); event.setLastSynchronizationDate(OffsetDateTime.now().minusDays(2)); return event.planOn(calendar); }
From source file:FactFind.PersonalDetails.java
static String CalculateAge(String DOB) { LocalDate today = LocalDate.now(); String[] str_array = DOB.split("/"); LocalDate birthday = LocalDate.of(Integer.parseInt(str_array[2]), Month.of(Integer.parseInt(str_array[1])), Integer.parseInt(str_array[0])); Period p = Period.between(birthday, today); return Integer.toString(p.getYears()); }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testUpdateGender() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventUsername = initEvent(categories); Event event = eventUsername.getKey(); try {// w w w. j a v a 2s . c om TicketReservationModification trm = new TicketReservationModification(); trm.setAmount(2); trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId()); TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty()); Date expiration = DateUtils.addDays(new Date(), 1); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), expiration, Optional.empty(), Optional.empty(), Locale.ENGLISH, false); ticketReservationManager.confirm("TOKEN", null, event, reservationId, "email@email.ch", new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, null, new TotalPrice(1000, 10, 0, 0), Optional.empty(), Optional.of(PaymentProxy.ON_SITE), false, null, null, null); List<Ticket> tickets = ticketRepository.findTicketsInReservation(reservationId); UpdateTicketOwnerForm first = new UpdateTicketOwnerForm(); first.setEmail("email@email.ch"); //first.setTShirtSize("SMALL"); //first.setGender("F"); first.setFirstName("Full"); first.setLastName("Name"); UpdateTicketOwnerForm second = new UpdateTicketOwnerForm(); //second.setTShirtSize("SMALL-F"); second.setEmail("email@email.ch"); second.setFirstName("Full"); second.setLastName("Name"); PartialTicketPDFGenerator generator = TemplateProcessor.buildPartialPDFTicket(Locale.ITALIAN, event, ticketReservationManager.findById(reservationId).get(), ticketCategoryRepository.getByIdAndActive(tickets.get(0).getCategoryId(), event.getId()), organizationRepository.getById(event.getOrganizationId()), templateManager, fileUploadManager, ""); ticketReservationManager.updateTicketOwner(tickets.get(0), Locale.ITALIAN, event, first, (t) -> "", (t) -> "", Optional.empty()); ticketReservationManager.updateTicketOwner(tickets.get(1), Locale.ITALIAN, event, second, (t) -> "", (t) -> "", Optional.empty()); //FIXME //dataMigrator.fillTicketsGender(); //ticketRepository.findTicketsInReservation(reservationId).forEach(t -> assertEquals("F", t.getGender())); } finally { eventManager.deleteEvent(event.getId(), eventUsername.getValue()); } }
From source file:net.tourbook.photo.internal.manager.PhotoImageLoader.java
/** * Get image from thumb store with the requested image quality. * //from ww w .j a v a 2 s. c om * @param _photo * @param requestedImageQuality * @return */ private Image loadImageFromStore(final ImageQuality requestedImageQuality) { /* * check if image is available in the thumbstore */ final IPath requestedStoreImageFilePath = ThumbnailStore.getStoreImagePath(_photo, requestedImageQuality); final String imageStoreFilePath = requestedStoreImageFilePath.toOSString(); final File storeImageFile = new File(imageStoreFilePath); if (storeImageFile.isFile() == false) { return null; } // photo image is available in the thumbnail store Image storeImage = null; /* * touch store file when it is not yet done today, this is done to track last access time so * that a store cleanup can check the date */ final LocalDate dtModified = TimeTools.getZonedDateTime(storeImageFile.lastModified()).toLocalDate(); if (dtModified.equals(LocalDate.now()) == false) { storeImageFile.setLastModified(TimeTools.now().toInstant().toEpochMilli()); } try { storeImage = new Image(_display, imageStoreFilePath); loadImageProperties(requestedStoreImageFilePath); } catch (final Exception e) { StatusUtil.log(NLS.bind("Image cannot be loaded with SWT (1): \"{0}\"", //$NON-NLS-1$ imageStoreFilePath), e); } finally { if (storeImage == null) { String message = "Image \"{0}\" cannot be loaded and an exception did not occure.\n" //$NON-NLS-1$ + "The image file is available but it's possible that SWT.ERROR_NO_HANDLES occured"; //$NON-NLS-1$ System.out.println(UI.timeStampNano() + NLS.bind(message, imageStoreFilePath)); PhotoImageCache.disposeThumbs(null); /* * try loading again */ try { storeImage = new Image(_display, imageStoreFilePath); } catch (final Exception e) { StatusUtil.log(NLS.bind("Image cannot be loaded with SWT (2): \"{0}\"", //$NON-NLS-1$ imageStoreFilePath), e); } finally { if (storeImage == null) { message = "Image cannot be loaded again with SWT, even when disposing the image cache: \"{0}\" "; //$NON-NLS-1$ System.out.println(UI.timeStampNano() + NLS.bind(message, imageStoreFilePath)); } } } } return storeImage; }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testIncreaseEventSeatsWithAnUnboundedCategory() { 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, "", false, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);//from ww w . j a v a2s. co m Event event = pair.getKey(); EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0", ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null); eventManager.updateEventPrices(event, update, pair.getValue()); List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId()); assertNotNull(tickets); assertFalse(tickets.isEmpty()); assertEquals(20, tickets.size()); assertEquals(20, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue()); waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); tickets = ticketRepository.findFreeByEventId(event.getId()); assertEquals(40, tickets.size()); assertEquals(40, tickets.stream().filter(t -> t.getCategoryId() == null).count()); }