@Test public void testLocalizedAssetAttribute() { final ProductModel product = new ProductModel(); product.setCode("productCode"); final ComposedTypeModel composedType = new ComposedTypeModel(); final MetaAttributeData metaAttribute = new MetaAttributeData(); metaAttribute.setBaseType(FhAttributeBaseType.ASSET); metaAttribute.setAttributeId("description"); metaAttribute.setQualifier("description"); when(typeService.getComposedTypeForClass(product.getClass())).thenReturn(composedType); when(Boolean.valueOf(typeService.hasAttribute(composedType, "description"))).thenReturn(Boolean.TRUE); final Collection<Locale> locales = Arrays.asList(Locale.US); when(modelService.getAttributeValue(product, "description")).thenReturn("HUUUGE"); final Collection<FhAttributeData> attributeDatas = simpleAttributeProvider.getAttribute(product, metaAttribute, locales); verify(i18nService, atLeastOnce()).setCurrentLocale(Locale.US); assertNotNull(attributeDatas); assertEquals(1, attributeDatas.size()); final FhAttributeData attributeData = attributeDatas.iterator().next(); assertEquals("productCode", attributeData.getItemId()); assertEquals("description", attributeData.getAttributeId()); assertEquals(FhAttributeBaseType.ASSET, attributeData.getBaseType()); final Table<Optional<String>, Optional<Locale>, String> values = attributeData.getValues(); assertNotNull(values); assertEquals(1, values.size()); final String description = values.get(Optional.empty(), Optional.of(Locale.US)); assertEquals("HUUUGE", description); }
@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 String qualifier = metaAttribute.getQualifier(); final ComposedTypeModel composedType = typeService.getComposedTypeForClass(product.getClass()); if (typeService.hasAttribute(composedType, qualifier)) { if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { final Object value = getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public Object execute() { getI18nService().setCurrentLocale(locale); return getAttributeValue(product, qualifier); } }); addValues(table, locale, value, metaAttribute); } } else { final Object value = modelService.getAttributeValue(product, qualifier); addValues(table, null, value, metaAttribute); } } return table; }
SimpleAttributeProvider 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 String qualifier = metaAttribute.getQualifier(); final ComposedTypeModel composedType = typeService.getComposedTypeForClass(product.getClass()); if (typeService.hasAttribute(composedType, qualifier)) { if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { final Object value = getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public Object execute() { getI18nService().setCurrentLocale(locale); return getAttributeValue(product, qualifier); } }); addValues(table, locale, value, metaAttribute); } } else { final Object value = modelService.getAttributeValue(product, qualifier); addValues(table, null, value, metaAttribute); } } return table; } }
SimpleAttributeProvider 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 String qualifier = metaAttribute.getQualifier(); final ComposedTypeModel composedType = typeService.getComposedTypeForClass(product.getClass()); if (typeService.hasAttribute(composedType, qualifier)) { if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { final Object value = getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public Object execute() { getI18nService().setCurrentLocale(locale); return getAttributeValue(product, qualifier); } }); addValues(table, locale, value, metaAttribute); } } else { final Object value = modelService.getAttributeValue(product, qualifier); addValues(table, null, value, metaAttribute); } } return table; }  }
SimpleAttributeProvider 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 String qualifier = metaAttribute.getQualifier(); final ComposedTypeModel composedType = typeService.getComposedTypeForClass(product.getClass()); if (typeService.hasAttribute(composedType, qualifier)) { if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { final Object value = getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public Object execute() { getI18nService().setCurrentLocale(locale); return getAttributeValue(product, qualifier); } }); addValues(table, locale, value, metaAttribute); } } else { final Object value = modelService.getAttributeValue(product, qualifier); addValues(table, null, value, metaAttribute); } } return table; }  ModelService getModelService(); @Required void setModelService(final ModelService modelService); SessionService getSessionService(); @Required void setSessionService(final SessionService sessionService); TypeService getTypeService(); @Required void setTypeService(final TypeService typeService); VariantsService getVariantsService(); @Required void setVariantsService(final VariantsService variantsService); I18NService getI18nService(); @Required void setI18nService(final I18NService i18nService); }
SimpleAttributeProvider 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 String qualifier = metaAttribute.getQualifier(); final ComposedTypeModel composedType = typeService.getComposedTypeForClass(product.getClass()); if (typeService.hasAttribute(composedType, qualifier)) { if (CollectionUtils.isNotEmpty(locales) && isLocalizedAttribute(metaAttribute)) { for (final Locale locale : locales) { final Object value = getSessionService().executeInLocalView(new SessionExecutionBody() { @Override public Object execute() { getI18nService().setCurrentLocale(locale); return getAttributeValue(product, qualifier); } }); addValues(table, locale, value, metaAttribute); } } else { final Object value = modelService.getAttributeValue(product, qualifier); addValues(table, null, value, metaAttribute); } } return table; }  ModelService getModelService(); @Required void setModelService(final ModelService modelService); SessionService getSessionService(); @Required void setSessionService(final SessionService sessionService); TypeService getTypeService(); @Required void setTypeService(final TypeService typeService); VariantsService getVariantsService(); @Required void setVariantsService(final VariantsService variantsService); I18NService getI18nService(); @Required void setI18nService(final I18NService i18nService);  }