Example #1
0
from datacatalogtordf import Catalog, Dataset

# Create catalog object
catalog = Catalog()
catalog.identifier = "http://example.com/catalogs/1"
catalog.title = {"en": "A dataset catalog"}
catalog.publisher = "https://example.com/publishers/1"

# Create a dataset:
dataset = Dataset()
dataset.identifier = "http://example.com/datasets/1"
dataset.title = {"nb": "inntektsAPI", "en": "incomeAPI"}
#
# Add concept to catalog:
catalog.datasets.append(dataset)

# get rdf representation in turtle (default)
rdf = catalog.to_rdf()
print(rdf.decode())
Example #2
0
def _add_mandatory_catalog_props(catalog: Catalog) -> None:
    catalog.title = {"nb": "NAV åpne APIer"}
    catalog.identifier = os.environ["COLLECTION_IDENTIFIER"]
    catalog.publisher = URI(os.environ["PUBLISHER"])
Example #3
0
def main(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    search = req.params.get('search')
    if not search:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            search = req_body.get('search')

    assetType = req.params.get('assetType')
    if not assetType:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            search = req_body.get('assetType')

    entityType = req.params.get('entityType')
    if not entityType:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            search = req_body.get('entityType')

    if search:
        
        logging.info(search)
        logging.info(assetType)
        logging.info(entityType)

        # search purview
        value = entitySearch(search)

        if int(json.loads(value)['@search.count']) > 0:
            logging.info(json.loads(value)['@search.count'])
        else:
            logging.info("Nothing was returned from the search")
            return func.HttpResponse(
             "This HTTP triggered function executed successfully, but no search criteria was returned from the Purview catalog. Pass a search in the query string or in the request body for a response.",
             status_code=200
        )

        #parse the response
        objToexport = []
        score = 0
        #loop through all of the results and filter on the assetType and entityType
        
        jsonObj = json.loads(value)
        
        for obj in jsonObj['value'] :
            if (obj['assetType'][0] == assetType) and (obj['entityType'] == entityType):       
                #if there are multiple objects returned, select the one with the highest score
                if (obj['@search.score'] > score):
                    objToexport = obj
                    score = obj['@search.score']

        # return function if not match has been found in the data returned from Purview
        if(len(objToexport) == 0):
            logging.info("No match was found in the Purview catalog for the search, assetType and entityType combination entityType: {0} {1} {2} ".format(search, assetType, entityType))
            return func.HttpResponse(
             f"No match was found in the Purview catalog for search : {search}  assetType: {assetType} entityType: {entityType} ",
             status_code=200
        )

        publisher = os.environ.get('publisher')
        logging.info(objToexport['assetType'])
        logging.info(objToexport['entityType']) 
        logging.info(objToexport['@search.score'])
        logging.info(objToexport['qualifiedName'])
        logging.info(objToexport['name'])
        logging.info(publisher)
        logging.info(score)

        # Create catalog object
        catalog = Catalog()
        catalog.identifier = objToexport['qualifiedName']
        catalog.title = {"en": objToexport['name']}
        catalog.publisher = publisher

        # Create a dataset:
        dataset = Dataset()
        dataset.identifier = objToexport['qualifiedName']
        dataset.title = {"nb": objToexport['name'], "en": objToexport['name']}
        #
        # Add dataset to catalog:
        catalog.datasets.append(dataset)

        # get rdf representation in turtle (default)
        rdf = catalog.to_rdf()
        logging.info(rdf.decode())


        # write the rdf to Azure storage
        msg.set(rdf.decode())

        # return the function 
        return func.HttpResponse(f"The HTTP triggered function for {search} executed successfully. The assetType provided was: {assetType} and the entityType was: {entityType }")

    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully, but no search criteria was supplied. Pass a search in the query string or in the request body for a response.",
             status_code=200
        )