Ejemplo n.º 1
0
  /**
   * A stateless method that will validate an IMF PackingList document
   *
   * @param pkl - a payload record for a Packing List document
   * @return list of error messages encountered while validating a Packing List document
   * @throws IOException - any I/O related error is exposed through an IOException
   */
  public static List<ErrorLogger.ErrorObject> validatePKL(PayloadRecord pkl) throws IOException {
    IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();

    if (pkl.getPayloadAssetType() != PayloadRecord.PayloadAssetType.PackingList) {
      throw new IMFException(
          String.format(
              "Payload asset type is %s, expected asset type %s",
              pkl.getPayloadAssetType(), PayloadRecord.PayloadAssetType.PackingList.toString()),
          imfErrorLogger);
    }
    try {
      PackingList packingList = new PackingList(new ByteArrayByteRangeProvider(pkl.getPayload()));
      imfErrorLogger.addAllErrors(packingList.getErrors());
    } catch (IMFException e) {
      imfErrorLogger.addAllErrors(e.getErrors());
    }
    return imfErrorLogger.getErrors();
  }
Ejemplo n.º 2
0
  /**
   * A stateless method that determines if the Asset type of the payload is an IMF AssetMap,
   * Packinglist or Composition
   *
   * @param payloadRecord - a payload record corresponding to the asset whose type needs to be
   *     confirmed Note: for now this method only supports text/xml documents identified in the PKL
   *     application/mxf asset types cannot be determined.
   * @return asset type of the payload either one of AssetMap, PackingList or Composition
   * @throws IOException - any I/O related error is exposed through an IOException
   */
  public static PayloadRecord.PayloadAssetType getPayloadType(PayloadRecord payloadRecord)
      throws IOException {

    ResourceByteRangeProvider resourceByteRangeProvider =
        new ByteArrayByteRangeProvider(payloadRecord.getPayload());
    if (AssetMap.isFileOfSupportedSchema(resourceByteRangeProvider)) {
      return PayloadRecord.PayloadAssetType.AssetMap;
    } else if (PackingList.isFileOfSupportedSchema(resourceByteRangeProvider)) {
      return PayloadRecord.PayloadAssetType.PackingList;
    } else if (Composition.isCompositionPlaylist(resourceByteRangeProvider)) {
      return PayloadRecord.PayloadAssetType.CompositionPlaylist;
    }
    return PayloadRecord.PayloadAssetType.Unknown;
  }
