From 64051887ce031b36d74349496912e5c337801c15 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 11 Oct 2021 14:02:22 +0300 Subject: [PATCH] [Trunk | Explore]: parsingFunctions.class.ts: [Bug fix] Parse contexts properly when a label is null/undefined or empty string (result landing page). --- .../landing-utils/parsingFunctions.class.ts | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/landingPages/landing-utils/parsingFunctions.class.ts b/landingPages/landing-utils/parsingFunctions.class.ts index 3d844fcc..65a7a806 100644 --- a/landingPages/landing-utils/parsingFunctions.class.ts +++ b/landingPages/landing-utils/parsingFunctions.class.ts @@ -599,49 +599,59 @@ export class ParsingFunctions { "labelCategory": string, "idCategory": string, "labelConcept": string, "idConcept": string }>(); - + let position = 0; let labels = ""; let context; let length = Array.isArray(_contexts) ? _contexts.length : 1; for (let i = 0; i < length; i++) { + let numOfCategories: number = 0; // count categories with label context = Array.isArray(_contexts) ? _contexts[i] : _contexts; - if (context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) { + if (context.label && context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) { if (context.hasOwnProperty("category")) { let category; let length2 = Array.isArray(context['category']) ? context['category'].length : 1; for (let z = 0; z < length2; z++) { + let numOfConcepts: number = 0; // count category concepts with label category = Array.isArray(context['category']) ? context['category'][z] : context['category']; - if (category.hasOwnProperty("concept")) { + if (category.label && category.hasOwnProperty("concept")) { let categoryConcept; let length1 = Array.isArray(category['concept']) ? category['concept'].length : 1; for (let j = 0; j < length1; j++) { categoryConcept = Array.isArray(category['concept']) ? category['concept'][j] : category['concept']; - - contexts[position] = {"labelContext": "", "idContext": "", - "labelCategory": "", "idCategory": "", - "labelConcept": "", "idConcept": ""}; - contexts[position]['labelContext'] = context.label; - contexts[position]['idContext'] = context.id; - contexts[position]['labelCategory'] = category.label; - contexts[position]['idCategory'] = category.id; - contexts[position]['labelConcept'] = categoryConcept.label; - contexts[position]['idConcept'] = categoryConcept.id; - position++; + // initalize if there is concept label or this is the last concept of the category and there were no concepts + // otherwise we could have multiple entries for the same category but without concepts + if(categoryConcept.label || (numOfConcepts == 0 && j == (length1 - 1))) { + contexts[position] = { + "labelContext": "", "idContext": "", + "labelCategory": "", "idCategory": "", + "labelConcept": "", "idConcept": "" + }; + contexts[position]['labelContext'] = context.label; + contexts[position]['idContext'] = context.id; + contexts[position]['labelCategory'] = category.label; + contexts[position]['idCategory'] = category.id; + contexts[position]['labelConcept'] = categoryConcept.label ? categoryConcept.label : null; + contexts[position]['idConcept'] = categoryConcept.label ? categoryConcept.id : null; + + position++; + numOfConcepts++; + } } - } else { + } else if(category.label || (numOfCategories == 0 && z == (length2 - 1))) { contexts[position] = {"labelContext": "", "idContext": "", "labelCategory": "", "idCategory": "", "labelConcept": "", "idConcept": ""}; contexts[position]['labelContext'] = context.label; contexts[position]['idContext'] = context.id; - contexts[position]['labelCategory'] = category.label; - contexts[position]['idCategory'] = category.id; + contexts[position]['labelCategory'] = category.label ? category.label : null; + contexts[position]['idCategory'] = category.label ? category.id : null; contexts[position]['labelConcept'] = null; contexts[position]['idConcept'] = null; position++; + numOfCategories++; } } } else {