<commit_before>var debug = require('debug')('p3api-server:cachemiddleware');
var conf = require("../config");
var when = require("promised-io/promise").when;
var defer = require("promised-io/promise").defer;
var jsonpatch = require("json-patch");
var solrjs = require("solrjs");
var SOLR_URL = conf.get("solr").url;
var Request = require("request");

var userModifiableProperties = [
	"genome_status",
	"strain",
	"serovar",
	"biovar",
	"pathovar",
	"mlst",
	"other_typing",
	"culture_collection",
	"type_strain",
	"completion_date",
	"publication",
	"bioproject_accession",
	"biosample_accession",
	"assembly_accession",
	"sra_accession",
	"ncbi_project_id",
	"refseq_project_id",
	"genbank_accessions",
	"refseq_accessions",
	"sequencing_centers",
	"sequencing_status",
	"sequencing_platform",
	"sequencing_depth",
	"assembly_method",
	"isolation_source",
	"isolation_site",
	"isolation_comments",
	"collection_date",
	"collection_year",
	"isolation_country",
	"geographic_location",
	"latitude",
	"longitude",
	"altitude",
	"depth",
	"other_environmental",
	"host_name",
	"host_gender",
	"host_age",
	"host_health",
	"body_sample_site",
	"body_sample_subsite",
	"other_clinical",
	"antimicrobial_resistance",
	"antimicrobial_resistance_evidence",
	"gram_stain",
	"cell_shape",
	"motility",
	"sporulation",
	"temperature_range",
	"optimal_temperature",
	"salinity",
	"oxygen_requirement",
	"habitat",
	"disease",
	"additional_metadata",
	"comments"
];

function postDocs(docs,type){
        var defs = [];
        var def = new defer();
        var url = conf.get("solr").url + "/"+type+"/update?wt=json&overwrite=true&commit=true";
        //console.log("POST URL: ", url, " #docs:", docs.length);
        Request(url, {
                json: true,
                method: "POST",
                headers: { "content-type": "application/json", "accept":"application/json" },
                body: docs
        }, function(err,response,body){
                if (err || body.error){
                        console.log("Error POSTing to : " + type +" - " + ( err||body.error.msg));
                        def.reject(err);
                        return;
                }
             //   console.log("POST RESPONSE BODY: ", JSON.stringify(body));
                def.resolve(true);
        });

        return def.promise;
}

function solrCommit(type,hard){
        var def = new defer();
//        console.log("Begin " +(hard?"hard":"soft") + " Commit for ", type);
        Request(conf.get("solr").url + "/" + type + "/update?wt=json&" + (hard?"commit":"softCommit") + "=true",{},function(err,response,body){
                if (err) { def.reject(err); return; }
                //console.log("COMMIT " + type + " RESPONSE BODY: ", JSON.stringify(body));
                def.resolve(true);
        });
        return def.promise;
}

module.exports = function(req,res,next){<commit_msg>softcommit would be better<commit_after>var debug = require('debug')('p3api-server:cachemiddleware');
var conf = require("../config");
var when = require("promised-io/promise").when;
var defer = require("promised-io/promise").defer;
var jsonpatch = require("json-patch");
var solrjs = require("solrjs");
var SOLR_URL = conf.get("solr").url;
var Request = require("request");

var userModifiableProperties = [
	"genome_status",
	"strain",
	"serovar",
	"biovar",
	"pathovar",
	"mlst",
	"other_typing",
	"culture_collection",
	"type_strain",
	"completion_date",
	"publication",
	"bioproject_accession",
	"biosample_accession",
	"assembly_accession",
	"sra_accession",
	"ncbi_project_id",
	"refseq_project_id",
	"genbank_accessions",
	"refseq_accessions",
	"sequencing_centers",
	"sequencing_status",
	"sequencing_platform",
	"sequencing_depth",
	"assembly_method",
	"isolation_source",
	"isolation_site",
	"isolation_comments",
	"collection_date",
	"collection_year",
	"isolation_country",
	"geographic_location",
	"latitude",
	"longitude",
	"altitude",
	"depth",
	"other_environmental",
	"host_name",
	"host_gender",
	"host_age",
	"host_health",
	"body_sample_site",
	"body_sample_subsite",
	"other_clinical",
	"antimicrobial_resistance",
	"antimicrobial_resistance_evidence",
	"gram_stain",
	"cell_shape",
	"motility",
	"sporulation",
	"temperature_range",
	"optimal_temperature",
	"salinity",
	"oxygen_requirement",
	"habitat",
	"disease",
	"additional_metadata",
	"comments"
];

function postDocs(docs,type){
        var defs = [];
        var def = new defer();
        var url = conf.get("solr").url + "/"+type+"/update?wt=json&overwrite=true&softCommit=true";
        //console.log("POST URL: ", url, " #docs:", docs.length);
        Request(url, {
                json: true,
                method: "POST",
                headers: { "content-type": "application/json", "accept":"application/json" },
                body: docs
        }, function(err,response,body){
                if (err || body.error){
                        console.log("Error POSTing to : " + type +" - " + ( err||body.error.msg));
                        def.reject(err);
                        return;
                }
             //   console.log("POST RESPONSE BODY: ", JSON.stringify(body));
                def.resolve(true);
        });

        return def.promise;
}

function solrCommit(type,hard){
        var def = new defer();
//        console.log("Begin " +(hard?"hard":"soft") + " Commit for ", type);
        Request(conf.get("solr").url + "/" + type + "/update?wt=json&" + (hard?"commit":"softCommit") + "=true",{},function(err,response,body){
                if (err) { def.reject(err); return; }
                //console.log("COMMIT " + type + " RESPONSE BODY: ", JSON.stringify(body));
                def.resolve(true);
        });
        return def.promise;
}

module.exports = function(req,res,next){
{'fraction_non_alphanumeric': 0.1713497672815032, 'fraction_numerical': 0.0003447681434235477, 'mean_word_length': 3.2599118942731278, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '6395019', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1930, 'n_words': 320}