Search in sources :

Example 1 with Translation

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);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Translation

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";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Translation(org.broadleafcommerce.common.i18n.domain.Translation) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Translation

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);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) TranslationForm(org.broadleafcommerce.openadmin.web.form.TranslationForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Translation

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";
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Translation

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;
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) HashMap(java.util.HashMap) Element(net.sf.ehcache.Element) StandardCacheItem(org.broadleafcommerce.common.extension.StandardCacheItem) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Translation (org.broadleafcommerce.common.i18n.domain.Translation)26 TranslationImpl (org.broadleafcommerce.common.i18n.domain.TranslationImpl)8 ArrayList (java.util.ArrayList)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 StandardCacheItem (org.broadleafcommerce.common.extension.StandardCacheItem)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Element (net.sf.ehcache.Element)4 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)4 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)4 Predicate (javax.persistence.criteria.Predicate)3 TranslatedEntity (org.broadleafcommerce.common.i18n.domain.TranslatedEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)2 TranslationForm (org.broadleafcommerce.openadmin.web.form.TranslationForm)2