List of usage examples for java.util Locale forLanguageTag
public static Locale forLanguageTag(String languageTag)
From source file:alfio.manager.TicketReservationManager.java
public void updateTicketOwner(Ticket ticket, Locale locale, Event event, UpdateTicketOwnerForm updateTicketOwner, PartialTicketTextGenerator confirmationTextBuilder, PartialTicketTextGenerator ownerChangeTextBuilder, Optional<UserDetails> userDetails) { Ticket preUpdateTicket = ticketRepository.findByUUID(ticket.getUuid()); Map<String, String> preUpdateTicketFields = ticketFieldRepository.findAllByTicketId(ticket.getId()).stream() .collect(Collectors.toMap(TicketFieldValue::getName, TicketFieldValue::getValue)); String newEmail = updateTicketOwner.getEmail().trim(); CustomerName customerName = new CustomerName(updateTicketOwner.getFullName(), updateTicketOwner.getFirstName(), updateTicketOwner.getLastName(), event); ticketRepository.updateTicketOwner(ticket.getUuid(), newEmail, customerName.getFullName(), customerName.getFirstName(), customerName.getLastName()); ///*from ww w .j a v a2 s . c o m*/ Locale userLocale = Optional.ofNullable(StringUtils.trimToNull(updateTicketOwner.getUserLanguage())) .map(Locale::forLanguageTag).orElse(locale); ticketRepository.updateOptionalTicketInfo(ticket.getUuid(), userLocale.getLanguage()); ticketFieldRepository.updateOrInsert(updateTicketOwner.getAdditional(), ticket.getId(), event.getId()); Ticket newTicket = ticketRepository.findByUUID(ticket.getUuid()); if (newTicket.getStatus() == TicketStatus.ACQUIRED && (!StringUtils.equalsIgnoreCase(newEmail, ticket.getEmail()) || !StringUtils.equalsIgnoreCase(customerName.getFullName(), ticket.getFullName()))) { sendTicketByEmail(newTicket, userLocale, event, confirmationTextBuilder); } boolean admin = isAdmin(userDetails); if (!admin && StringUtils.isNotBlank(ticket.getEmail()) && !StringUtils.equalsIgnoreCase(newEmail, ticket.getEmail()) && ticket.getStatus() == TicketStatus.ACQUIRED) { Locale oldUserLocale = Locale.forLanguageTag(ticket.getUserLanguage()); String subject = messageSource.getMessage("ticket-has-changed-owner-subject", new Object[] { event.getDisplayName() }, oldUserLocale); notificationManager.sendSimpleEmail(event, ticket.getEmail(), subject, () -> ownerChangeTextBuilder.generate(newTicket)); if (event.getBegin().isBefore(ZonedDateTime.now(event.getZoneId()))) { Organization organization = organizationRepository.getById(event.getOrganizationId()); notificationManager.sendSimpleEmail(event, organization.getEmail(), "WARNING: Ticket has been reassigned after event start", () -> ownerChangeTextBuilder.generate(newTicket)); } } if (admin) { TicketReservation reservation = findById(ticket.getTicketsReservationId()) .orElseThrow(IllegalStateException::new); //if the current user is admin, then it would be good to update also the name of the Reservation Owner String username = userDetails.get().getUsername(); log.warn("Reservation {}: forced assignee replacement old: {} new: {}", reservation.getId(), reservation.getFullName(), username); ticketReservationRepository.updateAssignee(reservation.getId(), username); } pluginManager.handleTicketAssignment(newTicket); Ticket postUpdateTicket = ticketRepository.findByUUID(ticket.getUuid()); Map<String, String> postUpdateTicketFields = ticketFieldRepository.findAllByTicketId(ticket.getId()) .stream().collect(Collectors.toMap(TicketFieldValue::getName, TicketFieldValue::getValue)); auditUpdateTicket(preUpdateTicket, preUpdateTicketFields, postUpdateTicket, postUpdateTicketFields, event.getId()); }
From source file:alfio.manager.TicketReservationManager.java
void sendReminderForOfflinePayments() { Date expiration = truncate(//from ww w . j a v a2 s . co m addHours(new Date(), configurationManager .getIntConfigValue(Configuration.getSystemConfiguration(OFFLINE_REMINDER_HOURS), 24)), Calendar.DATE); ticketReservationRepository.findAllOfflinePaymentReservationForNotification(expiration).stream() .map(reservation -> { Optional<Ticket> ticket = ticketRepository.findFirstTicketInReservation(reservation.getId()); Optional<Event> event = ticket.map(t -> eventRepository.findById(t.getEventId())); Optional<Locale> locale = ticket.map(t -> Locale.forLanguageTag(t.getUserLanguage())); return Triple.of(reservation, event, locale); }).filter(p -> p.getMiddle().isPresent()).filter(p -> { Event event = p.getMiddle().get(); return truncate( addHours(new Date(), configurationManager.getIntConfigValue(Configuration.from( event.getOrganizationId(), event.getId(), OFFLINE_REMINDER_HOURS), 24)), Calendar.DATE).compareTo(p.getLeft().getValidity()) >= 0; }).map(p -> Triple.of(p.getLeft(), p.getMiddle().get(), p.getRight().get())).forEach(p -> { TicketReservation reservation = p.getLeft(); Event event = p.getMiddle(); Map<String, Object> model = prepareModelForReservationEmail(event, reservation); Locale locale = p.getRight(); ticketReservationRepository.flagAsOfflinePaymentReminderSent(reservation.getId()); notificationManager.sendSimpleEmail(event, reservation.getEmail(), messageSource.getMessage("reservation.reminder.mail.subject", new Object[] { getShortReservationID(event, reservation.getId()) }, locale), () -> templateManager.renderTemplate(event, TemplateResource.REMINDER_EMAIL, model, locale)); }); }
From source file:alfio.manager.TicketReservationManager.java
public void releaseTicket(Event event, TicketReservation ticketReservation, final Ticket ticket) { TicketCategory category = ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId()); if (!CategoryEvaluator.isTicketCancellationAvailable(ticketCategoryRepository, ticket)) { throw new IllegalStateException("Cannot release reserved tickets"); }/*from www . j a v a 2s . co m*/ String reservationId = ticketReservation.getId(); //#365 - reset UUID when releasing a ticket int result = ticketRepository.releaseTicket(reservationId, UUID.randomUUID().toString(), event.getId(), ticket.getId()); Validate.isTrue(result == 1, String.format("Expected 1 row to be updated, got %d", result)); if (category.isAccessRestricted() || !category.isBounded()) { ticketRepository.unbindTicketsFromCategory(event.getId(), category.getId(), singletonList(ticket.getId())); } Organization organization = organizationRepository.getById(event.getOrganizationId()); Map<String, Object> model = TemplateResource.buildModelForTicketHasBeenCancelled(organization, event, ticket); Locale locale = Locale.forLanguageTag(Optional.ofNullable(ticket.getUserLanguage()).orElse("en")); notificationManager.sendSimpleEmail(event, ticket.getEmail(), messageSource.getMessage("email-ticket-released.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.TICKET_HAS_BEEN_CANCELLED, model, locale)); String ticketCategoryDescription = ticketCategoryDescriptionRepository .findByTicketCategoryIdAndLocale(category.getId(), ticket.getUserLanguage()).orElse(""); List<AdditionalServiceItem> additionalServiceItems = additionalServiceItemRepository .findByReservationUuid(reservationId); Map<String, Object> adminModel = TemplateResource.buildModelForTicketHasBeenCancelledAdmin(organization, event, ticket, ticketCategoryDescription, additionalServiceItems, asi -> additionalServiceTextRepository.findByLocaleAndType(asi.getAdditionalServiceId(), locale.getLanguage(), AdditionalServiceText.TextType.TITLE)); notificationManager.sendSimpleEmail(event, organization.getEmail(), messageSource.getMessage("email-ticket-released.admin.subject", new Object[] { ticket.getId(), event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.TICKET_HAS_BEEN_CANCELLED_ADMIN, adminModel, locale)); int deletedValues = ticketFieldRepository.deleteAllValuesForTicket(ticket.getId()); log.debug("deleting {} field values for ticket {}", deletedValues, ticket.getId()); auditingRepository.insert(reservationId, null, event.getId(), Audit.EventType.CANCEL_TICKET, new Date(), Audit.EntityType.TICKET, Integer.toString(ticket.getId())); if (ticketRepository.countTicketsInReservation(reservationId) == 0 && !transactionRepository.loadOptionalByReservationId(reservationId).isPresent()) { deleteReservation(event, reservationId, false); auditingRepository.insert(reservationId, null, event.getId(), Audit.EventType.CANCEL_RESERVATION, new Date(), Audit.EntityType.RESERVATION, reservationId); } else { extensionManager.handleTicketCancelledForEvent(event, Collections.singletonList(ticket.getUuid())); } }
From source file:alfio.manager.TicketReservationManager.java
public void validateAndConfirmOfflinePayment(String reservationId, Event event, BigDecimal paidAmount, String username) {// w w w .ja va 2 s . co m TicketReservation reservation = findByPartialID(reservationId); Optional<OrderSummary> optionalOrderSummary = optionally(() -> orderSummaryForReservationId( reservation.getId(), event, Locale.forLanguageTag(reservation.getUserLanguage()))); Validate.isTrue(optionalOrderSummary.isPresent(), "Reservation not found"); OrderSummary orderSummary = optionalOrderSummary.get(); Validate.isTrue(MonetaryUtil.centsToUnit(orderSummary.getOriginalTotalPrice().getPriceWithVAT()) .compareTo(paidAmount) == 0, "paid price differs from due price"); confirmOfflinePayment(event, reservation.getId(), username); }
From source file:net.www_eee.portal.channels.ProxyChannel.java
@Override protected void doViewRequestImpl(final Page.Request pageRequest, final ViewResponse viewResponse) throws WWWEEEPortal.Exception, WebApplicationException { final HttpClientContext proxyContext = doProxyRequest(pageRequest, Mode.VIEW); final @NonNull HttpResponse proxyResponse = proxyContext.getResponse(); final URL proxiedFileURL = HttpUtil.getRequestTargetURL(proxyContext); try (final CloseableHttpClient proxyClient = Objects .requireNonNull((CloseableHttpClient) proxyContext.getAttribute(HTTP_CLIENT_CONTEXT_ID))) { final MimeType responseContentType = getProxyResponseHeader(pageRequest, proxyResponse, "Content-Type", IOUtil::newMimeType);//from www . ja va 2 s . co m viewResponse.setContentType( (responseContentType != null) ? RESTUtil.getMediaType(responseContentType) : null); viewResponse.setLastModified(getProxyResponseHeader(pageRequest, proxyResponse, "Last-Modified", (s) -> ZonedDateTime.parse(s, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant())); viewResponse.setCacheControl(mergeCacheControl(viewResponse.getCacheControl(), getProxyResponseHeader(pageRequest, proxyResponse, "Cache-Control", CacheControl::valueOf))); viewResponse.setExpires(getProxyResponseHeader(pageRequest, proxyResponse, "Expires", (s) -> ZonedDateTime.parse(s, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant())); viewResponse .setEntityTag(getProxyResponseHeader(pageRequest, proxyResponse, "ETag", EntityTag::valueOf)); viewResponse.setLocale(getProxyResponseHeader(pageRequest, proxyResponse, "Content-Language", (h) -> Locale.forLanguageTag( CollUtil.first(Arrays.asList(StringUtil.COMMA_SEPARATED_PATTERN.split(h))).get()))); if (isRenderedUsingXMLView(pageRequest, proxyResponse, responseContentType)) { renderXMLView(pageRequest, viewResponse, proxyResponse, proxiedFileURL, responseContentType); } else if (isRenderedUsingTextView(pageRequest, proxyResponse, responseContentType)) { renderTextView(pageRequest, viewResponse, proxyResponse, proxiedFileURL, responseContentType); } else { renderResourceReferenceView(pageRequest, viewResponse, proxiedFileURL, responseContentType); } } catch (WWWEEEPortal.Exception wpe) { LogAnnotation.annotate(wpe, "ProxyContext", proxyContext, null, false); LogAnnotation.annotate(wpe, "ProxyResponse", proxyResponse, null, false); LogAnnotation.annotate(wpe, "ProxiedFileURL", proxiedFileURL, null, false); // This wouldn't be necessary if any of the previous annotations could actually toString() themselves usefully. throw wpe; } catch (IOException ioe) { throw new WWWEEEPortal.OperationalException(ioe); } return; }
From source file:net.www_eee.portal.channels.ProxyChannel.java
@Override protected Response doResourceRequestImpl(final Page.Request pageRequest) throws WWWEEEPortal.Exception, WebApplicationException { final HttpClientContext proxyContext = doProxyRequest(pageRequest, Mode.RESOURCE); @SuppressWarnings("resource") final CloseableHttpClient proxyClient = Objects .requireNonNull((CloseableHttpClient) proxyContext.getAttribute(HTTP_CLIENT_CONTEXT_ID)); final @NonNull HttpResponse proxyResponse = proxyContext.getResponse(); try {//from ww w .ja va 2 s . co m final Response.ResponseBuilder responseBuilder = Response.ok(); responseBuilder.lastModified(getProxyResponseHeader(pageRequest, proxyResponse, "Last-Modified", (s) -> Date.from(ZonedDateTime.parse(s, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant()))); final MimeType responseContentType = getProxyResponseHeader(pageRequest, proxyResponse, "Content-Type", IOUtil::newMimeType); responseBuilder.type((responseContentType != null) ? RESTUtil.getMediaType(responseContentType) : null); responseBuilder.cacheControl(mergeCacheControl(getCacheControlDefault().orElse(null), getProxyResponseHeader(pageRequest, proxyResponse, "Cache-Control", CacheControl::valueOf))); responseBuilder.expires(getProxyResponseHeader(pageRequest, proxyResponse, "Expires", (s) -> Date.from(ZonedDateTime.parse(s, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant()))); responseBuilder.tag(getProxyResponseHeader(pageRequest, proxyResponse, "ETag", EntityTag::valueOf)); responseBuilder.language(getProxyResponseHeader(pageRequest, proxyResponse, "Content-Language", (h) -> Locale.forLanguageTag(StringUtil.COMMA_SEPARATED_PATTERN.split("")[0]).toString())); final HttpEntity proxyResponseEntity = proxyResponse.getEntity(); final Long contentLength = (proxyResponseEntity != null) ? Long.valueOf(proxyResponseEntity.getContentLength()) : null; responseBuilder.header("Content-Length", contentLength); if (proxyResponseEntity != null) { responseBuilder.entity(HttpUtil.getDataSource(proxyResponseEntity, proxyClient)); } else { try { proxyClient.close(); } catch (IOException ioe) { throw new WWWEEEPortal.OperationalException(ioe); } } return responseBuilder.build(); } catch (WWWEEEPortal.Exception wpe) { LogAnnotation.annotate(wpe, "ProxyContext", proxyContext, null, false); LogAnnotation.annotate(wpe, "ProxyResponse", proxyResponse, null, false); try { LogAnnotation.annotate(wpe, "ProxiedFileURL", HttpUtil.getRequestTargetURL(proxyContext), null, false); // This wouldn't be necessary if any of the previous annotations could actually toString() themselves usefully. } catch (Exception e) { } throw wpe; } }
From source file:com.joliciel.talismane.TalismaneConfigImpl.java
public LanguageDetectorAnnotatedCorpusReader getLanguageCorpusReader() { try {//w w w . j ava 2 s . co m if (languageCorpusReader == null) { File languageCorpusMapFile = this.getFile(languageCorpusMapPath); Scanner languageCorpusMapScanner = new Scanner(new BufferedReader(new InputStreamReader( new FileInputStream(languageCorpusMapFile), this.getInputCharset().name()))); Map<Locale, Reader> languageMap = new HashMap<Locale, Reader>(); while (languageCorpusMapScanner.hasNextLine()) { String line = languageCorpusMapScanner.nextLine(); String[] parts = line.split("\t"); Locale locale = Locale.forLanguageTag(parts[0]); String corpusPath = parts[1]; File corpusFile = this.getFile(corpusPath); Reader corpusReader = new BufferedReader( new InputStreamReader(new FileInputStream(corpusFile), this.getInputCharset().name())); languageMap.put(locale, corpusReader); } languageCorpusMapScanner.close(); languageCorpusReader = this.getLanguageDetectorService().getDefaultReader(languageMap); } this.setCorpusReaderAttributes(languageCorpusReader); return languageCorpusReader; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }