如何在 hybris 中获取现有的 MediaContainerModel?
How to get an existing MediaContainerModel in hybris?
我尝试在 MediaService
的帮助下获取 MediaFormatModel, MediaModel, MediaFolderModel
等,但只有 MediaContainer
无法从 MediaService
获取,我尝试使用 ModelService
.只有一种可能性我发现通过获取 MediaModel
我们可以获得 MediaContainerModel
但我需要通过传递限定符来获取特定的 MediaContainerModel
。例如:
final MediaModel mm1 = mediaService.getMedia(catalogVersion, "picture515x515");
final MediaFormatModel mf1200 = mediaService.getFormat("1200x1200");
final MediaFolderModel mfm = mediaService.getFolder("convertedimages");
有什么帮助吗?
您始终可以使用 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)
{
...
}
我得到的解决方案如下
@Autowired
MediaContainerService mediaContainerService;
......
MediaContainerModel mediaContainer = null;
尝试
{
mediaContainer =
mediaContainerService.getMediaContainerForQualifier("testContainer");
}
捕获(最终异常 e)
{
mediaContainer = createMediaContainer("testContainer");
}
mediaContainer.setCatalogVersion(目录版本);
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;
}
}
我尝试在 MediaService
的帮助下获取 MediaFormatModel, MediaModel, MediaFolderModel
等,但只有 MediaContainer
无法从 MediaService
获取,我尝试使用 ModelService
.只有一种可能性我发现通过获取 MediaModel
我们可以获得 MediaContainerModel
但我需要通过传递限定符来获取特定的 MediaContainerModel
。例如:
final MediaModel mm1 = mediaService.getMedia(catalogVersion, "picture515x515");
final MediaFormatModel mf1200 = mediaService.getFormat("1200x1200");
final MediaFolderModel mfm = mediaService.getFolder("convertedimages");
有什么帮助吗?
您始终可以使用 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)
{
...
}
我得到的解决方案如下
@Autowired
MediaContainerService mediaContainerService;
......
MediaContainerModel mediaContainer = null;
尝试
{
mediaContainer =
mediaContainerService.getMediaContainerForQualifier("testContainer");
}
捕获(最终异常 e)
{
mediaContainer = createMediaContainer("testContainer");
}
mediaContainer.setCatalogVersion(目录版本);
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;
}
}