public List buildPackingList_2016()

in src/main/java/com/netflix/imflibrary/writerTools/PackingListBuilder.java [410:491]


    public List<ErrorLogger.ErrorObject> buildPackingList_2016(@Nonnull org.smpte_ra.schemas._2067_2._2016.pkl.UserText annotationText,
                                                         @Nonnull org.smpte_ra.schemas._2067_2._2016.pkl.UserText issuer,
                                                         @Nonnull org.smpte_ra.schemas._2067_2._2016.pkl.UserText creator,
                                                         @Nonnull List<PackingListBuilderAsset_2016> assets) throws IOException, SAXException, JAXBException {

        int numErrors = imfErrorLogger.getNumberOfErrors();
        org.smpte_ra.schemas._2067_2._2016.pkl.PackingListType packingListType = IMFPKLObjectFieldsFactory.constructPackingListType_2016();
        packingListType.setId(UUIDHelper.fromUUID(this.uuid));
        packingListType.setIconId(this.iconId);
        packingListType.setAnnotationText(annotationText);
        packingListType.setIssueDate(this.issueDate);
        packingListType.setIssuer(issuer);
        packingListType.setCreator(creator);
        packingListType.setGroupId(this.groupId);
        org.smpte_ra.schemas._2067_2._2016.pkl.PackingListType.AssetList assetList = new org.smpte_ra.schemas._2067_2._2016.pkl.PackingListType.AssetList();
        List<org.smpte_ra.schemas._2067_2._2016.pkl.AssetType> packingListAssets = assetList.getAsset();
        for(PackingListBuilderAsset_2016 asset : assets){
            org.smpte_ra.schemas._2067_2._2016.pkl.AssetType packingListAssetType = new org.smpte_ra.schemas._2067_2._2016.pkl.AssetType();
            packingListAssetType.setId(asset.getUUID());
            packingListAssetType.setAnnotationText(asset.getAnnotationText());
            packingListAssetType.setHash(asset.getHash());
            packingListAssetType.setSize(asset.getSize());
            packingListAssetType.setType(asset.getAssetType().toString());
            packingListAssetType.setOriginalFileName(asset.getOriginalFileName());
            packingListAssetType.setHashAlgorithm(asset.getHashAlgorithm());
            packingListAssets.add(packingListAssetType);
        }
        packingListType.setAssetList(assetList);

        //The following attributes are optional setting them to null so that the JAXB Marshaller will not marshall them
        packingListType.setSigner(null);
        packingListType.setSignature(null);

        File outputFile = new File(this.workingDirectory + File.separator + this.pklFileName);
        boolean formatted = true;
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try(
                InputStream packingListSchemaAsAStream = contextClassLoader.getResourceAsStream("org/smpte_ra/schemas/st2067_2_2016/PKL/packingList_schema.xsd");
                InputStream dsigSchemaAsAStream = contextClassLoader.getResourceAsStream("org/w3/_2000_09/xmldsig/xmldsig-core-schema.xsd");
                OutputStream outputStream = new FileOutputStream(outputFile);
        )
        {
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI );
            StreamSource[] schemaSources = new StreamSource[2];
            //The order in which these schema sources are initialized is important because some elements in the
            //PackingList schema depend on types defined in the DSig schema.
            schemaSources[0] = new StreamSource(dsigSchemaAsAStream);
            schemaSources[1] = new StreamSource(packingListSchemaAsAStream);
            Schema schema = schemaFactory.newSchema(schemaSources);

            JAXBContext jaxbContext = JAXBContext.newInstance("org.smpte_ra.schemas._2067_2._2016.pkl");
            Marshaller marshaller = jaxbContext.createMarshaller();
            ValidationEventHandlerImpl validationEventHandler = new ValidationEventHandlerImpl(true);
            marshaller.setEventHandler(validationEventHandler);
            marshaller.setSchema(schema);
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);

            /*marshaller.marshal(cplType, output);
            workaround for 'Error: unable to marshal type "AssetMapType" as an element because it is missing an @XmlRootElement annotation'
            as found at https://weblogs.java.net/blog/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always
             */
            marshaller.marshal(new JAXBElement<>(new QName("http://www.smpte-ra.org/schemas/2067-2/2016/PKL", "PackingList"), org.smpte_ra.schemas._2067_2._2016.pkl.PackingListType.class, packingListType), outputStream);
            outputStream.close();

            if(validationEventHandler.hasErrors())
            {
                //TODO : Perhaps a candidate for a Lambda
                for(ValidationEventHandlerImpl.ValidationErrorObject validationErrorObject : validationEventHandler.getErrors()) {
                    this.imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_PKL_ERROR, validationErrorObject.getValidationEventSeverity(), validationErrorObject.getErrorMessage());
                }
            }
        }

        if(this.imfErrorLogger.getNumberOfErrors() > numErrors){
            List<ErrorLogger.ErrorObject> fatalErrors = imfErrorLogger.getErrors(IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, numErrors, this.imfErrorLogger.getNumberOfErrors());
            if(fatalErrors.size() > 0){
                throw new IMFAuthoringException(String.format("Following FATAL errors were detected while building the PackingList document %s", fatalErrors.toString()));
            }
        }

        return imfErrorLogger.getErrors();
    }