Ejemplo n.º 3
0
  /**
   * A stateless method that will validate IMF AssetMap and PackingList documents for all the data
   * that should be cross referenced by both
   *
   * @param assetMapPayload - a payload record for an AssetMap document
   * @param pklPayloads - a list of payload records for Packing List documents referenced by the
   *     AssetMap
   * @return list of error messages encountered while validating an AssetMap document
   * @throws IOException - any I/O related error is exposed through an IOException
   */
  public static List<ErrorLogger.ErrorObject> validatePKLAndAssetMap(
      PayloadRecord assetMapPayload, List<PayloadRecord> pklPayloads) throws IOException {
    IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
    List<PayloadRecord> packingListPayloadRecords = Collections.unmodifiableList(pklPayloads);

    if (assetMapPayload.getPayloadAssetType() != PayloadRecord.PayloadAssetType.AssetMap) {
      imfErrorLogger.addError(
          IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR,
          IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
          String.format(
              "Payload asset type is %s, expected asset type %s",
              assetMapPayload.getPayloadAssetType(),
              PayloadRecord.PayloadAssetType.AssetMap.toString()));
    }

    ResourceByteRangeProvider assetMapByteRangeProvider =
        new ByteArrayByteRangeProvider(assetMapPayload.getPayload());
    AssetMap assetMapObjectModel = null;
    try {
      assetMapObjectModel = new AssetMap(assetMapByteRangeProvider);
      imfErrorLogger.addAllErrors(assetMapObjectModel.getErrors());

      if (assetMapObjectModel.getPackingListAssets().size() == 0) {
        imfErrorLogger.addError(
            IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR,
            IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
            String.format(
                "Asset map should reference atleast one PackingList, %d " + "references found",
                assetMapObjectModel.getPackingListAssets().size()));
      }
    } catch (IMFException e) {
      imfErrorLogger.addAllErrors(e.getErrors());
    }

    List<ResourceByteRangeProvider> packingLists = new ArrayList<>();
    for (PayloadRecord payloadRecord : packingListPayloadRecords) {
      if (payloadRecord.getPayloadAssetType() != PayloadRecord.PayloadAssetType.PackingList) {
        imfErrorLogger.addError(
            IMFErrorLogger.IMFErrors.ErrorCodes.IMF_MASTER_PACKAGE_ERROR,
            IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
            String.format(
                "Payload asset type is %s, expected asset type %s",
                assetMapPayload.getPayloadAssetType(),
                PayloadRecord.PayloadAssetType.PackingList.toString()));
      } else {
        packingLists.add(new ByteArrayByteRangeProvider(payloadRecord.getPayload()));
      }
    }

    if (packingLists.size() == 0) {
      imfErrorLogger.addError(
          IMFErrorLogger.IMFErrors.ErrorCodes.IMF_MASTER_PACKAGE_ERROR,
          IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
          String.format(
              "Atleast one PackingList is expected, %d were detected", packingLists.size()));
    }

    if (imfErrorLogger.hasFatalErrors()) {
      return imfErrorLogger.getErrors();
    }

    List<PackingList> packingListObjectModels = new ArrayList<>();
    for (ResourceByteRangeProvider resourceByteRangeProvider : packingLists) {
      try {
        PackingList packingList = new PackingList(resourceByteRangeProvider);
        packingListObjectModels.add(packingList);
        imfErrorLogger.addAllErrors(packingList.getErrors());
      } catch (IMFException e) {
        imfErrorLogger.addAllErrors(e.getErrors());
        return imfErrorLogger.getErrors();
      }
    }
    List<UUID> assetUUIDsAssetMapList = new ArrayList<>();
    for (AssetMap.Asset asset : assetMapObjectModel.getAssetList()) {
      assetUUIDsAssetMapList.add(asset.getUUID());
    }

    /*
            //Sort the UUIDs in the AssetMap
            assetUUIDsAssetMapList.sort(new Comparator<UUID>() {
                                        @Override
                                        public int compare(UUID o1, UUID o2) {
                                            return o1.compareTo(o2);
                                        }
                                    });
    */

    /* Collect all the assets in all of the PKLs that are a part of this IMP delivery */
    List<UUID> assetUUIDsPackingList = new ArrayList<>();
    for (PackingList packingList : packingListObjectModels) {
      assetUUIDsPackingList.add(
          packingList
              .getUUID()); // PKL's UUID is also added to this list since that should be present in
                           // the AssetMap
      for (PackingList.Asset asset : packingList.getAssets()) {
        assetUUIDsPackingList.add(asset.getUUID());
      }
    }

    /*
            //Sort the UUIDs in the PackingList
            assetUUIDsPackingList.sort(new Comparator<UUID>() {
                @Override
                public int compare(UUID o1, UUID o2) {
                    return o1.compareTo(o2);
                }
            });
    */

    /* Check to see if all the Assets referenced in the PKL are also referenced by the Asset Map */
    Set<UUID> assetUUIDsAssetMapSet = new HashSet<>(assetUUIDsAssetMapList);
    Set<UUID> assetUUIDsPKLSet = new HashSet<>(assetUUIDsPackingList);

    StringBuilder unreferencedPKLAssetsUUIDs = new StringBuilder();
    for (UUID uuid : assetUUIDsPKLSet) {
      if (!assetUUIDsAssetMapSet.contains(uuid)) {
        unreferencedPKLAssetsUUIDs.append(uuid.toString());
        unreferencedPKLAssetsUUIDs.append(", ");
      }
    }

    if (!unreferencedPKLAssetsUUIDs.toString().isEmpty()) {
      imfErrorLogger.addError(
          IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR,
          IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
          String.format(
              "The following UUID/s %s in the Packing list are not referenced by the AssetMap.",
              unreferencedPKLAssetsUUIDs.toString()));
      return imfErrorLogger.getErrors();
    }

    /* Check if all the assets in the AssetMap that are supposed to be PKLs have the same UUIDs as the PKLs themselves */
    Set<UUID> packingListAssetsUUIDsSet = new HashSet<>();
    for (AssetMap.Asset asset : assetMapObjectModel.getPackingListAssets()) {
      packingListAssetsUUIDsSet.add(asset.getUUID());
    }
    StringBuilder unreferencedPKLUUIDs = new StringBuilder();
    for (PackingList packingList : packingListObjectModels) {
      if (!packingListAssetsUUIDsSet.contains(packingList.getUUID())) {
        unreferencedPKLUUIDs.append(packingList.getUUID());
      }
    }
    if (!unreferencedPKLUUIDs.toString().isEmpty()) {
      imfErrorLogger.addError(
          IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR,
          IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
          String.format(
              "The following Packing lists %s are not referenced in the AssetMap",
              unreferencedPKLUUIDs.toString()));
      return imfErrorLogger.getErrors();
    }
    return imfErrorLogger.getErrors();
  }