<commit_before>var cip = require('./cip-methods.js');
var Q = require('q');

var result_mapping = [
    {'key': 'id',
     'short': 'id'},
    {'key': '{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'filename'
    },
    {'key': <KEY>}',
     'short': 'license',
    },
    {'key': '{9b071045-118c-4f42-afa1-c3121783ac66}',
     'short': 'creator',
    },
    {'key': '{af4b2e2c-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'copyright',
    },
    {'key': '{2ce9c8eb-b83d-4a91-9d09-2141cac7de12}',
     'short': 'description',
    },
    {'key': '{af4b2e12-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'height_in'
    },
    {'key': '{af4b2e11-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'width_in'
    },
    {'key': '{af4b2e0f-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'dpi',
    },
    {'key': '{418a4c92-fe63-11d3-9030-0080ad80c556}',
     'short': 'longitude',
    },
    {'key': '{418a4c91-fe63-11d3-9030-0080ad80c556}',
     'short': 'latitude',
    },
    {'key': '{ca6903b8-c3c4-47fa-9592-2d486d766ce0}',
     'short': 'actorname',
    },
    {'key': '{38664623-b081-4251-8c1c-383ef57ac54d}',
     'short': 'locationnote'
    },
    {'key': <KEY>}',
     'short': 'year'
    },
    {'key': '{76f2cca6-3652-40ee-b198-5d0afe931caa}',
     'short': 'inventory_number' // Inventar nr.
     //'short': 'assetno'
    },
    {'key': <KEY>
     'short': 'creation_time_from'
    },
    {'key': <KEY>}',
     'short': 'creation_time_to'
    },
    {'key': '{<KEY>}',
     'short': 'acceptance_time_from'
    },
    {'key': '{0db7de9e-37fa-47a5-b087-0b1e6066ee86}',
     'short': 'acceptance_time_to'
    },
    {'key': '{1cb94319-9e1f-428e-993f-a78c78947f60}',
     'short': 'timenote'
    },
    {'key': '{8e820869-e338-4761-aa88-3dcd89f8cbae}',
     'short': 'archiveno'
    },
    {'key': '{d6025301-ef5e-4722-b101-78fd28262a98}',
     'short': 'topno'
    },
    {'key': '{8ac71e5d-5ca9-42cf-8c21-02c41e1af5cd}',
     'short': 'archivename'
    },
    {'key': '{9aef60d3-38b4-4e47-8104-d018b83ea6c6}',
     'short': 'object_number' // Genstandsnummer
     //'short': 'unitno'
    },
    {'key': '{51b661a3-585e-4dbd-9e98-85e12ad91190}',
     'short': 'place'
    },
    {'key': '{24252838-de09-46e4-8f7d-f3fb85cde78f}',
     'short': 'city'
    },
    {'key': '{<KEY>}',
     'short': 'short_title'
    },
    {'key': '{af4b2e0c-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'categories'
    },
    {'key': '{659ca0c6-92d8-4f7a-af58-8a3c69df2ede}',
     'short': 'street'
    },
    {'key': '{ed64a9f8-8d19-4f60-a615-5bd3b188e98a}',
     'short': 'address'
    },
    {'key': '{<KEY>
     'short': 'zipcode'
    },
    {'key': '{af4b2e02-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'modification_time'
    },
    {'key': '{a493be21-0f70-4cae-9394-703eca848bad}',
     'short': 'review_state'
    },
    {'key': '{bf7a30ac-e53b-4147-95e0-aea8c71340ca}',
     'short': 'cropping_status'
    },
    {'key': '{af4b2e71-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'related_sub_assets'
    },
    {'key': '{af4b2e72-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'related_master_assets'
    },
    {'key': '{05f6f3f0-833a-45a0-ade4-8e48542f37ef}',
     'short': 'width_px'
    },
    {'key': <KEY>
     'short': 'height_px'
    },
    {'key': '{af4b2e14-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'file_size'
    }
];

exports.result_mapping = result_mapping;

function format_result(fields) {
    var result = {};

    for(var i=0; i < result_mapping.length; ++i) {
        if(result_mapping[i].key in fields) {
            result[result_mapping[i].short] = fields[result_mapping[i].key];
        }
    }

    return result;
}

exports.format_result = format_result;

