<commit_before>/**
 * Jsonix CSW unmarshaller
 *
 * */

Ows4js.Csw ={};

Ows4js.Csw = function(url) {
    // init by doing a GetCapabilities and parsing metadata
    this.url = url;
    console.log(this.url);
    var getCapabilities = new Ows4js.Csw.GetCapabilities();
    // XML to Post.
    var myXML = Ows4js.Csw.marshalDocument(getCapabilities);
    // TODO change the httpRequest sync to async.
    // TODO CallBack or a Promise ?
    var capabilities;
    var httpRequest;
    try{
        httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
        capabilities = Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
    }catch (e){ // String file
        httpRequest = Ows4js.Util.httpGet(this.url,"application/xml");
        capabilities = Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
    }

    this.serviceIdentification = capabilities['csw:Capabilities'].serviceIdentification;
    this.serviceProvider = capabilities['csw:Capabilities'].serviceProvider;
    this.operationsMetadata = capabilities['csw:Capabilities'].operationsMetadata;
    this.filterCapabilities = capabilities['csw:Capabilities'].filterCapabilities;

    console.log(this);

    this.version = '2.0.2';
};

/**
 *
 * Operations List:
 *
 * GetCapabilities
 * Transaction
 * GetRepositoryItem
 * DescribeRecord
 * GetDomain
 * GetRecordById
 * GetRecords
 * Harvest
 *
 * */

/**
 * Operation name: GetRecords
 *
 * */

Ows4js.Csw.prototype.GetRecords = function(startPosition, maxRecords, filter) {

    var query;
    if (filter === undefined || filter === null) {
        query = new Ows4js.Csw.Query('full');
    } else {
        // Create Query
         query = new Ows4js.Csw.Query('full', new Ows4js.Csw.Constraint(filter));
    }
    // Create de GetRecords Action.
    var recordAction = new Ows4js.Csw.GetRecords(startPosition, maxRecords, query);
    // XML to Post.
    var myXML = Ows4js.Csw.marshalDocument(recordAction);
    // Post XML
    // TODO change the httpRequest sync to async.
    // TODO CallBack or a Promise ?
    var httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
    return  Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
};

// TODO check the dependencies. Maybe the dependencies must passed through the constructor?
Ows4js.Csw.jsonnixContext = new Jsonix.Context(
    [
        OWS_1_0_0,
        DC_1_1,
        DCT,
        XLink_1_0,
        SMIL_2_0,
        SMIL_2_0_Language,
        GML_3_1_1,
        Filter_1_1_0,
        CSW_2_0_2
    ],
    {
        namespacePrefixes: {
            'http://www.opengis.net/cat/csw/2.0.2': 'csw',
            "http://www.opengis.net/ogc": 'ogc',
            "http://www.opengis.net/gml": "gml"
        },
        mappingStyle : 'simplified'
    }
);

Ows4js.Csw.marshalDocument = function(object){
    return Ows4js.Csw.jsonnixContext.createMarshaller().marshalDocument(object);
};

Ows4js.Csw.unmarshalDocument = function(xml){
    return Ows4js.Csw.jsonnixContext.createUnmarshaller().unmarshalDocument(xml);
};

Ows4js.Csw.unmarshalString = function(string){
    return Ows4js.Csw.jsonnixContext.createUnmarshaller().unmarshalString(string);
};

/**
 * Operation name: GetRecordById
 **/

Ows4js.Csw.prototype.GetRecordById = function(id_list) {
    var byIdAction = new Ows4js.Csw.GetRecordById(id_list);
    //console.log(byIdAction);
    var myXML = Ows4js.Csw.marshalDocument(byIdAction);
    //console.log(myXML);
    var httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
    //console.log(httpRequest.responseXML);
    return Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
};

Ows4js.Csw.prototype.getOperationByName = function(name) {
    return  this.operationsMetadata.operation.filter(function(element){
        return element.name === name;
    })[0];
};

/**
 * Operation name: GetDomain
 * */

Ows4js.Csw.prototype.GetDomain = function(propertyName){
    var getdomainAction = new Ows4js.Csw.GetDomain(propertyName);
    var myXML = Ows4js.Csw.marshalDocument(getdomainAction);
    //console.log(myXML);
    var httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
    //console.log(httpRequest.responseXML);
    return Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
};

/**
 * Templates for Requests
 * */

/**
 * Constraint Request Template
 * */

Ows4js.Csw.Constraint = function(filter){
    this.TYPE_NAME = "CSW_2_0_2.QueryConstraintType";
    this.version = "1.1.0";
    this.filter = filter;
};

/**
 * GetRecords Request Template
 *
 * This Objects already use the simple mapping style from jsonix
 * */

Ows4js.Csw.GetRecords = function(startPosition, maxRecords, query){
    this['csw:GetRecords'] = {
        TYPE_NAME: "CSW_2_0_2.GetRecordsType",
        abstractQuery: query,
        startPosition: startPosition,
        maxRecords: 10,
        resultType: "results",
        service: "CSW",
        version: "2.0.2"
    };
};

/**
 * GetRecordById Request Template
 *
 * This Objects already use the simple mapping style from jsonix
 * */

