Commit a0004ca8 authored by Giuseppe Tropea's avatar Giuseppe Tropea
Browse files

pushing fromspec to nosqlDB

parent 61c68dc9
Loading
Loading
Loading
Loading
+47 −11
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ fullapi = JSON.parse(fullapi);

var i_am_inside = false;

let testcases_fromspec = [];
var testcasemetadata = {};
testcasemetadata.seqnumber = 0;
testcasemetadata.progressive_subid = 0;
@@ -20,7 +21,7 @@ while(current_index < number_of_blocks) {
            console.log("H2 group not Str!");
            process.exit();
        }
        // we collect all the words composing the clause name, example: "5.6 Context Information Provision"
        // we collect all the words composing the higher-level clause name, example: "5.6 Context Information Provision"
        // but skip the first token because it is the clause number
        testcasemetadata.descriptive_group = value[2].slice(1).filter(el => el.t != "Space").map(el => el.c).join(" ");
    }
@@ -32,16 +33,18 @@ while(current_index < number_of_blocks) {
        // we create metadata for all testcases of this operation:
        // the first token is the clause number
        testcasemetadata.clause_number = value[2][0].c;
        // the group is composed of the first two words of the group descriptive header string taken from the API document
        // the group identifier is composed of the first two words of the group descriptive header string, by removing spaces
        testcasemetadata.group_fromspec = compact_string_array(testcasemetadata.descriptive_group.split(" ").slice(0, 2));
        // the subgroup is composed of the remaining (after 2 till end) words of the group header string taken from the API document
        // the subgroup is composed of the remaining (after 2 till end) words of the group descriptive header string
        testcasemetadata.subgroup_fromspec = compact_string_array(testcasemetadata.descriptive_group.split(" ").slice(2));
        // for the name of the operation we collect all the words composing the sub-clause name, example "5.6.1 Create Entity"
        // but skip the first token because it is the sub-clause number  
        // then we collect, for the name of the operation, all the words composing the lowe-level name, example "5.6.1 Create Entity"
        // but skip the first token because it is the clause number  
        testcasemetadata.descriptive_operation = value[2].slice(1).filter(el => el.t != "Space").map(el => el.c).join(" ");
        console.log("         H3 - "+testcasemetadata.descriptive_group+" - "+testcasemetadata.descriptive_operation);
        // the operation is composed from the descriptive header string of the operation itself taken from the API document
        // the operation identifier is composed from the descriptive header string of the operation itself, by removing spaces
        testcasemetadata.operation_fromspec = compact_string_array(testcasemetadata.descriptive_operation.split(" "));
        // now we need to infer the sub-sub-group, which is the object of the operation, f.e. if the
        // operation is "Create Entity", the the sub-sub-group is "Entity"
    }
    if (is_a_behaviour_header(type, value) && i_am_inside === false) {
        i_am_inside = true;
@@ -58,10 +61,12 @@ while(current_index < number_of_blocks) {
    else if (i_am_inside === true) {
        if (type === "BulletList" || type === "Para") {
            testcasemetadata.progressive_subid++;
            testcasemetadata.tp_id = testcasemetadata.seqnumber.toString().padStart(3, '0') + "_" + testcasemetadata.progressive_subid.toString().padStart(2, '0')
            testcasemetadata.tp_id_fromspec = testcasemetadata.seqnumber.toString().padStart(3, '0') + "_" + testcasemetadata.progressive_subid.toString().padStart(2, '0')
            testcasemetadata.description = value.filter(el => el.t === "Str").map(el => el.c).join(" ");
            console.log("..collecting BLock "+current_index+" of "+value.length+" in "+testcasemetadata.tp_id);
            outputLogger.log(testcasemetadata.tp_id)
            // push a deep copy of the object into the array
            testcases_fromspec.push(JSON.parse(JSON.stringify(testcasemetadata)));
            console.log("..collecting BLock "+current_index+" of "+value.length+" in "+testcasemetadata.tp_id_fromspec);
            outputLogger.log(testcasemetadata.tp_id_fromspec)
            outputLogger.log(testcasemetadata.group_fromspec+"/"+testcasemetadata.subgroup_fromspec+"/"+testcasemetadata.operation_fromspec+"/");
            outputLogger.log(testcasemetadata.clause_number);
            outputLogger.log(testcasemetadata.description);
@@ -74,8 +79,39 @@ while(current_index < number_of_blocks) {
    current_index++;
}

// The URL of the REST endpoint of the NoSQL database
const dburl = "http://ec2-18-153-159-20.eu-central-1.compute.amazonaws.com:5555/fromspec";
// Making a DELETE request
fetch(dburl, { method: 'DELETE' })
  .then(response => console.log(`Delete response status: ${response.status}`))
  .catch(error => console.error('Error:', error));
// Set the appropriate headers for JSON
const headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  // Include any other headers the API requires
};
// Making the POST request
fetch(dburl, {
  method: 'POST',
  headers: headers,
  body: JSON.stringify(testcases_fromspec)
})
.then(response => {
  console.log(`Post response status: ${response.status}`);
  return response.text();
})
.then(text => console.log(text))
.catch(error => console.error('Error:', error));







// check if we are entering a level-4 header that spells "5.x.x.x Behaviour"
// or a level-3 common Behaviour greater that 5.5.2
// or a level-3 common Behaviour greater than 5.5.2
function is_a_behaviour_header(type, value) {
    if (type === "Header" && value[0] === 4 && value[2][0].c.startsWith("5.") && value[2][2].c === "Behaviour") {
        return true;
@@ -112,7 +148,7 @@ function is_a_apigroup_header(type, value) {
    return false;
}

// check if we are parsing a level-2 API operation header
// check if we are parsing a level-3 API operation header
function is_a_apioperation_header(type, value) {
    if (type === "Header" && value[0] === 3 && value[2][0].c.startsWith("5.")) {
        return true;