Search in sources :

Example 6 with StandardCacheItem

use of org.broadleafcommerce.common.extension.StandardCacheItem in project BroadleafCommerce by BroadleafCommerce.

the class TranslationServiceImpl method getTemplateTranslatedValue.

protected String getTemplateTranslatedValue(String standardCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) {
    String cacheKey = getCacheKey(ResultType.TEMPLATE, entityType);
    StandardCacheItem translation = null;
    LocalePair override = null;
    for (TranslationOverrideStrategy strategy : strategies) {
        override = strategy.getLocaleBasedTemplateValue(cacheKey, property, entityType, entityId, localeCode, localeCountryCode, specificPropertyKey, generalPropertyKey);
        if (override != null) {
            translation = override.getSpecificItem();
            if (!strategy.validateTemplateProcessing(standardCacheKey, cacheKey)) {
                return null;
            }
            break;
        }
    }
    if (override == null) {
        throw new IllegalStateException("Expected at least one TranslationOverrideStrategy to return a valid value");
    }
    return translation == null ? null : replaceEmptyWithNullResponse(((Translation) translation.getCacheItem()).getTranslatedValue());
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) StandardCacheItem(org.broadleafcommerce.common.extension.StandardCacheItem)

Example 7 with StandardCacheItem

use of org.broadleafcommerce.common.extension.StandardCacheItem in project BroadleafCommerce by BroadleafCommerce.

the class TranslationServiceImpl method lookupTranslationFromMap.

@Override
public StandardCacheItem lookupTranslationFromMap(String key, Map<String, Map<String, StandardCacheItem>> propertyTranslationMap, String entityId) {
    StandardCacheItem cacheItem = null;
    if (propertyTranslationMap.containsKey(key)) {
        Map<String, StandardCacheItem> byEntity = propertyTranslationMap.get(key);
        cacheItem = byEntity.get(entityId);
    }
    return cacheItem;
}
Also used : StandardCacheItem(org.broadleafcommerce.common.extension.StandardCacheItem)

Example 8 with StandardCacheItem

use of org.broadleafcommerce.common.extension.StandardCacheItem in project BroadleafCommerce by BroadleafCommerce.

the class TranslationServiceImpl method getOverrideTranslatedValue.

protected String getOverrideTranslatedValue(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode) {
    boolean specificTranslationDeleted = false;
    boolean generalTranslationDeleted = false;
    StandardCacheItem specificTranslation = null;
    StandardCacheItem generalTranslation = null;
    String specificPropertyKey = property + "_" + localeCountryCode;
    String generalPropertyKey = property + "_" + localeCode;
    String response = null;
    String cacheKey = getCacheKey(ResultType.STANDARD, entityType);
    LocalePair override = null;
    for (TranslationOverrideStrategy strategy : strategies) {
        override = strategy.getLocaleBasedOverride(property, entityType, entityId, localeCode, localeCountryCode, cacheKey);
        if (override != null) {
            specificTranslation = override.getSpecificItem();
            generalTranslation = override.getGeneralItem();
            break;
        }
    }
    if (override == null) {
        throw new IllegalStateException("Expected at least one TranslationOverrideStrategy to return a valid value");
    }
    if (specificTranslation != null) {
        if (ItemStatus.DELETED.equals(specificTranslation.getItemStatus())) {
            specificTranslationDeleted = true;
        } else {
            if (specificTranslation.getCacheItem() instanceof Translation) {
                response = ((Translation) specificTranslation.getCacheItem()).getTranslatedValue();
            } else {
                response = (String) specificTranslation.getCacheItem();
            }
            return replaceEmptyWithNullResponse(response);
        }
    }
    if (generalTranslation != null) {
        if (ItemStatus.DELETED.equals(generalTranslation.getItemStatus())) {
            generalTranslationDeleted = true;
            // If the general translation is override deleted and we've only got a general local code - we're done
            if (specificTranslationDeleted || !localeCountryCode.contains("_")) {
                return null;
            }
        } else {
            if (generalTranslation.getCacheItem() instanceof Translation) {
                response = ((Translation) generalTranslation.getCacheItem()).getTranslatedValue();
            } else {
                response = (String) generalTranslation.getCacheItem();
            }
            // If the general translation is override and we've only got a general local code - we're done
            if (specificTranslationDeleted || !localeCountryCode.contains("_")) {
                return replaceEmptyWithNullResponse(response);
            }
            // We have a valid general override - don't check for general template value
            generalTranslationDeleted = true;
        }
    }
    // Check for a Template Match
    if (specificTranslationDeleted) {
        // only check general properties since we explicitly deleted specific properties at standard (site) level
        specificPropertyKey = generalPropertyKey;
    } else if (generalTranslationDeleted) {
        // only check specific properties since we explicitly deleted general properties at standard (site) level
        generalPropertyKey = specificPropertyKey;
    }
    String templateResponse = getTemplateTranslatedValue(cacheKey, property, entityType, entityId, localeCode, localeCountryCode, specificPropertyKey, generalPropertyKey);
    if (templateResponse != null) {
        response = templateResponse;
    }
    return response;
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) StandardCacheItem(org.broadleafcommerce.common.extension.StandardCacheItem)

Aggregations

StandardCacheItem (org.broadleafcommerce.common.extension.StandardCacheItem)8 Translation (org.broadleafcommerce.common.i18n.domain.Translation)6 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Element (net.sf.ehcache.Element)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 ItemStatus (org.broadleafcommerce.common.extension.ItemStatus)1 Site (org.broadleafcommerce.common.site.domain.Site)1