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());
}
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;
}
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;
}
Aggregations