Untitled

 avatar
unknown
plain_text
2 months ago
5.0 kB
3
Indexable

  public static compareMRLWithComponent = async (
    mrlEntity: IssuingAuthorityComponentsRequirementList[],
    component: Component
  ): Promise<CompareMRLWithComponentResponse> => {
    const methodName = 'compareMRLWithComponent';
    logger.info('Comparing MRL with component', {
      class: VerificationModificationHelper.className,
      method: methodName,
      mrlEntity,
      component
    });
    const componentAttributeTypeIdMap = new Map<string, number>();
    const componentDocumentTypeIdMap = new Map<string, number>();
    const componentDocumentUploadTypeIdMap = new Map<string, number>();
    const componentInstructionTypeIdMap = new Map<string, number>();

    const mrlAttributeTypeIdMap = new Map<string, number>();
    const mrlDocumentTypeIdMap = new Map<string, number>();
    const mrlDocumentUploadTypeIdMap = new Map<string, number>();
    const mrlInstructionTypeIdMap = new Map<string, number>();

    const emptyAttributeSet = new Set<string>();
    const emptyDocumentSet = new Set<string>();
    const emptyDocumentUploadSet = new Set<string>();
    const emptyInstructionSet = new Set<string>();

    for (const mrl of mrlEntity) {
      switch (mrl.type) {
        case MrlType.DOCUMENT:
          mrl?.typeDetails?.forEach((typeDetail: TypeDetails) => {
            mrlDocumentTypeIdMap.set(typeDetail.typeId, typeDetail.minCount);
          });
          break;

        case MrlType.DOCUMENT_UPLOAD:
          mrl?.typeDetails?.forEach((typeDetail: TypeDetails) => {
            mrlDocumentUploadTypeIdMap.set(
              typeDetail.typeId,
              typeDetail.minCount
            );
          });
          break;

        case MrlType.ATTRIBUTE:
          mrl?.typeDetails?.forEach((typeDetail: TypeDetails) => {
            mrlAttributeTypeIdMap.set(typeDetail.typeId, typeDetail.minCount);
          });
          break;

        case MrlType.INSTRUCTION:
          mrl?.typeDetails?.forEach((typeDetail: TypeDetails) => {
            mrlInstructionTypeIdMap.set(typeDetail.typeId, typeDetail.minCount);
          });
          break;

        default:
          break;
      }
    }

    if (component && component.mrlDetails && component.mrlDetails.length) {
      component.mrlDetails.forEach((mrl) => {
        if (!mrl?.typeId?.length) return;

        let currentVal;

        switch (mrl.type) {
          case MrlType.DOCUMENT:
            currentVal = componentDocumentTypeIdMap.get(mrl.typeId);
            componentDocumentTypeIdMap.set(mrl.typeId, (currentVal || 0) + 1);
            break;

          case MrlType.ATTRIBUTE:
            currentVal = componentAttributeTypeIdMap.get(mrl.typeId);
            componentAttributeTypeIdMap.set(mrl.typeId, (currentVal || 0) + 1);
            break;

          case MrlType.DOCUMENT_UPLOAD:
            currentVal = componentDocumentUploadTypeIdMap.get(mrl.typeId);
            componentDocumentUploadTypeIdMap.set(
              mrl.typeId,
              (currentVal || 0) + 1
            );
            break;

          case MrlType.INSTRUCTION:
            currentVal = componentInstructionTypeIdMap.get(mrl.typeId);
            componentInstructionTypeIdMap.set(
              mrl.typeId,
              (currentVal || 0) + 1
            );
            break;

          default:
            break;
        }
      });
    }

    for (const [key, value] of mrlAttributeTypeIdMap) {
      if (
        !componentAttributeTypeIdMap.has(key) ||
        componentAttributeTypeIdMap.get(key) < value
      ) {
        emptyAttributeSet.add(key);
      }
    }
    for (const [key, value] of mrlDocumentTypeIdMap) {
      if (
        !componentDocumentTypeIdMap.has(key) ||
        componentDocumentTypeIdMap.get(key) < value
      ) {
        emptyDocumentSet.add(key);
      }
    }
    for (const [key, value] of mrlDocumentUploadTypeIdMap) {
      if (
        !componentDocumentUploadTypeIdMap.has(key) ||
        componentDocumentUploadTypeIdMap.get(key) < value
      ) {
        emptyDocumentUploadSet.add(key);
      }
    }
    for (const [key, value] of mrlInstructionTypeIdMap) {
      if (
        !componentInstructionTypeIdMap.has(key) ||
        componentInstructionTypeIdMap.get(key) < value
      ) {
        emptyInstructionSet.add(key);
      }
    }

    if (
      emptyAttributeSet.size === 0 &&
      emptyDocumentSet.size === 0 &&
      emptyDocumentUploadSet.size === 0 &&
      emptyInstructionSet.size === 0
    ) {
      return {
        isResolved: true,
        emptyAttributeSet,
        emptyDocumentSet,
        emptyDocumentUploadSet,
        emptyInstructionSet
      };
    }
    const result = {
      isResolved: false,
      emptyAttributeSet,
      emptyDocumentSet,
      emptyDocumentUploadSet,
      emptyInstructionSet
    };
    logger.info('MRL Comparison Result: ', {
      class: VerificationModificationHelper.className,
      method: 'getRequestedRaisedByFromUserType',
      result
    });
    return result;
  };
Editor is loading...
Leave a Comment