use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.
the class LocaleDaoImpl method findLocaleByCode.
/**
* @return The locale for the passed in code
*/
@Override
public Locale findLocaleByCode(String localeCode) {
Query query = em.createNamedQuery("BC_READ_LOCALE_BY_CODE");
query.setParameter("localeCode", localeCode);
query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
List<Locale> localeList = (List<Locale>) query.getResultList();
if (localeList.size() >= 1) {
if (localeList.size() > 1) {
LOG.warn("Locale code " + StringUtil.sanitize(localeCode) + " exists for more than one locale");
}
return localeList.get(0);
}
return null;
}
use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.
the class LocaleDaoImpl method findDefaultLocale.
/**
* Returns the page template with the passed in id.
*
* @return The default locale
*/
@Override
public Locale findDefaultLocale() {
Query query = em.createNamedQuery("BC_READ_DEFAULT_LOCALE");
query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
List<Locale> localeList = (List<Locale>) query.getResultList();
if (localeList.size() >= 1) {
if (localeList.size() > 1) {
LOG.warn("There is more than one default locale configured");
}
return localeList.get(0);
}
return null;
}
use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.
the class OrderDaoImpl method readNamedOrderForCustomer.
@Override
@SuppressWarnings("unchecked")
public Order readNamedOrderForCustomer(final Customer customer, final String name) {
final Query query = em.createNamedQuery("BC_READ_NAMED_ORDER_FOR_CUSTOMER");
query.setParameter("customerId", customer.getId());
query.setParameter("orderStatus", OrderStatus.NAMED.getType());
query.setParameter("orderName", name);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
List<Order> orders = query.getResultList();
// Filter out orders that don't match the current locale (if one is set)
if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
ListIterator<Order> iter = orders.listIterator();
while (iter.hasNext()) {
Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
Order order = iter.next();
if (locale != null && !locale.equals(order.getLocale())) {
iter.remove();
}
}
}
// Apply any additional filters that extension modules have registered
if (orders != null && !orders.isEmpty() && extensionManager != null) {
extensionManager.getProxy().applyAdditionalOrderLookupFilter(customer, name, orders);
}
return orders == null || orders.isEmpty() ? null : orders.get(0);
}
use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.
the class I18nSolrIndexServiceExtensionHandler method addPropertyValues.
@Override
public ExtensionResultStatusType addPropertyValues(Indexable indexable, Field field, FieldType fieldType, Map<String, Object> values, String propertyName, List<Locale> locales) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Set<String> processedLocaleCodes = new HashSet<String>();
ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
if (field.getTranslatable()) {
result = ExtensionResultStatusType.HANDLED;
TranslationConsiderationContext.setTranslationConsiderationContext(getTranslationEnabled());
TranslationConsiderationContext.setTranslationService(translationService);
BroadleafRequestContext tempContext = BroadleafRequestContext.getBroadleafRequestContext();
if (tempContext == null) {
tempContext = new BroadleafRequestContext();
BroadleafRequestContext.setBroadleafRequestContext(tempContext);
}
Locale originalLocale = tempContext.getLocale();
try {
for (Locale locale : locales) {
String localeCode = locale.getLocaleCode();
if (Boolean.FALSE.equals(locale.getUseCountryInSearchIndex())) {
int pos = localeCode.indexOf("_");
if (pos > 0) {
localeCode = localeCode.substring(0, pos);
if (processedLocaleCodes.contains(localeCode)) {
continue;
} else {
locale = localeService.findLocaleByCode(localeCode);
}
}
}
processedLocaleCodes.add(localeCode);
tempContext.setLocale(locale);
Object propertyValue = shs.getPropertyValue(indexable, propertyName);
values.put(localeCode, propertyValue);
}
} finally {
// Reset the original locale.
tempContext.setLocale(originalLocale);
}
}
return result;
}
use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.
the class I18nSolrIndexServiceExtensionHandler method getLocalePrefix.
/**
* If the field is translatable, take the current locale and add that as a prefix.
* @param context
* @param field
* @return
*/
protected ExtensionResultStatusType getLocalePrefix(Field field, List<String> prefixList) {
if (field.getTranslatable()) {
if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
if (locale != null) {
String localeCode = locale.getLocaleCode();
if (!Boolean.TRUE.equals(locale.getUseCountryInSearchIndex())) {
int pos = localeCode.indexOf("_");
if (pos > 0) {
localeCode = localeCode.substring(0, pos);
}
}
prefixList.add(localeCode);
return ExtensionResultStatusType.HANDLED_CONTINUE;
}
}
}
return ExtensionResultStatusType.NOT_HANDLED;
}
Aggregations