예제 #1
0
def test_minimal_xsd(xsd40):
    """Test that example XML converts to example JSON."""
    xsd40.assertValid(
        etree.XML(
            tostring({
                'identifier': {
                    'identifierType': 'DOI',
                    'identifier': '10.1234/foo.bar',
                },
                'creators': [{
                    'creatorName': 'Nielsen, Lars Holm',
                }, {
                    'creatorName': 'Nielsen, Lars Holm',
                    'nameIdentifier': {
                        'nameIdentifier': '1234',
                        'schemeURI': 'http://orcid.org',
                        'nameIdentifierScheme': 'ORCID',
                    }
                }],
                'titles': [{
                    'title': 'Minimal Test Case',
                }],
                'publisher':
                'Invenio Software',
                'publicationYear':
                '2016',
                'resourceType': {
                    'resourceTypeGeneral': 'Dataset'
                }
            }).encode('utf8')))
예제 #2
0
def generate_new_doi(*args):
    # If you want to generate XML for earlier versions, you need to use either the
    # schema31, schema40 or schema41 instead.

    data = {
        "identifier": {
            "identifier": prefix + "/RDS." + str(args[0]),
            "identifierType": "DOI"
        },
        "creators": [{
            "creatorName": organization
        }],
        "titles": [{
            "title": args[1]
        }],
        "publisher":
        "ICIMOD",
        "publicationYear":
        args[2],
        "language":
        "en-us",
        "resourceType": {
            "resourceTypeGeneral": "Dataset"
        },
        "rightsList": [{
            "rights":
            "Creative Commons Attribution 4.0 International (CC-BY-4.0)",
            "rightsURI": "https://creativecommons.org/licenses/by/4.0",
            "lang": "en-us"
        }],
        "descriptions": [{
            "descriptionType": "Abstract",
            "description": args[3]
        }],
    }

    # Validate dictionary
    # assert schema41.validate(data)

    # Generate DataCite XML from dictionary.
    doc = schema41.tostring(data)
    # print(doc)

    # Initialize the MDS client.
    d = DataCiteMDSClient(
        username=login_user,
        password=login_pass,
        url=url,
        prefix=prefix,
    )

    # Set metadata for DOI
    d.metadata_post(doc)

    # Mint new DOI
    d.doi_post(prefix + '/RDS.' + str(args[0]), args[4])

    logging.basicConfig(filename='logs/DOI_generation_Log_' + date_time +
                        '.log',
                        filemode='w',
                        format='%(asctime)s - %(message)s',
                        level=logging.INFO)
    logging.info("{} DOI Registration for id={} and title={}".format(
        args[5], args[0], args[1]))
    print(args[5], prefix + '/RDS.' + str(args[0]), args[4])
예제 #3
0
if __name__ == '__main__':

    ids = getmdIDs()

    for item in ids:
        try:
            print(item)

            documentInfo = database.DocumentInfo()
            documentInfo.mdId = item
            documentInfo = database.process(documentInfo)

            xname = "D:/doi_out/" + str(item) + ".xml"
            fxname = open(xname, 'w+')
            fxname.write(schema41.tostring(documentInfo.data))
            fxname.close()
            d = getDataCiteClient()
            d.metadata_post(schema41.tostring(documentInfo.data))
            doi = documentInfo.data['identifier']['identifier']
            d.doi_post(doi, documentInfo.url)
            database.logDoiMinted(documentInfo)

            print(
                "update metadata_document set doi_created = getdate() where md_id ="
                + str(item))
            print("xml file saved in " + xname)
            print('done')
        except datacite.errors.DataCiteServerError as error:
            print(error)
        except:
예제 #4
0
def test_json_to_xml(example_xml_file41, example_json41, xsd41):
    """Test that example XML converts to example JSON."""
    xsd41.assertValid(etree.XML(example_xml_file41.encode('utf8')))
    xsd41.assertValid(etree.XML(tostring(example_json41).encode('utf8')))