我是Sap Hybris的初学者。我创建了一个完美的CronJob。它返回所有状态已批准的产品,并在本地C:// ...
中生成CSV文件但我想在HMC MEDIA中创建或转换我的CSV文件到媒体?有人能帮助我吗?
我已经通过了Hybris维基,但我不明白。
感谢大家!
答案 0 :(得分:3)
要实现此目的,您只需创建Media对象,并将文件附加到创建的对象,如:
private MediaModel createMedia(final File file) throws MediaIOException, IllegalArgumentException, FileNotFoundException
{
final CatalogVersionModel catalogVersion = catalogVersionService.getCatalogVersion("MY_MEDIA_CATALOG", "VERSION");
MediaModel mediaModel;
try
{
mediaModel = mediaService.getMedia(catalogVersion, file.getName());
}
catch (final UnknownIdentifierException e)
{
mediaModel = modelService.create(MediaModel.class);
}
mediaModel.setCode(file.getName());
mediaModel.setCatalogVersion(catalogVersion);
mediaModel.setMime("text/csv");
mediaModel.setRealFileName(file.getName());
modelService.save(mediaModel);
mediaService.setStreamForMedia(mediaModel, new FileInputStream(file));
//Remove file
FileUtils.removeFile(file);
return mediaModel;
}