Ows4js.Csw.GetRecordById = function(ids){
    this['csw:GetRecordById'] ={
        TYPE_NAME: "CSW_2_0_2.GetRecordByIdType",
        elementSetName: {
            ObjectTYPE_NAME: "CSW_2_0_2.ElementSetNameType",
            value: "full"
        },
        id: ids,<commit_msg>Fix GetRecords object<commit_after>/**
 * Jsonix CSW unmarshaller
 *
 * */

Ows4js.Csw ={};

Ows4js.Csw = function(url) {
    // init by doing a GetCapabilities and parsing metadata
    this.url = url;
    console.log(this.url);
    var getCapabilities = new Ows4js.Csw.GetCapabilities();
    // XML to Post.
    var myXML = Ows4js.Csw.marshalDocument(getCapabilities);
    // TODO change the httpRequest sync to async.
    // TODO CallBack or a Promise ?
    var capabilities;
    var httpRequest;
    try{
        httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
        capabilities = Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
    }catch (e){ // String file
        httpRequest = Ows4js.Util.httpGet(this.url,"application/xml");
        capabilities = Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
    }

    this.serviceIdentification = capabilities['csw:Capabilities'].serviceIdentification;
    this.serviceProvider = capabilities['csw:Capabilities'].serviceProvider;
    this.operationsMetadata = capabilities['csw:Capabilities'].operationsMetadata;
    this.filterCapabilities = capabilities['csw:Capabilities'].filterCapabilities;

    console.log(this);

    this.version = '2.0.2';
};

/**
 *
 * Operations List:
 *
 * GetCapabilities
 * Transaction
 * GetRepositoryItem
 * DescribeRecord
 * GetDomain
 * GetRecordById
 * GetRecords
 * Harvest
 *
 * */

/**
 * Operation name: GetRecords
 *
 * */

Ows4js.Csw.prototype.GetRecords = function(startPosition, maxRecords, filter) {

    var query;
    if (filter === undefined || filter === null) {
        query = new Ows4js.Csw.Query('full');
    } else {
        // Create Query
         query = new Ows4js.Csw.Query('full', new Ows4js.Csw.Constraint(filter));
    }
    // Create de GetRecords Action.
    var recordAction = new Ows4js.Csw.GetRecords(startPosition, maxRecords, query);
    // XML to Post.
    var myXML = Ows4js.Csw.marshalDocument(recordAction);
    // Post XML
    // TODO change the httpRequest sync to async.
    // TODO CallBack or a Promise ?
    var httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
    return  Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
};

// TODO check the dependencies. Maybe the dependencies must passed through the constructor?
Ows4js.Csw.jsonnixContext = new Jsonix.Context(
    [
        OWS_1_0_0,
        DC_1_1,
        DCT,
        XLink_1_0,
        SMIL_2_0,
        SMIL_2_0_Language,
        GML_3_1_1,
        Filter_1_1_0,
        CSW_2_0_2
    ],
    {
        namespacePrefixes: {
            'http://www.opengis.net/cat/csw/2.0.2': 'csw',
            "http://www.opengis.net/ogc": 'ogc',
            "http://www.opengis.net/gml": "gml"
        },
        mappingStyle : 'simplified'
    }
);

Ows4js.Csw.marshalDocument = function(object){
    return Ows4js.Csw.jsonnixContext.createMarshaller().marshalDocument(object);
};

Ows4js.Csw.unmarshalDocument = function(xml){
    return Ows4js.Csw.jsonnixContext.createUnmarshaller().unmarshalDocument(xml);
};

Ows4js.Csw.unmarshalString = function(string){
    return Ows4js.Csw.jsonnixContext.createUnmarshaller().unmarshalString(string);
};

/**
 * Operation name: GetRecordById
 **/

Ows4js.Csw.prototype.GetRecordById = function(id_list) {
    var byIdAction = new Ows4js.Csw.GetRecordById(id_list);
    //console.log(byIdAction);
    var myXML = Ows4js.Csw.marshalDocument(byIdAction);
    //console.log(myXML);
    var httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
    //console.log(httpRequest.responseXML);
    return Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
};

Ows4js.Csw.prototype.getOperationByName = function(name) {
    return  this.operationsMetadata.operation.filter(function(element){
        return element.name === name;
    })[0];
};

/**
 * Operation name: GetDomain
 * */

Ows4js.Csw.prototype.GetDomain = function(propertyName){
    var getdomainAction = new Ows4js.Csw.GetDomain(propertyName);
    var myXML = Ows4js.Csw.marshalDocument(getdomainAction);
    //console.log(myXML);
    var httpRequest = Ows4js.Util.httpPost(this.url, "application/xml", myXML);
    //console.log(httpRequest.responseXML);
    return Ows4js.Csw.unmarshalDocument(httpRequest.responseXML);
};

/**
 * Templates for Requests
 * */

/**
 * Constraint Request Template
 * */

Ows4js.Csw.Constraint = function(filter){
    this.TYPE_NAME = "CSW_2_0_2.QueryConstraintType";
    this.version = "1.1.0";
    this.filter = filter;
};

/**
 * GetRecords Request Template
 *
 * This Objects already use the simple mapping style from jsonix
 * */

Ows4js.Csw.GetRecords = function(startPosition, maxRecords, query){
    this['csw:GetRecords'] = {
        TYPE_NAME: "CSW_2_0_2.GetRecordsType",
        abstractQuery: query,
        startPosition: startPosition,
        maxRecords: maxRecords,
        resultType: "results",
        service: "CSW",
        version: "2.0.2"
    };
};

/**
 * GetRecordById Request Template
 *
 * This Objects already use the simple mapping style from jsonix
 * */

Ows4js.Csw.GetRecordById = function(ids){
    this['csw:GetRecordById'] ={
        TYPE_NAME: "CSW_2_0_2.GetRecordByIdType",
        elementSetName: {
            ObjectTYPE_NAME: "CSW_2_0_2.ElementSetNameType",
            value: "full"
        },
        id: ids,
{'fraction_non_alphanumeric': 0.1264518546272012, 'fraction_numerical': 0.015548894717122518, 'mean_word_length': 3.191990577149588, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 14}, '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': '6012727', 'n_tokens_mistral': 3573, 'n_tokens_neox': 3530, 'n_words': 619}