如何在hybris中获得现有的MediaContainerModel?

时间:2015-05-16 07:34:29

标签: hybris

我试图在 MediaService 的帮助下获取 MediaFormatModel,MediaModel,MediaFolderModel 等,但只有MediaContainer无法从MediaService获取,我尝试使用ModelService。我发现只有一种可能性,通过获取MediaModel,我们可以获得MediaContainerModel,但我需要通过传递限定符来获取特定的MediaContainerModel。
例如

最终MediaModel mm1 = mediaService.getMedia(catalogVersion,“picture515x515”);
最终MediaFormatModel mf1200 = mediaService.getFormat(“1200x1200”);
final MediaFolderModel mfm = mediaService.getFolder(“convertedimages”);

任何帮助?

3 个答案:

答案 0 :(得分:1)

您始终可以使用 flexiblesearh getModelByExample

检索模型
CatalogVersionModel catalogVersion = catalogVersionService.getCatalogVersion("yourCatalogName", "version");

MediaContainerModel container = new MediaContainerModel();
container.setCatalogVersion(catalogVersion);
container.setQualifier("yourQualifier");
try
{
    container = flexibleSearchService.getModelByExample(container);
}//no container found
catch (final ModelNotFoundException ex)
{
   ...
}

答案 1 :(得分:1)

     private MediaContainerModel getExistingMediaContainer(CatalogVersionModel catalogVersion, String qualifier) {
    final String query = "SELECT {" + MediaContainerModel.PK + "} FROM {" + MediaContainerModel._TYPECODE + "} "
            + "WHERE {" + MediaContainerModel.QUALIFIER + "} = ?qualifier AND " + "{" + MediaContainerModel.CATALOGVERSION + "} = ?catalogVersion";
    final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(query);
    fQuery.addQueryParameter("qualifier", qualifier);
    fQuery.addQueryParameter("catalogVersion", catalogVersion);
    final SearchResult<MediaContainerModel> searchResult = flexibleSearchService.search(fQuery);
    if (searchResult.getTotalCount() > 0) {
        return searchResult.getResult().get(0);
    } else {
        return null;
    }
}

答案 2 :(得分:0)

我得到了我们可以得到的解决方案

@Autowired
    MediaContainerService mediaContainerService;

......

MediaContainerModel mediaContainer = null;
            尝试
            {
                mediaContainer =
mediaContainerService.getMediaContainerForQualifier(&#34; testContainer&#34;);             }
            catch(最终例外e)
            {
                mediaContainer = createMediaContainer(&#34; testContainer&#34;);
            }
            mediaContainer.setCatalogVersion(catalogVersion);