@Test public void testGetLocalizedCategory() { final ProductModel product = new ProductModel(); product.setCode("productCode"); final MetaAttributeData metaAttribute = new MetaAttributeData(); metaAttribute.setBaseType(FhAttributeBaseType.SET); metaAttribute.setAttributeId("category"); final CategoryModel category1 = new CategoryModel(); category1.setCode("cat1"); final CategoryModel category2 = new CategoryModel(); category2.setCode("cat2"); final CategoryModel category3 = new CategoryModel(); category3.setCode("cat3"); final Collection<Locale> locales = Arrays.asList(Locale.ENGLISH, Locale.JAPANESE); final Collection<CategoryModel> categoryCollection = Arrays.asList(category1, category2, category3); when(fhCategorySource.findCategoriesForProduct(product)).thenReturn(categoryCollection); when(modelService.getAttributeValue(category1, "code")).thenReturn(category1); when(modelService.getAttributeValue(category2, "code")).thenReturn(category2); when(modelService.getAttributeValue(category3, "code")).thenReturn(category3); when(sanitizeIdStrategy.sanitizeIdWithNumber(category1.toString())).thenReturn("cat_test1"); when(sanitizeIdStrategy.sanitizeIdWithNumber(category2.toString())).thenReturn("cat_test2"); when(sanitizeIdStrategy.sanitizeIdWithNumber(category3.toString())).thenReturn("cat_test3"); final Collection<FhAttributeData> fhAttributeData = categoryCodeProvider.getAttribute(product, metaAttribute, locales); assertNotNull(fhAttributeData); assertEquals(1, fhAttributeData.size()); }
@Override protected HashBasedTable<Optional<String>, Optional<Locale>, String> getAttributeValue(final Collection<Locale> locales, final ProductModel product, final MetaAttributeData metaAttribute) { final HashBasedTable<Optional<String>, Optional<Locale>, String> table = HashBasedTable.create(); final Collection<CategoryModel> categories = getCategorySource().findCategoriesForProduct(product); if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public void executeWithoutResult() { getI18nService().setCurrentLocale(locale); for (final CategoryModel category : categories) { addValues(table, locale, getPropertyValue(category), metaAttribute); } } }); } } else { for (final CategoryModel category : categories) { addValues(table, null, getPropertyValue(category), metaAttribute); } } return table; }
CategoryCodeProvider extends AbstractAttributeProvider { @Override protected HashBasedTable<Optional<String>, Optional<Locale>, String> getAttributeValue(final Collection<Locale> locales, final ProductModel product, final MetaAttributeData metaAttribute) { final HashBasedTable<Optional<String>, Optional<Locale>, String> table = HashBasedTable.create(); final Collection<CategoryModel> categories = getCategorySource().findCategoriesForProduct(product); if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public void executeWithoutResult() { getI18nService().setCurrentLocale(locale); for (final CategoryModel category : categories) { addValues(table, locale, getPropertyValue(category), metaAttribute); } } }); } } else { for (final CategoryModel category : categories) { addValues(table, null, getPropertyValue(category), metaAttribute); } } return table; } }
CategoryCodeProvider extends AbstractAttributeProvider { @Override protected HashBasedTable<Optional<String>, Optional<Locale>, String> getAttributeValue(final Collection<Locale> locales, final ProductModel product, final MetaAttributeData metaAttribute) { final HashBasedTable<Optional<String>, Optional<Locale>, String> table = HashBasedTable.create(); final Collection<CategoryModel> categories = getCategorySource().findCategoriesForProduct(product); if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public void executeWithoutResult() { getI18nService().setCurrentLocale(locale); for (final CategoryModel category : categories) { addValues(table, locale, getPropertyValue(category), metaAttribute); } } }); } } else { for (final CategoryModel category : categories) { addValues(table, null, getPropertyValue(category), metaAttribute); } } return table; }  }
CategoryCodeProvider extends AbstractAttributeProvider { @Override protected HashBasedTable<Optional<String>, Optional<Locale>, String> getAttributeValue(final Collection<Locale> locales, final ProductModel product, final MetaAttributeData metaAttribute) { final HashBasedTable<Optional<String>, Optional<Locale>, String> table = HashBasedTable.create(); final Collection<CategoryModel> categories = getCategorySource().findCategoriesForProduct(product); if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public void executeWithoutResult() { getI18nService().setCurrentLocale(locale); for (final CategoryModel category : categories) { addValues(table, locale, getPropertyValue(category), metaAttribute); } } }); } } else { for (final CategoryModel category : categories) { addValues(table, null, getPropertyValue(category), metaAttribute); } } return table; }  FhCategorySource getCategorySource(); void setCategorySource(final FhCategorySource categorySource); ModelService getModelService(); void setModelService(final ModelService modelService); SessionService getSessionService(); void setSessionService(final SessionService sessionService); I18NService getI18nService(); void setI18nService(final I18NService i18nService); }
CategoryCodeProvider extends AbstractAttributeProvider { @Override protected HashBasedTable<Optional<String>, Optional<Locale>, String> getAttributeValue(final Collection<Locale> locales, final ProductModel product, final MetaAttributeData metaAttribute) { final HashBasedTable<Optional<String>, Optional<Locale>, String> table = HashBasedTable.create(); final Collection<CategoryModel> categories = getCategorySource().findCategoriesForProduct(product); if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public void executeWithoutResult() { getI18nService().setCurrentLocale(locale); for (final CategoryModel category : categories) { addValues(table, locale, getPropertyValue(category), metaAttribute); } } }); } } else { for (final CategoryModel category : categories) { addValues(table, null, getPropertyValue(category), metaAttribute); } } return table; }  FhCategorySource getCategorySource(); void setCategorySource(final FhCategorySource categorySource); ModelService getModelService(); void setModelService(final ModelService modelService); SessionService getSessionService(); void setSessionService(final SessionService sessionService); I18NService getI18nService(); void setI18nService(final I18NService i18nService);  }