use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method deleteTranslation.
/**
* Deletes the translation specified by the translation id
*
* @param request
* @param response
* @param model
* @param id
* @param form
* @param result
* @return the result of a call to {@link #viewTranslation}, which renders the list grid
* @throws Exception
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") final TranslationForm form, BindingResult result) throws Exception {
adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
SectionCrumb sectionCrumb = new SectionCrumb();
sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.OTHER);
entityForm.setCeilingEntityClassname(Translation.class.getName());
entityForm.setEntityType(TranslationImpl.class.getName());
Field id = new Field();
id.setName("id");
id.setValue(String.valueOf(form.getTranslationId()));
entityForm.getFields().put("id", id);
entityForm.setId(String.valueOf(form.getTranslationId()));
String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
service.removeEntity(entityForm, sectionCriteria, sectionCrumbs);
return viewTranslation(request, response, model, form, result);
}
use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method showUpdateTranslation.
@RequestMapping(value = "/update", method = RequestMethod.GET)
public String showUpdateTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = new ArrayList<>();
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH);
Translation t = translationService.findTranslationById(form.getTranslationId());
form.setTranslatedValue(t.getTranslatedValue());
EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.UPDATE);
entityForm.setId(String.valueOf(form.getTranslationId()));
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/translationAdd");
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_TRANSLATION.getType());
return "modules/modalContainer";
}
use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method updateTranslation.
/**
* Updates the given translation id to the new locale code and translated value
*
* @param request
* @param response
* @param model
* @param entityForm
* @param result
* @return the result of a call to {@link #viewTranslation}, which renders the list grid
* @throws Exception
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
final TranslationForm form = getTranslationForm(entityForm);
adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
SectionCrumb sectionCrumb = new SectionCrumb();
sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
entityForm.setCeilingEntityClassname(Translation.class.getName());
entityForm.setEntityType(TranslationImpl.class.getName());
Field id = new Field();
id.setName("id");
id.setValue(String.valueOf(form.getTranslationId()));
entityForm.getFields().put("id", id);
entityForm.setId(String.valueOf(form.getTranslationId()));
String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
service.updateEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
return viewTranslation(request, response, model, form, result);
}
use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method viewTranslation.
/**
* Invoked when the translation button is clicked on a given translatable field
*
* @param request
* @param response
* @param model
* @param form
* @param result
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception {
if (extensionManager != null) {
extensionManager.getProxy().applyTransformation(form);
}
adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH);
List<Translation> translations = translationService.getTranslations(form.getCeilingEntity(), form.getEntityId(), form.getPropertyName());
ListGrid lg = formService.buildListGrid(translations, form.getIsRte());
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("form", form);
model.addAttribute("listGrid", lg);
model.addAttribute("viewType", "modal/translationListGrid");
model.addAttribute("modalHeaderType", ModalHeaderType.TRANSLATION.getType());
return "modules/modalContainer";
}
use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.
the class ThresholdCacheTranslationOverrideStrategy method getLocaleBasedOverride.
@Override
public LocalePair getLocaleBasedOverride(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String basicCacheKey) {
String specificPropertyKey = property + "_" + localeCountryCode;
String generalPropertyKey = property + "_" + localeCode;
Element cacheResult = translationSupport.getCache().get(basicCacheKey);
Element result;
LocalePair response = new LocalePair();
if (cacheResult == null) {
statisticsService.addCacheStat(CacheStatType.TRANSLATION_CACHE_HIT_RATE.toString(), false);
if (dao.countTranslationEntries(entityType, ResultType.STANDARD_CACHE) < translationSupport.getThresholdForFullCache()) {
Map<String, Map<String, StandardCacheItem>> propertyTranslationMap = new HashMap<String, Map<String, StandardCacheItem>>();
List<StandardCacheItem> convertedList = dao.readConvertedTranslationEntries(entityType, ResultType.STANDARD_CACHE);
if (!CollectionUtils.isEmpty(convertedList)) {
for (StandardCacheItem standardCache : convertedList) {
Translation translation = (Translation) standardCache.getCacheItem();
String key = translation.getFieldName() + "_" + translation.getLocaleCode();
if (!propertyTranslationMap.containsKey(key)) {
propertyTranslationMap.put(key, new HashMap<String, StandardCacheItem>());
}
propertyTranslationMap.get(key).put(translation.getEntityId(), standardCache);
}
}
Element newElement = new Element(basicCacheKey, propertyTranslationMap);
translationSupport.getCache().put(newElement);
result = newElement;
} else {
// Translation is dual discriminated by site and catalog, which can make it impossible to find results under normal
// circumstances because the two discriminators can cancel eachother out. We use the CATALOG_ONLY ResultType
// to force the system to only honor the catalog discrimination during this call.
Translation translation = dao.readTranslation(entityType, entityId, property, localeCode, localeCountryCode, ResultType.CATALOG_ONLY);
buildSingleItemResponse(response, translation);
return response;
}
} else {
result = cacheResult;
statisticsService.addCacheStat(CacheStatType.TRANSLATION_CACHE_HIT_RATE.toString(), true);
}
Map<String, Map<String, StandardCacheItem>> propertyTranslationMap = (Map<String, Map<String, StandardCacheItem>>) result.getObjectValue();
// Check For a Specific Standard Site Match (language and country)
StandardCacheItem specificTranslation = translationSupport.lookupTranslationFromMap(specificPropertyKey, propertyTranslationMap, entityId);
// Check For a General Match (language and country)
StandardCacheItem generalTranslation = translationSupport.lookupTranslationFromMap(generalPropertyKey, propertyTranslationMap, entityId);
response.setSpecificItem(specificTranslation);
response.setGeneralItem(generalTranslation);
return response;
}
Aggregations