Commit 1b4ba7b0 authored by Noel Alonso's avatar Noel Alonso
Browse files

Transforma script de groovy a painless

parent c3b1a107
Loading
Loading
Loading
Loading
+32 −22
Original line number Diff line number Diff line
def filterByConfidence = { confidence -> params.confidences.contains(confidence) }
def filterByPathTaxon = { pathTaxon -> params.taxons.contains(pathTaxon) }
def filterByMisidentification = {
	taxon -> taxon.registers.findAll { reg ->
		params.taxons.contains(reg.misidentification)
boolean filterByConfidence(def confidence, def params) {
	params.confidences.contains(confidence);
}
boolean filterByPathTaxon(def pathTaxon, def params) {
	params.taxons.contains(pathTaxon);
}
def addRegisters = { taxon ->
	["registers": taxon.registers.findAll {
		reg -> filterByConfidence(reg.confidence)
	}]
}

_source.properties.registerCount = 0;
_source.properties.taxonCount = 0;

_source.properties.taxons.findAll { tax ->
	if (filterByPathTaxon(tax.path) || filterByPathTaxon(tax.equivalent) || filterByMisidentification(tax)) {
			tax << addRegisters(tax);
boolean filterByMisidentification(def taxon, def params) {

			if (tax.registers.size() > 0) {
				_source.properties.registerCount += tax.registers.size();
				_source.properties.taxonCount++;
	for (reg in taxon.registers) {
		if (params.taxons.contains(reg.misidentification))
			return true;
	}
	return false;
}
	return false;

def getRegisters(def taxon, def params) {
	return ["registers": taxon.registers.findAll(reg -> filterByConfidence(reg.confidence, params))];
}

void checkRegister(def result, def taxon, def params) {
	if (filterByPathTaxon(taxon.path, params) || filterByPathTaxon(taxon.equivalent, params) || filterByMisidentification(taxon, params)) {
			def taxonRegisters = getRegisters(taxon, params);

			if (taxonRegisters.registers.size() > 0) {
				result['properties.registerCount'] += taxon.registers.size();
				result['properties.taxonCount'] ++;
			}
	}
}

Map result = new HashMap();

result['properties.registerCount'] = 0;
result['properties.taxonCount'] = 0;

for (tax in params._source.properties.taxons) {
	checkRegister(result, tax, params);
}

_source.properties.remove("taxons");
return result;