// This expects that the related_master_assets has been parsed using the
// cip-methods.js's parse_binary_relations
function extend_from_master(nm, metadata) {
    // We expect the formatted metadata to contain a binary field with related
    // master asset ids.
    if(!metadata.related_master_assets || metadata.related_master_assets.length === 0) {
        return metadata;
    }
    // We expect only one master asset.
    if(metadata.related_master_assets.length !== 1) {
        // Compile a textual representation of the master asset id's.
        var master_asset_summary = JSON.stringify(metadata.related_master_assets);
        throw new Error( 'Expected exactly one master asset, received ' +
            metadata.related_master_assets.length+ ': ' +master_asset_summary );
    }
    // Deriving the single master asset id.
    var master_asset_id = metadata.related_master_assets[0].id;

    console.log('Extending metadata of asset '+metadata.id+' with master asset ' + master_asset_id);

    return cip.get_asset(nm, metadata.catalog, master_asset_id)
    .then(function(master_asset) {
        var master_asset_metadata = format_result(master_asset.fields);<commit_msg>Adding TODOs to remove console.logs<commit_after>var cip = require('./cip-methods.js');
var Q = require('q');

var result_mapping = [
    {'key': 'id',
     'short': 'id'},
    {'key': '{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'filename'
    },
    {'key': <KEY>
     'short': 'license',
    },
    {'key': '{9b071045-118c-4f42-afa1-c3121783ac66}',
     'short': 'creator',
    },
    {'key': '{af4b2e2c-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'copyright',
    },
    {'key': '{2ce9c8eb-b83d-4a91-9d09-2141cac7de12}',
     'short': 'description',
    },
    {'key': '{af4b2e12-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'height_in'
    },
    {'key': '{af4b2e11-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'width_in'
    },
    {'key': '{af4b2e0f-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'dpi',
    },
    {'key': '{418a4c92-fe63-11d3-9030-0080ad80c556}',
     'short': 'longitude',
    },
    {'key': '{418a4c91-fe63-11d3-9030-0080ad80c556}',
     'short': 'latitude',
    },
    {'key': '{ca6903b8-c3c4-47fa-9592-2d486d766ce0}',
     'short': 'actorname',
    },
    {'key': '{38664623-b081-4251-8c1c-383ef57ac54d}',
     'short': 'locationnote'
    },
    {'key': <KEY>}',
     'short': 'year'
    },
    {'key': '{76f2cca6-3652-40ee-b198-5d0afe931caa}',
     'short': 'inventory_number' // Inventar nr.
     //'short': 'assetno'
    },
    {'key': '{<KEY>}',
     'short': 'creation_time_from'
    },
    {'key': <KEY>
     'short': 'creation_time_to'
    },
    {'key': '{<KEY>}',
     'short': 'acceptance_time_from'
    },
    {'key': '{0db7de9e-37fa-47a5-b087-0b1e6066ee86}',
     'short': 'acceptance_time_to'
    },
    {'key': '{1cb94319-9e1f-428e-993f-a78c78947f60}',
     'short': 'timenote'
    },
    {'key': '{<KEY>
     'short': 'archiveno'
    },
    {'key': '{d6025301-ef5e-4722-b101-78fd28262a98}',
     'short': 'topno'
    },
    {'key': '{8ac71e5d-5ca9-42cf-8c21-02c41e1af5cd}',
     'short': 'archivename'
    },
    {'key': '{9aef60d3-38b4-4e47-8104-d018b83ea6c6}',
     'short': 'object_number' // Genstandsnummer
     //'short': 'unitno'
    },
    {'key': '{51b661a3-585e-4dbd-9e98-85e12ad91190}',
     'short': 'place'
    },
    {'key': '{24252838-de09-46e4-8f7d-f3fb85cde78f}',
     'short': 'city'
    },
    {'key': '{<KEY>
     'short': 'short_title'
    },
    {'key': '{af4b2e0c-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'categories'
    },
    {'key': '{659ca0c6-92d8-4f7a-af58-8a3c69df2ede}',
     'short': 'street'
    },
    {'key': '{ed64a9f8-8d19-4f60-a615-5bd3b188e98a}',
     'short': 'address'
    },
    {'key': '{<KEY>
     'short': 'zipcode'
    },
    {'key': '{af4b2e02-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'modification_time'
    },
    {'key': '{a493be21-0f70-4cae-9394-703eca848bad}',
     'short': 'review_state'
    },
    {'key': '{bf7a30ac-e53b-4147-95e0-aea8c71340ca}',
     'short': 'cropping_status'
    },
    {'key': '{af4b2e71-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'related_sub_assets'
    },
    {'key': '{af4b2e72-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'related_master_assets'
    },
    {'key': '{05f6f3f0-833a-45a0-ade4-8e48542f37ef}',
     'short': 'width_px'
    },
    {'key': <KEY>
     'short': 'height_px'
    },
    {'key': '{af4b2e14-5f6a-11d2-8f20-0000c0e166dc}',
     'short': 'file_size'
    }
];

exports.result_mapping = result_mapping;

function format_result(fields) {
    var result = {};

    for(var i=0; i < result_mapping.length; ++i) {
        if(result_mapping[i].key in fields) {
            result[result_mapping[i].short] = fields[result_mapping[i].key];
        }
    }

    return result;
}

exports.format_result = format_result;

// This expects that the related_master_assets has been parsed using the
// cip-methods.js's parse_binary_relations
function extend_from_master(nm, metadata) {
    // We expect the formatted metadata to contain a binary field with related
    // master asset ids.
    if(!metadata.related_master_assets || metadata.related_master_assets.length === 0) {
        return metadata;
    }
    // We expect only one master asset.
    if(metadata.related_master_assets.length !== 1) {
        // Compile a textual representation of the master asset id's.
        var master_asset_summary = JSON.stringify(metadata.related_master_assets);
        throw new Error( 'Expected exactly one master asset, received ' +
            metadata.related_master_assets.length+ ': ' +master_asset_summary );
    }
    // Deriving the single master asset id.
    var master_asset_id = metadata.related_master_assets[0].id;
    
    // TODO: Remove this console.log when debugged.
    console.log('Extending metadata of asset '+metadata.id+' with master asset ' + master_asset_id);

    return cip.get_asset(nm, metadata.catalog, master_asset_id)
    .then(function(master_asset) {
        var master_asset_metadata = format_result(master_asset.fields);
        // TODO: Remove this console.log when debugged.
{'fraction_non_alphanumeric': 0.19071850193364542, 'fraction_numerical': 0.12273559943008346, 'mean_word_length': 3.004482477587612, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '470542', 'n_tokens_mistral': 4588, 'n_tokens_neox': 4192, 'n_words': 581}