@Override public Path resolvePermanentFilePath(Path path) { return filesSettings.getPermanentDirectory().resolve(path); } }
private Locale getTenantDefaultLocale() { return context.getSettings(GeneralSettings.class).getLocales().getMainLocale().getValue(); } }
@GET public Response listLocales() { List<Locale> locales; Map<String, String> endpoints = Maps.newHashMap(); GeneralSettings settings = context.getSettings(GeneralSettings.class); locales = settings.getLocales().getOtherLocales().getValue(); locales.add(settings.getLocales().getMainLocale().getValue()); for (Locale locale : locales) { endpoints.put(locale.toLanguageTag(), "/api/localization/theme/" + locale.toLanguageTag()); } return Response.ok(endpoints).build(); }
@Override public DateTime deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { String str = parser.getText().trim(); if (Strings.isNullOrEmpty(str)) { return null; } ConfigurationService configurationService = Utils.getComponent(ConfigurationService.class); GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); return new DateTime(str, DateTimeZone.forTimeZone(settings.getTime().getTimeZone().getValue())); } }
LocalesSettings localesSettings = configurationService.getSettings(GeneralSettings.class).getLocales(); List<Locale> alternativeLocales = FluentIterable.from(localesSettings.getOtherLocales().getValue()) .filter(Predicates.notNull()).toList();
/** * Retrieves the contact email for a tenant. If the tenant is null ("global tenant"), then use the global site * settings * * @param tenant the tenant for which to get the contact email, or null for a global tenant * @return the found contact email or null if no contact email has been found */ private String getTenantContactEmail(Tenant tenant) { if (tenant == null) { return siteSettings.getContactEmail(); } else { return StringUtils.isNotBlank(tenant.getContactEmail()) ? tenant.getContactEmail() : generalSettings.getNotificationsEmail(); } }
/** * @see {@link org.xwiki.observation.EventListener#onEvent(org.xwiki.observation.event.Event, Object, Object)} */ public void onEvent(Event event, Object source, Object data) { GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); final Order order = (Order) source; final Locale customerLocale = webContext.getLocale(); final Tenant tenant = webContext.getTenant(); final Locale tenantLocale = settings.getLocales().getMainLocale().getValue(); final boolean withInvoice = invoicingService.isEnabledInContext(); Executors.newSingleThreadExecutor().submit(new Callable<Void>() { @Override public Void call() throws Exception { sendNotificationMails(order, tenant, customerLocale, tenantLocale, withInvoice); return null; } }); }
@Override public void supply(Map<String, Object> data) { // Manage list of locales and corresponding links String path = context.getRequest().getCanonicalPath(); Map<String, Map<String, String>> locales = Maps.newHashMap(); GeneralSettings settings = context.getSettings(GeneralSettings.class); final Locale mainLocale = settings.getLocales().getMainLocale().getValue(); locales.put(mainLocale.toLanguageTag(), buildLocale(mainLocale, path, true)); List<Locale> alternativeLocales = FluentIterable.from(settings.getLocales().getOtherLocales().getValue()).filter(Predicates.notNull()) .toList(); if (!alternativeLocales.isEmpty()) { for (final Locale locale : alternativeLocales) { locales.put(locale.toLanguageTag(), buildLocale(locale, path, false)); } } data.put("locales", locales); data.put("locale", buildLocale(context.getLocale(), path, mainLocale.equals(context.getLocale()))); data.put("localePath", context.isAlternativeLocale() ? ("/" + context.getLocale().toLanguageTag()) : ""); data.put("url", data.get("localePath") + path); data.put("canonicalUrl", path); }
@GET @Path("{slug}") @Authorized public Response getOrder(@PathParam("slug") String slug) { Order order = orderStore.get().findBySlug(slug); if (order == null) { return Response.status(Response.Status.NOT_FOUND).entity("Order not found").build(); } GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); final DateTimeZone tenantTz = DateTimeZone.forTimeZone(settings.getTime().getTimeZone().getValue()); return Response.ok(new OrderRepresentation(tenantTz, order)).build(); }
private Path getGlobalThemeDirectory(String themeId) { return filesSettings.getPermanentDirectory() .resolve(THEMES_FOLDER_NAME) .resolve(themeId); }
@Override public Mail emailToTenant() { return new Mail().from(generalSettings.getNotificationsEmail()).to(context.getTenant().getContactEmail()); }
@GET @Path(PAYMENT_RETURN_PATH + "/{order}") public WebView returnFromPaymentService(@Context UriInfo uriInfo, @PathParam("order") String orderId) { Map<String, Object> bindings = new HashMap<>(); if (StringUtils.isNotBlank(orderId)) { Order order = orderStore.get().findById(UUID.fromString(orderId)); if (order != null) { Optional<Address> da = order.getDeliveryAddress() != null ? Optional.fromNullable(order.getDeliveryAddress()) : Optional.<Address>absent(); Optional<Address> ba = order.getBillingAddress() != null ? Optional.fromNullable(order.getBillingAddress()) : Optional.<Address>absent(); bindings.putAll( prepareContext(order, order.getCustomer(), ba, da, webContext.getTenant(), configurationService.getSettings(GeneralSettings.class).getLocales().getMainLocale() .getValue())); } } return new WebView().template("checkout/success.html").with(WebView.Option.FALLBACK_ON_DEFAULT_THEME) .data(bindings); }
@GET @Authorized public ResultSetRepresentation<OrderRepresentation> getAllOrders( @QueryParam("number") @DefaultValue("50") Integer number, @QueryParam("offset") @DefaultValue("0") Integer offset) { GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); final DateTimeZone tenantTz = DateTimeZone.forTimeZone(settings.getTime().getTimeZone().getValue()); List<Order> orders = orderStore.get().findAllPaidOrAwaitingPayment(number, offset); Collection<OrderRepresentation> representations = Collections2.transform(orders, new Function<Order, OrderRepresentation>() { public OrderRepresentation apply(final Order order) { return new OrderRepresentation(tenantTz, order); } }); Integer total = this.orderStore.get().countAllPaidOrAwaitingPayment(); ResultSetRepresentation<OrderRepresentation> resultSet = new ResultSetRepresentation<>( "/api/orders", number, offset, new ArrayList<>(representations), total ); return resultSet; }
private Path getTenantThemeDirectory(String tenantSlug, String themeId) { return filesSettings.getPermanentDirectory() .resolve(TENANTS_FOLDER_NAME) .resolve(tenantSlug) .resolve(THEMES_FOLDER_NAME) .resolve(themeId); }
/** * @param tenant the tenant of the shop the customer checked out from * @param locale the main locale of the tenant * @return an optional notification email object, present if all information is there and valid and the template * exists, absent otherwise */ private MailTemplate getTenantNotificationEmail(Tenant tenant, Locale locale) { return new MailTemplate() .from(generalSettings.getNotificationsEmail()) .to(getTenantContactEmail(tenant)) .template("order-paid-tenant") .locale(locale); }
Optional.fromNullable(response.getOrder().getDeliveryAddress()), webContext.getTenant(), configurationService.getSettings(GeneralSettings.class).getLocales().getMainLocale().getValue()
/** * @return this gateway global (server-level) configuration file * * @param fileName the name of the file to retrieve */ protected File getGlobalConfigurationFile(String fileName) { return filesSettings.getPermanentDirectory() .resolve(PAYMENTS_DIRECTORY) .resolve(this.getId()) .resolve(fileName).toFile(); }
final InvoicingSettings invoicingSettings = configurationService.getSettings(InvoicingSettings.class, tenant); final Locale locale = settings.getLocales().getMainLocale().getValue();
public FileWatcher(ComponentManager componentManager) throws InitializationException { Preconditions.checkNotNull(componentManager); try { FilesSettings filesSettings = componentManager.getInstance(FilesSettings.class); this.observationManager = componentManager.getInstance(ObservationManager.class); this.permanentDirectory = filesSettings.getPermanentDirectory(); watchService = FileSystems.getDefault().newWatchService(); } catch (ComponentLookupException | IOException e) { throw new InitializationException("Failed to initialize the file watcher.", e); } }
/** * @return this gateway global (server-level) configuration file * * @param fileName the name of the file to retrieve */ protected Optional<File> getTenantConfigurationFile(String fileName) { if (this.context.getTenant() == null) { return Optional.absent(); } return Optional.of(filesSettings.getPermanentDirectory() .resolve(TENANTS_DIRECTORY) .resolve(this.context.getTenant().getSlug()) .resolve(PAYMENTS_DIRECTORY) .resolve(this.getId()) .resolve(fileName).toFile()); }