src/pds_doi_service/core/outputs/osti/osti_web_parser.py
def parse_dois_from_label(label_text, content_type=CONTENT_TYPE_JSON):
        """
        Parses a response from a query to the OSTI server (in JSON format) and
        returns a list of parsed Doi objects.

        Specific fields are extracted from input. Not all fields in the JSON are
        used.

        """
        dois = []
        errors = {}

        osti_response = json.loads(label_text)

        # Responses from OSTI come wrapped in 'records' key, strip it off
        # before continuing
        if "records" in osti_response:
            osti_response = osti_response["records"]

        # Multiple records may come in a list, or a single dict may be provided
        # for a single record, make the loop work either way
        if not isinstance(osti_response, list):
            osti_response = [osti_response]

        for index, record in enumerate(osti_response):
            if record.get("status", "").lower() == "error":
                logger.error(f"Errors reported for record index {index + 1}")

                # Check for any errors reported back from OSTI and save
                # them off to be returned
                cur_errors = []

                if "errors" in record:
                    cur_errors.extend(record["errors"])

                if "doi_message" in record and len(record["doi_message"]):
                    cur_errors.append(record["doi_message"])

                errors[index] = cur_errors

            # Make sure all the mandatory fields are present
            if not all([field in record for field in DOIOstiJsonWebParser._mandatory_fields]):
                raise InputFormatException(
                    "Provided JSON is missing one or more mandatory fields: "
                    f'({", ".join(DOIOstiJsonWebParser._mandatory_fields)})'
                )

            identifier = DOIOstiJsonWebParser._get_identifier(record)

            timestamp = datetime.now()

            doi = Doi(
                title=record["title"],
                publication_date=datetime.strptime(record["publication_date"], "%Y-%m-%d"),
                product_type=ProductType(record["product_type"]),
                product_type_specific=record.get("product_type_specific"),
                pds_identifier=identifier,
                status=DoiStatus(record.get("status", DoiStatus.Unknown).lower()),
                date_record_added=timestamp,
                date_record_updated=timestamp,
            )

            # Parse for some optional fields that may not be present in
            # every record from OSTI.
            doi = DOIOstiJsonWebParser._parse_optional_fields(doi, record)

            dois.append(doi)

        return dois, errors

        Parses a response from a query to the OSTI server (in JSON format) and
        returns a list of parsed Doi objects.

        Specific fields are extracted from input. Not all fields in the JSON are
        used.

        
Parses a response from a query to the OSTI server (in JSON format) and
returns a list of parsed Doi objects.

Specific fields are extracted from input. Not all fields in the JSON are
used.
Parses a response from a query to the OSTI server ( in JSON format ) and returns a list of parsed Doi objects . Specific fields are extracted from input . Not all fields in the JSON are used .
def parse_dois_from_label(label_text, content_type=CONTENT_TYPE_JSON):
        dois = []
        errors = {}
        osti_response = json.loads(label_text)
        if "records" in osti_response:
            osti_response = osti_response["records"]
        if not isinstance(osti_response, list):
            osti_response = [osti_response]
        for index, record in enumerate(osti_response):
            if record.get("status", "").lower() == "error":
                logger.error(f"Errors reported for record index {index + 1}")
                cur_errors = []
                if "errors" in record:
                    cur_errors.extend(record["errors"])
                if "doi_message" in record and len(record["doi_message"]):
                    cur_errors.append(record["doi_message"])
                errors[index] = cur_errors
            if not all([field in record for field in DOIOstiJsonWebParser._mandatory_fields]):
                raise InputFormatException(
                    "Provided JSON is missing one or more mandatory fields: "
                    f'({", ".join(DOIOstiJsonWebParser._mandatory_fields)})'
                )
            identifier = DOIOstiJsonWebParser._get_identifier(record)
            timestamp = datetime.now()
            doi = Doi(
                title=record["title"],
                publication_date=datetime.strptime(record["publication_date"], "%Y-%m-%d"),
                product_type=ProductType(record["product_type"]),
                product_type_specific=record.get("product_type_specific"),
                pds_identifier=identifier,
                status=DoiStatus(record.get("status", DoiStatus.Unknown).lower()),
                date_record_added=timestamp,
                date_record_updated=timestamp,
            )
            doi = DOIOstiJsonWebParser._parse_optional_fields(doi, record)
            dois.append(doi)
        return dois, errors
def parse_dois_from_label ( label_text , content_type = CONTENT_TYPE_JSON ) : dois = [ ] errors = { } osti_response = json . loads ( label_text ) if "records" in osti_response : osti_response = osti_response [ "records" ] if not isinstance ( osti_response , list ) : osti_response = [ osti_response ] for index , record in enumerate ( osti_response ) : if record . get ( "status" , "" ) . lower ( ) == "error" : logger . error ( f"Errors reported for record index {index + 1}" ) cur_errors = [ ] if "errors" in record : cur_errors . extend ( record [ "errors" ] ) if "doi_message" in record and len ( record [ "doi_message" ] ) : cur_errors . append ( record [ "doi_message" ] ) errors [ index ] = cur_errors if not all ( [ field in record for field in DOIOstiJsonWebParser . _mandatory_fields ] ) : raise InputFormatException ( "Provided JSON is missing one or more mandatory fields: " f'({", ".join(DOIOstiJsonWebParser._mandatory_fields)})' ) identifier = DOIOstiJsonWebParser . _get_identifier ( record ) timestamp = datetime . now ( ) doi = Doi ( title = record [ "title" ] , publication_date = datetime . strptime ( record [ "publication_date" ] , "%Y-%m-%d" ) , product_type = ProductType ( record [ "product_type" ] ) , product_type_specific = record . get ( "product_type_specific" ) , pds_identifier = identifier , status = DoiStatus ( record . get ( "status" , DoiStatus . Unknown ) . lower ( ) ) , date_record_added = timestamp , date_record_updated = timestamp , ) doi = DOIOstiJsonWebParser . _parse_optional_fields ( doi , record ) dois . append ( doi ) return dois , errors
Parses a response from a query to the OSTI server (in JSON format) and
returns a list of parsed Doi objects.
Parses a response from a query to the OSTI server ( in JSON format ) and returns a list of parsed Doi objects .
"""
        Parses a response from a query to the OSTI server (in JSON format) and
        returns a list of parsed Doi objects.

        Specific fields are extracted from input. Not all fields in the JSON are
        used.

        """ # Responses from OSTI come wrapped in 'records' key, strip it off # before continuing # Multiple records may come in a list, or a single dict may be provided # for a single record, make the loop work either way # Check for any errors reported back from OSTI and save # them off to be returned # Make sure all the mandatory fields are present # Parse for some optional fields that may not be present in # every record from OSTI.
label_text
content_type