in src/main/java/com/netflix/imflibrary/writerTools/IMPBuilder.java [125:259]
public static List<ErrorLogger.ErrorObject> buildIMPWithoutCreatingNewCPL_2013(@Nonnull String annotationText,
@Nonnull String issuer,
@Nonnull List<? extends Composition.VirtualTrack> virtualTracks,
@Nonnull String applicationId,
@Nonnull Map<UUID, IMFTrackFileInfo> trackFileInfoMap,
@Nonnull File workingDirectory,
@Nonnull File cplFile) throws IOException, ParserConfigurationException, SAXException, JAXBException, URISyntaxException {
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
int numErrors = imfErrorLogger.getNumberOfErrors();
Set<String> applicationIds = Collections.singleton(applicationId);
String coreConstraintsSchema = CoreConstraints.fromApplicationId(applicationIds);
if (coreConstraintsSchema == null)
coreConstraintsSchema = CoreConstraints.NAMESPACE_IMF_2013;
Composition.VirtualTrack mainImageVirtualTrack = null;
for(Composition.VirtualTrack virtualTrack : virtualTracks){
if(virtualTrack.getSequenceTypeEnum() == Composition.SequenceTypeEnum.MainImageSequence){
mainImageVirtualTrack = virtualTrack;
break;
}
}
if(mainImageVirtualTrack == null){
throw new IMFAuthoringException(String.format("Exactly 1 MainImageSequence virtual track is required to create an IMP, none present"));
}
/* No need to build a new CPL because we already have it in cplFile */
if(!cplFile.exists()){
throw new IMFAuthoringException(String.format("CompositionPlaylist file does not exist, cannot generate the rest of the documents"));
}
byte[] cplHash = IMFUtils.generateSHA1Hash(cplFile);
/**
* Build the PackingList
*/
UUID pklUUID = IMFUUIDGenerator.getInstance().generateUUID();
PackingListBuilder packingListBuilder = new PackingListBuilder(pklUUID,
IMFUtils.createXMLGregorianCalendar(),
workingDirectory,
imfErrorLogger);
org.smpte_ra.schemas._429_8._2007.pkl.UserText pklAnnotationText = PackingListBuilder.buildPKLUserTextType_2007(annotationText, "en");
org.smpte_ra.schemas._429_8._2007.pkl.UserText creator = PackingListBuilder.buildPKLUserTextType_2007("Photon PackingListBuilder", "en");
org.smpte_ra.schemas._429_8._2007.pkl.UserText pklIssuer = PackingListBuilder.buildPKLUserTextType_2007(issuer, "en");
List<PackingListBuilder.PackingListBuilderAsset_2007> packingListBuilderAssets = new ArrayList<>();
/**
* Build the CPL asset to be entered into the PackingList
*/
UUID cplUUID = IMFUtils.extractUUIDFromCPLFile(cplFile, imfErrorLogger);
PackingListBuilder.PackingListBuilderAsset_2007 cplAsset =
new PackingListBuilder.PackingListBuilderAsset_2007(cplUUID,
PackingListBuilder.buildPKLUserTextType_2007(annotationText, "en"),
Arrays.copyOf(cplHash, cplHash.length),
cplFile.length(),
PackingListBuilder.PKLAssetTypeEnum.TEXT_XML,
PackingListBuilder.buildPKLUserTextType_2007(cplFile.getName(), "en"));
packingListBuilderAssets.add(cplAsset);
Set<Map.Entry<UUID, IMFTrackFileInfo>> trackFileMetadataEntriesSet = trackFileInfoMap.entrySet().stream().filter( e -> !(e.getValue().isExcludeFromPackage())).collect(Collectors.toSet());
for(Map.Entry<UUID, IMFTrackFileInfo> entry : trackFileMetadataEntriesSet){
PackingListBuilder.PackingListBuilderAsset_2007 asset =
new PackingListBuilder.PackingListBuilderAsset_2007(entry.getKey(),
PackingListBuilder.buildPKLUserTextType_2007(annotationText, "en"),
Arrays.copyOf(entry.getValue().getHash(), entry.getValue().getHash().length),
entry.getValue().getLength(),
PackingListBuilder.PKLAssetTypeEnum.APP_MXF,
PackingListBuilder.buildPKLUserTextType_2007(entry.getValue().getOriginalFileName(), "en"));
packingListBuilderAssets.add(asset);
}
imfErrorLogger.addAllErrors(packingListBuilder.buildPackingList_2007(pklAnnotationText, pklIssuer, creator,
packingListBuilderAssets));
imfErrorLogger.addAllErrors(packingListBuilder.getErrors());
if(imfErrorLogger.getErrors(IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, numErrors, imfErrorLogger.getNumberOfErrors()).size() > 0){
throw new IMFAuthoringException(String.format("Fatal errors occurred while generating the PackingList. Please see following error messages %s", Utilities.serializeObjectCollectionToString(imfErrorLogger.getErrors(IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, numErrors, imfErrorLogger.getNumberOfErrors()))));
}
numErrors = (imfErrorLogger.getNumberOfErrors() > 0) ? imfErrorLogger.getNumberOfErrors()-1 : 0;
File pklFile = new File(workingDirectory + File.separator + packingListBuilder.getPKLFileName());
if(!pklFile.exists()){
throw new IMFAuthoringException(String.format("PackingList file does not exist in the working directory %s, cannot generate the rest of the documents", workingDirectory.getAbsolutePath
()));
}
/**
* Build the AssetMap
*/
UUID assetMapUUID = IMFUUIDGenerator.getInstance().generateUUID();
List<AssetMapBuilder.Asset> assetMapAssets = new ArrayList<>();
for(PackingListBuilder.PackingListBuilderAsset_2007 pklAsset : packingListBuilderAssets){
AssetMapBuilder.Chunk chunk = new AssetMapBuilder.Chunk(pklAsset.getOriginalFileName().getValue(), pklAsset.getSize().longValue());
List<AssetMapBuilder.Chunk> chunkList = new ArrayList<>();
chunkList.add(chunk);
AssetMapBuilder.Asset amAsset = new AssetMapBuilder.Asset(UUIDHelper.fromUUIDAsURNStringToUUID(pklAsset.getUUID()),
AssetMapBuilder.buildAssetMapUserTextType_2007(pklAsset.getAnnotationText().getValue(), "en"),
false,
chunkList);
assetMapAssets.add(amAsset);
}
//Add the PKL as an AssetMap asset
List<AssetMapBuilder.Chunk> chunkList = new ArrayList<>();
AssetMapBuilder.Chunk chunk = new AssetMapBuilder.Chunk(pklFile.getName(), pklFile.length());
chunkList.add(chunk);
AssetMapBuilder.Asset amAsset = new AssetMapBuilder.Asset(pklUUID,
AssetMapBuilder.buildAssetMapUserTextType_2007(pklAnnotationText.getValue(), "en"),
true,
chunkList);
assetMapAssets.add(amAsset);
AssetMapBuilder assetMapBuilder = new AssetMapBuilder(assetMapUUID,
AssetMapBuilder.buildAssetMapUserTextType_2007(annotationText, "en"),
AssetMapBuilder.buildAssetMapUserTextType_2007("Photon AssetMapBuilder", "en"),
IMFUtils.createXMLGregorianCalendar(),
AssetMapBuilder.buildAssetMapUserTextType_2007(issuer, "en"),
assetMapAssets,
workingDirectory,
imfErrorLogger);
assetMapBuilder.build();
if(imfErrorLogger.getErrors(IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, numErrors, imfErrorLogger.getNumberOfErrors()).size() > 0){
throw new IMFAuthoringException(String.format("Fatal errors occurred while generating the AssetMap. Please see following error messages %s",
Utilities.serializeObjectCollectionToString(imfErrorLogger.getErrors(IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, numErrors, imfErrorLogger.getNumberOfErrors()))));
}
File assetMapFile = new File(workingDirectory + File.separator + assetMapBuilder.getAssetMapFileName());
if(!assetMapFile.exists()){
throw new IMFAuthoringException(String.format("AssetMap file does not exist in the working directory %s", workingDirectory.getAbsolutePath
()));
}
return imfErrorLogger.getErrors();
}