From 57b9b5ae6754f667358401ca5d8ea9b3f8dc949d Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Thu, 21 Jul 2022 16:11:17 +0200 Subject: [PATCH 1/7] feat: introduced constants for IATI.cloud fields and updated to new field names --- .../filter-api/utils/activityscope.ts | 3 +- .../filter-api/utils/activitystatus.ts | 3 +- .../filter-api/utils/budgetlines.ts | 7 +- .../filter-api/utils/collaborationtype.ts | 3 +- .../controllers/filter-api/utils/countries.ts | 3 +- .../controllers/filter-api/utils/currency.ts | 3 +- .../filter-api/utils/defaultaidtype.ts | 3 +- .../utils/defaultaidtypecategory.ts | 3 +- .../utils/defaultaidtypevocabulary.ts | 3 +- .../filter-api/utils/defaultfinancetype.ts | 3 +- .../filter-api/utils/defaultflowtype.ts | 3 +- .../filter-api/utils/defaulttiedstatus.ts | 3 +- .../filter-api/utils/documentlinkcategory.ts | 3 +- server/controllers/filter-api/utils/donors.ts | 3 +- .../controllers/filter-api/utils/hierarchy.ts | 3 +- .../filter-api/utils/humscopevocab.ts | 3 +- .../filter-api/utils/iativersion.ts | 3 +- .../controllers/filter-api/utils/language.ts | 3 +- .../controllers/filter-api/utils/locations.ts | 11 +- .../filter-api/utils/organisations.ts | 8 +- .../filter-api/utils/otheridentifiertype.ts | 3 +- .../filter-api/utils/policymarker.ts | 3 +- .../filter-api/utils/publishers.ts | 8 +- .../controllers/filter-api/utils/regions.ts | 5 +- .../filter-api/utils/reportingorgtype.ts | 3 +- server/controllers/filter-api/utils/sdgs.ts | 32 +-- .../controllers/filter-api/utils/sectors.ts | 3 +- .../filter-api/utils/sectorvocab.ts | 3 +- .../filter-api/utils/thematicareas.ts | 5 +- .../filter-api/utils/transactionflowtype.ts | 3 +- .../utils/transactionreceiverorg.ts | 3 +- .../filter-api/utils/transactiontiedstatus.ts | 3 +- .../filter-api/utils/transactiontype.ts | 3 +- .../utils/transactionvaluecurrency.ts | 3 +- server/controllers/search-api/countries.ts | 3 +- server/controllers/search-api/donors.ts | 11 +- .../controllers/search-api/organisations.ts | 13 +- server/controllers/search-api/sectors.ts | 5 +- .../controllers/search-api/thematicareas.ts | 5 +- .../table-api/SectorsController.ts | 5 +- server/static/activityDetailConsts.ts | 207 +++++++++++++++-- server/static/apiFilterFields.ts | 219 ++++++++++++++++++ server/static/globalSearchFields.ts | 68 +++--- server/static/sortKeys.ts | 18 +- server/utils/filters.ts | 110 +++++---- server/utils/globalSearch.ts | 10 +- 46 files changed, 660 insertions(+), 171 deletions(-) create mode 100644 server/static/apiFilterFields.ts diff --git a/server/controllers/filter-api/utils/activityscope.ts b/server/controllers/filter-api/utils/activityscope.ts index 9a47b54..be7044a 100644 --- a/server/controllers/filter-api/utils/activityscope.ts +++ b/server/controllers/filter-api/utils/activityscope.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_ACTIVITY_SCOPE_CODE } from "../../../static/apiFilterFields"; export function getActivituScopeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getActivituScopeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "activity_scope_code", + field: AF_ACTIVITY_SCOPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/activitystatus.ts b/server/controllers/filter-api/utils/activitystatus.ts index 9daa17c..5c2bdcf 100644 --- a/server/controllers/filter-api/utils/activitystatus.ts +++ b/server/controllers/filter-api/utils/activitystatus.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_ACTIVITY_STATUS_CODE } from "../../../static/apiFilterFields"; export function getActivituStatusOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getActivituStatusOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "activity_status_code", + field: AF_ACTIVITY_STATUS_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/budgetlines.ts b/server/controllers/filter-api/utils/budgetlines.ts index b08142d..0a98837 100644 --- a/server/controllers/filter-api/utils/budgetlines.ts +++ b/server/controllers/filter-api/utils/budgetlines.ts @@ -8,13 +8,14 @@ import { translatedLines, budgetLineCodes2Values } from "../../../static/budgetLineConsts"; +import { AF_TAG_CODE } from "../../../static/apiFilterFields"; export function getBudgetLinesOptions(filterString = "*:*") { return new Promise((resolve, reject) => { const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( { - q: `${filterString} AND tag_code:243066*`, - fl: "tag_code", + q: `${filterString} AND ${AF_TAG_CODE}:243066*`, + fl: AF_TAG_CODE, rows: 20000 }, "&", @@ -29,7 +30,7 @@ export function getBudgetLinesOptions(filterString = "*:*") { const actualData = get(callResponse, "data.response.docs", []); const result: any = []; actualData.forEach((activity: any) => { - activity.tag_code.forEach((tc: string) => { + activity[`"${AF_TAG_CODE}"`].forEach((tc: string) => { const budgetLine = get(budgetLineCodes2Values, tc, null); if (budgetLine) { const fItemIndex = findIndex(result, { code: tc }); diff --git a/server/controllers/filter-api/utils/collaborationtype.ts b/server/controllers/filter-api/utils/collaborationtype.ts index 89989d4..6bed0ca 100644 --- a/server/controllers/filter-api/utils/collaborationtype.ts +++ b/server/controllers/filter-api/utils/collaborationtype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_COLLABORATION_TYPE_CODE } from "../../../static/apiFilterFields"; export function getCollaborationTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getCollaborationTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "collaboration_type_code", + field: AF_COLLABORATION_TYPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/countries.ts b/server/controllers/filter-api/utils/countries.ts index 6f4b255..2c513c8 100644 --- a/server/controllers/filter-api/utils/countries.ts +++ b/server/controllers/filter-api/utils/countries.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatCountryOptions } from "."; +import { AF_COUNTRY } from "../../../static/apiFilterFields"; export function getCountriesOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getCountriesOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "recipient_country_code", + field: AF_COUNTRY, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/currency.ts b/server/controllers/filter-api/utils/currency.ts index cf0c617..31a130c 100644 --- a/server/controllers/filter-api/utils/currency.ts +++ b/server/controllers/filter-api/utils/currency.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_CURRENCY } from "../../../static/apiFilterFields"; export function getCurrencyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getCurrencyOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_currency", + field: AF_DEFAULT_CURRENCY, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/defaultaidtype.ts b/server/controllers/filter-api/utils/defaultaidtype.ts index 2afc88e..c986314 100644 --- a/server/controllers/filter-api/utils/defaultaidtype.ts +++ b/server/controllers/filter-api/utils/defaultaidtype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatAidTypeOptions } from "."; import { tranlatedAidTypes } from "../../../static/codelists"; +import { AF_DEFAULT_AID_TYPE_CODE } from "../../../static/apiFilterFields"; export function getDefaultAidTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -11,7 +12,7 @@ export function getDefaultAidTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_aid_type_code", + field: AF_DEFAULT_AID_TYPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/defaultaidtypecategory.ts b/server/controllers/filter-api/utils/defaultaidtypecategory.ts index 8b34ffd..8ac6bf8 100644 --- a/server/controllers/filter-api/utils/defaultaidtypecategory.ts +++ b/server/controllers/filter-api/utils/defaultaidtypecategory.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_AID_TYPE_CATEGORY_CODE } from "../../../static/apiFilterFields"; export function getDefaultAidTypeCategoryOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDefaultAidTypeCategoryOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_aid_type_category_code", + field: AF_DEFAULT_AID_TYPE_CATEGORY_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts b/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts index e2489f3..a4d0934 100644 --- a/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts +++ b/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_AID_TYPE_VOCABULARY } from "../../../static/apiFilterFields"; export function getDefaultAidTypeVocabOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDefaultAidTypeVocabOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_aid_type_vocabulary", + field: AF_DEFAULT_AID_TYPE_VOCABULARY, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/defaultfinancetype.ts b/server/controllers/filter-api/utils/defaultfinancetype.ts index 819eb8a..f347556 100644 --- a/server/controllers/filter-api/utils/defaultfinancetype.ts +++ b/server/controllers/filter-api/utils/defaultfinancetype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_FINANCE_CODE } from "../../../static/apiFilterFields"; export function getDefaultFinanceTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDefaultFinanceTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_finance_type_code", + field: AF_DEFAULT_FINANCE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/defaultflowtype.ts b/server/controllers/filter-api/utils/defaultflowtype.ts index 83e61d6..999d0b3 100644 --- a/server/controllers/filter-api/utils/defaultflowtype.ts +++ b/server/controllers/filter-api/utils/defaultflowtype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_FLOW_TYPE_CODE } from "../../../static/apiFilterFields"; export function getDefaultFlowTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDefaultFlowTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_flow_type_code", + field: AF_DEFAULT_FLOW_TYPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/defaulttiedstatus.ts b/server/controllers/filter-api/utils/defaulttiedstatus.ts index 097173b..967c231 100644 --- a/server/controllers/filter-api/utils/defaulttiedstatus.ts +++ b/server/controllers/filter-api/utils/defaulttiedstatus.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_TIED_STATUS_CODE } from "../../../static/apiFilterFields"; export function getDefaultTiedStatusOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDefaultTiedStatusOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_tied_status_code", + field: AF_DEFAULT_TIED_STATUS_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/documentlinkcategory.ts b/server/controllers/filter-api/utils/documentlinkcategory.ts index a856aaa..cc5d222 100644 --- a/server/controllers/filter-api/utils/documentlinkcategory.ts +++ b/server/controllers/filter-api/utils/documentlinkcategory.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DOCUMENT_LINK_CATEGORY_CODE } from "../../../static/apiFilterFields"; export function getDocumentLinkCategoryOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDocumentLinkCategoryOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "document_link_category_code", + field: AF_DOCUMENT_LINK_CATEGORY_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/donors.ts b/server/controllers/filter-api/utils/donors.ts index bd0e40b..83af78d 100644 --- a/server/controllers/filter-api/utils/donors.ts +++ b/server/controllers/filter-api/utils/donors.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatOrganisationsOptions } from "."; +import { AF_TRANSACTION_PROVIDER_ORG_REF } from "../../../static/apiFilterFields"; export function getDonorsOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getDonorsOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/hierarchy.ts b/server/controllers/filter-api/utils/hierarchy.ts index 7e3ade6..ef1c682 100644 --- a/server/controllers/filter-api/utils/hierarchy.ts +++ b/server/controllers/filter-api/utils/hierarchy.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import orderBy from "lodash/orderBy"; import querystring from "querystring"; +import { AF_HIERARCHY } from "../../../static/apiFilterFields"; export function getHierarchyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getHierarchyOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "hierarchy", + field: AF_HIERARCHY, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/humscopevocab.ts b/server/controllers/filter-api/utils/humscopevocab.ts index 3e0b563..826acc6 100644 --- a/server/controllers/filter-api/utils/humscopevocab.ts +++ b/server/controllers/filter-api/utils/humscopevocab.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_HUMANITARIAN_SCOPE_VOCABULARY } from "../../../static/apiFilterFields"; export function getHumanitarianScopeVocabs(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getHumanitarianScopeVocabs(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "humanitarian_scope_vocabulary", + field: AF_HUMANITARIAN_SCOPE_VOCABULARY, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/iativersion.ts b/server/controllers/filter-api/utils/iativersion.ts index 855fd75..5c4615a 100644 --- a/server/controllers/filter-api/utils/iativersion.ts +++ b/server/controllers/filter-api/utils/iativersion.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_IATI_VERSION } from "../../../static/apiFilterFields"; export function getIATIVersionOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getIATIVersionOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "dataset_iati_version", + field: AF_IATI_VERSION, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/language.ts b/server/controllers/filter-api/utils/language.ts index e48d407..c357157 100644 --- a/server/controllers/filter-api/utils/language.ts +++ b/server/controllers/filter-api/utils/language.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_DEFAULT_LANG } from "../../../static/apiFilterFields"; export function getLanguageOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getLanguageOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "default_lang", + field: AF_DEFAULT_LANG, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/locations.ts b/server/controllers/filter-api/utils/locations.ts index b861e73..18fc925 100644 --- a/server/controllers/filter-api/utils/locations.ts +++ b/server/controllers/filter-api/utils/locations.ts @@ -6,6 +6,11 @@ import { formatCountryOptions, formatLocationOptions } from "."; +import { + AF_COUNTRY, + AF_REGION, + AF_REGION_NAME +} from "../../../static/apiFilterFields"; export function getLocationsOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -14,17 +19,17 @@ export function getLocationsOptions(filterString = "*:*") { "json.facet": JSON.stringify({ countries: { type: "terms", - field: "recipient_country_code", + field: AF_COUNTRY, limit: -1 }, regions: { type: "terms", - field: "recipient_region_code", + field: AF_REGION, limit: -1, facet: { sub: { type: "terms", - field: "recipient_region_name", + field: AF_REGION_NAME, limit: 1 } } diff --git a/server/controllers/filter-api/utils/organisations.ts b/server/controllers/filter-api/utils/organisations.ts index 2c08f47..f1f9861 100644 --- a/server/controllers/filter-api/utils/organisations.ts +++ b/server/controllers/filter-api/utils/organisations.ts @@ -3,6 +3,10 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatOrganisationsOptions2 } from "."; // import { orgDacChannel } from "../../../static/orgDacChannel"; +import { + AF_PARTICIPATING_ORG_REF, + AF_PARTICIPATING_ORG_NARRATIVE +} from "../../../static/apiFilterFields"; export function getOrganisationsOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -11,12 +15,12 @@ export function getOrganisationsOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "participating_org_ref", + field: AF_PARTICIPATING_ORG_REF, limit: -1, facet: { names: { type: "terms", - field: "participating_org_narrative", + field: AF_PARTICIPATING_ORG_NARRATIVE, limit: 2 } } diff --git a/server/controllers/filter-api/utils/otheridentifiertype.ts b/server/controllers/filter-api/utils/otheridentifiertype.ts index 755ce40..0f41102 100644 --- a/server/controllers/filter-api/utils/otheridentifiertype.ts +++ b/server/controllers/filter-api/utils/otheridentifiertype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_OTHER_IDENTIFIER_TYPE } from "../../../static/apiFilterFields"; export function getOtherIdentifierTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getOtherIdentifierTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "other_identifier_type", + field: AF_OTHER_IDENTIFIER_TYPE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/policymarker.ts b/server/controllers/filter-api/utils/policymarker.ts index f3a0f00..8525174 100644 --- a/server/controllers/filter-api/utils/policymarker.ts +++ b/server/controllers/filter-api/utils/policymarker.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_POLICY_MARKER_CODE } from "../../../static/apiFilterFields"; export function getPolicyMarkerOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getPolicyMarkerOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "policy_marker_code", + field: AF_POLICY_MARKER_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/publishers.ts b/server/controllers/filter-api/utils/publishers.ts index c42a198..9fb9d50 100644 --- a/server/controllers/filter-api/utils/publishers.ts +++ b/server/controllers/filter-api/utils/publishers.ts @@ -2,6 +2,10 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatPublishersOptions } from "."; +import { + AF_REPORTING_ORG_NARRATIVE, + AF_REPORTING_ORG_REF +} from "../../../static/apiFilterFields"; export function getPublishersOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,12 +14,12 @@ export function getPublishersOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "reporting_org_ref", + field: AF_REPORTING_ORG_REF, limit: -1, facet: { sub: { type: "terms", - field: "reporting_org_narrative", + field: AF_REPORTING_ORG_NARRATIVE, limit: 1 } } diff --git a/server/controllers/filter-api/utils/regions.ts b/server/controllers/filter-api/utils/regions.ts index 734e7f6..c85166a 100644 --- a/server/controllers/filter-api/utils/regions.ts +++ b/server/controllers/filter-api/utils/regions.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatRegionOptions } from "."; +import { AF_REGION, AF_REGION_NAME } from "../../../static/apiFilterFields"; export function getRegionsOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,12 +11,12 @@ export function getRegionsOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "recipient_region_code", + field: AF_REGION, limit: -1, facet: { sub: { type: "terms", - field: "recipient_region_name", + field: AF_REGION_NAME, limit: 1 } } diff --git a/server/controllers/filter-api/utils/reportingorgtype.ts b/server/controllers/filter-api/utils/reportingorgtype.ts index 3273085..6fe1edb 100644 --- a/server/controllers/filter-api/utils/reportingorgtype.ts +++ b/server/controllers/filter-api/utils/reportingorgtype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import { formatOrgOptions } from "."; import querystring from "querystring"; +import { AF_REPORTING_ORG_TYPE_CODE } from "../../../static/apiFilterFields"; export function getReportingOrgTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getReportingOrgTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "reporting_org_type_code", + field: AF_REPORTING_ORG_TYPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/sdgs.ts b/server/controllers/filter-api/utils/sdgs.ts index cda2c43..d499899 100644 --- a/server/controllers/filter-api/utils/sdgs.ts +++ b/server/controllers/filter-api/utils/sdgs.ts @@ -5,13 +5,17 @@ import orderBy from "lodash/orderBy"; import querystring from "querystring"; import findIndex from "lodash/findIndex"; import { GOALS, TARGETS } from "../../../static/sdgs"; +import { + AF_TAG_CODE, + AF_TAG_VOCABULARY +} from "../../../static/apiFilterFields"; export function getSDGOptions(filterString = "*:*") { return new Promise((resolve, reject) => { const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( { - q: `${filterString} AND (tag_vocabulary:2 OR tag_vocabulary:3)`, - fl: "tag_code,tag_vocabulary", + q: `${filterString} AND (${AF_TAG_VOCABULARY}:2 OR ${AF_TAG_VOCABULARY}:3)`, + fl: `${AF_TAG_CODE},${AF_TAG_VOCABULARY}`, rows: 20000 }, "&", @@ -27,36 +31,36 @@ export function getSDGOptions(filterString = "*:*") { const goals: any = []; const targets: any = []; actualData.forEach((activity: any) => { - activity.tag_vocabulary.forEach((tv: string, index: number) => { + activity[AF_TAG_VOCABULARY].forEach((tv: string, index: number) => { if (tv === "2") { - if (activity.tag_code[index]) { + if (activity[AF_TAG_CODE][index]) { const fItemIndex = findIndex(goals, { - code: activity.tag_code[index] + code: activity[AF_TAG_CODE][index] }); - if (fItemIndex === -1 && activity.tag_code[index] !== "0") { + if (fItemIndex === -1 && activity[AF_TAG_CODE][index] !== "0") { goals.push({ name: get( - find(GOALS, { code: activity.tag_code[index] }), + find(GOALS, { code: activity[AF_TAG_CODE][index] }), "name", - activity.tag_code[index] + activity[AF_TAG_CODE][index] ), - code: activity.tag_code[index] + code: activity[AF_TAG_CODE][index] }); } } } else if (tv === "3") { - if (activity.tag_code[index]) { + if (activity[AF_TAG_CODE][index]) { const fItemIndex = findIndex(targets, { - code: activity.tag_code[index] + code: activity[AF_TAG_CODE][index] }); if (fItemIndex === -1) { targets.push({ name: get( - find(TARGETS, { code: activity.tag_code[index] }), + find(TARGETS, { code: activity[AF_TAG_CODE][index] }), "name", - activity.tag_code[index] + activity[AF_TAG_CODE][index] ), - code: activity.tag_code[index] + code: activity[AF_TAG_CODE][index] }); } } diff --git a/server/controllers/filter-api/utils/sectors.ts b/server/controllers/filter-api/utils/sectors.ts index 001249b..d539cc2 100644 --- a/server/controllers/filter-api/utils/sectors.ts +++ b/server/controllers/filter-api/utils/sectors.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatSectorOptions } from "."; import { getSectorsWithData } from "../../table-api/SectorsController"; +import { AF_SECTOR } from "../../../static/apiFilterFields"; export function getSectorsOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -11,7 +12,7 @@ export function getSectorsOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "sector_code", + field: AF_SECTOR, limit: -1 // missing: true, // facet: { diff --git a/server/controllers/filter-api/utils/sectorvocab.ts b/server/controllers/filter-api/utils/sectorvocab.ts index 4c03f28..7f9cd34 100644 --- a/server/controllers/filter-api/utils/sectorvocab.ts +++ b/server/controllers/filter-api/utils/sectorvocab.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_SECTOR_VOCABULARY } from "../../../static/apiFilterFields"; export function getSectorVocabularyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getSectorVocabularyOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "sector_vocabulary", + field: AF_SECTOR_VOCABULARY, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/thematicareas.ts b/server/controllers/filter-api/utils/thematicareas.ts index 8a0a505..ce2014c 100644 --- a/server/controllers/filter-api/utils/thematicareas.ts +++ b/server/controllers/filter-api/utils/thematicareas.ts @@ -5,13 +5,14 @@ import orderBy from "lodash/orderBy"; import querystring from "querystring"; import findIndex from "lodash/findIndex"; import { thematicAreaNames } from "../../../static/thematicAreaConsts"; +import { AF_TAG_CODE } from "../../../static/apiFilterFields"; export function getThematicAreaOptions(filterString = "*:*") { return new Promise((resolve, reject) => { const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( { - q: `${filterString} AND tag_code:Priority*`, - fl: "tag_code", + q: `${filterString} AND ${AF_TAG_CODE}:Priority*`, + fl: AF_TAG_CODE, rows: 20000 }, "&", diff --git a/server/controllers/filter-api/utils/transactionflowtype.ts b/server/controllers/filter-api/utils/transactionflowtype.ts index 5d16522..3acafe6 100644 --- a/server/controllers/filter-api/utils/transactionflowtype.ts +++ b/server/controllers/filter-api/utils/transactionflowtype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_TRANSACTION_FLOW_TYPE_CODE } from "../../../static/apiFilterFields"; export function getTransactionFlowTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getTransactionFlowTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_flow_type_code", + field: AF_TRANSACTION_FLOW_TYPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/transactionreceiverorg.ts b/server/controllers/filter-api/utils/transactionreceiverorg.ts index 9400ba3..d93cf47 100644 --- a/server/controllers/filter-api/utils/transactionreceiverorg.ts +++ b/server/controllers/filter-api/utils/transactionreceiverorg.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import { formatOrgOptions } from "."; import querystring from "querystring"; +import { AF_TRANSACTION_RECEIVER_ORG_REF } from "../../../static/apiFilterFields"; export function getTransactionReceiverOrgOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getTransactionReceiverOrgOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_receiver_org_ref", + field: AF_TRANSACTION_RECEIVER_ORG_REF, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/transactiontiedstatus.ts b/server/controllers/filter-api/utils/transactiontiedstatus.ts index 6a412ac..0631650 100644 --- a/server/controllers/filter-api/utils/transactiontiedstatus.ts +++ b/server/controllers/filter-api/utils/transactiontiedstatus.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_TRANSACTION_TIED_STATUS_CODE } from "../../../static/apiFilterFields"; export function getTransactionTiedStatusOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getTransactionTiedStatusOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_tied_status_code", + field: AF_TRANSACTION_TIED_STATUS_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/transactiontype.ts b/server/controllers/filter-api/utils/transactiontype.ts index e0c8c7e..356a734 100644 --- a/server/controllers/filter-api/utils/transactiontype.ts +++ b/server/controllers/filter-api/utils/transactiontype.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_TRANSACTION_TYPE_CODE } from "../../../static/apiFilterFields"; export function getTransactionTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getTransactionTypeOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_type", + field: AF_TRANSACTION_TYPE_CODE, limit: -1 } }), diff --git a/server/controllers/filter-api/utils/transactionvaluecurrency.ts b/server/controllers/filter-api/utils/transactionvaluecurrency.ts index dfc6938..03ae99a 100644 --- a/server/controllers/filter-api/utils/transactionvaluecurrency.ts +++ b/server/controllers/filter-api/utils/transactionvaluecurrency.ts @@ -2,6 +2,7 @@ import axios from "axios"; import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; +import { AF_TRANSACTION_VALUE_CURRENCY } from "../../../static/apiFilterFields"; export function getTransactionValueCurrencyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -10,7 +11,7 @@ export function getTransactionValueCurrencyOptions(filterString = "*:*") { "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_value_currency", + field: AF_TRANSACTION_VALUE_CURRENCY, limit: -1 } }), diff --git a/server/controllers/search-api/countries.ts b/server/controllers/search-api/countries.ts index 3515878..a5af825 100644 --- a/server/controllers/search-api/countries.ts +++ b/server/controllers/search-api/countries.ts @@ -4,6 +4,7 @@ import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getCountries } from "../../utils/globalSearch"; import { getFormattedSearchParam } from "../../utils/filters"; +import { AF_COUNTRY } from "../../static/apiFilterFields"; export function searchCountries(req: any, res: any) { if (!req.body.q || req.body.q.length === 0) { @@ -19,7 +20,7 @@ export function searchCountries(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "recipient_country_code", + field: AF_COUNTRY, limit, offset, numBuckets: true diff --git a/server/controllers/search-api/donors.ts b/server/controllers/search-api/donors.ts index e373074..348ea42 100644 --- a/server/controllers/search-api/donors.ts +++ b/server/controllers/search-api/donors.ts @@ -4,6 +4,11 @@ import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getDonors } from "../../utils/globalSearch"; import { getFormattedSearchParam } from "../../utils/filters"; +import { + AF_REPORTING_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_REF +} from "../../static/apiFilterFields"; export function searchDonors(req: any, res: any) { if (!req.body.q || req.body.q.length === 0) { @@ -15,11 +20,11 @@ export function searchDonors(req: any, res: any) { const limit = get(req.body, "rows", 10); const offset = get(req.body, "page", 0) * limit; const values = { - q: `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND transaction_provider_org_narrative:"${req.body.q}"`, + q: `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND ${AF_TRANSACTION_PROVIDER_ORG_NARRATIVE}:"${req.body.q}"`, "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit, offset, missing: true, @@ -27,7 +32,7 @@ export function searchDonors(req: any, res: any) { facet: { sub: { type: "terms", - field: "transaction_provider_org_narrative", + field: AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, limit: 1 } } diff --git a/server/controllers/search-api/organisations.ts b/server/controllers/search-api/organisations.ts index 5c2a17e..8dcc8ec 100644 --- a/server/controllers/search-api/organisations.ts +++ b/server/controllers/search-api/organisations.ts @@ -3,6 +3,11 @@ import get from "lodash/get"; import uniqBy from "lodash/uniqBy"; import querystring from "querystring"; import { genericError } from "../../utils/general"; +import { + AF_REPORTING_ORG_REF, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_REF +} from "../../static/apiFilterFields"; export function searchOrganisations(req: any, res: any) { if (!req.body.q || req.body.q.length === 0) { @@ -15,8 +20,8 @@ export function searchOrganisations(req: any, res: any) { const offset = get(req.body, "page", 0) * limit; const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( { - q: `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND participating_org_narrative:"${req.body.q}"`, - fl: "participating_org_ref,participating_org_narrative", + q: `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND ${AF_PARTICIPATING_ORG_NARRATIVE}:"${req.body.q}"`, + fl: `${AF_PARTICIPATING_ORG_REF},${AF_PARTICIPATING_ORG_NARRATIVE}`, rows: 20000 }, "&", @@ -32,11 +37,11 @@ export function searchOrganisations(req: any, res: any) { const actualData = get(callResponse, "data.response.docs", []); let orgs: any[] = []; actualData.forEach((doc: any) => { - doc.participating_org_ref.forEach((ref: string, index: number) => { + doc[AF_PARTICIPATING_ORG_REF].forEach((ref: string, index: number) => { if (ref.trim().length > 0) { orgs.push({ ref, - name: doc.participating_org_narrative[index] + name: doc[AF_PARTICIPATING_ORG_NARRATIVE][index] }); } }); diff --git a/server/controllers/search-api/sectors.ts b/server/controllers/search-api/sectors.ts index ab7ca46..ff33ed3 100644 --- a/server/controllers/search-api/sectors.ts +++ b/server/controllers/search-api/sectors.ts @@ -6,6 +6,7 @@ import { genericError } from "../../utils/general"; import { getSectors } from "../../utils/globalSearch"; import { dac3sectors } from "../../static/dac3sectors"; import { dac5sectors } from "../../static/dac5sectors"; +import { AF_REPORTING_ORG_REF, AF_SECTOR } from "../../static/apiFilterFields"; export function searchSectors(req: any, res: any) { if (!req.body.q || req.body.q.length === 0) { @@ -23,11 +24,11 @@ export function searchSectors(req: any, res: any) { .map((s: any) => s.code) .join(" "); const values = { - q: `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND (sector_code:"${req.body.q}" OR sector_code:(${fSectors}))`, + q: `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND (${AF_SECTOR}:"${req.body.q}" OR ${AF_SECTOR}:(${fSectors}))`, "json.facet": JSON.stringify({ items: { type: "terms", - field: "sector_code", + field: AF_SECTOR, limit, offset, numBuckets: true diff --git a/server/controllers/search-api/thematicareas.ts b/server/controllers/search-api/thematicareas.ts index a6188f5..0dc7ed4 100644 --- a/server/controllers/search-api/thematicareas.ts +++ b/server/controllers/search-api/thematicareas.ts @@ -5,6 +5,7 @@ import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getFormattedSearchParam } from "../../utils/filters"; import { thematicAreaNames } from "../../static/thematicAreaConsts"; +import { AF_TAG_CODE } from "../../static/apiFilterFields"; export function searchThematicareas(req: any, res: any) { if (!req.body.q || req.body.q.length === 0) { @@ -16,11 +17,11 @@ export function searchThematicareas(req: any, res: any) { const values = { q: `${getFormattedSearchParam( req.body.q - )} AND (tag_code:Priority* OR tag_code:(${req.body.q}))`, + )} AND (${AF_TAG_CODE}:Priority* OR ${AF_TAG_CODE}:(${req.body.q}))`, "json.facet": JSON.stringify({ items: { type: "terms", - field: "tag_code", + field: AF_TAG_CODE, limit: -1 } }), diff --git a/server/controllers/table-api/SectorsController.ts b/server/controllers/table-api/SectorsController.ts index aca3c6c..02dc2c4 100644 --- a/server/controllers/table-api/SectorsController.ts +++ b/server/controllers/table-api/SectorsController.ts @@ -9,6 +9,7 @@ import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getFormattedFilters } from "../../utils/filters"; import { sectorMapping } from "../../static/sectorMapping"; +import { AF_SECTOR, AF_SECTOR_NARRATIVE } from "../../static/apiFilterFields"; // exclude sectors that don't have data export function getSectorsWithData(sectorData: any) { @@ -41,14 +42,14 @@ export function sectorsTable(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "sector_code", + field: AF_SECTOR, limit: -1, missing: true, numBuckets: true, facet: { sub: { type: "terms", - field: "sector_narrative_text", + field: AF_SECTOR_NARRATIVE, limit: 1 } } diff --git a/server/static/activityDetailConsts.ts b/server/static/activityDetailConsts.ts index fccce23..a428e76 100644 --- a/server/static/activityDetailConsts.ts +++ b/server/static/activityDetailConsts.ts @@ -1,16 +1,193 @@ -export const activityMetadataFl = `default_currency,activity_status_code,collaboration_type_code, -capital_spend_percentage,default_flow_type_code,hierarchy, -iati_identifier,default_finance_type_code,default_tied_status_code, -default_lang,reporting_org:[json],title_narrative_text,title_narrative_lang,description_narrative_text,description_lang, -participating_org:[json],activity_date:[json],contact_info:[json], -recipient_country:[json],sector:[json], -policy_marker:[json],default_aid_type:[json],recipient_region:[json], -planned_disbursement_type,planned_disbursement_value,planned_disbursement_value_currency,planned_disbursement_period_start_iso_date,planned_disbursement_period_end_iso_date,planned_disbursement_provider_org_narrative_text, -budget:[json],document_link_title_narrative_text,document_link_url,document_link_category_code,other_identifier:[json],humanitarian_scope_type,humanitarian_scope_vocabulary,humanitarian_scope_code,humanitarian_scope_narrative_text, -location_point_pos,location_description_narrative_text,reporting_org_narrative,reporting_org_ref,crs_add:[json], -activity_date_type,activity_date_iso_date,fss:[json],related_activity_ref,related_activity_type,tag_code,tag_narrative_text,other_identifier_ref,other_identifier_owner_org_narrative_text, -country_budget_items_vocabulary,country_budget_items_budget_item_code,country_budget_items_budget_item_percentage,country_budget_items_budget_description_narrative_text, -legacy_data_name,legacy_data_value,legacy_data_iati_equivalent,conditions_condition_type,conditions_condition_narrative_text,activity_scope_code,transaction_recipient_country_code,transaction_sector_code`; +import { + AF_ACTIVITY_DATE_END_ACTUAL, + AF_ACTIVITY_DATE_END_PLANNED, + AF_ACTIVITY_DATE_START_ACTUAL, + AF_ACTIVITY_DATE_START_PLANNED, + AF_ACTIVITY_SCOPE_CODE, + AF_ACTIVITY_STATUS_CODE, + AF_BUDGET_PERIOD_END_ISO_DATE, + AF_BUDGET_PERIOD_START_ISO_DATE, + AF_BUDGET_STATUS_NAME, + AF_BUDGET_TYPE_NAME, + AF_CAPITAL_SPEND_PERCENTAGE, + AF_COLLABORATION_TYPE_CODE, + AF_CONTACT_INFO_TYPE, + AF_CONTACT_INFO_TELEPHONE, + AF_CONTACT_INFO_EMAIL, + AF_CONTACT_INFO_WEBSITE, + AF_CONTACT_INFO_ORG_NARRATIVE, + AF_CONTACT_INFO_DEPARTMENT_NARRATIVE, + AF_CONTACT_INFO_PERSON_NAME_NARRATIVE, + AF_CONTACT_INFO_JOB_TITLE_NARRATIVE, + AF_CONTACT_INFO_MAILING_ADDRESS_NARRATIVE, + AF_COUNTRY, + AF_COUNTRY_NAME, + AF_COUNTRY_PERCENTAGE, + AF_DEFAULT_AID_TYPE_CODE, + AF_DEFAULT_AID_TYPE_NAME, + AF_DEFAULT_AID_TYPE_VOCABULARY, + AF_DEFAULT_CURRENCY, + AF_DEFAULT_FINANCE_CODE, + AF_DEFAULT_FLOW_TYPE_CODE, + AF_DEFAULT_LANG, + AF_DEFAULT_TIED_STATUS_CODE, + AF_DOCUMENT_LINK_CATEGORY_CODE, + AF_HIERARCHY, + AF_HUMANITARIAN_SCOPE_CODE, + AF_HUMANITARIAN_SCOPE_VOCABULARY, + AF_IATI_IDENTIFIER, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_REF, + AF_PARTICIPATING_ORG_ROLE, + AF_PARTICIPATING_ORG_TYPE, + AF_POLICY_MARKER_CODE, + AF_POLICY_MARKER_NAME, + AF_POLICY_MARKER_SIGNIFICANCE, + AF_POLICY_MARKER_VOCABULARY_NAME, + AF_POLICY_MARKER_VOCABULARY_URI, + AF_REGION, + AF_REGION_NAME, + AF_REGION_PERCENTAGE, + AF_RELATED_ACTIVITY_REF, + AF_RELATED_ACTIVITY_TYPE, + AF_REPORTING_ORG_REF, + AF_REPORTING_ORG_TYPE_NAME, + AF_SECTOR, + AF_SECTOR_NAME, + AF_SECTOR_PERCENTAGE, + AF_TAG_CODE, + AF_TAG_NARRATIVE, + AF_TRANSACTION_COUNTRY, + AF_TRANSACTION_VALUE_CURRENCY, + AF_TITLE_NARRATIVE, + AF_TITLE_NARRATIVE_LANG, + AF_DESCRIPTION_NARRATIVE, + AF_DESCRIPTION_NARRATIVE_LANG, + AF_PLANNED_DISBURSEMENT_TYPE, + AF_PLANNED_DISBURSEMENT_VALUE, + AF_PLANNED_DISBURSEMENT_VALUE_CURRENCY, + AF_PLANNED_DISBURSEMENT_PERIOD_START_ISO_DATE, + AF_PLANNED_DISBURSEMENT_PERIOD_END_ISO_DATE, + AF_PLANNED_DISBURSEMENT_PROVIDER_ORG_NARRATIVE, + AF_DOCUMENT_LINK_NARRATIVE, + AF_DOCUMENT_LINK_URL, + AF_HUMANITARIAN_SCOPE_TYPE, + AF_HUMANITARIAN_SCOPE_NARRATIVE, + AF_LOCATION_POINT_POS, + AF_LOCATION_AF_DESCRIPTION_NARRATIVE, + AF_REPORTING_ORG_NARRATIVE, + AF_ACTIVITY_DATE_TYPE, + AF_ACTIVITY_DATE_ISO_DATE, + AF_OTHER_IDENTIFIER_REF, + AF_OTHER_IDENTIFIER_OWNER_ORG_NARRATIVE, + AF_COUNTRY_BUDGET_ITEMS_VOCABULARY, + AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_CODE, + AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_PERCENTAGE, + AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_DESCRIPTION_NARRATIVE, + AF_LEGACY_DATA_NAME, + AF_LEGACY_DATA_VALUE, + AF_LEGACY_DATA_IATI_EQUIVALENT, + AF_CONDITIONS_CONDITION_TYPE, + AF_CONDITIONS_CONDITION_NARRATIVE, + AF_TRANSACTION_SECTOR_CODE, + AF_TRANSACTION_TYPE_CODE, + AF_TRANSACTION_DATE_ISO_DATE, + AF_TRANSACTION +} from "./apiFilterFields"; -export const activityTransactionsFl = - "iati_identifier,transaction_date_iso_date,transaction_value,transaction_value_currency,transaction_type"; +export const activityMetadataFl = `${AF_DEFAULT_CURRENCY}, +${AF_ACTIVITY_STATUS_CODE}, +${AF_COLLABORATION_TYPE_CODE}, +${AF_CAPITAL_SPEND_PERCENTAGE}, +${AF_DEFAULT_FLOW_TYPE_CODE}, +${AF_HIERARCHY}, +${AF_IATI_IDENTIFIER}, +${AF_DEFAULT_FINANCE_CODE}, +${AF_DEFAULT_TIED_STATUS_CODE}, +${AF_DEFAULT_LANG}, +${AF_REPORTING_ORG_TYPE_NAME}, +${AF_TITLE_NARRATIVE}, +${AF_TITLE_NARRATIVE_LANG}, +${AF_DESCRIPTION_NARRATIVE}, +${AF_DESCRIPTION_NARRATIVE_LANG}, +${AF_PARTICIPATING_ORG_NARRATIVE}, +${AF_PARTICIPATING_ORG_REF}, +${AF_PARTICIPATING_ORG_TYPE}, +${AF_PARTICIPATING_ORG_ROLE}, +${AF_ACTIVITY_DATE_START_PLANNED}, +${AF_ACTIVITY_DATE_END_PLANNED}, +${AF_ACTIVITY_DATE_START_ACTUAL}, +${AF_ACTIVITY_DATE_END_ACTUAL}, +${AF_CONTACT_INFO_TYPE}, +${AF_CONTACT_INFO_TELEPHONE}, +${AF_CONTACT_INFO_EMAIL}, +${AF_CONTACT_INFO_WEBSITE}, +${AF_CONTACT_INFO_ORG_NARRATIVE}, +${AF_CONTACT_INFO_DEPARTMENT_NARRATIVE}, +${AF_CONTACT_INFO_PERSON_NAME_NARRATIVE}, +${AF_CONTACT_INFO_JOB_TITLE_NARRATIVE}, +${AF_CONTACT_INFO_MAILING_ADDRESS_NARRATIVE}, +${AF_COUNTRY}, +${AF_COUNTRY_NAME}, +${AF_COUNTRY_PERCENTAGE}, +${AF_SECTOR}, +${AF_SECTOR_NAME}, +${AF_SECTOR_PERCENTAGE}, +${AF_POLICY_MARKER_CODE}, +${AF_POLICY_MARKER_NAME}, +${AF_POLICY_MARKER_SIGNIFICANCE}, +${AF_POLICY_MARKER_VOCABULARY_NAME}, +${AF_POLICY_MARKER_VOCABULARY_URI}, +${AF_DEFAULT_AID_TYPE_CODE}, +${AF_DEFAULT_AID_TYPE_NAME}, +${AF_DEFAULT_AID_TYPE_VOCABULARY}, +${AF_REGION}, +${AF_REGION_NAME}, +${AF_REGION_PERCENTAGE}, +${AF_PLANNED_DISBURSEMENT_TYPE}, +${AF_PLANNED_DISBURSEMENT_VALUE}, +${AF_PLANNED_DISBURSEMENT_VALUE_CURRENCY}, +${AF_PLANNED_DISBURSEMENT_PERIOD_START_ISO_DATE}, +${AF_PLANNED_DISBURSEMENT_PERIOD_END_ISO_DATE}, +${AF_PLANNED_DISBURSEMENT_PROVIDER_ORG_NARRATIVE},// +${AF_BUDGET_TYPE_NAME}, +${AF_BUDGET_STATUS_NAME}, +${AF_BUDGET_PERIOD_START_ISO_DATE}, +${AF_BUDGET_PERIOD_END_ISO_DATE}, +${AF_DOCUMENT_LINK_NARRATIVE}, +${AF_DOCUMENT_LINK_URL}, +${AF_DOCUMENT_LINK_CATEGORY_CODE}, +${AF_HUMANITARIAN_SCOPE_TYPE}, +${AF_HUMANITARIAN_SCOPE_VOCABULARY}, +${AF_HUMANITARIAN_SCOPE_CODE}, +${AF_HUMANITARIAN_SCOPE_NARRATIVE}, +${AF_LOCATION_POINT_POS}, +${AF_LOCATION_AF_DESCRIPTION_NARRATIVE}, +${AF_REPORTING_ORG_NARRATIVE}, +${AF_REPORTING_ORG_REF}, +${AF_ACTIVITY_DATE_TYPE}, +${AF_ACTIVITY_DATE_ISO_DATE}, +${AF_RELATED_ACTIVITY_REF}, +${AF_RELATED_ACTIVITY_TYPE}, +${AF_TAG_CODE}, +${AF_TAG_NARRATIVE}, +${AF_OTHER_IDENTIFIER_REF}, +${AF_OTHER_IDENTIFIER_OWNER_ORG_NARRATIVE}, +${AF_COUNTRY_BUDGET_ITEMS_VOCABULARY}, +${AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_CODE}, +${AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_PERCENTAGE}, +${AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_DESCRIPTION_NARRATIVE}, +${AF_LEGACY_DATA_NAME}, +${AF_LEGACY_DATA_VALUE}, +${AF_LEGACY_DATA_IATI_EQUIVALENT}, +${AF_CONDITIONS_CONDITION_TYPE}, +${AF_CONDITIONS_CONDITION_NARRATIVE}, +${AF_ACTIVITY_SCOPE_CODE}, +${AF_TRANSACTION_COUNTRY}, +${AF_TRANSACTION_SECTOR_CODE}`; + +export const activityTransactionsFl = `${AF_IATI_IDENTIFIER}, +${AF_TRANSACTION_DATE_ISO_DATE}, +${AF_TRANSACTION}, +${AF_TRANSACTION_VALUE_CURRENCY}, +${AF_TRANSACTION_TYPE_CODE}`; diff --git a/server/static/apiFilterFields.ts b/server/static/apiFilterFields.ts new file mode 100644 index 0000000..c714cbf --- /dev/null +++ b/server/static/apiFilterFields.ts @@ -0,0 +1,219 @@ +// template, always prepend with `AF_` for API FIELD. +export const _API_FIELD = ""; + +// A +export const AF_ACTIVITY_DATE_END_ACTUAL = "activity-date.end-actual"; +export const AF_ACTIVITY_DATE_END_ACTUAL_UNDERSCORED = + "activity_date_end_actual_f"; +export const AF_ACTIVITY_DATE_END_COMMON = "activity-date.common.end"; +export const AF_ACTIVITY_DATE_END_PLANNED = "activity-date.end-planned"; +export const AF_ACTIVITY_DATE_END_PLANNED_UNDERSCORED = + "activity_date_end_planned_f"; +export const AF_ACTIVITY_DATE_ISO_DATE = "activity-date.iso-date"; +export const AF_ACTIVITY_DATE_START_ACTUAL = "activity-date.start-actual"; +export const AF_ACTIVITY_DATE_START_ACTUAL_UNDERSCORED = + "activity_date_start_actual"; +export const AF_ACTIVITY_DATE_START_COMMON = "activity-date.common.start"; +export const AF_ACTIVITY_DATE_START_PLANNED = "activity-date.start-planned"; +export const AF_ACTIVITY_DATE_START_PLANNED_UNDERSCORED = + "activity_date_start_planned_f"; +export const AF_ACTIVITY_DATE_TYPE = "activity-date.type"; +export const AF_ACTIVITY_SCOPE_CODE = "activity-scope.code"; +export const AF_ACTIVITY_STATUS_CODE = "activity-status.code"; + +// B +export const AF_BUDGET = "budget.value-usd"; +export const AF_BUDGET_TYPE_NAME = "budget.type.name"; +export const AF_BUDGET_PERIOD_START_ISO_DATE = "budget.period-start.iso-date"; +export const AF_BUDGET_PERIOD_END_ISO_DATE = "budget.period-end.iso-date"; +export const AF_BUDGET_STATUS_NAME = "budget.status.name"; +export const AF_BUDGET_VALUE = "budget.value"; +export const AF_BUDGET_VALUE_CURRENCY = "budget.value.currency"; +export const AF_BUDGET_VALUE_DATE = "budget.value.value-date"; +export const AF_BUDGET_VALUE_UNDERSCORED = "budget_value"; +export const AF_BUDGET_VALUE_USD_SUM = "budget.value-usd.sum"; + +// C +export const AF_CAPITAL_SPEND_PERCENTAGE = "capital-spend.percentage"; +export const AF_COLLABORATION_TYPE_CODE = "collaboration-type.code"; +export const AF_CONDITIONS_CONDITION_NARRATIVE = + "conditions.condition.narrative"; +export const AF_CONDITIONS_CONDITION_TYPE = "conditions.condition.type"; +export const AF_CONTACT_INFO_TYPE = "contact-info.type"; +export const AF_CONTACT_INFO_TELEPHONE = "contact-info.telephone"; +export const AF_CONTACT_INFO_EMAIL = "contact-info.email"; +export const AF_CONTACT_INFO_WEBSITE = "contact-info.website"; +export const AF_CONTACT_INFO_ORG_NARRATIVE = + "contact-info.organisation.narrative"; +export const AF_CONTACT_INFO_DEPARTMENT_NARRATIVE = + "contact-info.department.narrative"; +export const AF_CONTACT_INFO_PERSON_NAME_NARRATIVE = + "contact-info.person-name.narrative"; +export const AF_CONTACT_INFO_JOB_TITLE_NARRATIVE = + "contact-info.job-title.narrative"; +export const AF_CONTACT_INFO_MAILING_ADDRESS_NARRATIVE = + "contact-info.mailing-address.narrative"; +export const AF_COUNTRY = "recipient-country.code"; +export const AF_COUNTRY_NAME = "recipient-country.name"; +export const AF_COUNTRY_PERCENTAGE = "recipient-country.percentage"; +export const AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_CODE = + "country-budget-items.budget-item.code"; +export const AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_PERCENTAGE = + "country-budget-items.budget-item.percentage"; +export const AF_COUNTRY_BUDGET_ITEMS_BUDGET_ITEM_DESCRIPTION_NARRATIVE = + "country-budget-items.budget-item.description.narrative"; +export const AF_COUNTRY_BUDGET_ITEMS_VOCABULARY = + "country-budget-items.vocabulary"; + +// D +export const AF_DEFAULT_AID_TYPE_CATEGORY_CODE = + "default_aid_type_category_code"; +export const AF_DEFAULT_AID_TYPE_CODE = "default-aid-type.code"; +export const AF_DEFAULT_AID_TYPE_NAME = "default-aid-type.name"; +export const AF_DEFAULT_AID_TYPE_VOCABULARY = "default-aid-type.vocabulary"; +export const AF_DEFAULT_CURRENCY = "default-currency"; +export const AF_DEFAULT_FINANCE_CODE = "default-finance-type.code"; +export const AF_DEFAULT_FLOW_TYPE_CODE = "default-flow-type.code"; +export const AF_DEFAULT_LANG = "lang"; +export const AF_DESCRIPTION_NARRATIVE = "description.narrative"; +export const AF_DESCRIPTION_NARRATIVE_LANG = "description.narrative.lang"; +export const AF_DOCUMENT_LINK_CATEGORY_CODE = "document-link.category.code"; +export const AF_DOCUMENT_LINK_NARRATIVE = "document-link.title.narrative"; +export const AF_DOCUMENT_LINK_URL = "document-link.url"; +export const AF_DEFAULT_TIED_STATUS_CODE = "default-tied-status.code"; + +// H +export const AF_HIERARCHY = "hierarchy"; +export const AF_HUMANITARIAN_SCOPE_CODE = "humanitarian-scope.code"; +export const AF_HUMANITARIAN_SCOPE_NARRATIVE = "humanitarian-scope.narrative"; +export const AF_HUMANITARIAN_SCOPE_TYPE = "humanitarian-scope.type"; +export const AF_HUMANITARIAN_SCOPE_VOCABULARY = "humanitarian-scope.vocabulary"; + +// I +export const AF_IATI_IDENTIFIER = "iati-identifier"; +export const AF_IATI_VERSION = "dataset.extras.iati_version"; + +// L +export const AF_LEGACY_DATA_NAME = "legacy-data.name"; +export const AF_LEGACY_DATA_IATI_EQUIVALENT = "legacy-data.iati-equivalent"; +export const AF_LEGACY_DATA_VALUE = "legacy-data.value"; +export const AF_LOCATION_POINT_POS = "location.point.pos"; +export const AF_LOCATION_AF_DESCRIPTION_NARRATIVE = + "location.description.narrative"; + +// O +export const AF_OTHER_IDENTIFIER_OWNER_ORG_NARRATIVE = + "other-identifier.owner-org.narrative"; +export const AF_OTHER_IDENTIFIER_REF = "other-identifier.ref"; +export const AF_OTHER_IDENTIFIER_TYPE = "other-identifier.type"; + +// P +export const AF_PARTICIPATING_ORG_NARRATIVE = "participating-org.narrative"; +export const AF_PARTICIPATING_ORG_REF = "participating-org.ref"; +export const AF_PARTICIPATING_ORG_ROLE = "participating-org.role"; +export const AF_PARTICIPATING_ORG_TYPE = "participating-org.type"; +export const AF_POLICY_MARKER_CODE = "policy-marker.code"; +export const AF_POLICY_MARKER_COMBINED = "policy-marker.combined"; +export const AF_POLICY_MARKER_NAME = "policy-marker.name"; +export const AF_POLICY_MARKER_SIGNIFICANCE = "policy-marker.significance.name"; +export const AF_POLICY_MARKER_VOCABULARY_NAME = "policy-marker.vocabulary.name"; +export const AF_POLICY_MARKER_VOCABULARY_URI = "policy-marker.vocabulary-uri"; +export const AF_PLANNED_DISBURSEMENT_PERIOD_START_ISO_DATE = + "planned-disbursement.period-start.iso-date"; +export const AF_PLANNED_DISBURSEMENT_PERIOD_END_ISO_DATE = + "planned-disbursement.period-end.iso-date"; +export const AF_PLANNED_DISBURSEMENT_PROVIDER_ORG_NARRATIVE = + "planned-disbursement.provider-org.narrative"; +export const AF_PLANNED_DISBURSEMENT_TYPE = "planned-disbursement.type"; +export const AF_PLANNED_DISBURSEMENT_VALUE = "planned-disbursement.value"; +export const AF_PLANNED_DISBURSEMENT_VALUE_CURRENCY = + "planned-disbursement.value.currency"; + +// R +export const AF_REGION = "recipient-region.code"; +export const AF_REGION_NAME = "recipient-region.name"; +export const AF_REGION_PERCENTAGE = "recipient-region.percentage"; +export const AF_RELATED_ACTIVITY_REF = "related-activity.ref"; +export const AF_RELATED_ACTIVITY_TYPE = "related-activity.type"; +export const AF_REPORTING_ORG_REF = "reporting-org.ref"; +export const AF_REPORTING_ORG_NARRATIVE = "reporting-org.narrative"; +export const AF_REPORTING_ORG_TYPE_CODE = "reporting-org.type"; +export const AF_REPORTING_ORG_TYPE_NAME = "reporting-org.type.name"; +export const AF_REPORTING_ORG_SECONDARY_REPORTER = + "reporting-org.secondary-reporter"; +export const AF_RESULT_TITLE_NARRATIVE = "result.title.narrative"; +export const AF_RESULT_TYPE = "result.type"; +export const AF_RESULT_INDICATOR_MEASURE = "result.indicator.measure"; +export const AF_RESULT_INDICATOR_BASELINE_VALUE = + "result.indicator.baseline.value"; +export const AF_RESULT_INDICATOR_BASELINE_INDEX = + "result.indicator.baseline-index"; +export const AF_RESULT_INDICATOR_PERIOD_INDEX = "result.indicator.period-index"; +export const AF_RESULT_INDICATOR_PERIOD_START_DATE = + "result.indicator.period.period-start.iso-date"; +export const AF_RESULT_INDICATOR_PERIOD_END_DATE = + "result.indicator.period.period-end.iso-date"; +export const AF_RESULT_INDICATOR_PERIOD_ACTUAL_VALUE = + "result.indicator.period.actual.value"; +export const AF_RESULT_INDICATOR_PERIOD_TARGET_VALUE = + "result.indicator.period.target.value"; +export const AF_RESULT_INDICATOR_PERIOD_ACTUAL_INDEX = + "result.indicator.period.actual-index"; +export const AF_RESULT_INDICATOR_PERIOD_TARGET_INDEX = + "result.indicator.period.target-index"; +export const AF_RESULT_INDICATOR_TITLE_NARRATIVE = + "result.indicator.title.narrative"; +export const AF_RESULT_INDICATOR_AF_DESCRIPTION_NARRATIVE = + "result.indicator.description.narrative"; +export const AF_RESULT_INDICATOR_BASELINE_COMMENT_NARRATIVE = + "result.indicator.baseline.comment.narrative"; +export const AF_RESULT_INDICATOR_PERIOD_ACTUAL_COMMENT_NARRATIVE = + "result.indicator.period.actual.comment.narrative"; +export const AF_RESULT_INDICATOR_PERIOD_TARGET_COMMENT_NARRATIVE = + "result.indicator.period.target.comment.narrative"; +export const AF_RESULT_INDICATOR_ASCENDING = "result.indicator.ascending"; +export const AF_RESULT_INDICATOR_REFERENCE_CODE = + "result.indicator.reference.code"; +export const AF_RESULT_INDICATOR_AGGREGATION_STATUS = + "result.indicator.aggregation-status"; + +// S +export const AF_SECTOR = "sector.code"; +export const AF_SECTOR_NAME = "sector.name"; +export const AF_SECTOR_NARRATIVE = "sector.narrative"; +export const AF_SECTOR_PERCENTAGE = "sector.percentage"; +export const AF_SECTOR_VOCABULARY = "sector.vocabulary"; + +// T +export const AF_TAG_CODE = "tag.code"; +export const AF_TAG_NARRATIVE = "tag.narrative"; +export const AF_TAG_VOCABULARY = "tag.vocabulary"; +export const AF_TAG_VOCABULARY_NAME = "tag.vocabulary.name"; +export const AF_TITLE_NARRATIVE = "title.narrative"; +export const AF_TITLE_NARRATIVE_LANG = "title.narrative.lang"; +export const AF_TRANSACTION = "transaction.value"; +export const AF_TRANSACTION_UNDERSCORED = "transaction_value"; +export const AF_TRANSACTION_USD = "transaction.value-usd"; +export const AF_TRANSACTION_USD_UNDERSCORED = "transaction_value_usd"; +export const AF_TRANSACTION_COUNTRY = "transaction.recipient-country.code"; +export const AF_TRANSACTION_DATE_ISO_DATE = + "transaction.transaction-date.iso-date"; +export const AF_TRANSACTION_FLOW_TYPE_CODE = "transaction.flow-type.code"; +export const AF_TRANSACTION_HUMANITARIAN = "transaction.humanitarian"; +export const AF_TRANSACTION_PROVIDER_ORG_REF = "transaction.provider-org.ref"; +export const AF_TRANSACTION_PROVIDER_ORG_NARRATIVE = + "transaction.provider-org.narrative"; +export const AF_TRANSACTION_PROVIDER_ORG_PROVIDER_ACTIVITY_ID = + "transaction.provider-org.provider-activity-id"; +export const AF_TRANSACTION_RECEIVER_ORG_REF = "transaction.receiver-org.ref"; +export const AF_TRANSACTION_RECEIVER_ORG_NARRATIVE = + "transaction.receiver-org.narrative"; +export const AF_TRANSACTION_RECEIVER_ORG_RECEIVER_ACTIVITY_ID = + "transaction.receiver-org.receiver-activity-id"; +export const AF_TRANSACTION_REGION = "transaction.recipient-region.code"; +export const AF_TRANSACTION_SECTOR_CODE = "transaction.sector.code"; +export const AF_TRANSACTION_TIED_STATUS_CODE = "transaction.tied-status.code"; +export const AF_TRANSACTION_TYPE_CODE = "transaction.transaction-type.code"; +export const AF_TRANSACTION_VALUE = "transaction.value"; +export const AF_TRANSACTION_VALUE_CURRENCY = "transaction.value.currency"; +export const AF_TRANSACTION_VALUE_DATE = "transaction.value.value-date"; diff --git a/server/static/globalSearchFields.ts b/server/static/globalSearchFields.ts index 5636e3a..8882759 100644 --- a/server/static/globalSearchFields.ts +++ b/server/static/globalSearchFields.ts @@ -1,42 +1,54 @@ +import { + AF_COUNTRY, + AF_COUNTRY_NAME, + AF_DESCRIPTION_NARRATIVE, + AF_IATI_IDENTIFIER, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_REF, + AF_REPORTING_ORG_NARRATIVE, + AF_REPORTING_ORG_REF, + AF_TITLE_NARRATIVE, + AF_TRANSACTION_COUNTRY, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_REF +} from "./apiFilterFields"; + export const globalSearchFields = [ - "iati_identifier", - "title_narrative_text", - "participating_org_ref", - "recipient_country_code", - "reporting_org_narrative", - "description_narrative_text", - "participating_org_narrative", - "transaction_provider_org_ref", - "transaction_provider_org_narrative", - "transaction_recipient_country_code" + AF_IATI_IDENTIFIER, + AF_TITLE_NARRATIVE, + AF_PARTICIPATING_ORG_REF, + AF_COUNTRY, + AF_REPORTING_ORG_NARRATIVE, + AF_DESCRIPTION_NARRATIVE, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION_COUNTRY ]; export const globalSearchSelectFields = [ - "iati_identifier", - "reporting_org_ref", - "title_narrative_text", - "participating_org_ref", - "recipient_country_code", - "reporting_org_narrative", - "participating_org_narrative", - "transaction_provider_org_ref", - "transaction_provider_org_narrative", - "transaction_recipient_country_code" + AF_IATI_IDENTIFIER, + AF_REPORTING_ORG_REF, + AF_TITLE_NARRATIVE, + AF_PARTICIPATING_ORG_REF, + AF_COUNTRY, + AF_REPORTING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION_COUNTRY ]; -export const activitySearchFields = [ - "recipient_country_code", - "title_narrative_text" -]; +export const activitySearchFields = [AF_COUNTRY, AF_TITLE_NARRATIVE]; export const donorsSearchFields = [ - "transaction_provider_org_ref", - "transaction_provider_org_narrative" + AF_TRANSACTION_PROVIDER_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE ]; export const publishersSearchFields = [ - "reporting_org_ref", - "reporting_org_narrative" + AF_REPORTING_ORG_REF, + AF_REPORTING_ORG_NARRATIVE ]; export const sectorsSearchFields = ["", ""]; diff --git a/server/static/sortKeys.ts b/server/static/sortKeys.ts index 5360189..d38a127 100644 --- a/server/static/sortKeys.ts +++ b/server/static/sortKeys.ts @@ -1,10 +1,16 @@ +import { + AF_ACTIVITY_DATE_END_ACTUAL, + AF_ACTIVITY_DATE_START_ACTUAL, + AF_ACTIVITY_STATUS_CODE +} from "./apiFilterFields"; + export const sortKeys = { - "Start date asc": "activity_date_start_actual asc", - "Start date desc": "activity_date_start_actual desc", - "End date asc": "activity_date_end_actual asc", - "End date desc": "activity_date_end_actual desc", - "Status asc": "activity_status_code asc", - "Status desc": "activity_status_code desc", + "Start date asc": `${AF_ACTIVITY_DATE_START_ACTUAL} asc`, + "Start date desc": `${AF_ACTIVITY_DATE_START_ACTUAL} desc`, + "End date asc": `${AF_ACTIVITY_DATE_END_ACTUAL} asc`, + "End date desc": `${AF_ACTIVITY_DATE_END_ACTUAL} desc`, + "Status asc": `${AF_ACTIVITY_STATUS_CODE} asc`, + "Status desc": `${AF_ACTIVITY_STATUS_CODE} desc`, "Organisation asc": "index asc", "Organisation desc": "index desc", "Publisher asc": "index asc", diff --git a/server/utils/filters.ts b/server/utils/filters.ts index 2cfffd7..931dfb0 100644 --- a/server/utils/filters.ts +++ b/server/utils/filters.ts @@ -1,13 +1,25 @@ import get from "lodash/get"; import { globalSearchFields } from "../static/globalSearchFields"; - -const stickyPeriodFilter = `transaction_value_date:[2015-01-01T00:00:00Z TO *]`; +import { + AF_BUDGET_VALUE, + AF_COUNTRY, + AF_POLICY_MARKER_CODE, + AF_POLICY_MARKER_COMBINED, + AF_REGION, + AF_REPORTING_ORG_REF, + AF_SECTOR, + AF_TAG_CODE, + AF_TAG_NARRATIVE, + AF_TRANSACTION_VALUE_DATE +} from "../static/apiFilterFields"; + +const stickyPeriodFilter = `${AF_TRANSACTION_VALUE_DATE}:[2015-01-01T00:00:00Z TO *]`; export function getFormattedSearchParam(q: string) { const qstring = globalSearchFields .map((field: string) => `${field}:"${q}"`) .join(" OR "); - return `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND (${qstring}) AND (${stickyPeriodFilter})`; + return `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND (${qstring}) AND (${stickyPeriodFilter})`; } export function getFormattedFilters( @@ -23,13 +35,12 @@ export function getFormattedFilters( let localStickyPeriodFilter = stickyPeriodFilter; if (isFilterOption) { - localStickyPeriodFilter += - " OR transaction_value_date:[2015-01-01T00:00:00Z TO *]"; + localStickyPeriodFilter += ` OR ${AF_TRANSACTION_VALUE_DATE}:[2015-01-01T00:00:00Z TO *]`; } const filterKeys = Object.keys(filters); if (filterKeys.length === 0) { - return `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND (${localStickyPeriodFilter})`; + return `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND (${localStickyPeriodFilter})`; } let result = ""; @@ -40,38 +51,38 @@ export function getFormattedFilters( filterKeys.forEach((filterKey: string, index: number) => { const addTrailingAND = filterKeys.length - 1 !== index && - get(filterKeys, `[${index + 1}]`, "") !== "recipient_country_code" && - get(filterKeys, `[${index + 1}]`, "") !== "recipient_region_code"; - if (filterKey === "recipient_country_code") { + get(filterKeys, `[${index + 1}]`, "") !== AF_COUNTRY && + get(filterKeys, `[${index + 1}]`, "") !== AF_REGION; + if (filterKey === AF_COUNTRY) { locations.countries = filters[filterKey]; - } else if (filterKey === "recipient_region_code") { + } else if (filterKey === AF_REGION) { locations.regions = filters[filterKey]; - } else if (filterKey === "budget_value") { + } else if (filterKey === AF_BUDGET_VALUE) { result += `${filterKey}:[${filters[filterKey].join(" TO ")}]${ addTrailingAND ? " AND " : "" }`; } else if (filterKey === "years") { - result += `transaction_value_date:[${ + result += `${AF_TRANSACTION_VALUE_DATE}:[${ filters[filterKey][0] }-01-01T00:00:00Z TO ${filters[filterKey][1]}-12-31T23:59:59Z]${ addTrailingAND ? " AND " : "" }`; - } else if (filterKey === "tag_code" || filterKey === "tag_narrative") { - result += `(tag_code:(${filters[filterKey] + } else if (filterKey === AF_TAG_CODE || filterKey === AF_TAG_NARRATIVE) { + result += `(${AF_TAG_CODE}:(${filters[filterKey] .map((value: string) => `"${value.replace("|", ",")}"`) - .join(" ")}) OR tag_narrative:(${filters[filterKey] + .join(" ")}) OR ${AF_TAG_NARRATIVE}:(${filters[filterKey] .map((value: string) => `"${value.replace("|", ",")}"`) .join(" ")}))${addTrailingAND ? " AND " : ""}`; - } else if (filterKey === "sector_code") { - result += `sector_code:(${filters[filterKey] + } else if (filterKey === AF_SECTOR) { + result += `${AF_SECTOR}:(${filters[filterKey] .map((value: string) => `${value}${value.length < 5 ? "*" : ""}`) .join(" ")})${addTrailingAND ? " AND " : ""}`; } else if (filterKey === "budget_line") { - result += `tag_code:(${filters[filterKey] + result += `${AF_TAG_CODE}:(${filters[filterKey] .map((value: string) => `"${value}"`) .join(" ")})${addTrailingAND ? " AND " : ""}`; } else if (filterKey === "human_rights_approach") { - result += `tag_narrative:(${filters[filterKey] + result += `${AF_TAG_NARRATIVE}:(${filters[filterKey] .map((value: string) => `"${value}"`) .join(" ")})${addTrailingAND ? " AND " : ""}`; } @@ -80,8 +91,8 @@ export function getFormattedFilters( // .map((value: string) => `${value}*`) // .join(" ")})${addTrailingAND ? " AND " : ""}`; // } - else if (filterKey === "policy_marker_code") { - result += `policy_marker_combined:(${filters[filterKey] + else if (filterKey === AF_POLICY_MARKER_CODE) { + result += `${AF_POLICY_MARKER_COMBINED}:(${filters[filterKey] .map((code: string) => `${code}__1 ${code}__2 ${code}__3 ${code}__4`) .join(" ")})${addTrailingAND ? " AND " : ""}`; } else if (filterKey !== "year_period") { @@ -98,18 +109,18 @@ export function getFormattedFilters( if (locations.countries.length > 0 || locations.regions.length > 0) { result += `${result.length > 0 ? " AND " : ""}(${ locations.countries.length > 0 - ? `recipient_country_code:(${locations.countries.join(" ")})` + ? `${AF_COUNTRY}:(${locations.countries.join(" ")})` : "" }${ locations.regions.length > 0 ? `${ locations.countries.length > 0 ? "OR " : "" - }recipient_region_code:(${locations.regions.join(" ")})` + }${AF_REGION}:(${locations.regions.join(" ")})` : "" })`; } - return `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND (${result})`; + return `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND (${result})`; } export function getQuery(filters: any, search: string, searchFields: string[]) { @@ -118,7 +129,7 @@ export function getQuery(filters: any, search: string, searchFields: string[]) { } const filterKeys = Object.keys(filters); if (filterKeys.length === 0 && search.length === 0) { - return `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND (${stickyPeriodFilter})`; + return `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND (${stickyPeriodFilter})`; } let query = ""; @@ -130,52 +141,52 @@ export function getQuery(filters: any, search: string, searchFields: string[]) { filterKeys.forEach((filterKey: string, index: number) => { const addTrailingAND = filterKeys.length - 1 !== index && - get(filterKeys, `[${index + 1}]`, "") !== "recipient_country_code" && - get(filterKeys, `[${index + 1}]`, "") !== "recipient_region_code"; - if (filterKey === "recipient_country_code") { + get(filterKeys, `[${index + 1}]`, "") !== AF_COUNTRY && + get(filterKeys, `[${index + 1}]`, "") !== AF_REGION; + if (filterKey === AF_COUNTRY) { locations.countries = filters[filterKey]; - } else if (filterKey === "recipient_region_code") { + } else if (filterKey === AF_REGION) { locations.regions = filters[filterKey]; - } else if (filterKey === "budget_value") { + } else if (filterKey === AF_BUDGET_VALUE) { query += `${filterKey}:[${filters[filterKey].join(" TO ")}]${ addTrailingAND ? " AND " : "" }`; } else if (filterKey === "years") { - query += `transaction_value_date:[${ + query += `${AF_TRANSACTION_VALUE_DATE}:[${ filters[filterKey][0] }-01-01T00:00:00Z TO ${filters[filterKey][1]}-12-31T23:59:59Z]${ addTrailingAND ? " AND " : "" }`; - } else if (filterKey === "tag_code" || filterKey === "tag_narrative") { - query += `(tag_code:(${filters[filterKey] + } else if (filterKey === AF_TAG_CODE || filterKey === AF_TAG_NARRATIVE) { + query += `(${AF_TAG_CODE}:(${filters[filterKey] .map((value: string) => `"${value.replace("|", ",")}"`) - .join(" ")}) OR tag_narrative:(${filters[filterKey] + .join(" ")}) OR ${AF_TAG_NARRATIVE}:(${filters[filterKey] .map((value: string) => `"${value.replace("|", ",")}"`) .join(" ")}))${addTrailingAND ? " AND " : ""}`; - } else if (filterKey === "sector_code") { - query += `sector_code:(${filters[filterKey] + } else if (filterKey === AF_SECTOR) { + query += `${AF_SECTOR}:(${filters[filterKey] .map((value: string) => `${value}${value.length < 5 ? "*" : ""}`) .join(" ")})${addTrailingAND ? " AND " : ""}`; } else if (filterKey === "budget_line") { - query += `(tag_code:(${filters[filterKey] + query += `(${AF_TAG_CODE}:(${filters[filterKey] .map((value: string) => `"${value}"`) .join(" ")}))${addTrailingAND ? " AND " : ""}`; } else if (filterKey === "human_rights_approach") { - query += `tag_narrative:(${filters[filterKey] + query += `${AF_TAG_NARRATIVE}:(${filters[filterKey] .map((value: string) => `"${value}"`) .join(" ")}))${addTrailingAND ? " AND " : ""}`; } else if (filterKey === "period") { - query += `transaction_value_date:[${ + query += `${AF_TRANSACTION_VALUE_DATE}:[${ filters[filterKey][0].startDate - } TO *] AND transaction_value_date:[* TO ${ + } TO *] AND ${AF_TRANSACTION_VALUE_DATE}:[* TO ${ filters[filterKey][0].endDate }]${addTrailingAND ? " AND " : ""}`; - } else if (filterKey === "policy_marker_code") { - query += `policy_marker_combined:(${filters[filterKey] + } else if (filterKey === AF_POLICY_MARKER_CODE) { + query += `${AF_POLICY_MARKER_COMBINED}:(${filters[filterKey] .map((code: string) => `${code}__1 ${code}__2 ${code}__3 ${code}__4`) .join(" ")})${addTrailingAND ? " AND " : ""}`; } else if (filterKey === "year_period") { - query += `transaction_value_date:[${ + query += `${AF_TRANSACTION_VALUE_DATE}:[${ filters[filterKey] }-01-01T00:00:00Z TO ${filters[filterKey]}-12-31T23:59:59Z]${ addTrailingAND ? " AND " : "" @@ -215,24 +226,21 @@ export function getQuery(filters: any, search: string, searchFields: string[]) { if (locations.countries.length > 0 || locations.regions.length > 0) { query += `${query.length > 0 ? " AND " : ""}(${ locations.countries.length > 0 - ? `recipient_country_code:(${locations.countries.join(" ")})` + ? `${AF_COUNTRY}:(${locations.countries.join(" ")})` : "" }${ locations.regions.length > 0 ? `${ locations.countries.length > 0 ? "OR " : "" - }recipient_region_code:(${locations.regions.join(" ")})` + }${AF_REGION}:(${locations.regions.join(" ")})` : "" })`; } - return `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND (${query})`; + return `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND (${query})`; } +// TODO: Test and remove, casting no longer necessary as field names are identical across activity/transaction export function normalizeActivity2TransactionFilters(filterstring: string) { - return filterstring - .replace(/tag_narrative/g, "tag_code") - .replace(/sector_code/g, "activity_sector_code") - .replace(/recipient_region_code/g, "activity_recipient_region_code") - .replace(/recipient_country_code/g, "activity_recipient_country_code"); + return filterstring; } diff --git a/server/utils/globalSearch.ts b/server/utils/globalSearch.ts index e2cff3a..4f54162 100644 --- a/server/utils/globalSearch.ts +++ b/server/utils/globalSearch.ts @@ -2,6 +2,10 @@ import get from "lodash/get"; import find from "lodash/find"; import { translatedCountries } from "../static/countries"; import { sectorTranslations } from "../static/sectorTranslations"; +import { + AF_IATI_IDENTIFIER, + AF_TITLE_NARRATIVE +} from "../static/apiFilterFields"; interface ResultModel { link: string; @@ -12,8 +16,10 @@ interface ResultModel { export function getActivities(rawData: any) { return rawData.map((item: any) => ({ - name: get(item, "title_narrative_text[0]", ""), - link: `/project/${encodeURIComponent(get(item, "iati_identifier", ""))}` + name: get(item, `["${AF_TITLE_NARRATIVE}"][0]`, ""), + link: `/project/${encodeURIComponent( + get(item, `["${AF_IATI_IDENTIFIER}"]`, "") + )}` })); } From 527dc957d87ffaac775befd37620459336470ae6 Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Thu, 21 Jul 2022 16:35:11 +0200 Subject: [PATCH 2/7] feat: move detail-api controllers to new IATI.cloud --- server/controllers/detail-api/common.ts | 90 +++++++++++-------- server/controllers/detail-api/country.ts | 24 +++-- server/controllers/detail-api/donor.ts | 20 +++-- server/controllers/detail-api/organisation.ts | 20 +++-- server/controllers/detail-api/publisher.ts | 15 ++-- 5 files changed, 102 insertions(+), 67 deletions(-) diff --git a/server/controllers/detail-api/common.ts b/server/controllers/detail-api/common.ts index 99f814d..47a7c8f 100644 --- a/server/controllers/detail-api/common.ts +++ b/server/controllers/detail-api/common.ts @@ -13,14 +13,23 @@ import { orgTypesCodelist } from "../../static/orgTypesCodelist"; import { locationsMapping } from "../../static/locationsMapping"; import { partnerCountries } from "../../static/partnerCountries"; import { sectorTranslations } from "../../static/sectorTranslations"; +import { + AF_REPORTING_ORG_REF, + AF_PARTICIPATING_ORG_REF, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_REGION, + AF_REGION_NAME, + AF_SECTOR, + AF_TAG_NARRATIVE, + AF_PARTICIPATING_ORG_TYPE +} from "../static/apiFilterFields"; export function detailPageName(req: any, res: any) { const values = { - q: `reporting_org_ref:${process.env.MFA_PUBLISHER_REF} AND ${[ + q: `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND ${[ req.body.detail_type ]}:(${get(req.body.filters, `${req.body.detail_type}[0]`, "")})`, - fl: - "participating_org_ref,participating_org_narrative,recipient_region_code,recipient_region_name,sector_code", + fl: `${AF_PARTICIPATING_ORG_REF},${AF_PARTICIPATING_ORG_NARRATIVE},${AF_REGION},${AF_REGION_NAME},${AF_SECTOR}`, rows: 1 }; axios @@ -37,9 +46,9 @@ export function detailPageName(req: any, res: any) { .then(response => { const data = get(response.data, "response.docs[0]", null); let result = ""; - if (req.body.detail_type === "sector_code") { + if (req.body.detail_type === AF_SECTOR) { const fsector = find(sectorTranslations, { - code: parseInt(req.body.filters.sector_code[0], 10) + code: parseInt(req.body.filters[AF_SECTOR][0], 10) }); if (fsector) { res.json({ @@ -56,9 +65,9 @@ export function detailPageName(req: any, res: any) { res.json({ data: { names: { - name: req.body.filters.sector_code[0], - name_fi: req.body.filters.sector_code[0], - name_se: req.body.filters.sector_code[0] + name: req.body.filters[AF_SECTOR][0], + name_fi: req.body.filters[AF_SECTOR][0], + name_se: req.body.filters[AF_SECTOR][0] }, description: "" } @@ -67,14 +76,14 @@ export function detailPageName(req: any, res: any) { } if ( (!data || - (req.body.filters.participating_org_ref && - req.body.filters.participating_org_ref.length > 1)) && - req.body.detail_type === "participating_org_ref" + (req.body.filters[AF_PARTICIPATING_ORG_REF] && + req.body.filters[AF_PARTICIPATING_ORG_REF].length > 1)) && + req.body.detail_type === AF_PARTICIPATING_ORG_REF ) { const fOrgMapping = find(orgMapping, { code: parseInt( - req.body.filters.participating_org_ref[ - req.body.filters.participating_org_ref.length - 1 + req.body.filters[AF_PARTICIPATING_ORG_REF][ + req.body.filters[AF_PARTICIPATING_ORG_REF].length - 1 ], 10 ) @@ -92,25 +101,23 @@ export function detailPageName(req: any, res: any) { } } if (req.body.detail_type && data) { - if (req.body.detail_type === "recipient_country_code") { - const iso3 = getCountryISO3( - req.body.filters.recipient_country_code[0] - ); + if (req.body.detail_type === AF_COUNTRY) { + const iso3 = getCountryISO3(req.body.filters[AF_COUNTRY][0]); const fCountry = find(translatedCountries, { - code: req.body.filters.recipient_country_code[0] + code: req.body.filters[AF_COUNTRY][0] }); let isPartner = false; let region = ""; isPartner = find( partnerCountries, - (p: string) => p === req.body.filters.recipient_country_code[0] + (p: string) => p === req.body.filters[AF_COUNTRY][0] ) !== undefined; Object.keys(locationsMapping).forEach((key: string) => { const fRegion = find( locationsMapping[key], (c: string) => - c === get(req.body, "filters.recipient_country_code[0]", "") + c === get(req.body, `filters[${AF_COUNTRY}][0]`, "") ); if (fRegion) { region = key; @@ -197,17 +204,17 @@ export function detailPageName(req: any, res: any) { name: get( fCountry, "info.name", - req.body.filters.recipient_country_code[0] + req.body.filters[AF_COUNTRY][0] ), name_fi: get( fCountry, "info.name_fi", - req.body.filters.recipient_country_code[0] + req.body.filters[AF_COUNTRY][0] ), name_se: get( fCountry, "info.name_se", - req.body.filters.recipient_country_code[0] + req.body.filters[AF_COUNTRY][0] ), news: newsData.map((n: any) => ({ title: n.title, @@ -243,18 +250,23 @@ export function detailPageName(req: any, res: any) { } } if ( - req.body.detail_type === "participating_org_ref" && + req.body.detail_type === AF_PARTICIPATING_ORG_REF && result.length === 0 ) { const refIndex = findIndex( - data.participating_org_ref, - (ref: string) => ref === req.body.filters.participating_org_ref[0] + data[AF_PARTICIPATING_ORG_REF], + (ref: string) => + ref === req.body.filters[AF_PARTICIPATING_ORG_REF][0] + ); + result = get( + data, + `${AF_PARTICIPATING_ORG_NARRATIVE}[${refIndex}]`, + "" ); - result = get(data, `participating_org_narrative[${refIndex}]`, ""); const fOrgMapping = find(orgMapping, { code: parseInt( - req.body.filters.participating_org_ref[ - req.body.filters.participating_org_ref.length - 1 + req.body.filters[AF_PARTICIPATING_ORG_REF][ + req.body.filters[AF_PARTICIPATING_ORG_REF].length - 1 ], 10 ) @@ -263,25 +275,25 @@ export function detailPageName(req: any, res: any) { result = fOrgMapping.info.name; } } - if (req.body.detail_type === "recipient_region_code") { + if (req.body.detail_type === AF_REGION) { const refIndex = findIndex( - data.recipient_region_code, - (ref: string) => ref === req.body.filters.recipient_region_code[0] + data[AF_REGION], + (ref: string) => ref === req.body.filters[AF_REGION][0] ); - result = get(data, `recipient_region_name[${refIndex}]`, ""); + result = get(data, `${AF_REGION}[${refIndex}]`, ""); } - if (req.body.detail_type === "tag_narrative") { - result = req.body.filters.tag_narrative[0]; + if (req.body.detail_type === AF_TAG_NARRATIVE) { + result = req.body.filters[AF_TAG_NARRATIVE][0]; // get( // thematicAreaNames, // req.body.filters.tag_narrative[0].replace("|", ","), // "" // ).replace(" is the main priority area in this activity", ""); } - if (req.body.detail_type === "participating_org_type") { + if (req.body.detail_type === AF_PARTICIPATING_ORG_TYPE) { result = get( find(orgTypesCodelist, { - code: req.body.filters.participating_org_type[0] + code: req.body.filters[AF_PARTICIPATING_ORG_TYPE][0] }), "name", "" @@ -289,8 +301,8 @@ export function detailPageName(req: any, res: any) { } } if ( - req.body.detail_type !== "recipient_country_code" && - req.body.detail_type !== "sector_code" + req.body.detail_type !== AF_COUNTRY && + req.body.detail_type !== AF_SECTOR ) { res.json({ data: [result] diff --git a/server/controllers/detail-api/country.ts b/server/controllers/detail-api/country.ts index dbee0a0..49f801e 100644 --- a/server/controllers/detail-api/country.ts +++ b/server/controllers/detail-api/country.ts @@ -5,14 +5,20 @@ import querystring from "querystring"; import { countries } from "../../static/countries"; import { genericError } from "../../utils/general"; import { getFormattedFilters } from "../../utils/filters"; +import { + AF_COUNTRY, + AF_REPORTING_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_REF +} from "../../static/apiFilterFields"; export function countryDetail(req: any, res: any) { + const filters = getFormattedFilters(req.body.filters); const activitiesValues = { - q: getFormattedFilters(req.body.filters), + q: filters, "json.facet": JSON.stringify({ items: { type: "terms", - field: "recipient_country_code", + field: AF_COUNTRY, limit: 1, numBuckets: true } @@ -20,16 +26,16 @@ export function countryDetail(req: any, res: any) { rows: 0 }; const donorsValues = { - q: getFormattedFilters(req.body.filters), + q: filters, "json.facet": JSON.stringify({ items: { type: "terms", - field: "recipient_country_code", + field: AF_COUNTRY, limit: 1, facet: { sub: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit: -1, numBuckets: true } @@ -39,16 +45,16 @@ export function countryDetail(req: any, res: any) { rows: 0 }; const publishersValue = { - q: getFormattedFilters(req.body.filters), + q: filters, "json.facet": JSON.stringify({ items: { type: "terms", - field: "recipient_country_code", + field: AF_COUNTRY, limit: 1, facet: { sub: { type: "terms", - field: "reporting_org_ref", + field: AF_REPORTING_ORG_REF, limit: -1, numBuckets: true } @@ -90,7 +96,7 @@ export function countryDetail(req: any, res: any) { ) ]; const fCountry = find(countries, { - code: get(req.body, "filters.recipient_country_code[0]", "") + code: get(req.body, `filters[${AF_COUNTRY}][0]`, "") }); if (fCountry) { const wikiExcerptValue = { diff --git a/server/controllers/detail-api/donor.ts b/server/controllers/detail-api/donor.ts index 573673a..705a527 100644 --- a/server/controllers/detail-api/donor.ts +++ b/server/controllers/detail-api/donor.ts @@ -3,32 +3,38 @@ import get from "lodash/get"; import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getFormattedFilters } from "../../utils/filters"; +import { + AF_REPORTING_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_REF +} from "../../static/apiFilterFields"; export function donorDetail(req: any, res: any) { + let filters = getFormattedFilters(req.body.filters); const activitiesValues = { - q: getFormattedFilters(req.body.filters), + q: filters, "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit: 1, numBuckets: true } }), rows: 1, - fl: "transaction_provider_org_narrative" + fl: AF_TRANSACTION_PROVIDER_ORG_NARRATIVE }; const publishersValue = { - q: getFormattedFilters(req.body.filters), + q: filters, "json.facet": JSON.stringify({ items: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit: 1, facet: { sub: { type: "terms", - field: "reporting_org_ref", + field: AF_REPORTING_ORG_REF, limit: -1, numBuckets: true } @@ -65,7 +71,7 @@ export function donorDetail(req: any, res: any) { axios.spread((...responses) => { const name = get( responses[0], - "data.response.docs[0].transaction_provider_org_narrative[0]", + `data.response.docs[0]["${AF_TRANSACTION_PROVIDER_ORG_NARRATIVE}"][0]`, "" ); const activities = get(responses[0], "data.facets.items.buckets", []); diff --git a/server/controllers/detail-api/organisation.ts b/server/controllers/detail-api/organisation.ts index 8d99267..edcb81f 100644 --- a/server/controllers/detail-api/organisation.ts +++ b/server/controllers/detail-api/organisation.ts @@ -3,6 +3,12 @@ import get from "lodash/get"; import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getFormattedFilters } from "../../utils/filters"; +import { + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_REF, + AF_REPORTING_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_REF +} from "../../static/apiFilterFields"; export function organisationDetail(req: any, res: any) { const activitiesValues = { @@ -10,13 +16,13 @@ export function organisationDetail(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "participating_org_ref", + field: AF_PARTICIPATING_ORG_REF, limit: 1, numBuckets: true, facet: { sub: { type: "terms", - field: "participating_org_narrative", + field: AF_PARTICIPATING_ORG_NARRATIVE, limit: -1, numBuckets: true } @@ -30,12 +36,12 @@ export function organisationDetail(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "participating_org_ref", + field: AF_PARTICIPATING_ORG_REF, limit: 1, facet: { sub: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit: -1, numBuckets: true } @@ -49,12 +55,12 @@ export function organisationDetail(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "participating_org_ref", + field: AF_PARTICIPATING_ORG_REF, limit: 1, facet: { sub: { type: "terms", - field: "reporting_org_ref", + field: AF_REPORTING_ORG_REF, limit: -1, numBuckets: true } @@ -101,7 +107,7 @@ export function organisationDetail(req: any, res: any) { axios.spread((...responses) => { const name = get( responses[0], - "data.facets.items.buckets.sub[0].participating_org_narrative", + `data.facets.items.buckets.sub[0]["${AF_PARTICIPATING_ORG_NARRATIVE}"]`, "" ); const activities = get(responses[0], "data.facets.items.buckets", []); diff --git a/server/controllers/detail-api/publisher.ts b/server/controllers/detail-api/publisher.ts index 9fb5ff7..5717e12 100644 --- a/server/controllers/detail-api/publisher.ts +++ b/server/controllers/detail-api/publisher.ts @@ -3,6 +3,11 @@ import get from "lodash/get"; import querystring from "querystring"; import { genericError } from "../../utils/general"; import { getFormattedFilters } from "../../utils/filters"; +import { + AF_REPORTING_ORG_NARRATIVE, + AF_REPORTING_ORG_REF, + AF_TRANSACTION_PROVIDER_ORG_REF +} from "../../static/apiFilterFields"; export function publisherDetail(req: any, res: any) { const activitiesValues = { @@ -10,25 +15,25 @@ export function publisherDetail(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "reporting_org_ref", + field: AF_REPORTING_ORG_REF, limit: 1, numBuckets: true } }), rows: 1, - fl: "reporting_org_narrative" + fl: AF_REPORTING_ORG_NARRATIVE }; const donorsValues = { q: getFormattedFilters(req.body.filters), "json.facet": JSON.stringify({ items: { type: "terms", - field: "reporting_org_ref", + field: AF_REPORTING_ORG_REF, limit: 1, facet: { sub: { type: "terms", - field: "transaction_provider_org_ref", + field: AF_TRANSACTION_PROVIDER_ORG_REF, limit: -1, numBuckets: true } @@ -65,7 +70,7 @@ export function publisherDetail(req: any, res: any) { axios.spread((...responses) => { const name = get( responses[0], - "data.response.docs[0].reporting_org_narrative[0]", + `data.response.docs[0]["${AF_REPORTING_ORG_NARRATIVE}"][0]`, "" ); const activities = get(responses[0], "data.facets.items.buckets", []); From 2f9fb6691c1692e09f0fdae8fd18086a778f60e5 Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Wed, 27 Jul 2022 18:07:36 +0200 Subject: [PATCH 3/7] feat: refactored major blocking fields to use direct-indexing iati.cloud fields --- server/controllers/detail-api/activity.ts | 85 ++- server/controllers/detail-api/common.ts | 7 +- .../controllers/detail-api/utils/activity.ts | 549 +++++++++++----- .../filter-api/utils/budgetlines.ts | 2 +- .../filter-api/utils/thematicareas.ts | 2 +- .../table-api/ActivitiesController.ts | 38 +- server/controllers/viz-api/BarController.ts | 608 ++++++++---------- server/controllers/viz-api/GeoController.ts | 23 +- server/controllers/viz-api/SDGController.ts | 33 +- .../controllers/viz-api/SunburstController.ts | 66 +- .../viz-api/ThematicAreaController.ts | 45 +- .../controllers/viz-api/TreemapController.ts | 142 ++-- server/static/activityDetailConsts.ts | 14 +- server/static/apiFilterFields.ts | 25 + server/utils/general.ts | 1 + server/utils/parseJsonSolrField.ts | 9 - 16 files changed, 973 insertions(+), 676 deletions(-) delete mode 100644 server/utils/parseJsonSolrField.ts diff --git a/server/controllers/detail-api/activity.ts b/server/controllers/detail-api/activity.ts index fc1d2c9..2caf963 100644 --- a/server/controllers/detail-api/activity.ts +++ b/server/controllers/detail-api/activity.ts @@ -7,7 +7,6 @@ import { activityMetadataFl, activityTransactionsFl } from "../../static/activityDetailConsts"; -import { parseJsonSolrField } from "../../utils/parseJsonSolrField"; import { getCountries, getDates, @@ -20,6 +19,21 @@ import { getTransactions } from "./utils/activity"; import { getFieldValueLang } from "../../utils/getFieldValueLang"; +import { + AF_DESCRIPTION_NARRATIVE, + AF_DESCRIPTION_NARRATIVE_LANG, + AF_IATI_IDENTIFIER, + AF_REPORTING_ORG_NARRATIVE, + AF_REPORTING_ORG_REF, + AF_REPORTING_ORG_TYPE_NAME, + AF_TITLE_NARRATIVE, + AF_TITLE_NARRATIVE_LANG, + AF_TRANSACTION_COUNTRY, + AF_TRANSACTION_REGION, + AF_TRANSACTION_SECTOR_CODE, + AF_TRANSACTION_TYPE_CODE, + AF_TRANSACTION_VALUE +} from "../../static/apiFilterFields"; export function activityDetail(req: any, res: any) { const lang = req.body.lang || "en"; @@ -31,16 +45,16 @@ export function activityDetail(req: any, res: any) { } const decodedId = decodeURIComponent(req.body.activityId); const metadata = { - q: `iati_identifier:"${decodedId}"`, + q: `${AF_IATI_IDENTIFIER}:"${decodedId}"`, fl: activityMetadataFl }; const disbursements = { - q: `iati_identifier:"${decodedId}" AND (transaction_type:3)`, + q: `${AF_IATI_IDENTIFIER}:"${decodedId}" AND (${AF_TRANSACTION_TYPE_CODE}:3)`, fl: activityTransactionsFl, rows: 1000 }; const commitments = { - q: `iati_identifier:"${decodedId}" AND (transaction_type:2)`, + q: `${AF_IATI_IDENTIFIER}:"${decodedId}" AND (${AF_TRANSACTION_TYPE_CODE}:2)`, fl: activityTransactionsFl, rows: 1000 }; @@ -87,62 +101,65 @@ export function activityDetail(req: any, res: any) { res.json({ data: { metadata: { - iati_identifier: get(activityMetaData, "iati_identifier", ""), - reporting_org_ref: get(activityMetaData, "reporting_org_ref", ""), + iati_identifier: get( + activityMetaData, + `["${AF_IATI_IDENTIFIER}"]`, + "" + ), + reporting_org_ref: get( + activityMetaData, + AF_REPORTING_ORG_REF, + "" + ), reporting_org_narrative: get( activityMetaData, - "reporting_org_narrative", + `["${AF_REPORTING_ORG_NARRATIVE}"]`, [""] )[0], - reporting_org_type: parseJsonSolrField( - activityMetaData.reporting_org, - "type.name" + reporting_org_type: get( + activityMetaData, + AF_REPORTING_ORG_TYPE_NAME, + "" ), title: getFieldValueLang( lang, - get(activityMetaData, "title_narrative_text", [""]), - get(activityMetaData, "title_narrative_lang", [""]) + get(activityMetaData, `["${AF_TITLE_NARRATIVE}"]`, [""]), + get(activityMetaData, `["${AF_TITLE_NARRATIVE_LANG}"]`, [""]) ), - dates: getDates(get(activityMetaData, "activity_date", [])), + dates: getDates(activityMetaData), description: getFieldValueLang( lang, - get(activityMetaData, "description_narrative_text", [""]), - get(activityMetaData, "description_lang", [""]) - ), - participating_orgs: getParticipatingOrgs( - get(activityMetaData, "participating_org", []), - lang + get(activityMetaData, `["${AF_DESCRIPTION_NARRATIVE}"]`, [""]), + get(activityMetaData, `["${AF_DESCRIPTION_NARRATIVE_LANG}"]`, [ + "" + ]) ), + participating_orgs: getParticipatingOrgs(activityMetaData, lang), summary: getSummary(activityMetaData), countries: getCountries( - get(activityMetaData, "recipient_country", []), - get(activityMetaData, "transaction_recipient_country_code", []), + activityMetaData, + get(activityMetaData, AF_TRANSACTION_COUNTRY, []), lang ), regions: getRegions( - get(activityMetaData, "recipient_region", []), - get(activityMetaData, "transaction_recipient_region_code", []), + activityMetaData, + get(activityMetaData, AF_TRANSACTION_REGION, []), lang ), sectors: getSectors( - get(activityMetaData, "sector", []), - get(activityMetaData, "transaction_sector_code", []), - lang - ), - default_aid_types: getDefaultAidTypes( - get(activityMetaData, "default_aid_type", []), + activityMetaData, + get(activityMetaData, AF_TRANSACTION_SECTOR_CODE, null), lang ), - policy_markers: getPolicyMarkers( - get(activityMetaData, "policy_marker", []) - ) + default_aid_types: getDefaultAidTypes(activityMetaData, lang), + policy_markers: getPolicyMarkers(activityMetaData) }, transactions: getTransactions([ ...disbursementsData, ...commitmentsData ]), - disbursementsTotal: sumBy(disbursementsData, "transaction_value"), - commitmentsTotal: sumBy(commitmentsData, "transaction_value") + disbursementsTotal: sumBy(disbursementsData, AF_TRANSACTION_VALUE), + commitmentsTotal: sumBy(commitmentsData, AF_TRANSACTION_VALUE) } }); }) diff --git a/server/controllers/detail-api/common.ts b/server/controllers/detail-api/common.ts index 47a7c8f..d755c6e 100644 --- a/server/controllers/detail-api/common.ts +++ b/server/controllers/detail-api/common.ts @@ -14,6 +14,7 @@ import { locationsMapping } from "../../static/locationsMapping"; import { partnerCountries } from "../../static/partnerCountries"; import { sectorTranslations } from "../../static/sectorTranslations"; import { + AF_COUNTRY, AF_REPORTING_ORG_REF, AF_PARTICIPATING_ORG_REF, AF_PARTICIPATING_ORG_NARRATIVE, @@ -22,16 +23,17 @@ import { AF_SECTOR, AF_TAG_NARRATIVE, AF_PARTICIPATING_ORG_TYPE -} from "../static/apiFilterFields"; +} from "../../static/apiFilterFields"; export function detailPageName(req: any, res: any) { const values = { q: `${AF_REPORTING_ORG_REF}:${process.env.MFA_PUBLISHER_REF} AND ${[ req.body.detail_type - ]}:(${get(req.body.filters, `${req.body.detail_type}[0]`, "")})`, + ]}:(${get(req.body.filters, `["${req.body.detail_type}"][0]`, "")})`, fl: `${AF_PARTICIPATING_ORG_REF},${AF_PARTICIPATING_ORG_NARRATIVE},${AF_REGION},${AF_REGION_NAME},${AF_SECTOR}`, rows: 1 }; + axios .get( `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( @@ -310,7 +312,6 @@ export function detailPageName(req: any, res: any) { } }) .catch(errors => { - console.log(errors); genericError(errors, res); }); } diff --git a/server/controllers/detail-api/utils/activity.ts b/server/controllers/detail-api/utils/activity.ts index 68af214..25dbfd2 100644 --- a/server/controllers/detail-api/utils/activity.ts +++ b/server/controllers/detail-api/utils/activity.ts @@ -16,40 +16,123 @@ import { defaultTiedStatusCodelist, tranlatedAidTypes } from "../../../static/codelists"; +import { orgTypesCodelist } from "../../../static/orgTypesCodelist"; import { sectorTranslations } from "../../../static/sectorTranslations"; import { orgMapping } from "../../../static/orgMapping"; +import { + AF_ACTIVITY_DATE_END_ACTUAL, + AF_ACTIVITY_DATE_END_COMMON, + AF_ACTIVITY_DATE_END_PLANNED, + AF_ACTIVITY_DATE_START_ACTUAL, + AF_ACTIVITY_DATE_START_COMMON, + AF_ACTIVITY_DATE_START_PLANNED, + AF_ACTIVITY_SCOPE_CODE, + AF_ACTIVITY_STATUS_CODE, + AF_BUDGET_PERIOD_END_ISO_DATE, + AF_BUDGET_PERIOD_START_ISO_DATE, + AF_BUDGET_STATUS_NAME, + AF_BUDGET_TYPE_NAME, + AF_BUDGET_VALUE, + AF_BUDGET_VALUE_CURRENCY, + AF_CAPITAL_SPEND_PERCENTAGE, + AF_COLLABORATION_TYPE_CODE, + AF_CONTACT_INFO_TYPE, + AF_CONTACT_INFO_TELEPHONE, + AF_CONTACT_INFO_EMAIL, + AF_CONTACT_INFO_WEBSITE, + AF_CONTACT_INFO_ORG_NARRATIVE, + AF_CONTACT_INFO_DEPARTMENT_NARRATIVE, + AF_CONTACT_INFO_PERSON_NAME_NARRATIVE, + AF_CONTACT_INFO_JOB_TITLE_NARRATIVE, + AF_CONTACT_INFO_MAILING_ADDRESS_NARRATIVE, + AF_COUNTRY, + AF_COUNTRY_NAME, + AF_COUNTRY_PERCENTAGE, + AF_DEFAULT_AID_TYPE_CODE, + AF_DEFAULT_AID_TYPE_NAME, + AF_DEFAULT_AID_TYPE_VOCABULARY, + AF_DEFAULT_FINANCE_CODE, + AF_DEFAULT_FLOW_TYPE_CODE, + AF_DEFAULT_TIED_STATUS_CODE, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_NARRATIVE_LANG, + AF_PARTICIPATING_ORG_REF, + AF_PARTICIPATING_ORG_ROLE, + AF_PARTICIPATING_ORG_TYPE, + AF_PARTICIPATING_ORG_NARRATIVE_INDEX, + AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX, + AF_PARTICIPATING_ORG_REF_INDEX, + AF_PARTICIPATING_ORG_ROLE_INDEX, + AF_PARTICIPATING_ORG_TYPE_INDEX, + AF_POLICY_MARKER_CODE, + AF_POLICY_MARKER_NAME, + AF_POLICY_MARKER_SIGNIFICANCE, + AF_POLICY_MARKER_VOCABULARY_NAME, + AF_POLICY_MARKER_VOCABULARY_URI, + AF_REGION, + AF_REGION_NAME, + AF_REGION_PERCENTAGE, + AF_SECTOR, + AF_SECTOR_NAME, + AF_SECTOR_PERCENTAGE, + AF_TAG_CODE, + AF_TAG_NARRATIVE, + AF_TAG_VOCABULARY, + AF_TAG_VOCABULARY_NAME, + AF_TRANSACTION_VALUE_CURRENCY, + AF_RELATED_ACTIVITY_REF, + AF_IATI_IDENTIFIER, + AF_TRANSACTION_TYPE_CODE, + AF_TRANSACTION_DATE_ISO_DATE, + AF_TRANSACTION_RECEIVER_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION +} from "../../../static/apiFilterFields"; -export function getDates(data: any) { - const parsedData = data.map((item: any) => JSON.parse(item)); - const start = find( - parsedData, - (item: any) => item.type.code === "2" || item.type.code === "1" - ); - const end = find( - parsedData, - (item: any) => item.type.code === "4" || item.type.code === "3" - ); +function formatDate(dateStr: string): string { + if (!dateStr) return dateStr; + return get(dateStr.split("T"), "[0]", dateStr); +} - const dates = [ - start ? new Date(start.iso_date).toLocaleDateString("en-GB") : "", - end ? new Date(end.iso_date).toLocaleDateString("en-GB") : "" - ]; +export function getDates(data: any) { + // Data contains all activity metadata, we need to extract the start and end dates. + const start = get(data, `["${AF_ACTIVITY_DATE_START_COMMON}"]`, null); + const end = get(data, `["${AF_ACTIVITY_DATE_END_COMMON}"]`, null); + const dates = [start ? formatDate(start) : "", end ? formatDate(end) : ""]; return dates; } +/** unused */ export function getBudget(data: any) { - const parsedData = data.map((item: any) => JSON.parse(item)); - return parsedData.map((item: any) => ({ - type: item.type.name, - status: item.status.name, - start: item.period_start, - end: item.period_end, - value: item.value.value.toLocaleString("en-US", { - style: "currency", - currency: item.value.currency.code - }) - })); + // data contains all the activityMetadata. We need to extract relevant + // fields from the expanded fields. + // The resulting value field should look like `value: "€400,000.00"` + const budget_type_name = get(data, `["${AF_BUDGET_TYPE_NAME}"]`, []); + const budget_status_name = get(data, `["${AF_BUDGET_STATUS_NAME}"]`, []); + const budget_start = get(data, `["${AF_BUDGET_PERIOD_START_ISO_DATE}"]`, []); + const budget_end = get(data, `["${AF_BUDGET_PERIOD_END_ISO_DATE}"]`, []); + const budget_value = get(data, `["${AF_BUDGET_VALUE}"]`, []); + const budget_value_currency = get( + data, + `["${AF_BUDGET_VALUE_CURRENCY}"]`, + [] + ); + let result: any[] = []; + budget_value.forEach((value: any, index: number) => { + const currency = get(budget_value_currency, `[${index}]`, ""); + result.push({ + type: get(budget_type_name, `[${index}]`, ""), + status: get(budget_status_name, `[${index}]`, ""), + start: get(budget_start, `[${index}]`, ""), + end: get(budget_end, `[${index}]`, ""), + value: value.toLocaleString("en-US", { + style: "currency", + currency: currency + }) + }); + }); + return result; } export function getParticipatingOrgs( @@ -57,94 +140,184 @@ export function getParticipatingOrgs( lang: string, withRole?: boolean ) { - const parsedData = data.map((item: any) => JSON.parse(item)); - return parsedData.map((item: any) => { - let fNameLang = find( - get(item, "narrative", []), - (narrative: any) => narrative.lang.code === lang + // data contains all the activityMetadata. We need to extract relevant + // fields from the expanded fields. + const participating_org_name = get( + data, + `["${AF_PARTICIPATING_ORG_NARRATIVE}"]`, + [] + ); + const participating_org_name_lang = get( + data, + `["${AF_PARTICIPATING_ORG_NARRATIVE_LANG}"]`, + [] + ); + const participating_org_ref = get( + data, + `["${AF_PARTICIPATING_ORG_REF}"]`, + [] + ); + const participating_org_type = get( + data, + `["${AF_PARTICIPATING_ORG_TYPE}"]`, + [] + ); + const participating_org_role = get( + data, + `["${AF_PARTICIPATING_ORG_ROLE}"]`, + [] + ); + let result: any[] = []; + // participating_org_role is a required field for p-orgs. + participating_org_role.forEach((role: any, index: number) => { + const po_index: number = data[AF_PARTICIPATING_ORG_ROLE_INDEX][index]; + const po_ref_index: number = data[AF_PARTICIPATING_ORG_REF_INDEX][po_index]; + const po_type_index: number = + data[AF_PARTICIPATING_ORG_TYPE_INDEX][po_index]; + const po_narrative_index: number = + data[AF_PARTICIPATING_ORG_NARRATIVE_INDEX][po_index]; + const po_narrative_lang_index: number = + data[AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX][po_index]; + + const ref = get(participating_org_ref, `[${po_ref_index}]`, ""); + const type_code = get(participating_org_type, `[${po_type_index}]`, ""); + const type = get( + find(orgTypesCodelist, { code: type_code }), + "name", + "no data" ); - if (!fNameLang) { - const fOrg = find(orgMapping, (org: any) => org.code === item.ref); + const url = + ref !== "" ? `/organisation/${encodeURIComponent(ref)}/projects` : ""; + + let name = ""; + // check if there is any narrative + if (po_narrative_index !== -1) { + // if there is a narrative, check the lang + let breakNarrative = false; + let count = 0; + do { + let searchIndex = po_narrative_index + po_narrative_lang_index + count; + // TODO: This is a hack due to the PO_NARRATIVE_LANG_INDEX not resolving correctly + if (po_narrative_lang_index === -1) { + searchIndex += 1; + } + let langVal = + po_narrative_lang_index === -1 // if there is no langIndex the default is taken + ? "en" + : participating_org_name_lang[searchIndex]; + if (langVal === lang) { + name = participating_org_name[searchIndex]; + breakNarrative = true; + } + // Check if the next lang index is 0, or the end of the list is found. + // if the lang index is 0, it means we have reached a narrative related to a different participating_org + let nextVal = get( + participating_org_name_lang, + `[${searchIndex + 1}]`, + -2 + ); + if ([0, -2].includes(nextVal)) { + breakNarrative = true; + } + count += 1; + } while (!breakNarrative); + } + + // if the name was not found, check the ref in the org mapping. + if (name === "") { + const fOrg = find(orgMapping, (org: any) => org.code === ref); if (fOrg) { - fNameLang = { - text: get(fOrg.info, `name${lang === "en" ? "" : `_${lang}`}`, "") - }; + name = get(fOrg.info, `name${lang === "en" ? "" : `_${lang}`}`, ""); } } - let org: { + + if (!name) { + name = get(participating_org_name, index, "no data"); + } + let resultOrg: { name: string; reference: string; type: string; url: string; role?: string; } = { - name: fNameLang ? fNameLang.text : get(item, "narrative[0].text", ""), - reference: item.ref, - type: get(item, "type.name", "no data"), - url: `/organisations/${encodeURIComponent(item.ref)}` + name, + reference: ref, + type, + url }; if (withRole) { - org = { - ...org, - role: get(item, "role.name", "no data") + const roles = ["", "Funding", "Accountable", "Extending", "Implementing"]; + resultOrg = { + ...resultOrg, + role: roles[role] }; } - return org; + + result.push(resultOrg); }); + return result; } export function getSummary(data: any) { const status = get( - find(activityStatusCodelist, { code: data.activity_status_code }), + find(activityStatusCodelist, { + code: data[AF_ACTIVITY_STATUS_CODE] + }), "name", "no data" ); const scope = get( - find(activityScopeCodelist, { code: data.activity_scope_code }), + find(activityScopeCodelist, { + code: data[AF_ACTIVITY_SCOPE_CODE] + }), "name", "no data" ); const collaboration_type = get( - find(collaborationTypeCodelist, { code: data.collaboration_type_code }), + find(collaborationTypeCodelist, { + code: data[AF_COLLABORATION_TYPE_CODE] + }), "name", "no data" ); const default_flow_type = get( - find(defaultFlowTypeCodelist, { code: data.default_flow_type_code }), + find(defaultFlowTypeCodelist, { + code: data[AF_DEFAULT_FLOW_TYPE_CODE] + }), "name", "no data" ); const default_finance_type = get( - find(defaultFinanceTypeCodelist, { code: data.default_finance_type_code }), + find(defaultFinanceTypeCodelist, { + code: data[AF_DEFAULT_FINANCE_CODE] + }), "name", "no data" ); const default_tied_status = get( - find(defaultTiedStatusCodelist, { code: data.default_tied_status_code }), + find(defaultTiedStatusCodelist, { + code: data[AF_DEFAULT_TIED_STATUS_CODE] + }), "name", "no data" ); - const dates = data.activity_date.map((item: any) => JSON.parse(item)); const planned_start = get( - find(dates, (item: any) => item.type.code === "1"), - "iso_date", + data, + `["${AF_ACTIVITY_DATE_START_PLANNED}"]`, "no data" ); const actual_start = get( - find(dates, (item: any) => item.type.code === "2"), - "iso_date", + data, + `["${AF_ACTIVITY_DATE_START_ACTUAL}"]`, "no data" ); const planned_end = get( - find(dates, (item: any) => item.type.code === "3"), - "iso_date", - "no data" - ); - const actual_end = get( - find(dates, (item: any) => item.type.code === "4"), - "iso_date", + data, + `["${AF_ACTIVITY_DATE_END_PLANNED}"]`, "no data" ); + const actual_end = get(data, `["${AF_ACTIVITY_DATE_END_ACTUAL}"]`, "no data"); return { status, scope, @@ -164,32 +337,41 @@ export function getCountries( transaction_recipient_country_codes: any, lang: string ) { - const parsedData = countries.map((item: any) => JSON.parse(item)); + // countries contains all the activityMetadata. We need to extract relevant + // fields from the expanded fields. + const country_code = get(countries, `["${AF_COUNTRY}"]`, []); + const country_name = get(countries, `["${AF_COUNTRY_NAME}"]`, []); + const country_percentage = get(countries, `["${AF_COUNTRY_PERCENTAGE}"]`, []); transaction_recipient_country_codes.forEach((item: any) => { const fCountry = find(countriesCodelist, { code: item }); if (fCountry) { - parsedData.push({ - country: fCountry - }); + country_code.push(fCountry.code); + country_name.push(fCountry.name); + country_percentage.push(""); } }); - return parsedData.map((item: any) => { + let result: any[] = []; + country_code.forEach((code: any, index: number) => { const fTranslatedItem = find(translatedCountries, { - code: item.country.code + code: code + }); + + const name = fTranslatedItem + ? get( + fTranslatedItem.info, + `name${lang === "en" ? "" : `_${lang}`}`, + get(country_name, `[${index}]`, "") + ) + : get(country_name, `[${index}]`, ""); + + result.push({ + name, + code, + percentage: get(country_percentage, `[${index}]`, ""), + url: `/country/${encodeURIComponent(name)}/projects` }); - return { - name: fTranslatedItem - ? get( - fTranslatedItem.info, - `name${lang === "en" ? "" : `_${lang}`}`, - item.country.name - ) - : item.country.name, - code: item.country.code, - percentage: item.country.percentage || "no data", - url: `/countries/${encodeURIComponent(item.country.code)}` - }; }); + return result; } export function getRegions( @@ -197,36 +379,45 @@ export function getRegions( transaction_recipient_region_codes: any, lang: string ) { - const parsedData = regions.map((item: any) => JSON.parse(item)); + // regions contains all the activityMetadata. We need to extract relevant + // fields from the expanded fields. + const region_code = get(regions, `["${AF_REGION}"]`, []); + const region_name = get(regions, `["${AF_REGION_NAME}"]`, []); + const region_percentage = get(regions, `["${AF_REGION_PERCENTAGE}"]`, []); transaction_recipient_region_codes.forEach((item: any) => { const fRegion = find(translatedCountries, { code: item }); if (fRegion) { - parsedData.push({ - region: { - code: fRegion.code, - name: fRegion.info.name - } - }); + region_code.push(fRegion.code); + region_name.push(fRegion.info.name); + region_percentage.push("no data"); } }); - return parsedData.map((item: any) => { + + // Review: was formerly using name_ which is the country, + // and was using the item.country.name which does not exist on + // the field that was being queried. + let result: any[] = []; + region_code.forEach((code: any, index: number) => { const fTranslatedItem = find(translatedCountries, { - code: item.region.code + code: code + }); + const name = fTranslatedItem + ? get( + fTranslatedItem.info, + `region_1${lang === "en" ? "" : `_${lang}`}`, + get(region_name, `[${index}]`, "") + ) + : get(region_name, `[${index}]`, ""); + result.push({ + name, + code, + percentage: get(region_percentage, `[${index}]`, "no data") }); - return { - name: fTranslatedItem - ? get( - fTranslatedItem.info, - `name${lang === "en" ? "" : `_${lang}`}`, - item.region.name - ) - : item.country.name, - code: item.region.code, - percentage: item.region.percentage || "no data" - }; }); + return result; } +/** unused */ export function getLocations(coordinates: any, texts: any) { let max = coordinates; if (texts.length > max.length) { @@ -243,6 +434,7 @@ export function getLocations(coordinates: any, texts: any) { return result; } +/** unused */ export function getHumanitarianScopes( types: any, vocabs: any, @@ -276,64 +468,119 @@ export function getSectors( transaction_sector_codes: any, lang: string ) { - const parsedData = sectors.map((item: any) => JSON.parse(item)); - transaction_sector_codes.map((item: any) => ({ - sector: { - name: item, - code: item - } - })); - return parsedData.map((item: any) => { + // sectors contains all the activityMetadata. We need to extract + // the sector information from the expanded fields. + const sector_name = get(sectors, `["${AF_SECTOR_NAME}"]`, []); + const sector_code = get(sectors, `["${AF_SECTOR}"]`, []); + const sector_percentage = get(sectors, `["${AF_SECTOR_PERCENTAGE}"]`, []); + + // Review: this part was not refactored to new IATI.cloud + // because the output of the map is not used. + // transaction_sector_codes.map((item: any) => ({ + // sector: { + // name: item, + // code: item + // } + // })); + + let result: any[] = []; + sector_code.forEach((code: any, index: number) => { const fTranslatedItem = find(sectorTranslations, { - code: parseInt(item.sector.code, 10) + code: parseInt(code, 10) + }); + + const name = fTranslatedItem + ? get( + fTranslatedItem.info, + `name${lang === "en" ? "" : `_${lang}`}`, + get(sector_name, `[${index}]`, "") + ) + : get(sector_name, `[${index}]`, ""); + + result.push({ + name, + code, + url: `/sectors/${code}`, + percentage: get(sector_percentage, `[${index}]`, "no data") }); - return { - name: fTranslatedItem - ? get( - fTranslatedItem.info, - `name${lang === "en" ? "" : `_${lang}`}`, - item.sector.name - ) - : item.sector.name, - code: item.sector.code, - url: `/sectors/${item.sector.code}`, - percentage: item.percentage || "no data" - }; }); + return result; } export function getDefaultAidTypes(data: any, lang: string) { - const parsedData = data.map((item: any) => JSON.parse(item)); - return parsedData.map((item: any) => { + // data contains all the activityMetadata, we need to + // retrieve a list of default-aid-type values + const default_aid_type_code = get( + data, + `["${AF_DEFAULT_AID_TYPE_CODE}"]`, + [] + ); + const default_aid_type_name = get( + data, + `["${AF_DEFAULT_AID_TYPE_NAME}"]`, + [] + ); + const default_aid_type_vocabulary = get( + data, + `["${AF_DEFAULT_AID_TYPE_VOCABULARY}"]`, + [] + ); + + let result: any[] = []; + default_aid_type_code.forEach((code: any, index: number) => { const fTranslatedItem = find(tranlatedAidTypes, { - code: get(item, "aid_type.code", "") + code: code + }); + const name = fTranslatedItem + ? get(fTranslatedItem.info, `name${lang === "en" ? "" : `_${lang}`}`) + : get(default_aid_type_name, `[${index}]`, "no data"); + result.push({ + code, + name, + vocabulary: get(default_aid_type_vocabulary, `[${index}]`, "no data") }); - return { - name: fTranslatedItem - ? get(fTranslatedItem.info, `name${lang === "en" ? "" : `_${lang}`}`) - : get(item, "aid_type.name", "no data"), - code: get(item, "aid_type.code", "no data"), - vocabulary: item.aid_type.vocabulary.name - }; }); + return result; } export function getPolicyMarkers(data: any) { - const parsedData = data.map((item: any) => JSON.parse(item)); - return filter( - parsedData, - (item: any) => - item.significance && - item.significance.name.toLowerCase() !== "not targeted" - ).map((item: any) => ({ - name: item.policy_marker.name, - code: item.policy_marker.code, - significance: item.significance.name, - vocabulary_uri: item.vocabulary_uri || "no data", - vocabulary: item.vocabulary.name - })); + // data contains all the activity metadata. We need to extract the + // expanded fields from it. + const policy_marker_code = get(data, `["${AF_POLICY_MARKER_CODE}"]`, []); + const policy_marker_name = get(data, `["${AF_POLICY_MARKER_NAME}"]`, []); + const policy_marker_significance = get( + data, + `["${AF_POLICY_MARKER_SIGNIFICANCE}"]`, + [] + ); + const policy_marker_vocabulary_uri = get( + data, + `["${AF_POLICY_MARKER_VOCABULARY_URI}"]`, + [] + ); + const policy_marker_vocabulary = get( + data, + `["${AF_POLICY_MARKER_VOCABULARY_NAME}"]`, + [] + ); + const result: any[] = []; + policy_marker_code.forEach((code: any, index: number) => { + if ( + get(policy_marker_name, `[${index}]`, "").toLowerCase() !== "not targeted" + ) { + result.push({ + name: get(policy_marker_name, `[${index}]`, ""), + code, + significance: get(policy_marker_significance, `[${index}]`, ""), + vocabulary_uri: get(policy_marker_vocabulary_uri, `[${index}]`, ""), + vocabulary: get(policy_marker_vocabulary, `[${index}]`, "") + }); + } + }); + return result; } +/** unused */ export function getTags(tag_codes: any, tag_narrative_texts: any) { return tag_codes.map((code: any, index: number) => ({ code, @@ -341,6 +588,7 @@ export function getTags(tag_codes: any, tag_narrative_texts: any) { })); } +/** unused */ export function getContactInfo(contact_data: any, reporting_org: any) { if (contact_data.length === 0) { return { @@ -376,6 +624,7 @@ export function getContactInfo(contact_data: any, reporting_org: any) { }; } +/** unused */ export function getOtherIdentifiers( other_indentifier_refs: any, other_identifier_owner_org_narrative_texts: any @@ -386,6 +635,7 @@ export function getOtherIdentifiers( })); } +/** unused */ export function getCountryBudgetItems( vocabs: any, codes: any, @@ -411,6 +661,7 @@ export function getCountryBudgetItems( return result; } +/** unused */ export function getPlannedDisbursements( values: any, types: any, @@ -458,6 +709,7 @@ export function getPlannedDisbursements( return result; } +/** unused */ export function getDocumentLinks(texts: any, urls: any, categories: any) { let max = texts; if (urls.length > max.length) { @@ -477,6 +729,7 @@ export function getDocumentLinks(texts: any, urls: any, categories: any) { return result; } +/** unused */ export function getRelatedActivities(refs: any, types: any) { let max = refs; if (types.length > max.length) { @@ -495,6 +748,7 @@ export function getRelatedActivities(refs: any, types: any) { return result; } +/** unused */ export function getLegacyData(names: any, values: any, iati_equivalents: any) { let max = names; if (values.length > max.length) { @@ -514,6 +768,7 @@ export function getLegacyData(names: any, values: any, iati_equivalents: any) { return result; } +/** unused */ export function getConditions(types: any, texts: any) { let max = types; if (texts.length > max.length) { @@ -531,9 +786,9 @@ export function getConditions(types: any, texts: any) { export function getTransactions(data: any) { const transactions = data.map((item: any) => ({ - date: item.transaction_date_iso_date.slice(0, 4), - type: item.transaction_type, - value: item.transaction_value + date: item[AF_TRANSACTION_DATE_ISO_DATE].slice(0, 4), + type: item[AF_TRANSACTION_TYPE_CODE], + value: item[AF_TRANSACTION] })); const groupedYears = groupBy(transactions, "date"); diff --git a/server/controllers/filter-api/utils/budgetlines.ts b/server/controllers/filter-api/utils/budgetlines.ts index 0a98837..6d1dd7b 100644 --- a/server/controllers/filter-api/utils/budgetlines.ts +++ b/server/controllers/filter-api/utils/budgetlines.ts @@ -30,7 +30,7 @@ export function getBudgetLinesOptions(filterString = "*:*") { const actualData = get(callResponse, "data.response.docs", []); const result: any = []; actualData.forEach((activity: any) => { - activity[`"${AF_TAG_CODE}"`].forEach((tc: string) => { + activity[AF_TAG_CODE].forEach((tc: string) => { const budgetLine = get(budgetLineCodes2Values, tc, null); if (budgetLine) { const fItemIndex = findIndex(result, { code: tc }); diff --git a/server/controllers/filter-api/utils/thematicareas.ts b/server/controllers/filter-api/utils/thematicareas.ts index ce2014c..17572ed 100644 --- a/server/controllers/filter-api/utils/thematicareas.ts +++ b/server/controllers/filter-api/utils/thematicareas.ts @@ -27,7 +27,7 @@ export function getThematicAreaOptions(filterString = "*:*") { const actualData = get(callResponse, "data.response.docs", []); let items: any = []; actualData.forEach((activity: any) => { - activity.tag_code.forEach((tc: string) => { + activity[AF_TAG_CODE].forEach((tc: string) => { if (tc.indexOf("Priority") > -1) { const fItemIndex = findIndex(items, { code: tc }); if (fItemIndex === -1) { diff --git a/server/controllers/table-api/ActivitiesController.ts b/server/controllers/table-api/ActivitiesController.ts index 8936691..b1dc88a 100644 --- a/server/controllers/table-api/ActivitiesController.ts +++ b/server/controllers/table-api/ActivitiesController.ts @@ -22,7 +22,30 @@ import { activitySearchFields } from "../../static/globalSearchFields"; import { sectorTranslations } from "../../static/sectorTranslations"; +import { + AF_ACTIVITY_DATE_END_PLANNED, + AF_ACTIVITY_DATE_START_PLANNED, + AF_ACTIVITY_STATUS_CODE, + AF_COUNTRY, + AF_IATI_IDENTIFIER, + AF_TITLE_NARRATIVE, + AF_TRANSACTION_COUNTRY, + AF_DEFAULT_AID_TYPE_CODE, + AF_DEFAULT_AID_TYPE_NAME, + AF_DEFAULT_AID_TYPE_VOCABULARY, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_NARRATIVE_LANG, + AF_PARTICIPATING_ORG_REF, + AF_PARTICIPATING_ORG_ROLE, + AF_PARTICIPATING_ORG_TYPE, + AF_PARTICIPATING_ORG_NARRATIVE_INDEX, + AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX, + AF_PARTICIPATING_ORG_REF_INDEX, + AF_PARTICIPATING_ORG_ROLE_INDEX, + AF_PARTICIPATING_ORG_TYPE_INDEX +} from "../../static/apiFilterFields"; +/** Basic functionality has been mapped, needs future steps to fully convert to direct-indexing */ export function activitiesTable(req: any, res: any) { const lang = req.body.lang || "en"; const rows = get(req.body, "rows", 10); @@ -37,7 +60,7 @@ export function activitiesTable(req: any, res: any) { const values = { q: getQuery(filters, search, globalSearchFields), - fl: `iati_identifier,default_aid_type:[json],participating_org:[json],title_narrative_text,title_narrative_lang,description_narrative_text,description_lang,recipient_country_code,transaction_recipient_country_code,recipient_region_code,transaction_recipient_region_code,sector_code,transaction_sector_code,budget_value,budget_type,transaction_type,transaction_value,activity_date_start_planned,activity_date_end_planned`, + fl: `iati_identifier,${AF_DEFAULT_AID_TYPE_CODE},${AF_DEFAULT_AID_TYPE_NAME},${AF_DEFAULT_AID_TYPE_VOCABULARY},${AF_PARTICIPATING_ORG_NARRATIVE},${AF_PARTICIPATING_ORG_NARRATIVE_LANG},${AF_PARTICIPATING_ORG_REF},${AF_PARTICIPATING_ORG_TYPE},${AF_PARTICIPATING_ORG_ROLE},${AF_PARTICIPATING_ORG_ROLE_INDEX},${AF_PARTICIPATING_ORG_REF_INDEX},${AF_PARTICIPATING_ORG_TYPE_INDEX},${AF_PARTICIPATING_ORG_NARRATIVE_INDEX},${AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX},title_narrative_text,title_narrative_lang,description_narrative_text,description_lang,recipient_country_code,transaction_recipient_country_code,recipient_region_code,transaction_recipient_region_code,sector_code,transaction_sector_code,budget_value,budget_type,transaction_type,transaction_value,activity_date_start_planned,activity_date_end_planned`, start, rows, sort: "iati_identifier desc" @@ -61,7 +84,7 @@ export function activitiesTable(req: any, res: any) { const result = actualData.map((activity: any) => { const startDate = activity.activity_date_start_planned || ""; const endDate = activity.activity_date_end_planned || ""; - const aidTypes = getDefaultAidTypes(activity.default_aid_type, lang) + const aidTypes = getDefaultAidTypes(activity, lang) .map((type: any) => type.name) .join(", "); const code = get(activity, "iati_identifier", ""); @@ -97,14 +120,9 @@ export function activitiesTable(req: any, res: any) { return ""; }) : []; - const orgs = filter( - getParticipatingOrgs( - get(activity, "participating_org", []), - lang, - true - ), - { role: "Extending" } - ) + const orgs = filter(getParticipatingOrgs(activity, lang, true), { + role: "Extending" + }) .map((org: any) => org.name) .join(", "); let disbursed = 0; diff --git a/server/controllers/viz-api/BarController.ts b/server/controllers/viz-api/BarController.ts index bdf7312..14f38a6 100644 --- a/server/controllers/viz-api/BarController.ts +++ b/server/controllers/viz-api/BarController.ts @@ -18,270 +18,27 @@ import { translatedLines, budgetLineCodes2Values } from "../../static/budgetLineConsts"; - -export function budgetLineBarChart1(req: any, res: any) { - const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - { - q: `${getFormattedFilters( - get(req.body, "filters", {}) - )} AND tag_vocabulary:99 AND tag_code:2*`, - fl: "tag_code,budget_value,budget_value_date", - rows: 10000 - }, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}`; - - axios - .get(url) - .then(call1Response => { - const actualData = get(call1Response, "data.response.docs", []); - const filteredData = filter( - actualData, - (doc: any) => doc.tag_code[0] === "2" - ); - let years: string[] = []; - filteredData.forEach((doc: any) => { - if (doc.budget_value_date) { - years = [ - ...years, - ...doc.budget_value_date.map((item: any) => item.slice(0, 4)) - ]; - } - }); - years = uniq(years); - const yearsData = years.map((year: string) => { - const data = filter(filteredData, (doc: any) => { - if (doc.budget_value_date) { - return find( - doc.budget_value_date, - (item: any) => item.slice(0, 4) === year - ); - } - return false; - }); - let tags: string[] = []; - data.forEach((doc: any) => { - tags = [...tags, ...doc.tag_code]; - }); - tags = uniq(tags); - tags = filter(tags, (tag: string) => tag[0] === "2"); - const tagsData = tags.map((tag: string) => { - const tagData = filter( - data, - (doc: any) => doc.tag_code.indexOf(tag) > -1 - ); - let totalBudget = 0; - tagData.forEach((doc: any) => { - if (doc.budget_value) { - totalBudget += sum(doc.budget_value); - } - }); - return { - name: tag, - code: tag, - value: totalBudget - }; - }); - return { - year, - value: sumBy(tagsData, "value"), - children: tagsData - }; - }); - res.json({ - count: yearsData.length, - vizData: yearsData - }); - }) - .catch(error => { - genericError(error, res); - }); -} - -export function ODAbarChart1(req: any, res: any) { - axios - .get( - `${process.env.DS_SOLR_API}/activity/?q=reporting_org_ref:${process.env.MFA_PUBLISHER_REF}&facet=on&facet.pivot=activity_date_start_actual&fl=facet_counts&rows=0` - ) - .then(call1Response => { - const activityYears = uniq( - get( - call1Response, - "data.facet_counts.facet_pivot.activity_date_start_actual", - [] - ).map((item: any) => item.value.split("-")[0]) - ); - - let yearFacetsObj = {}; - - activityYears.forEach((yearValue: any) => { - yearFacetsObj = { - ...yearFacetsObj, - [`${yearValue}_total`]: { - type: "query", - q: `transaction_value_date:[${yearValue}-01-01T00:00:00Z TO ${yearValue}-12-31T23:59:59Z] AND (transaction_flow_type_code:10 OR default_flow_type_code:10) AND transaction_type:3`, - facet: { - value: "sum(transaction_value)" - } - }, - [`${yearValue}_exclusive`]: { - type: "query", - q: `transaction_value_date:[${yearValue}-01-01T00:00:00Z TO ${yearValue}-12-31T23:59:59Z] AND tag_vocabulary:99 AND tag_code:243066* AND transaction_type:3`, - facet: { - value: "sum(transaction_value)" - } - } - }; - }); - - const values = { - q: getFormattedFilters(get(req.body, "filters", {})), - "json.facet": JSON.stringify(yearFacetsObj), - rows: 0 - }; - - axios - .get( - `${process.env.DS_SOLR_API}/transaction/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(call2Response => { - const actualData = get(call2Response, "data.facets", {}); - - const result: any = []; - - activityYears.forEach((year: any) => { - const total = get(actualData, `${year}_total.value`, 0); - const exclusive = get(actualData, `${year}_exclusive.value`, 0); - const other = total - exclusive; - - if (total > 0) { - result.push({ - year: parseInt(year, 10), - exclusive, - other, - exclusiveColor: "#ACD1D1", - otherColor: "#7491CE", - gni: 0, - gniColor: "#AE4764" - }); - } - }); - - res.json({ - count: get(call2Response, "data.response.numFound", 0), - vizData: orderBy(result, "year", "asc") - }); - }) - .catch(error => { - genericError(error, res); - }); - }) - .catch(error => { - genericError(error, res); - }); -} - -export function budgetLineBarChart2(req: any, res: any) { - axios - .get( - `${process.env.DS_SOLR_API}/activity/?q=reporting_org_ref:${process.env.MFA_PUBLISHER_REF}&facet=on&facet.pivot=activity_date_start_actual&fl=facet_counts&rows=0` - ) - .then(call1Response => { - const activityYears = uniq( - get( - call1Response, - "data.facet_counts.facet_pivot.activity_date_start_actual", - [] - ).map((item: any) => item.value.split("-")[0]) - ); - - let yearFacetsObj = {}; - - activityYears.forEach((yearValue: any) => { - yearFacetsObj = { - ...yearFacetsObj, - [`${yearValue}`]: { - type: "query", - q: `transaction_value_date:[${yearValue}-01-01T00:00:00Z TO ${yearValue}-12-31T23:59:59Z] AND tag_vocabulary:99 AND tag_code:243066* AND transaction_type:3`, - facet: { - lines: { - type: "terms", - field: "tag_code", - limit: -1, - facet: { value: "sum(transaction_value)" } - } - } - } - }; - }); - - const values = { - q: getFormattedFilters(get(req.body, "filters", {})), - "json.facet": JSON.stringify(yearFacetsObj), - rows: 0 - }; - - axios - .get( - `${process.env.DS_SOLR_API}/transaction/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(call2Response => { - const actualData = get(call2Response, "data.facets", {}); - - const result: any = []; - - activityYears.forEach((year: any) => { - const tags = get(actualData, `${year}.lines.buckets`, []); - - if (tags.length > 0) { - let item = { - year: parseInt(year, 10) - }; - tags.forEach((tag: any) => { - const linename = get(budgetLineCodes2Values, tag.val, null); - if (linename) { - item = { - ...item, - [linename]: tag.value, - [`${linename}Color`]: get(colors, tag.val, "") - }; - } - }); - result.push(item); - } - }); - - res.json({ - count: get(call2Response, "data.response.numFound", 0), - vizData: result - }); - }) - .catch(error => { - genericError(error, res); - }); - }) - .catch(error => { - genericError(error, res); - }); -} +import { + AF_TAG_CODE, + AF_TAG_VOCABULARY, + AF_BUDGET_VALUE, + AF_BUDGET_VALUE_UNDERSCORED, + AF_BUDGET_VALUE_DATE, + AF_REPORTING_ORG_REF, + AF_TRANSACTION_VALUE_DATE, + AF_TRANSACTION_FLOW_TYPE_CODE, + AF_TRANSACTION_TYPE_CODE, + AF_TRANSACTION_UNDERSCORED, + AF_DEFAULT_FLOW_TYPE_CODE, + AF_TRANSACTION, + AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED, + AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX +} from "../../static/apiFilterFields"; export function ODAbarChart(req: any, res: any) { const totalURL = `${ @@ -292,8 +49,8 @@ export function ODAbarChart(req: any, res: any) { get(req.body, "filters", {}), false, true - )} AND (transaction_flow_type_code:10 OR default_flow_type_code:10) AND transaction_type:3`, - fl: "transaction_type,transaction_value,transaction_value_date", + )} AND (${AF_TRANSACTION_FLOW_TYPE_CODE}:10 OR ${AF_DEFAULT_FLOW_TYPE_CODE}:10) AND ${AF_TRANSACTION_TYPE_CODE}:3`, + fl: `${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION},${AF_TRANSACTION_VALUE_DATE}`, rows: 20000 }, "&", @@ -303,7 +60,8 @@ export function ODAbarChart(req: any, res: any) { } )}`; - const orgTotalURL = `${process.env.DS_SOLR_API}/organisation/?q=organisation_identifier:${process.env.MFA_PUBLISHER_REF}&fl=organisation_total_expenditure`; + /** Review: organisation_identifier, needs to be fixed on solr before it can be migrated */ + const orgTotalURL = `${process.env.DS_SOLR_API}/organisation/?q=organisation_identifier:${process.env.MFA_PUBLISHER_REF}&fl=${AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED},${AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX}`; const exclusiveURL = `${ process.env.DS_SOLR_API @@ -313,8 +71,8 @@ export function ODAbarChart(req: any, res: any) { get(req.body, "filters", {}), false, true - )} tag_code:243066* AND transaction_type:3`, - fl: "transaction_type,transaction_value,transaction_value_date", + )} ${AF_TAG_CODE}:243066* AND ${AF_TRANSACTION_TYPE_CODE}:3`, + fl: `${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION},${AF_TRANSACTION_VALUE_DATE}`, rows: 20000 }, "&", @@ -323,68 +81,110 @@ export function ODAbarChart(req: any, res: any) { encodeURIComponent: (str: string) => str } )}`; - axios .all([axios.get(totalURL), axios.get(exclusiveURL), axios.get(orgTotalURL)]) .then( axios.spread((...responses) => { let totalRes = get(responses[0], "data.response.docs", []); let exclusiveRes = get(responses[1], "data.response.docs", []); - let orgtotalRes = get( - responses[2], - "data.response.docs[0].organisation_total_expenditure", - [] - ); - + let orgtotalRes = get(responses[2], "data.response.docs[0]", []); totalRes = totalRes.map((item: any) => { const valueIndex = findIndex( - item.transaction_type, + item[AF_TRANSACTION_TYPE_CODE], (t: string) => t === "3" ); - const value = get(item, `transaction_value[${valueIndex}]`, 0); + const value = get(item, `["${AF_TRANSACTION}"][${valueIndex}]`, 0); return { value, - year: get(item, `transaction_value_date[${valueIndex}]`, "").slice( - 0, - 4 - ) + year: get( + item, + `["${AF_TRANSACTION_VALUE_DATE}"][${valueIndex}]`, + "" + ).slice(0, 4) }; }); - orgtotalRes = orgtotalRes.map((item: any) => { - const parseditem = JSON.parse(item); - return { - value: parseditem.value.value, - year: parseditem.period_start.slice(0, 4), - exclusive: sumBy( - filter( - parseditem.expense_line, - (line: any) => line.ref.indexOf("24.30.66.") > -1 - ).map((line: any) => line.value), - "value" - ), - gni: sumBy( - filter( - parseditem.expense_line, - (line: any) => line.ref.indexOf("ODA/GNI") > -1 - ).map((line: any) => line.value), - "value" - ) - }; + // process the organisation total expenditure. + let organisationTotalExpenditures = []; + // value is 1..1 + const allValues = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED]; + const allYears = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START]; + + const lineRefs = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF]; + const lineValues = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE]; + const lineIndexes = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX]; + const lineRefIndexes = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX]; + const lineValueIndexes = + orgtotalRes[ + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX + ]; + let expenselineStartIndex = 0; + allValues.forEach((value: number, valueIndex: number) => { + let exclusiveValues = []; + let gniValues = []; + + const year = allYears[valueIndex].slice(0, 4); // year is also 1..1 + const numberOfExpenseLines = lineIndexes[valueIndex]; + const expenselineEndIndex = + expenselineStartIndex + numberOfExpenseLines; + + if (numberOfExpenseLines !== 0) { + const expenselineValueIndexes = lineValueIndexes.slice( + expenselineStartIndex, + expenselineEndIndex + ); + const expenselineRefIndexes = lineRefIndexes.slice( + expenselineStartIndex, + expenselineEndIndex + ); + + expenselineValueIndexes.forEach( + (expenselineValueIndex, expenselineIndex: number) => { + const expenselineRefIndex = + expenselineRefIndexes[expenselineIndex]; + const expenselineValue = + lineValues[expenselineStartIndex + expenselineValueIndex]; + const expenselineRef = + lineRefs[expenselineStartIndex + expenselineRefIndex]; + + if (expenselineRef.indexOf("24.30.66.") > -1) { + exclusiveValues.push(expenselineValue); + } else if (expenselineRef.indexOf("ODA/GNI") > -1) { + gniValues.push(expenselineValue); + } + } + ); + } + expenselineStartIndex = expenselineEndIndex; + + organisationTotalExpenditures.push({ + value: value, + year: year, + exclusive: sum(exclusiveValues), + gni: sum(gniValues) + }); }); + orgtotalRes = organisationTotalExpenditures; exclusiveRes = exclusiveRes.map((item: any) => { const valueIndex = findIndex( - item.transaction_type, + item[AF_TRANSACTION_TYPE_CODE], (t: string) => t === "3" ); - const value = get(item, `transaction_value[${valueIndex}]`, 0); + const value = get(item, `["${AF_TRANSACTION}"][${valueIndex}]`, 0); return { value, - year: get(item, `transaction_value_date[${valueIndex}]`, "").slice( - 0, - 4 - ) + year: get( + item, + `["${AF_TRANSACTION_VALUE_DATE}"][${valueIndex}]`, + "" + ).slice(0, 4) }; }); @@ -454,8 +254,7 @@ export function ODAbarChart(req: any, res: any) { export function budgetLineBarChart(req: any, res: any) { const extra_param = get(req.body, "extra_param", ""); const yearFilter = get(req.body, "filters.years", []); - const orgTotalURL = `${process.env.DS_SOLR_API}/organisation/?q=organisation_identifier:${process.env.MFA_PUBLISHER_REF}&fl=organisation_total_expenditure`; - + const orgTotalURL = `${process.env.DS_SOLR_API}/organisation/?q=organisation_identifier:${process.env.MFA_PUBLISHER_REF}&fl=${AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED},${AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX},${AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX}`; if ( yearFilter.length > 0 && parseInt(yearFilter[0], 10) < 2015 && @@ -464,23 +263,70 @@ export function budgetLineBarChart(req: any, res: any) { axios .get(orgTotalURL) .then(response => { - let orgtotalRes = get( - response, - "data.response.docs[0].organisation_total_expenditure", - [] - ); - orgtotalRes = orgtotalRes.map((item: any) => { - const parseditem = JSON.parse(item); - return { - value: parseditem.value.value, - year: parseditem.period_start.slice(0, 4), - lines: filter( - parseditem.expense_line, - (line: any) => line.ref.indexOf("24.30.66.") > -1 - ) - }; - }); + let orgtotalRes = get(response, "data.response.docs[0]", []); + + // process the organisation total expenditure. + let organisationTotalExpenditures = []; + // value is 1..1 + const allValues = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED]; + const allYears = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START]; + + const lineRefs = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF]; + const lineValues = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE]; + const lineIndexes = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX]; + const lineRefIndexes = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX]; + const lineValueIndexes = + orgtotalRes[ + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX + ]; + let expenselineStartIndex = 0; + allValues.forEach((value: number, valueIndex: number) => { + const lines = []; + const year = allYears[valueIndex].slice(0, 4); // year is also 1..1 + const numberOfExpenseLines = lineIndexes[valueIndex]; + const expenselineEndIndex = + expenselineStartIndex + numberOfExpenseLines; + + if (numberOfExpenseLines !== 0) { + const expenselineValueIndexes = lineValueIndexes.slice( + expenselineStartIndex, + expenselineEndIndex + ); + const expenselineRefIndexes = lineRefIndexes.slice( + expenselineStartIndex, + expenselineEndIndex + ); + + expenselineValueIndexes.forEach( + (expenselineValueIndex, expenselineIndex: number) => { + const expenselineRefIndex = + expenselineRefIndexes[expenselineIndex]; + const expenselineValue = + lineValues[expenselineStartIndex + expenselineValueIndex]; + const expenselineRef = + lineRefs[expenselineStartIndex + expenselineRefIndex]; + + if (expenselineRef.indexOf("24.30.66.") > -1) { + lines.push({ expenselineRef, value: expenselineValue }); + } + } + ); + } + expenselineStartIndex = expenselineEndIndex; + organisationTotalExpenditures.push({ + value, + year, + lines + }); + }); + orgtotalRes = organisationTotalExpenditures; let result = find(orgtotalRes, { year: yearFilter[0] }); result = get(result, "lines", []).map((line: string) => { @@ -490,7 +336,7 @@ export function budgetLineBarChart(req: any, res: any) { line: get(translatedLine, "info.name", ref), line_fi: get(translatedLine, "info.name_fi", ref), line_se: get(translatedLine, "info.name_se", ref), - value: line.value.value, + value: line.value, code: line.ref, valueColor: get(colors, ref, "") }; @@ -510,9 +356,8 @@ export function budgetLineBarChart(req: any, res: any) { get(req.body, "filters", {}), false, true - )} AND tag_code:243066* AND transaction_type:3`, - fl: - "transaction_type,transaction_value,transaction_value_date,tag_code", + )} AND ${AF_TAG_CODE}:243066* AND ${AF_TRANSACTION_TYPE_CODE}:3`, + fl: `${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION},${AF_TRANSACTION_VALUE_DATE},${AF_TAG_CODE}`, rows: 20000 }, "&", @@ -527,36 +372,88 @@ export function budgetLineBarChart(req: any, res: any) { .then( axios.spread((...responses) => { let exclusiveRes = get(responses[0], "data.response.docs", []); - let orgtotalRes = get( - responses[1], - "data.response.docs[0].organisation_total_expenditure", - [] - ); + let orgtotalRes = get(responses[1], "data.response.docs[0]", []); + + // process the organisation total expenditure. + let organisationTotalExpenditures = []; + // value is 1..1 + const allValues = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED]; + const allYears = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START]; + + const lineRefs = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF]; + const lineValues = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE]; + const lineIndexes = + orgtotalRes[AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX]; + const lineRefIndexes = + orgtotalRes[ + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX + ]; + const lineValueIndexes = + orgtotalRes[ + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX + ]; + let expenselineStartIndex = 0; + allValues.forEach((value: number, valueIndex: number) => { + const lines = []; + const year = allYears[valueIndex].slice(0, 4); // year is also 1..1 + const numberOfExpenseLines = lineIndexes[valueIndex]; + const expenselineEndIndex = + expenselineStartIndex + numberOfExpenseLines; + + if (numberOfExpenseLines !== 0) { + const expenselineValueIndexes = lineValueIndexes.slice( + expenselineStartIndex, + expenselineEndIndex + ); + const expenselineRefIndexes = lineRefIndexes.slice( + expenselineStartIndex, + expenselineEndIndex + ); + + expenselineValueIndexes.forEach( + (expenselineValueIndex, expenselineIndex: number) => { + const expenselineRefIndex = + expenselineRefIndexes[expenselineIndex]; + const expenselineValue = + lineValues[expenselineStartIndex + expenselineValueIndex]; + const expenselineRef = + lineRefs[expenselineStartIndex + expenselineRefIndex]; + + if (expenselineRef.indexOf("24.30.66.") > -1) { + lines.push({ + ref: expenselineRef, + value: expenselineValue + }); + } + } + ); + } + expenselineStartIndex = expenselineEndIndex; - orgtotalRes = orgtotalRes.map((item: any) => { - const parseditem = JSON.parse(item); - return { - value: parseditem.value.value, - year: parseditem.period_start.slice(0, 4), - lines: filter( - parseditem.expense_line, - (line: any) => line.ref.indexOf("24.30.66.") > -1 - ) - }; + organisationTotalExpenditures.push({ + value, + year, + lines + }); }); + orgtotalRes = organisationTotalExpenditures; exclusiveRes = exclusiveRes.map((item: any) => { const valueIndex = findIndex( - item.transaction_type, + item[AF_TRANSACTION_TYPE_CODE], (t: string) => t === "3" ); - const value = get(item, `transaction_value[${valueIndex}]`, 0); + const value = get(item, `["${AF_TRANSACTION}"][${valueIndex}]`, 0); return { value, - tags: get(item, "tag_code", []), + tags: get(item, AF_TAG_CODE, []), year: get( item, - `transaction_value_date[${valueIndex}]`, + `["${AF_TRANSACTION_VALUE_DATE}"][${valueIndex}]`, "" ).slice(0, 4) }; @@ -564,7 +461,6 @@ export function budgetLineBarChart(req: any, res: any) { const groupedTotalOrg = groupBy(orgtotalRes, "year"); const groupedExclusive = groupBy(exclusiveRes, "year"); - const years = uniq([ ...Object.keys(groupedTotalOrg), ...Object.keys(groupedExclusive) @@ -622,15 +518,15 @@ export function budgetLineBarChart(req: any, res: any) { const tagnamese = get(translatedLine, "info.name_se", null); if (tagname) { if (yearObj[tagname]) { - yearObj[tagname] += item.value.value; - yearObj[`${tagnamefi}_fi`] += item.value.value; - yearObj[`${tagnamese}_se`] += item.value.value; + yearObj[tagname] += item.value; + yearObj[`${tagnamefi}_fi`] += item.value; + yearObj[`${tagnamese}_se`] += item.value; } else { yearObj = { ...yearObj, - [tagname]: item.value.value, - [`${tagnamefi}_fi`]: item.value.value, - [`${tagnamese}_se`]: item.value.value, + [tagname]: item.value, + [`${tagnamefi}_fi`]: item.value, + [`${tagnamese}_se`]: item.value, [`${tagname}Code`]: ref, [`${tagnamefi}Code`]: ref, [`${tagnamese}Code`]: ref, diff --git a/server/controllers/viz-api/GeoController.ts b/server/controllers/viz-api/GeoController.ts index 430e18d..d9cf85b 100644 --- a/server/controllers/viz-api/GeoController.ts +++ b/server/controllers/viz-api/GeoController.ts @@ -10,18 +10,26 @@ import { getFormattedFilters, normalizeActivity2TransactionFilters } from "../../utils/filters"; +import { + AF_COUNTRY, + AF_TRANSACTION_UNDERSCORED, + AF_TRANSACTION_COUNTRY, + AF_TRANSACTION_TYPE_CODE, + AF_REGION, + AF_TRANSACTION_REGION +} from "../../static/apiFilterFields"; export function geoChart(req: any, res: any) { const values = { q: `${normalizeActivity2TransactionFilters( getFormattedFilters(get(req.body, "filters", {}), true) - )} AND transaction_type:3`, + )} AND ${AF_TRANSACTION_TYPE_CODE}:3`, "json.facet": JSON.stringify({ items: { type: "terms", - field: "activity_recipient_country_code", + field: AF_COUNTRY, limit: -1, - facet: { sum: "sum(transaction_value)" } + facet: { sum: `sum(${AF_TRANSACTION_UNDERSCORED})` } } }), rows: 0 @@ -33,14 +41,13 @@ export function geoChart(req: any, res: any) { "json.facet": JSON.stringify({ unallocable: { type: "query", - query: - "transaction_type:3 AND (activity_recipient_country_code:998 OR transaction_recipient_country_code:998 OR activity_recipient_region_code:998 OR transaction_recipient_region_code:998)", - facet: { sum: "sum(transaction_value)" } + query: `${AF_TRANSACTION_TYPE_CODE}:3 AND (${AF_COUNTRY}:998 OR ${AF_TRANSACTION_COUNTRY}:998 OR ${AF_REGION}:998 OR ${AF_TRANSACTION_REGION}:998)`, + facet: { sum: `sum(${AF_TRANSACTION_UNDERSCORED})` } }, total: { type: "query", - query: "transaction_type:3", - facet: { sum: "sum(transaction_value)" } + query: `${AF_TRANSACTION_TYPE_CODE}:3`, + facet: { sum: `sum(${AF_TRANSACTION_UNDERSCORED})` } } }), rows: 0 diff --git a/server/controllers/viz-api/SDGController.ts b/server/controllers/viz-api/SDGController.ts index ce1782f..5ae2180 100644 --- a/server/controllers/viz-api/SDGController.ts +++ b/server/controllers/viz-api/SDGController.ts @@ -7,14 +7,20 @@ import findIndex from "lodash/findIndex"; import { GOALS } from "../../static/sdgs"; import { genericError } from "../../utils/general"; import { getFormattedFilters } from "../../utils/filters"; +import { + AF_TRANSACTION_UNDERSCORED, + AF_TRANSACTION_TYPE_CODE, + AF_TAG_CODE, + AF_TAG_VOCABULARY +} from "../../static/apiFilterFields"; export function SDGViz(req: any, res: any) { const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( { q: `${getFormattedFilters( get(req.body, "filters", {}) - )} AND tag_vocabulary:2 AND (transaction_type:2 OR transaction_type:3)`, - fl: "tag_code,transaction_type,transaction_value", + )} AND ${AF_TAG_VOCABULARY}:2 AND (${AF_TRANSACTION_TYPE_CODE}:2 OR ${AF_TRANSACTION_TYPE_CODE}:3)`, + fl: `${AF_TAG_CODE},${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION_UNDERSCORED}`, rows: 20000 }, "&", @@ -32,27 +38,38 @@ export function SDGViz(req: any, res: any) { goals.forEach((goal: any, index: number) => { const goalActivities = filter(activities, (act: any) => - find(act.tag_code, (c: string) => c === goal.code) + find(act[AF_TAG_CODE], (c: string) => c === goal.code) ); let disbursed = 0; let committed = 0; goalActivities.forEach((item: any) => { - if (item.transaction_type && item.transaction_value) { + if ( + item[AF_TRANSACTION_TYPE_CODE] && + item[AF_TRANSACTION_UNDERSCORED] + ) { const disbTransIndex = findIndex( - item.transaction_type, + item[AF_TRANSACTION_TYPE_CODE], (tt: string) => tt === "3" ); const comTransIndex = findIndex( - item.transaction_type, + item[AF_TRANSACTION_TYPE_CODE], (tt: string) => tt === "2" ); if (disbTransIndex > -1) { - disbursed += get(item, `transaction_value[${disbTransIndex}]`, 0); + disbursed += get( + item, + `${AF_TRANSACTION_UNDERSCORED}[${disbTransIndex}]`, + 0 + ); } if (comTransIndex > -1) { - committed += get(item, `transaction_value[${comTransIndex}]`, 0); + committed += get( + item, + `${AF_TRANSACTION_UNDERSCORED}[${comTransIndex}]`, + 0 + ); } } }); diff --git a/server/controllers/viz-api/SunburstController.ts b/server/controllers/viz-api/SunburstController.ts index 8700d2c..8149350 100644 --- a/server/controllers/viz-api/SunburstController.ts +++ b/server/controllers/viz-api/SunburstController.ts @@ -15,6 +15,12 @@ import { getFormattedFilters, normalizeActivity2TransactionFilters } from "../../utils/filters"; +import { + AF_SECTOR, + AF_SECTOR_PERCENTAGE, + AF_TRANSACTION_TYPE_CODE, + AF_TRANSACTION_UNDERSCORED +} from "../../static/apiFilterFields"; // exclude sectors that don't have data function getSectorsWithData(sectorData: any) { @@ -79,9 +85,8 @@ export function basicSunburstChart(req: any, res: any) { { q: `${normalizeActivity2TransactionFilters( getFormattedFilters(get(req.body, "filters", {}), true) - )} AND transaction_type:(2 3)`, - fl: - "activity_sector_code,activity_sector_percentage,transaction_type,transaction_value", + )} AND ${AF_TRANSACTION_TYPE_CODE}:(2 3)`, + fl: `${AF_SECTOR},${AF_SECTOR_PERCENTAGE},${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION_UNDERSCORED}`, rows: 50000 }, "&", @@ -98,37 +103,35 @@ export function basicSunburstChart(req: any, res: any) { const rawSectors: any = []; rawData.forEach((doc: any) => { - get(doc, "activity_sector_code", []).forEach( - (sector: string, index: number) => { - const fSectorIndex = findIndex(rawSectors, { val: sector }); - const percentage = get(doc, `sector_percentage[${index}]`, 100); - const data = { - val: sector, - committed: { value: 0 }, - disbursed: { value: 0 } - }; - if (doc.transaction_type === "2") { - if (fSectorIndex > -1) { - rawSectors[fSectorIndex].committed.value += - (doc.transaction_value * percentage) / 100; - } else { - data.committed.value = - (doc.transaction_value * percentage) / 100; - } - } else if (doc.transaction_type === "3") { - if (fSectorIndex > -1) { - rawSectors[fSectorIndex].disbursed.value += - (doc.transaction_value * percentage) / 100; - } else { - data.disbursed.value = - (doc.transaction_value * percentage) / 100; - } + get(doc, AF_SECTOR, []).forEach((sector: string, index: number) => { + const fSectorIndex = findIndex(rawSectors, { val: sector }); + const percentage = get(doc, `${AF_SECTOR_PERCENTAGE}[${index}]`, 100); + const data = { + val: sector, + committed: { value: 0 }, + disbursed: { value: 0 } + }; + if (doc[AF_TRANSACTION_TYPE_CODE][0] === "2") { + if (fSectorIndex > -1) { + rawSectors[fSectorIndex].committed.value += + (doc[AF_TRANSACTION_UNDERSCORED] * percentage) / 100; + } else { + data.committed.value = + (doc[AF_TRANSACTION_UNDERSCORED] * percentage) / 100; } - if (fSectorIndex === -1) { - rawSectors.push(data); + } else if (doc[AF_TRANSACTION_TYPE_CODE][0] === "3") { + if (fSectorIndex > -1) { + rawSectors[fSectorIndex].disbursed.value += + (doc[AF_TRANSACTION_UNDERSCORED] * percentage) / 100; + } else { + data.disbursed.value = + (doc[AF_TRANSACTION_UNDERSCORED] * percentage) / 100; } } - ); + if (fSectorIndex === -1) { + rawSectors.push(data); + } + }); }); let baseData = { @@ -360,7 +363,6 @@ export function basicSunburstChart(req: any, res: any) { }); }) .catch(error => { - console.log(error); genericError(error, res); }); } diff --git a/server/controllers/viz-api/ThematicAreaController.ts b/server/controllers/viz-api/ThematicAreaController.ts index 5ce7db3..ffe321b 100644 --- a/server/controllers/viz-api/ThematicAreaController.ts +++ b/server/controllers/viz-api/ThematicAreaController.ts @@ -10,16 +10,33 @@ import { normalizeActivity2TransactionFilters } from "../../utils/filters"; import { thematicAreaNames } from "../../static/thematicAreaConsts"; +import { + AF_TAG_CODE, + AF_TAG_VOCABULARY, + AF_BUDGET_VALUE, + AF_BUDGET_VALUE_UNDERSCORED, + AF_BUDGET_VALUE_DATE, + AF_REPORTING_ORG_REF, + AF_TRANSACTION_VALUE_DATE, + AF_TRANSACTION_FLOW_TYPE_CODE, + AF_TRANSACTION_TYPE_CODE, + AF_TRANSACTION_UNDERSCORED, + AF_DEFAULT_FLOW_TYPE_CODE, + AF_TRANSACTION, + AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED, + AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF, + AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE +} from "../../static/apiFilterFields"; const sizes = [120, 100, 80, 60]; - export function thematicAreasChart(req: any, res: any) { const url = `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( { q: `${getFormattedFilters( get(req.body, "filters", {}) - )} AND tag_code:Priority* AND transaction_type:3 AND tag_vocabulary:99`, - fl: "tag_code,transaction_type,transaction_value", + )} AND ${AF_TAG_CODE}:Priority* AND ${AF_TRANSACTION_TYPE_CODE}:3 AND ${AF_TAG_VOCABULARY}:99`, + fl: `${AF_TAG_CODE},${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION_UNDERSCORED}`, rows: 20000 }, "&", @@ -35,23 +52,27 @@ export function thematicAreasChart(req: any, res: any) { const activities = get(call1Response, "data.response.docs", []); const items: any = []; activities.forEach((activity: any) => { - activity.tag_code.forEach((tc: string) => { + activity[AF_TAG_CODE].forEach((tc: string) => { if (tc.indexOf("Priority") > -1) { const fItemIndex = findIndex(items, { name: tc }); const disbTransIndex = findIndex( - activity.transaction_type, + activity[AF_TRANSACTION_TYPE_CODE], (tt: string) => tt === "3" ); if (fItemIndex === -1) { items.push({ name: tc, area: get(thematicAreaNames, tc, ""), - value: get(activity, `transaction_value[${disbTransIndex}]`, 0) + value: get( + activity, + `${AF_TRANSACTION_UNDERSCORED}[${disbTransIndex}]`, + 0 + ) }); } else { items[fItemIndex].value += get( activity, - `transaction_value[${disbTransIndex}]`, + `${AF_TRANSACTION_UNDERSCORED}[${disbTransIndex}]`, 0 ); } @@ -272,8 +293,8 @@ export function thematicAreasChart2(req: any, res: any) { { q: `${normalizeActivity2TransactionFilters( getFormattedFilters(get(req.body, "filters", {})) - )} AND tag_code:Priority* AND transaction_type:3 AND tag_vocabulary:99`, - fl: "tag_code,transaction_type,transaction_value", + )} AND ${AF_TAG_CODE}:Priority* AND ${AF_TRANSACTION_TYPE_CODE}:3 AND ${AF_TAG_VOCABULARY}:99`, + fl: `${AF_TAG_CODE},${AF_TRANSACTION_TYPE_CODE},${AF_TRANSACTION_UNDERSCORED}`, rows: 20000 }, "&", @@ -289,19 +310,19 @@ export function thematicAreasChart2(req: any, res: any) { const transactions = get(call1Response, "data.response.docs", []); const items: any = []; transactions.forEach((transaction: any) => { - transaction.tag_code.forEach((tc: string) => { + transaction[AF_TAG_CODE].forEach((tc: string) => { if (tc.indexOf("Priority") > -1) { const fItemIndex = findIndex(items, { name: tc }); if (fItemIndex === -1) { items.push({ name: tc, area: get(thematicAreaNames, tc, ""), - value: get(transaction, `transaction_value`, 0) + value: get(transaction, `${AF_TRANSACTION_UNDERSCORED}`, 0) }); } else { items[fItemIndex].value += get( transaction, - `transaction_value`, + `${AF_TRANSACTION_UNDERSCORED}`, 0 ); } diff --git a/server/controllers/viz-api/TreemapController.ts b/server/controllers/viz-api/TreemapController.ts index 8465fdd..5f5843f 100644 --- a/server/controllers/viz-api/TreemapController.ts +++ b/server/controllers/viz-api/TreemapController.ts @@ -15,6 +15,25 @@ import { getFormattedFilters, normalizeActivity2TransactionFilters } from "../../utils/filters"; +import { + AF_IATI_IDENTIFIER, + AF_TITLE_NARRATIVE, + AF_COUNTRY, + AF_REGION, + AF_REGION_NAME, + AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_REF, + AF_PARTICIPATING_ORG_ROLE, + AF_PARTICIPATING_ORG_TYPE, + AF_REPORTING_ORG_NARRATIVE, + AF_REPORTING_ORG_REF, + AF_REPORTING_ORG_TYPE_NAME, + AF_TRANSACTION_USD, + AF_TRANSACTION_UNDERSCORED, + AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, + AF_TRANSACTION_PROVIDER_ORG_REF, + AF_TRANSACTION_TYPE_CODE +} from "../../static/apiFilterFields"; export function projectsTreemapChart(req: any, res: any) { const url = `${process.env.DS_SOLR_API}/transaction/?${querystring.stringify( @@ -25,17 +44,17 @@ export function projectsTreemapChart(req: any, res: any) { "json.facet": JSON.stringify({ items: { type: "terms", - field: "iati_identifier", + field: AF_IATI_IDENTIFIER, limit: -1, facet: { name: { type: "terms", - field: "title_narrative" + field: AF_TITLE_NARRATIVE }, disbursed: { type: "query", - q: "transaction_type:3", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:3`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } } } } @@ -83,41 +102,41 @@ export function locationsTreemapChart(req: any, res: any) { "json.facet": JSON.stringify({ countries: { type: "terms", - field: "activity_recipient_country_code", + field: AF_COUNTRY, limit: -1, facet: { disbursed: { type: "query", - q: "transaction_type:3", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:3`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } }, committed: { type: "query", - q: "transaction_type:2", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:2`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } } } }, regions: { type: "terms", - field: "activity_recipient_region_code", + field: AF_REGION, limit: -1, facet: { disbursed: { type: "query", - q: "transaction_type:3", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:3`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } }, committed: { type: "query", - q: "transaction_type:2", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:2`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } } } }, regionNames: { type: "terms", - field: "activity_recipient_region_name", + field: AF_REGION_NAME, limit: -1 } }), @@ -190,9 +209,8 @@ export function organisationsTreemapChart2(req: any, res: any) { { q: `${getFormattedFilters( get(req.body, "filters", {}) - )} AND participating_org_ref:* AND (transaction_type:3 OR transaction_type:2)`, - fl: - "transaction_value,transaction_type,participating_org_ref,participating_org_type,participating_org_narrative,participating_org_role", + )} AND ${AF_PARTICIPATING_ORG_REF}:* AND (${AF_TRANSACTION_TYPE_CODE}:3 OR ${AF_TRANSACTION_TYPE_CODE}:2)`, + fl: `${AF_TRANSACTION_UNDERSCORED},${AF_TRANSACTION_TYPE_CODE},${AF_PARTICIPATING_ORG_REF},${AF_PARTICIPATING_ORG_TYPE},${AF_PARTICIPATING_ORG_NARRATIVE},${AF_PARTICIPATING_ORG_ROLE}`, rows: 20000 }, "&", @@ -208,49 +226,65 @@ export function organisationsTreemapChart2(req: any, res: any) { const actualData = get(call1Response, "data.response.docs", []); let orgTypes: string[] = []; actualData.forEach((doc: any) => { - if (doc.transaction_value && doc.transaction_type) { + if (doc[AF_TRANSACTION_UNDERSCORED] && doc[AF_TRANSACTION_TYPE_CODE]) { doc.disbursed = 0; doc.committed = 0; - doc.transaction_type.forEach((type: string, index: number) => { - if (type === "3") { - doc.disbursed += get(doc, `transaction_value[${index}]`, 0); - } else if (type === "2") { - doc.committed += get(doc, `transaction_value[${index}]`, 0); + doc[AF_TRANSACTION_TYPE_CODE].forEach( + (type: string, index: number) => { + if (type === "3") { + doc.disbursed += get( + doc, + `${AF_TRANSACTION_UNDERSCORED}[${index}]`, + 0 + ); + } else if (type === "2") { + doc.committed += get( + doc, + `${AF_TRANSACTION_UNDERSCORED}[${index}]`, + 0 + ); + } } - }); + ); } - orgTypes = [...orgTypes, ...doc.participating_org_type]; + orgTypes = [...orgTypes, ...doc[AF_PARTICIPATING_ORG_TYPE]]; }); orgTypes = uniq(orgTypes); const orgTypesData = orgTypes.map((type: string) => { const data = filter( actualData, - (doc: any) => doc.participating_org_type.indexOf(type) > -1 + (doc: any) => doc[AF_PARTICIPATING_ORG_TYPE].indexOf(type) > -1 ); let orgs: any[] = []; data.forEach((doc: any) => { - doc.participating_org_ref.forEach((orgRef: string, index: number) => { - const orgRole = get(doc.participating_org_role, `[${index}]`, ""); - if (orgRole !== "1") { - const fOrg = find(orgs, { ref: orgRef }); - if (fOrg) { - fOrg.value += doc.disbursed; - fOrg.committed += doc.committed; - } else { - orgs.push({ - ref: orgRef, - name: get( - doc.participating_org_narrative, - `[${index}]`, - orgRef - ), - value: doc.disbursed, - committed: doc.committed, - orgs: [] - }); + doc[AF_PARTICIPATING_ORG_REF].forEach( + (orgRef: string, index: number) => { + const orgRole = get( + doc[AF_PARTICIPATING_ORG_ROLE], + `[${index}]`, + "" + ); + if (orgRole !== "1") { + const fOrg = find(orgs, { ref: orgRef }); + if (fOrg) { + fOrg.value += doc.disbursed; + fOrg.committed += doc.committed; + } else { + orgs.push({ + ref: orgRef, + name: get( + doc[AF_PARTICIPATING_ORG_NARRATIVE], + `[${index}]`, + orgRef + ), + value: doc.disbursed, + committed: doc.committed, + orgs: [] + }); + } } } - }); + ); }); orgs = orgs.map((org: any) => ({ ...org, @@ -285,27 +319,27 @@ export function organisationsTreemapChart(req: any, res: any) { { q: `${normalizeActivity2TransactionFilters( getFormattedFilters(get(req.body, "filters", {})) - )} AND participating_org_ref:* AND (transaction_type:3 OR transaction_type:2)`, + )} AND ${AF_PARTICIPATING_ORG_REF}:* AND (${AF_TRANSACTION_TYPE_CODE}:3 OR ${AF_TRANSACTION_TYPE_CODE}:2)`, "json.facet": JSON.stringify({ items: { type: "terms", - field: "participating_org_ref", + field: AF_PARTICIPATING_ORG_REF, limit: -1, facet: { names: { type: "terms", - field: "participating_org_narrative", + field: AF_PARTICIPATING_ORG_NARRATIVE, limit: 2 }, disbursed: { type: "query", - q: "transaction_type:3", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:3`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } }, committed: { type: "query", - q: "transaction_type:2", - facet: { value: "sum(transaction_value)" } + q: `${AF_TRANSACTION_TYPE_CODE}:2`, + facet: { value: `sum(${AF_TRANSACTION_UNDERSCORED})` } } } } diff --git a/server/static/activityDetailConsts.ts b/server/static/activityDetailConsts.ts index a428e76..e70d4e1 100644 --- a/server/static/activityDetailConsts.ts +++ b/server/static/activityDetailConsts.ts @@ -37,9 +37,15 @@ import { AF_HUMANITARIAN_SCOPE_VOCABULARY, AF_IATI_IDENTIFIER, AF_PARTICIPATING_ORG_NARRATIVE, + AF_PARTICIPATING_ORG_NARRATIVE_LANG, AF_PARTICIPATING_ORG_REF, AF_PARTICIPATING_ORG_ROLE, AF_PARTICIPATING_ORG_TYPE, + AF_PARTICIPATING_ORG_NARRATIVE_INDEX, + AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX, + AF_PARTICIPATING_ORG_REF_INDEX, + AF_PARTICIPATING_ORG_ROLE_INDEX, + AF_PARTICIPATING_ORG_TYPE_INDEX, AF_POLICY_MARKER_CODE, AF_POLICY_MARKER_NAME, AF_POLICY_MARKER_SIGNIFICANCE, @@ -111,9 +117,15 @@ ${AF_TITLE_NARRATIVE_LANG}, ${AF_DESCRIPTION_NARRATIVE}, ${AF_DESCRIPTION_NARRATIVE_LANG}, ${AF_PARTICIPATING_ORG_NARRATIVE}, +${AF_PARTICIPATING_ORG_NARRATIVE_LANG}, ${AF_PARTICIPATING_ORG_REF}, ${AF_PARTICIPATING_ORG_TYPE}, ${AF_PARTICIPATING_ORG_ROLE}, +${AF_PARTICIPATING_ORG_NARRATIVE_INDEX}, +${AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX}, +${AF_PARTICIPATING_ORG_REF_INDEX}, +${AF_PARTICIPATING_ORG_ROLE_INDEX}, +${AF_PARTICIPATING_ORG_TYPE_INDEX}, ${AF_ACTIVITY_DATE_START_PLANNED}, ${AF_ACTIVITY_DATE_END_PLANNED}, ${AF_ACTIVITY_DATE_START_ACTUAL}, @@ -149,7 +161,7 @@ ${AF_PLANNED_DISBURSEMENT_VALUE}, ${AF_PLANNED_DISBURSEMENT_VALUE_CURRENCY}, ${AF_PLANNED_DISBURSEMENT_PERIOD_START_ISO_DATE}, ${AF_PLANNED_DISBURSEMENT_PERIOD_END_ISO_DATE}, -${AF_PLANNED_DISBURSEMENT_PROVIDER_ORG_NARRATIVE},// +${AF_PLANNED_DISBURSEMENT_PROVIDER_ORG_NARRATIVE}, ${AF_BUDGET_TYPE_NAME}, ${AF_BUDGET_STATUS_NAME}, ${AF_BUDGET_PERIOD_START_ISO_DATE}, diff --git a/server/static/apiFilterFields.ts b/server/static/apiFilterFields.ts index c714cbf..29ec13b 100644 --- a/server/static/apiFilterFields.ts +++ b/server/static/apiFilterFields.ts @@ -1,4 +1,5 @@ // template, always prepend with `AF_` for API FIELD. +// keep open export const _API_FIELD = ""; // A @@ -106,12 +107,36 @@ export const AF_OTHER_IDENTIFIER_OWNER_ORG_NARRATIVE = "other-identifier.owner-org.narrative"; export const AF_OTHER_IDENTIFIER_REF = "other-identifier.ref"; export const AF_OTHER_IDENTIFIER_TYPE = "other-identifier.type"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_VALUE_UNDERSCORED = + "organisation_total_expenditure_value"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_PERIOD_START = + "total-expenditure.period-start.iso-date"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF = + "total-expenditure.expense-line.ref"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE = + "total-expenditure.expense-line.value"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_INDEX = + "total-expenditure.expense-line-index"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_REF_INDEX = + "total-expenditure.expense-line.ref-index"; +export const AF_ORGANISATION_TOTAL_EXPENDITURE_EXPENSE_LINE_VALUE_INDEX = + "total-expenditure.expense-line.val-index"; // P export const AF_PARTICIPATING_ORG_NARRATIVE = "participating-org.narrative"; +export const AF_PARTICIPATING_ORG_NARRATIVE_LANG = + "participating-org.narrative.lang"; export const AF_PARTICIPATING_ORG_REF = "participating-org.ref"; export const AF_PARTICIPATING_ORG_ROLE = "participating-org.role"; export const AF_PARTICIPATING_ORG_TYPE = "participating-org.type"; +export const AF_PARTICIPATING_ORG_NARRATIVE_INDEX = + "participating-org.narrative-index"; +export const AF_PARTICIPATING_ORG_NARRATIVE_LANG_INDEX = + "participating-org.narrative.lang-index"; +export const AF_PARTICIPATING_ORG_REF_INDEX = "participating-org.ref-index"; +export const AF_PARTICIPATING_ORG_ROLE_INDEX = "participating-org.role-index"; +export const AF_PARTICIPATING_ORG_TYPE_INDEX = "participating-org.type-index"; + export const AF_POLICY_MARKER_CODE = "policy-marker.code"; export const AF_POLICY_MARKER_COMBINED = "policy-marker.combined"; export const AF_POLICY_MARKER_NAME = "policy-marker.name"; diff --git a/server/utils/general.ts b/server/utils/general.ts index 2ae8b15..5ba2b6a 100644 --- a/server/utils/general.ts +++ b/server/utils/general.ts @@ -1,4 +1,5 @@ export function genericError(error: any, res: any) { const _error = error.response ? error.response.data : error; + console.log(_error); return res.json(_error); } diff --git a/server/utils/parseJsonSolrField.ts b/server/utils/parseJsonSolrField.ts deleted file mode 100644 index 15ae265..0000000 --- a/server/utils/parseJsonSolrField.ts +++ /dev/null @@ -1,9 +0,0 @@ -import get from "lodash/get"; - -export function parseJsonSolrField(obj: any, field: string) { - if (!obj) { - return ""; - } - const value = JSON.parse(obj); - return get(value, field, ""); -} From 4a9eff107f94a8e2bb8a231a469a54859893c81e Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Thu, 28 Jul 2022 12:31:17 +0200 Subject: [PATCH 4/7] feat: removed all connection to deprecated Django API --- README.md | 2 - .../filter-api/utils/activityscope.ts | 42 +- .../filter-api/utils/activitystatus.ts | 42 +- .../controllers/filter-api/utils/codelists.ts | 4611 +++++++++++++++++ .../filter-api/utils/collaborationtype.ts | 40 +- .../controllers/filter-api/utils/currency.ts | 42 +- .../utils/defaultaidtypecategory.ts | 42 +- .../utils/defaultaidtypevocabulary.ts | 41 +- .../filter-api/utils/defaultfinancetype.ts | 42 +- .../filter-api/utils/defaultflowtype.ts | 42 +- .../filter-api/utils/defaulttiedstatus.ts | 42 +- .../filter-api/utils/documentlinkcategory.ts | 42 +- server/controllers/filter-api/utils/donors.ts | 38 +- .../controllers/filter-api/utils/hierarchy.ts | 1 + .../filter-api/utils/humscopevocab.ts | 40 +- .../filter-api/utils/iativersion.ts | 42 +- .../controllers/filter-api/utils/language.ts | 42 +- .../filter-api/utils/otheridentifiertype.ts | 40 +- .../filter-api/utils/policymarker.ts | 54 +- .../filter-api/utils/reportingorgtype.ts | 42 +- .../filter-api/utils/sectorvocab.ts | 42 +- .../filter-api/utils/transactionflowtype.ts | 42 +- .../utils/transactionreceiverorg.ts | 40 +- .../filter-api/utils/transactiontiedstatus.ts | 42 +- .../filter-api/utils/transactiontype.ts | 42 +- .../utils/transactionvaluecurrency.ts | 42 +- 26 files changed, 4949 insertions(+), 630 deletions(-) create mode 100644 server/controllers/filter-api/utils/codelists.ts diff --git a/README.md b/README.md index dc955c0..6d97c4e 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ PROJECT_URL=http://localhost:3000 # data DS_SOLR_API=https://iati.cloud/search -DS_REST_API=https://iati.cloud/api MFA_PUBLISHER_REF=FI-3 HDRO_API=http://ec2-54-174-131-205.compute-1.amazonaws.com/API/HDRO_API.php UM_FI_API=https://um.fi/o/public-api/v1/content @@ -59,7 +58,6 @@ Project will be running on http://localhost:4200/api BACKEND_PORT=4200 MFA_PUBLISHER_REF=FI-3 PROJECT_URL=http://localhost:4200 -DS_REST_API=https://iati.cloud/api DS_SOLR_API=https://iati.cloud/search HDRO_API=http://ec2-54-174-131-205.compute-1.amazonaws.com/API/HDRO_API.php UM_FI_API=https://um.fi/o/public-api/v1/content diff --git a/server/controllers/filter-api/utils/activityscope.ts b/server/controllers/filter-api/utils/activityscope.ts index be7044a..28b8edd 100644 --- a/server/controllers/filter-api/utils/activityscope.ts +++ b/server/controllers/filter-api/utils/activityscope.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_ACTIVITY_SCOPE_CODE } from "../../../static/apiFilterFields"; +import { activityScopeCodelist } from "./codelists"; export function getActivituScopeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getActivituScopeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = activityScopeCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/ActivityScope/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/activitystatus.ts b/server/controllers/filter-api/utils/activitystatus.ts index 5c2bdcf..a3c4d61 100644 --- a/server/controllers/filter-api/utils/activitystatus.ts +++ b/server/controllers/filter-api/utils/activitystatus.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_ACTIVITY_STATUS_CODE } from "../../../static/apiFilterFields"; +import { activityStatusCodelist } from "./codelists"; export function getActivituStatusOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getActivituStatusOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = activityStatusCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/ActivityStatus/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/codelists.ts b/server/controllers/filter-api/utils/codelists.ts new file mode 100644 index 0000000..3b1e56e --- /dev/null +++ b/server/controllers/filter-api/utils/codelists.ts @@ -0,0 +1,4611 @@ +export const organisationIdentifierCodelist = [ + { + code: "XI-IATI-1001", + name: "The Coca-Cola Export Corporation" + }, + { + code: "XI-IATI-1002", + name: "United Mission to Nepal" + }, + { + code: "XI-IATI-ACATBA", + name: + "Association Centrafricaine de Traduction de la Bible et Alphabetisation" + }, + { + code: "XI-IATI-ADVZ", + name: "Agência de Desenvolvimento do Vale do Zambeze" + }, + { + code: "XI-IATI-AGR", + name: "AgResults" + }, + { + code: "XI-IATI-AIAS", + name: "Administração de Infra-Estruturas de Águas e Saneamento" + }, + { + code: "XI-IATI-AJS", + name: "Associations des Juristes Sénégalaises (AJS)" + }, + { + code: "XI-IATI-ATTIC", + name: + "Association of Technicians in Information Technology and Communication (ATTIC)" + }, + { + code: "XI-IATI-BBDN", + name: "Bangladesh Business & Disability Network" + }, + { + code: "XI-IATI-EBRD", + name: "European Bank for Reconstruction and Development" + }, + { + code: "XI-IATI-BEH", + name: "Benedictine Eye Hospital, Tororo" + }, + { + code: "XI-IATI-CABI", + name: "CABI" + }, + { + code: "XI-IATI-CWSEC", + name: "The Commonwealth Secretariat" + }, + { + code: "XI-IATI-DGF", + name: "Democratic Governance Facility" + }, + { + code: "XI-IATI-EC_DEVCO", + name: "European Commission – Development and Cooperation" + }, + { + code: "XI-IATI-EC_ECHO", + name: "European Commission - Humanitarian Aid & Civil Protection" + }, + { + code: "XI-IATI-ESFD", + name: "Economic and Social Fund for Development" + }, + { + code: "XI-IATI-EC_FPI", + name: "European Commission – Service for Foreign Policy Instruments" + }, + { + code: "XI-IATI-EC_NEAR", + name: "European Commission - Neighbourhood and Enlargement Negotiations" + }, + { + code: "XI-IATI-EFRD", + name: "Engage Foundation for Research and Dialogue" + }, + { + code: "XI-IATI-FIABEL", + name: "Federation of Institutional Actors Belgium (FIABEL)" + }, + { + code: "XI-IATI-GREDO", + name: "Gargaar Relief and Development Organization" + }, + { + code: "XI-IATI-IADB", + name: "Inter-American Development Bank" + }, + { + code: "XI-IATI-IFDC", + name: "International Fertilizer Development Center" + }, + { + code: "XI-IATI-IKI", + name: "International Climate Initiative (IKI)" + }, + { + code: "XI-IATI-KHF", + name: "The King Hussein Foundation (KHF)" + }, + { + code: "XI-IATI-LPI", + name: "Living Peace Institute" + }, + { + code: "XI-IATI-MIF", + name: "Multilateral Investment Fund (MIF)" + }, + { + code: "XI-IATI-NSO", + name: "Netherlands Space Office" + }, + { + code: "XI-IATI-OCHASDC", + name: + "United Nations Office for the Coordination of Humanitarian Affairs - Specially-Designated Contributions" + }, + { + code: "XI-IATI-SGJ", + name: "Somali Gender Justice" + }, + { + code: "XI-IATI-SPR", + name: + "Synergie des Femmes pour la Paix et la Réconciliation des Peuples des Grands Lacs d'Afrique (SPR)" + }, + { + code: "XI-IATI-SWSC", + name: "Somali Women Study Centre" + }, + { + code: "XI-IATI-UCES", + name: "Umbrella for Community Education in Somalia" + }, + { + code: "XI-IATI-UDC", + name: "United Darfur Committees" + }, + { + code: "XI-IATI-UNPF", + name: "UN Pooled funds" + }, + { + code: "XI-IATI-WARDI", + name: "Wardi Relief and Development Initiative" + }, + { + code: "XI-IATI-WAI", + name: "WASH Alliance International" + }, + { + code: "XI-IATI-WBTF", + name: "World Bank Trust Funds (WBTF)" + }, + { + code: "XI-IATI-WVDRC", + name: "World Vision DRC" + }, + { + code: "AT-1", + name: "Federal Ministry of Finance" + }, + { + code: "AT-10", + name: "Ministry for Agriculture and Environment" + }, + { + code: "AT-11", + name: "Ministry of Defense" + }, + { + code: "AT-12", + name: "Ministry of Interior" + }, + { + code: "AT-2", + name: "Various ministries" + }, + { + code: "AT-3", + name: "Federal Government of Austria" + }, + { + code: "AT-4", + name: "Oesterreichische Kontrollbank AG" + }, + { + code: "AT-5", + name: "Federal Ministry of Foreign Affairs" + }, + { + code: "AT-6", + name: "Provincial governments, local communities " + }, + { + code: "AT-8", + name: "Austrian Development Agency" + }, + { + code: "AT-9", + name: "Education and Science Ministry" + }, + { + code: "AT-99", + name: "Miscellaneous" + }, + { + code: "AU-5", + name: "Australian Agency for International Development" + }, + { + code: "AU-72", + name: "Export Finance and Insurance Corporation" + }, + { + code: "BE-10", + name: "Directorate General for Co-operation and Development" + }, + { + code: "BE-20", + name: "Official Federal Service of Foreign Affairs (excl. DGCD)" + }, + { + code: "BE-30", + name: "Official Federal Service of Finance" + }, + { + code: "BE-31", + name: "Ducroire National Office" + }, + { + code: "BE-39", + name: "Other Official Federal Services" + }, + { + code: "BE-70", + name: "Flanders Official Regional Ministries" + }, + { + code: "BE-80", + name: "Walloon Official Regional Ministries" + }, + { + code: "BE-91", + name: "Brussels Official Regional Ministries" + }, + { + code: "BE-94", + name: "German speaking Official Regional Ministries" + }, + { + code: "CA-1", + name: "Canadian International Development Agency" + }, + { + code: "CA-2", + name: "International Development Research Centre" + }, + { + code: "CA-31", + name: "Export Development Corporation" + }, + { + code: "CA-4", + name: "Department of Finance" + }, + { + code: "CH-1", + name: "Federal Administration (various departments)" + }, + { + code: "CH-10", + name: "Swiss Agency for the Environment, Forests and Landscape " + }, + { + code: "CH-11", + name: "Municipalities" + }, + { + code: "CH-4", + name: "Swiss Agency for Development and Co-operation" + }, + { + code: "CH-5", + name: "State Secretariat for Economic Affairs" + }, + { + code: "CH-6", + name: "Federal Department of Foreign Affairs" + }, + { + code: "CH-7", + name: "State Secretariat for Education and Research" + }, + { + code: "CH-8", + name: "Federal Office for Migration" + }, + { + code: "CH-9", + name: "Federal Department for Defence, Civil Protection and Sports " + }, + { + code: "DE-1", + name: "Bundesministerium für Wirtschaftliche Zusammenarbeit und Entwicklung" + }, + { + code: "DE-11", + name: "Foreign Office" + }, + { + code: "DE-12", + name: "Federal States & Local Governments" + }, + { + code: "DE-14", + name: "Federal Institutions" + }, + { + code: "DE-16", + name: "Federal Ministries" + }, + { + code: "DE-17", + name: "Foundations/Societies/Misc. (non federal)" + }, + { + code: "DE-2", + name: "Kreditanstalt für Wiederaufbau" + }, + { + code: "DE-34", + name: "Hermes Kreditversicherungs-AG" + }, + { + code: "DE-4", + name: "German Investment and Development Company" + }, + { + code: "DE-52", + name: "Deutsche Gesellschaft für Technische Zusammenarbeit" + }, + { + code: "DK-1", + name: "Ministry of Foreign Affairs" + }, + { + code: "DK-2", + name: "Danish International Development Agency (Not in CRS Directives)" + }, + { + code: "DK-4", + name: "Not in CRS Directives" + }, + { + code: "DK-72", + name: "EKR" + }, + { + code: "ES-1", + name: "Instituto de Credito Oficial" + }, + { + code: "ES-10", + name: "Ministry of Environment" + }, + { + code: "ES-11", + name: "Ministry of Health" + }, + { + code: "ES-12", + name: "Ministry of Labour and Social Affairs" + }, + { + code: "ES-13", + name: "Ministry of Interior" + }, + { + code: "ES-14", + name: "Ministry of Public Administration" + }, + { + code: "ES-15", + name: "Compania Espanola de Seguros de Credito a la Exportación" + }, + { + code: "ES-16", + name: "Municipalities" + }, + { + code: "ES-17", + name: "Miscellaneous" + }, + { + code: "ES-18", + name: "Ministry of Science and Technology" + }, + { + code: "ES-19", + name: "Ministry of Defense" + }, + { + code: "ES-2", + name: "Autonomous Governments" + }, + { + code: "ES-4", + name: "Ministry of Agriculture, Fisheries, and Food " + }, + { + code: "ES-5", + name: "Ministry of Foreign Affairs" + }, + { + code: "ES-6", + name: "Ministry of Economy and Finance" + }, + { + code: "ES-7", + name: "Ministry of Education, Culture and Sports " + }, + { + code: "ES-8", + name: "Ministry of Public Works" + }, + { + code: "ES-9", + name: "Ministry of Industry and Energy" + }, + { + code: "EU-1", + name: "Commission of the European Communities" + }, + { + code: "EU-2", + name: "European Development Fund" + }, + { + code: "EU-3", + name: "European Investment Bank" + }, + { + code: "EU-4", + name: "Humanitarian Aid Office of the European Commission" + }, + { + code: "FI-1", + name: "Finnish Government" + }, + { + code: "FI-2", + name: "FinnFund" + }, + { + code: "FI-3", + name: "Ministry of Foreign Affairs" + }, + { + code: "FI-4", + name: "FIDE" + }, + { + code: "FI-72", + name: "FinnVera" + }, + { + code: "FR-10", + name: "Ministry of Economy, Finance and Industry " + }, + { + code: "FR-17", + name: "Ministry of Education, Higher education and Research " + }, + { + code: "FR-3", + name: "French Development Agency" + }, + { + code: "FR-43", + name: "Coface" + }, + { + code: "FR-6", + name: "Ministry of Foreign Affairs" + }, + { + code: "GB-1", + name: "Department for International Development" + }, + { + code: "GB-2", + name: "CDC Capital Partners PLC" + }, + { + code: "GB-5", + name: "Export Credit Guarantee Department" + }, + { + code: "GR-1", + name: "Ministry of Foreign Affairs" + }, + { + code: "GR-2", + name: "Ministry of National Economy" + }, + { + code: "GR-20", + name: "Miscellaneous" + }, + { + code: "GR-3", + name: + "Ministry of the Interior, Public Administration and Decentralisation " + }, + { + code: "GR-4", + name: "Ministry of National Defence" + }, + { + code: "GR-5", + name: "Ministry of the Environment, Land Planning and Public Works " + }, + { + code: "GR-6", + name: "Ministry of National Education and Religions" + }, + { + code: "GR-7", + name: "Ministry of Agriculture" + }, + { + code: "GR-8", + name: "Ministry of Health - Welfare" + }, + { + code: "GR-9", + name: "Ministry of Merchant Marine" + }, + { + code: "IE-1", + name: "Department of Foreign Affairs" + }, + { + code: "IE-71", + name: "Department of Industry and Commerce" + }, + { + code: "IT-2", + name: "Agenzia Erogazioni Per l'Agricoltura" + }, + { + code: "IT-4", + name: "Direzione Generale per la Cooperazione allo Sviluppo" + }, + { + code: "IT-5", + name: "Not in CRS Directives" + }, + { + code: "IT-7", + name: "Central administration" + }, + { + code: "IT-74", + name: "Sezione Speciale per l'Assicurazione del Credito all'Esportazione" + }, + { + code: "IT-8", + name: "Local administration" + }, + { + code: "IT-9", + name: "Artigiancassa" + }, + { + code: "JP-1", + name: "Ministry of Agriculture, Forestry and Fisheries " + }, + { + code: "JP-10", + name: "Japan Overseas Development Co-operation" + }, + { + code: "JP-11", + name: "Japan Bank for International Co-operation" + }, + { + code: "JP-12", + name: "Other Ministries" + }, + { + code: "JP-13", + name: "Public Corporations" + }, + { + code: "JP-14", + name: "Prefectures" + }, + { + code: "JP-15", + name: "Ordinance-designed Cities" + }, + { + code: "JP-2", + name: "Ministry of Foreign Affairs" + }, + { + code: "JP-7", + name: "Overseas Fishery Co-operation Foundation" + }, + { + code: "JP-71", + name: "Nippon Export and Investment Insurance" + }, + { + code: "JP-8", + name: "Japanese International Co-operation Agency" + }, + { + code: "LU-1", + name: "Lux-Development" + }, + { + code: "LU-2", + name: "Ministry of Foreign Affairs" + }, + { + code: "LU-22", + name: "Ducroire Office" + }, + { + code: "NL-1", + name: "Ministry of Foreign Affairs (DGIS)" + }, + { + code: "NL-33", + name: "NCM Credit Management Worldwide" + }, + { + code: "NL-4", + name: + "Netherlands Gov. through Netherlands Investment Bank for Developing Countries" + }, + { + code: "NO-1", + name: "Norwegian Agency for Development Co-operation" + }, + { + code: "NO-4", + name: "Ministry of Foreign Affairs" + }, + { + code: "NO-7", + name: "Statens Nærings og Distriksutviklingsfond" + }, + { + code: "NO-71", + name: "Garantiinstituttet for Eksportkreditt" + }, + { + code: "NO-72", + name: "Eksport Finans" + }, + { + code: "NO-8", + name: "NORFUND" + }, + { + code: "NZ-1", + name: "Ministry of Foreign Affairs and Trade" + }, + { + code: "NZ-2", + name: "New Zealand International Aid and Development Agency" + }, + { + code: "PT-1", + name: "Portuguese Government" + }, + { + code: "PT-2", + name: "Institute for Portuguese Development Aid" + }, + { + code: "PT-3", + name: "Other" + }, + { + code: "PT-71", + name: "Conselho de garantias financeiras" + }, + { + code: "SE-2", + name: "Ministry of Foreign Affairs" + }, + { + code: "SE-6", + name: "Swedish International Development Authority" + }, + { + code: "SE-71", + name: "Swedish Export Credits Guarantee Board" + }, + { + code: "US-1", + name: "Agency for International Development" + }, + { + code: "US-10", + name: "Peace Corps" + }, + { + code: "US-11", + name: "State Department" + }, + { + code: "US-12", + name: "Trade and Development Agency" + }, + { + code: "US-13", + name: "African Development Foundation" + }, + { + code: "US-15", + name: "Centers for Disease Control and Prevention" + }, + { + code: "US-16", + name: "National Institutes of Health" + }, + { + code: "US-17", + name: "Department of Labor" + }, + { + code: "US-2", + name: "Department of Agriculture" + }, + { + code: "US-31", + name: "Export Import Bank" + }, + { + code: "US-5", + name: "Department of Transportation" + }, + { + code: "US-6", + name: "Department of Treasury" + }, + { + code: "US-7", + name: "Department of Defense" + }, + { + code: "US-8", + name: "Miscellaneous" + }, + { + code: "US-9", + name: "Department of Interior" + }, + { + code: "41101", + name: "Convention to Combat Desertification" + }, + { + code: "41102", + name: "Desert Locust Control Organisation for Eastern Africa" + }, + { + code: "41103", + name: "Economic Commission for Africa" + }, + { + code: "41104", + name: "Economic Commission for Latin America and the Caribbean" + }, + { + code: "41105", + name: "Economic and Social Commission for Western Asia" + }, + { + code: "41106", + name: "Economic and Social Commission for Asia and the Pacific" + }, + { + code: "41107", + name: + "International Atomic Energy Agency (Contributions to Technical Cooperation Fund Only)" + }, + { + code: "41108", + name: "International Fund for Agricultural Development" + }, + { + code: "41109", + name: + "International Research and Training Institute for the Advancement of Women" + }, + { + code: "41110", + name: "Joint United Nations Programme on HIV/AIDS" + }, + { + code: "41111", + name: "United Nations Capital Development Fund" + }, + { + code: "41112", + name: "United Nations Conference on Trade and Development" + }, + { + code: "41114", + name: "United Nations Development Programme" + }, + { + code: "41116", + name: "United Nations Environment Programme" + }, + { + code: "41118", + name: "United Nations Framework Convention on Climate Change" + }, + { + code: "41119", + name: "United Nations Population Fund" + }, + { + code: "41120", + name: "United Nations Human Settlement Programme" + }, + { + code: "41121", + name: + "United Nations Office of the United Nations High Commissioner for Refugees" + }, + { + code: "41122", + name: "United Nations Children's Fund" + }, + { + code: "41123", + name: "United Nations Industrial Development Organisation" + }, + { + code: "41124", + name: "United Nations Development Fund for Women" + }, + { + code: "41125", + name: "United Nations Institute for Training and Research" + }, + { + code: "41126", + name: "United Nations Mine Action Service" + }, + { + code: "41127", + name: "United Nations Office of Co-ordination of Humanitarian Affairs" + }, + { + code: "41128", + name: "United Nations Office on Drugs and Crime" + }, + { + code: "41129", + name: "United Nations Research Institute for Social Development" + }, + { + code: "41130", + name: + "United Nations Relief and Works Agency for Palestine Refugees in the Near East" + }, + { + code: "41131", + name: "United Nations System Staff College" + }, + { + code: "41132", + name: "United Nations System Standing Committee on Nutrition" + }, + { + code: "41133", + name: "United Nations Special Initiative on Africa" + }, + { + code: "41134", + name: "United Nations University (including Endowment Fund)" + }, + { + code: "41135", + name: "United Nations Volunteers" + }, + { + code: "41136", + name: "United Nations Voluntary Fund on Disability" + }, + { + code: "41137", + name: + "United Nations Voluntary Fund for Technical Co-operation in the Field of Human Rights" + }, + { + code: "41138", + name: "United Nations Voluntary Fund for Victims of Torture" + }, + { + code: "41140", + name: "World Food Programme" + }, + { + code: "41141", + name: + "United Nations Peacebuilding Fund (Window Two: Restricted Contributions Only)" + }, + { + code: "41142", + name: "United Nations Democracy Fund" + }, + { + code: "41143", + name: "World Health Organisation - core voluntary contributions account" + }, + { + code: "41301", + name: "Food and Agricultural Organisation" + }, + { + code: "41302", + name: "International Labour Organisation" + }, + { + code: "41303", + name: "International Telecommunications Union" + }, + { + code: "41304", + name: "United Nations Educational, Scientific and Cultural Organisation " + }, + { + code: "41305", + name: "United Nations" + }, + { + code: "41306", + name: "Universal Postal Union" + }, + { + code: "41307", + name: "World Health Organisation - assessed contributions" + }, + { + code: "41308", + name: "World Intellectual Property Organisation" + }, + { + code: "41309", + name: "World Meteorological Organisation" + }, + { + code: "41310", + name: + "United Nations Department of Peacekeeping Operations (excluding UNTSO, UNMOGIP, UNFICYP, UNDOF) " + }, + { + code: "41311", + name: + "United Nations Peacebuilding Fund (Window One: Flexible Contributions Only)" + }, + { + code: "41312", + name: "International Atomic Energy Agency - assessed contributions" + }, + { + code: "41313", + name: + "United Nations High Commissioner for Human Rights (extrabudgetary contributions only)" + }, + { + code: "41314", + name: + "United Nations Economic Commission for Europe (extrabudgetary contributions only)" + }, + { + code: "42001", + name: "European Commission - Development Share of Budget" + }, + { + code: "42003", + name: "European Commission - European Development Fund" + }, + { + code: "42004", + name: "European Investment Bank (interest subsidies only)" + }, + { + code: "42005", + name: + "Facility for Euro-Mediterranean Investment and Partnership Trust Fund" + }, + { + code: "42006", + name: "Global Energy Efficiency and Renewable Energy Fund" + }, + { + code: "43001", + name: + "International Monetary Fund - Poverty Reduction and Growth Facility Trust" + }, + { + code: "43002", + name: + "International Monetary Fund - Poverty Reduction and Growth Facility - Heavily Indebted Poor Countries Initiative Trust (includes HIPC, PRGF and PRGF-HIPC sub-accounts) " + }, + { + code: "43003", + name: + "International Monetary Fund - Subsidization of IMF Emergency Assistance for Natural Disasters" + }, + { + code: "44001", + name: "International Bank for Reconstruction and Development" + }, + { + code: "44002", + name: "International Development Association" + }, + { + code: "44003", + name: + "International Development Association - Heavily Indebted Poor Countries Debt Initiative Trust Fund" + }, + { + code: "44004", + name: "International Finance Corporation" + }, + { + code: "44005", + name: "Multilateral Investment Guarantee Agency" + }, + { + code: "44006", + name: "Advance Market Commitments" + }, + { + code: "44007", + name: + "International Development Association - Multilateral Debt Relief Initiative" + }, + { + code: "45001", + name: "World Trade Organisation - International Trade Centre" + }, + { + code: "45002", + name: "World Trade Organisation - Advisory Centre on WTO Law" + }, + { + code: "45003", + name: "World Trade Organisation - Doha Development Agenda Global Trust Fund" + }, + { + code: "46001", + name: "African Solidarity Fund" + }, + { + code: "46002", + name: "African Development Bank" + }, + { + code: "46003", + name: "African Development Fund" + }, + { + code: "46004", + name: "Asian Development Bank" + }, + { + code: "46005", + name: "Asian Development Fund" + }, + { + code: "46006", + name: "Black Sea Trade and Development Bank" + }, + { + code: "46007", + name: "Central American Bank for Economic Integration" + }, + { + code: "46008", + name: "Andean Development Corporation" + }, + { + code: "46009", + name: "Caribbean Development Bank" + }, + { + code: "46012", + name: + "Inter-American Development Bank, Inter-American Investment Corporation and Multilateral Investment Fund " + }, + { + code: "46013", + name: "Inter-American Development Fund for Special Operations" + }, + { + code: "47001", + name: "African Capacity Building Foundation" + }, + { + code: "47002", + name: "Asian Productivity Organisation" + }, + { + code: "47003", + name: "Association of South East Asian Nations: Economic Co-operation" + }, + { + code: "47004", + name: "ASEAN Cultural Fund" + }, + { + code: "47005", + name: "African Union (excluding peacekeeping facilities)" + }, + { + code: "47008", + name: "World Vegetable Centre" + }, + { + code: "47009", + name: "African and Malagasy Council for Higher Education" + }, + { + code: "47010", + name: "Commonwealth Agency for Public Administration and Management" + }, + { + code: "47011", + name: "Caribbean Community Secretariat" + }, + { + code: "47012", + name: "Caribbean Epidemiology Centre" + }, + { + code: "47013", + name: "Commonwealth Foundation" + }, + { + code: "47014", + name: "Commonwealth Fund for Technical Co-operation" + }, + { + code: "47015", + name: "Consultative Group on International Agricultural Research" + }, + { + code: "47016", + name: "Commonwealth Institute" + }, + { + code: "47017", + name: "International Centre for Tropical Agriculture" + }, + { + code: "47018", + name: "Centre for International Forestry Research" + }, + { + code: "47019", + name: "International Centre for Advanced Mediterranean Agronomic Studies" + }, + { + code: "47020", + name: "International Maize and Wheat Improvement Centre" + }, + { + code: "47021", + name: "International Potato Centre" + }, + { + code: "47022", + name: + "Convention on International Trade in Endangered Species of Wild Flora and Fauna" + }, + { + code: "47023", + name: "Commonwealth Legal Advisory Service" + }, + { + code: "47024", + name: "Commonwealth Media Development Fund" + }, + { + code: "47025", + name: "Commonwealth of Learning" + }, + { + code: "47026", + name: "Community of Portuguese Speaking Countries" + }, + { + code: "47027", + name: "Colombo Plan" + }, + { + code: "47028", + name: "Commonwealth Partnership for Technical Management" + }, + { + code: "47029", + name: "Sahel and West Africa Club" + }, + { + code: "47030", + name: "Commonwealth Scientific Council" + }, + { + code: "47031", + name: "Commonwealth Small States Office" + }, + { + code: "47032", + name: "Commonwealth Trade and Investment Access Facility" + }, + { + code: "47033", + name: "Commonwealth Youth Programme" + }, + { + code: "47034", + name: "Economic Community of West African States" + }, + { + code: "47035", + name: "Environmental Development Action in the Third World" + }, + { + code: "47036", + name: "European and Mediterranean Plant Protection Organisation" + }, + { + code: "47037", + name: "Eastern-Regional Organisation of Public Administration" + }, + { + code: "47038", + name: + "INTERPOL Fund for Aid and Technical Assistance to Developing Countries" + }, + { + code: "47040", + name: "Forum Fisheries Agency" + }, + { + code: "47041", + name: "Food and Fertilizer Technology Centre" + }, + { + code: "47042", + name: "Foundation for International Training" + }, + { + code: "47043", + name: "Global Crop Diversity Trust" + }, + { + code: "47044", + name: "Global Environment Facility" + }, + { + code: "47045", + name: "Global Fund to Fight AIDS, Tuberculosis and Malaria " + }, + { + code: "47046", + name: "International Organisation of the Francophonic" + }, + { + code: "47047", + name: "International African Institute" + }, + { + code: "47048", + name: "Inter-American Indian Institute" + }, + { + code: "47049", + name: + "International Bureau of Education - International Educational Reporting System (IERS)" + }, + { + code: "47050", + name: "International Cotton Advisory Committee" + }, + { + code: "47051", + name: "International Centre for Agricultural Research in Dry Areas" + }, + { + code: "47053", + name: "Centre for Health and Population Research" + }, + { + code: "47054", + name: "International Centre of Insect Physiology and Ecology" + }, + { + code: "47055", + name: + "International Centre for Development Oriented Research in Agriculture" + }, + { + code: "47056", + name: "World AgroForestry Centre" + }, + { + code: "47057", + name: "International Crop Research for Semi-Arid Tropics" + }, + { + code: "47058", + name: "International Institute for Democracy and Electoral Assistance" + }, + { + code: "47059", + name: "International Development Law Organisation" + }, + { + code: "47060", + name: "International Institute for Cotton" + }, + { + code: "47061", + name: "Inter-American Institute for Co-operation on Agriculture" + }, + { + code: "47062", + name: "International Institute of Tropical Agriculture" + }, + { + code: "47063", + name: "International Livestock Research Institute" + }, + { + code: "47064", + name: "International Network for Bamboo and Rattan" + }, + { + code: "47065", + name: "Intergovernmental Oceanographic Commission" + }, + { + code: "47066", + name: "International Organisation for Migration" + }, + { + code: "47067", + name: "Intergovernmental Panel on Climate Change" + }, + { + code: "47068", + name: "Asia-Pacific Fishery Commission" + }, + { + code: "47069", + name: "Biodiversity International" + }, + { + code: "47070", + name: "International Rice Research Institute" + }, + { + code: "47071", + name: "International Seed Testing Association" + }, + { + code: "47073", + name: "International Tropical Timber Organisation" + }, + { + code: "47074", + name: "International Vaccine Institute" + }, + { + code: "47075", + name: "International Water Management Institute" + }, + { + code: "47076", + name: "Justice Studies Centre of the Americas" + }, + { + code: "47077", + name: "Mekong River Commission" + }, + { + code: "47078", + name: "Multilateral Fund for the Implementation of the Montreal Protocol" + }, + { + code: "47079", + name: "Organisation of American States" + }, + { + code: "47080", + name: + "Organisation for Economic Co-operation and Development (Contributions to special funds for Technical Co-operation Activities Only)" + }, + { + code: "47081", + name: "OECD Development Centre" + }, + { + code: "47082", + name: "Organisation of Eastern Caribbean States" + }, + { + code: "47083", + name: "Pan-American Health Organisation" + }, + { + code: "47084", + name: "Pan-American Institute of Geography and History" + }, + { + code: "47085", + name: "Pan-American Railway Congress Association" + }, + { + code: "47086", + name: "Private Infrastructure Development Group" + }, + { + code: "47087", + name: "Pacific Islands Forum Secretariat" + }, + { + code: "47088", + name: "Relief Net" + }, + { + code: "47089", + name: "Southern African Development Community" + }, + { + code: "47090", + name: "Southern African Transport and Communications Commission" + }, + { + code: "47091", + name: "(Colombo Plan) Special Commonwealth African Assistance Programme" + }, + { + code: "47092", + name: "South East Asian Fisheries Development Centre" + }, + { + code: "47093", + name: "South East Asian Ministers of Education" + }, + { + code: "47094", + name: "South Pacific Applied Geoscience Commission" + }, + { + code: "47095", + name: "South Pacific Board for Educational Assessment" + }, + { + code: "47096", + name: "Secretariat of the Pacific Community" + }, + { + code: "47097", + name: "Pacific Regional Environment Programme" + }, + { + code: "47098", + name: "Unrepresented Nations and Peoples' Organisation" + }, + { + code: "47099", + name: "University of the South Pacific" + }, + { + code: "47100", + name: "West African Monetary Union" + }, + { + code: "47101", + name: "Africa Rice Centre" + }, + { + code: "47102", + name: "World Customs Organisation Fellowship Programme" + }, + { + code: "47103", + name: "World Maritime University" + }, + { + code: "47104", + name: "WorldFish Centre" + }, + { + code: "47105", + name: "Common Fund for Commodities" + }, + { + code: "47106", + name: "Geneva Centre for the Democratic Control of Armed Forces" + }, + { + code: "47107", + name: "International Finance Facility for Immunisation" + }, + { + code: "47108", + name: "Multi-Country Demobilisation and Reintegration Program" + }, + { + code: "47109", + name: + "Asia-Pacific Economic Cooperation Support Fund (except contributions tied to counter-terrorism activities)" + }, + { + code: "47110", + name: "Organisation of the Black Sea Economic Cooperation" + }, + { + code: "47111", + name: "Adaptation Fund" + }, + { + code: "47112", + name: + "Central European Initiative - Special Fund for Climate and Environmental Protection" + }, + { + code: "47113", + name: "Economic and Monetary Community of Central Africa" + }, + { + code: "47116", + name: + "Integrated Framework for Trade-Related Technical Assistance to Least Developed Countries" + }, + { + code: "47117", + name: "New Partnership for Africa's Development" + }, + { + code: "47118", + name: + "Regional Organisation for the Strengthening of Supreme Audit Institutions of Francophone Sub-Saharan Countries" + }, + { + code: "47119", + name: "Sahara and Sahel Observatory" + }, + { + code: "47120", + name: "South Asian Association for Regional Cooperation" + }, + { + code: "47121", + name: "United Cities and Local Governments of Africa" + }, + { + code: "47122", + name: "Global Alliance for Vaccines and Immunization" + }, + { + code: "47123", + name: "Geneva International Centre for Humanitarian Demining" + }, + { + code: "47125", + name: + "European Bank for Reconstruction and Development - Early Transition Countries Initiative" + }, + { + code: "47126", + name: + "European Bank for Reconstruction and Development - Western Balkans Trust Fund" + }, + { + code: "47127", + name: "Latin-American Energy Organisation" + }, + { + code: "21001", + name: "Association of Geoscientists for International Development" + }, + { + code: "21002", + name: "Agency for International Trade Information and Co-operation" + }, + { + code: "21003", + name: "Latin American Council for Social Sciences" + }, + { + code: "21004", + name: + "Council for the Development of Economic and Social Research in Africa" + }, + { + code: "21005", + name: "Consumer Unity and Trust Society International" + }, + { + code: "21006", + name: "Development Gateway Foundation" + }, + { + code: "21007", + name: "Environmental Liaison Centre International" + }, + { + code: "21008", + name: "Eurostep" + }, + { + code: "21009", + name: "Forum for Agricultural Research in Africa" + }, + { + code: "21010", + name: "Forum for African Women Educationalists" + }, + { + code: "21011", + name: "Global Campaign for Education" + }, + { + code: "21013", + name: "Health Action International" + }, + { + code: "21014", + name: "Human Rights Information and Documentation Systems" + }, + { + code: "21015", + name: "International Catholic Rural Association" + }, + { + code: "21016", + name: "International Committee of the Red Cross" + }, + { + code: "21017", + name: "International Centre for Trade and Sustainable Development" + }, + { + code: "21018", + name: "International Federation of Red Cross and Red Crescent Societies" + }, + { + code: "21019", + name: "International Federation of Settlements and Neighbourhood Centres" + }, + { + code: "21020", + name: "International HIV/AIDS Alliance" + }, + { + code: "21021", + name: "International Institute for Environment and Development" + }, + { + code: "21022", + name: "International Network for Alternative Financial Institutions" + }, + { + code: "21023", + name: "International Planned Parenthood Federation" + }, + { + code: "21024", + name: "Inter Press Service, International Association " + }, + { + code: "21025", + name: "International Seismological Centre" + }, + { + code: "21026", + name: "International Service for Human Rights" + }, + { + code: "21027", + name: "International Trust Fund for Demining and Mine Victims Assistance" + }, + { + code: "21028", + name: + "International University Exchange Fund - IUEF Stip. in Africa and Latin America" + }, + { + code: "21029", + name: "Doctors Without Borders" + }, + { + code: "21030", + name: "Pan African Institute for Development" + }, + { + code: "21031", + name: "PANOS Institute" + }, + { + code: "21032", + name: "Population Services International" + }, + { + code: "21033", + name: "Transparency International" + }, + { + code: "21034", + name: "International Union Against Tuberculosis and Lung Disease" + }, + { + code: "21035", + name: "World Organisation Against Torture" + }, + { + code: "21036", + name: "World University Service" + }, + { + code: "21037", + name: "Women's World Banking" + }, + { + code: "21038", + name: "International Alert" + }, + { + code: "21039", + name: "International Institute for Sustainable Development" + }, + { + code: "21040", + name: "International Women's Tribune Centre" + }, + { + code: "21041", + name: "Society for International Development" + }, + { + code: "21042", + name: "International Peacebuilding Alliance" + }, + { + code: "21043", + name: "European Parliamentarians for Africa" + }, + { + code: "21044", + name: "International Council for the Control of Iodine Deficiency Disorders" + }, + { + code: "21045", + name: "African Medical and Research Foundation" + }, + { + code: "21046", + name: "Agency for Cooperation and Research in Development" + }, + { + code: "21047", + name: "AgriCord" + }, + { + code: "21048", + name: "Association of African Universities" + }, + { + code: "21049", + name: "European Centre for Development Policy Management" + }, + { + code: "21050", + name: "Geneva Call" + }, + { + code: "21051", + name: "Institut Supérieur Panafricaine d'Economie Coopérative" + }, + { + code: "21053", + name: + "IPAS-Protecting Women's Health, Advancing Women's Reproductive Rights " + }, + { + code: "21054", + name: "Life and Peace Institute" + }, + { + code: "21055", + name: "Regional AIDS Training Network" + }, + { + code: "21056", + name: "Renewable Energy and Energy Efficiency Partnership" + }, + { + code: "21057", + name: "International Centre for Transitional Justice" + }, + { + code: "30001", + name: "Global Alliance for Improved Nutrition" + }, + { + code: "30003", + name: "Global e-Schools and Communities Initiative" + }, + { + code: "30004", + name: "Global Water Partnership" + }, + { + code: "30005", + name: "International AIDS Vaccine Initiative" + }, + { + code: "30006", + name: "International Partnership on Microbicides" + }, + { + code: "30007", + name: "Global Alliance for ICT and Development" + }, + { + code: "30008", + name: "Cities Alliance" + }, + { + code: "30009", + name: "Small Arms Survey" + }, + { + code: "30010", + name: "International drug purchase facility" + }, + { + code: "30011", + name: "International Union for the Conservation of Nature" + }, + { + code: "31001", + name: "Global Development Network" + }, + { + code: "31002", + name: "Global Knowledge Partnership" + } +]; + +export const humanitarianScopeVocabularyCodelist = [ + { + code: "1-2", + name: "Glide" + }, + { + code: "2-1", + name: "Humanitarian Plan" + }, + { + code: "99", + name: "Reporting Organisation" + } +]; + +export const versionCodelist = [ + { + code: "1.01", + name: "1.01" + }, + { + code: "1.02", + name: "1.02" + }, + { + code: "1.03", + name: "1.03" + }, + { + code: "1.04", + name: "1.04" + }, + { + code: "1.05", + name: "1.05" + }, + { + code: "2.01", + name: "2.01" + }, + { + code: "2.02", + name: "2.02" + }, + { + code: "2.03", + name: "2.03" + } +]; + +export const languageCodelist = [ + { + code: "aa", + name: "Afar" + }, + { + code: "ab", + name: "Abkhazian" + }, + { + code: "ae", + name: "Avestan" + }, + { + code: "af", + name: "Afrikaans" + }, + { + code: "ak", + name: "Akan" + }, + { + code: "am", + name: "Amharic" + }, + { + code: "an", + name: "Aragonese" + }, + { + code: "ar", + name: "Arabic" + }, + { + code: "as", + name: "Assamese" + }, + { + code: "av", + name: "Avaric" + }, + { + code: "ay", + name: "Aymara" + }, + { + code: "az", + name: "Azerbaijani" + }, + { + code: "ba", + name: "Bashkir" + }, + { + code: "be", + name: "Belarusian" + }, + { + code: "bg", + name: "Bulgarian" + }, + { + code: "bh", + name: "Bihari languages" + }, + { + code: "bi", + name: "Bislama" + }, + { + code: "bm", + name: "Bambara" + }, + { + code: "bn", + name: "Bengali" + }, + { + code: "bo", + name: "Tibetan" + }, + { + code: "br", + name: "Breton" + }, + { + code: "bs", + name: "Bosnian" + }, + { + code: "ca", + name: "Catalan; Valencian" + }, + { + code: "ce", + name: "Chechen" + }, + { + code: "ch", + name: "Chamorro" + }, + { + code: "co", + name: "Corsican" + }, + { + code: "cr", + name: "Cree" + }, + { + code: "cs", + name: "Czech" + }, + { + code: "cv", + name: "Chuvash" + }, + { + code: "cy", + name: "Welsh" + }, + { + code: "da", + name: "Danish" + }, + { + code: "de", + name: "German" + }, + { + code: "dv", + name: "Divehi; Dhivehi; Maldivian" + }, + { + code: "dz", + name: "Dzongkha" + }, + { + code: "ee", + name: "Ewe" + }, + { + code: "el", + name: "Greek" + }, + { + code: "en", + name: "English" + }, + { + code: "eo", + name: "Esperanto" + }, + { + code: "es", + name: "Spanish; Castilian" + }, + { + code: "et", + name: "Estonian" + }, + { + code: "eu", + name: "Basque" + }, + { + code: "fa", + name: "Persian" + }, + { + code: "ff", + name: "Fulah" + }, + { + code: "fi", + name: "Finnish" + }, + { + code: "fj", + name: "Fijian" + }, + { + code: "fo", + name: "Faroese" + }, + { + code: "fr", + name: "French" + }, + { + code: "fy", + name: "Western Frisian" + }, + { + code: "ga", + name: "Irish" + }, + { + code: "gd", + name: "Gaelic; Scottish Gaelic" + }, + { + code: "gl", + name: "Galician" + }, + { + code: "gn", + name: "Guarani" + }, + { + code: "gu", + name: "Gujarati" + }, + { + code: "gv", + name: "Manx" + }, + { + code: "ha", + name: "Hausa" + }, + { + code: "he", + name: "Hebrew" + }, + { + code: "hi", + name: "Hindi" + }, + { + code: "ho", + name: "Hiri Motu" + }, + { + code: "hr", + name: "Croatian" + }, + { + code: "ht", + name: "Haitian; Haitian Creole" + }, + { + code: "hu", + name: "Hungarian" + }, + { + code: "hy", + name: "Armenian" + }, + { + code: "hz", + name: "Herero" + }, + { + code: "id", + name: "Indonesian" + }, + { + code: "ig", + name: "Igbo" + }, + { + code: "ii", + name: "Sichuan Yi; Nuosu" + }, + { + code: "ik", + name: "Inupiaq" + }, + { + code: "io", + name: "Ido" + }, + { + code: "is", + name: "Icelandic" + }, + { + code: "it", + name: "Italian" + }, + { + code: "iu", + name: "Inuktitut" + }, + { + code: "ja", + name: "Japanese" + }, + { + code: "jv", + name: "Javanese" + }, + { + code: "ka", + name: "Georgian" + }, + { + code: "kg", + name: "Kongo" + }, + { + code: "ki", + name: "Kikuyu; Gikuyu" + }, + { + code: "kj", + name: "Kuanyama; Kwanyama" + }, + { + code: "kk", + name: "Kazakh" + }, + { + code: "kl", + name: "Kalaallisut; Greenlandic" + }, + { + code: "km", + name: "Central Khmer" + }, + { + code: "kn", + name: "Kannada" + }, + { + code: "ko", + name: "Korean" + }, + { + code: "kr", + name: "Kanuri" + }, + { + code: "ks", + name: "Kashmiri" + }, + { + code: "ku", + name: "Kurdish" + }, + { + code: "kv", + name: "Komi" + }, + { + code: "kw", + name: "Cornish" + }, + { + code: "ky", + name: "Kirghiz; Kyrgyz" + }, + { + code: "la", + name: "Latin" + }, + { + code: "lb", + name: "Luxembourgish; Letzeburgesch" + }, + { + code: "lg", + name: "Ganda" + }, + { + code: "li", + name: "Limburgan; Limburger; Limburgish" + }, + { + code: "ln", + name: "Lingala" + }, + { + code: "lo", + name: "Lao" + }, + { + code: "lt", + name: "Lithuanian" + }, + { + code: "lu", + name: "Luba-Katanga" + }, + { + code: "lv", + name: "Latvian" + }, + { + code: "mg", + name: "Malagasy" + }, + { + code: "mh", + name: "Marshallese" + }, + { + code: "mi", + name: "Maori" + }, + { + code: "mk", + name: "Macedonian" + }, + { + code: "ml", + name: "Malayalam" + }, + { + code: "mn", + name: "Mongolian" + }, + { + code: "mr", + name: "Marathi" + }, + { + code: "ms", + name: "Malay" + }, + { + code: "mt", + name: "Maltese" + }, + { + code: "my", + name: "Burmese" + }, + { + code: "na", + name: "Nauru" + }, + { + code: "nb", + name: "Bokmål, Norwegian; Norwegian Bokmål" + }, + { + code: "nd", + name: "Ndebele, North; North Ndebele" + }, + { + code: "ne", + name: "Nepali" + }, + { + code: "ng", + name: "Ndonga" + }, + { + code: "nl", + name: "Dutch; Flemish" + }, + { + code: "nn", + name: "Norwegian Nynorsk; Nynorsk, Norwegian" + }, + { + code: "no", + name: "Norwegian" + }, + { + code: "nr", + name: "Ndebele, South; South Ndebele" + }, + { + code: "nv", + name: "Navajo; Navaho" + }, + { + code: "ny", + name: "Chichewa; Chewa; Nyanja" + }, + { + code: "oc", + name: "Occitan (post 1500)" + }, + { + code: "oj", + name: "Ojibwa" + }, + { + code: "om", + name: "Oromo" + }, + { + code: "or", + name: "Oriya" + }, + { + code: "os", + name: "Ossetian; Ossetic" + }, + { + code: "pa", + name: "Panjabi; Punjabi" + }, + { + code: "pi", + name: "Pali" + }, + { + code: "pl", + name: "Polish" + }, + { + code: "ps", + name: "Pushto; Pashto" + }, + { + code: "pt", + name: "Portuguese" + }, + { + code: "qu", + name: "Quechua" + }, + { + code: "rm", + name: "Romansh" + }, + { + code: "rn", + name: "Rundi" + }, + { + code: "ro", + name: "Romanian; Moldavian; Moldovan" + }, + { + code: "ru", + name: "Russian" + }, + { + code: "rw", + name: "Kinyarwanda" + }, + { + code: "sa", + name: "Sanskrit" + }, + { + code: "sc", + name: "Sardinian" + }, + { + code: "sd", + name: "Sindhi" + }, + { + code: "se", + name: "Northern Sami" + }, + { + code: "sg", + name: "Sango" + }, + { + code: "si", + name: "Sinhala; Sinhalese" + }, + { + code: "sk", + name: "Slovak" + }, + { + code: "sl", + name: "Slovenian" + }, + { + code: "sm", + name: "Samoan" + }, + { + code: "sn", + name: "Shona" + }, + { + code: "so", + name: "Somali" + }, + { + code: "sq", + name: "Albanian" + }, + { + code: "sr", + name: "Serbian" + }, + { + code: "ss", + name: "Swati" + }, + { + code: "st", + name: "Sotho, Southern" + }, + { + code: "su", + name: "Sundanese" + }, + { + code: "sv", + name: "Swedish" + }, + { + code: "sw", + name: "Swahili" + }, + { + code: "ta", + name: "Tamil" + }, + { + code: "te", + name: "Telugu" + }, + { + code: "tg", + name: "Tajik" + }, + { + code: "th", + name: "Thai" + }, + { + code: "ti", + name: "Tigrinya" + }, + { + code: "tk", + name: "Turkmen" + }, + { + code: "tl", + name: "Tagalog" + }, + { + code: "tn", + name: "Tswana" + }, + { + code: "to", + name: "Tonga (Tonga Islands)" + }, + { + code: "tr", + name: "Turkish" + }, + { + code: "ts", + name: "Tsonga" + }, + { + code: "tt", + name: "Tatar" + }, + { + code: "tw", + name: "Twi" + }, + { + code: "ty", + name: "Tahitian" + }, + { + code: "ug", + name: "Uighur; Uyghur" + }, + { + code: "uk", + name: "Ukrainian" + }, + { + code: "ur", + name: "Urdu" + }, + { + code: "uz", + name: "Uzbek" + }, + { + code: "ve", + name: "Venda" + }, + { + code: "vi", + name: "Vietnamese" + }, + { + code: "vo", + name: "Volapük" + }, + { + code: "wa", + name: "Walloon" + }, + { + code: "wo", + name: "Wolof" + }, + { + code: "xh", + name: "Xhosa" + }, + { + code: "yi", + name: "Yiddish" + }, + { + code: "yo", + name: "Yoruba" + }, + { + code: "za", + name: "Zhuang; Chuang" + }, + { + code: "zh", + name: "Chinese" + }, + { + code: "zu", + name: "Zulu" + } +]; + +export const otherIdentifierCodelist = [ + { + code: "A1", + name: "Reporting Organisation's internal activity identifier" + }, + { + code: "A2", + name: "CRS Activity identifier" + }, + { + code: "A3", + name: "Previous Activity Identifier" + }, + { + code: "A9", + name: "Other Activity Identifier" + }, + { + code: "B1", + name: "Previous Reporting Organisation Identifier" + }, + { + code: "B9", + name: "Other Organisation Identifier" + } +]; + +export const policyMarkerCodelist = [ + { + code: "1", + name: "Gender Equality" + }, + { + code: "2", + name: "Aid to Environment" + }, + { + code: "3", + name: "Participatory Development/Good Governance" + }, + { + code: "4", + name: "Trade Development" + }, + { + code: "5", + name: + "Aid Targeting the Objectives of the Convention on Biological Diversity" + }, + { + code: "6", + name: + "Aid Targeting the Objectives of the Framework Convention on Climate Change - Mitigation" + }, + { + code: "7", + name: + "Aid Targeting the Objectives of the Framework Convention on Climate Change - Adaptation" + }, + { + code: "8", + name: + "Aid Targeting the Objectives of the Convention to Combat Desertification" + }, + { + code: "9", + name: "Reproductive, Maternal, Newborn and Child Health (RMNCH)" + }, + { + code: "10", + name: "Disaster Risk Reduction(DRR)" + }, + { + code: "11", + name: "Disability" + }, + { + code: "12", + name: "Nutrition" + }, + { + code: "development", + name: "Vocabulary 99 or 98" + }, + { + code: "vc", + name: "Vocabulary 99 or 98" + }, + { + code: "effective-gender-mainstreaming-egm", + name: "Vocabulary 99 or 98" + }, + { + code: "0", + name: "Vocabulary 99 or 98" + }, + { + code: "14", + name: "Vocabulary 99 or 98" + }, + { + code: "15", + name: "Vocabulary 99 or 98" + }, + { + code: "16", + name: "Vocabulary 99 or 98" + }, + { + code: "gender-and-equality", + name: "Vocabulary 99 or 98" + }, + { + code: "knowledge-solutions", + name: "Vocabulary 99 or 98" + }, + { + code: "gender-equity-gen", + name: "Vocabulary 99 or 98" + }, + { + code: "some-gender-elements-sge", + name: "Vocabulary 99 or 98" + }, + { + code: "neglected-tropical-diseases", + name: "Vocabulary 99 or 98" + }, + { + code: "e1", + name: "Vocabulary 99 or 98" + }, + { + code: "13", + name: "Vocabulary 99 or 98" + }, + { + code: "in", + name: "Vocabulary 99 or 98" + }, + { + code: "hc", + name: "Vocabulary 99 or 98" + }, + { + code: "104", + name: "Vocabulary 99 or 98" + }, + { + code: "101", + name: "Vocabulary 99 or 98" + }, + { + code: "102", + name: "Vocabulary 99 or 98" + }, + { + code: "103", + name: "Vocabulary 99 or 98" + }, + { + code: "2a", + name: "Vocabulary 99 or 98" + }, + { + code: "private-sector-development", + name: "Vocabulary 99 or 98" + }, + { + code: "e2", + name: "Vocabulary 99 or 98" + }, + { + code: "99", + name: "Vocabulary 99 or 98" + }, + { + code: "pepfar", + name: "Vocabulary 99 or 98" + }, + { + code: "e4", + name: "Vocabulary 99 or 98" + }, + { + code: "regional-integration", + name: "Vocabulary 99 or 98" + }, + { + code: "sdgs", + name: "Vocabulary 99 or 98" + }, + { + code: "environmentally-sustainable-growth", + name: "Vocabulary 99 or 98" + }, + { + code: "gender-equality", + name: "Vocabulary 99 or 98" + }, + { + code: "72040", + name: "Vocabulary 99 or 98" + }, + { + code: "72010", + name: "Vocabulary 99 or 98" + }, + { + code: "72050", + name: "Vocabulary 99 or 98" + }, + { + code: "governance-and-capacity-development", + name: "Vocabulary 99 or 98" + }, + { + code: "19", + name: "Vocabulary 99 or 98" + }, + { + code: "21", + name: "Vocabulary 99 or 98" + }, + { + code: "inclusive-economic-growth", + name: "Vocabulary 99 or 98" + }, + { + code: "partnerships", + name: "Vocabulary 99 or 98" + }, + { + code: "e3", + name: "Vocabulary 99 or 98" + }, + { + code: "20", + name: "Vocabulary 99 or 98" + }, + { + code: "22", + name: "Vocabulary 99 or 98" + }, + { + code: "18", + name: "Vocabulary 99 or 98" + }, + { + code: "un", + name: "Vocabulary 99 or 98" + }, + { + code: "b03", + name: "Vocabulary 99 or 98" + }, + { + code: "e5", + name: "Vocabulary 99 or 98" + }, + { + code: "ss", + name: "Vocabulary 99 or 98" + }, + { + code: "nt", + name: "Vocabulary 99 or 98" + }, + { + code: "2b", + name: "Vocabulary 99 or 98" + }, + { + code: "na", + name: "Vocabulary 99 or 98" + }, + { + code: "plannl-a", + name: "Vocabulary 99 or 98" + }, + { + code: "plannl-d", + name: "Vocabulary 99 or 98" + }, + { + code: "plannl-b", + name: "Vocabulary 99 or 98" + }, + { + code: "gender-equality-code", + name: "Vocabulary 99 or 98" + }, + { + code: "plannl-c", + name: "Vocabulary 99 or 98" + }, + { + code: "plan-aogd-3", + name: "Vocabulary 99 or 98" + }, + { + code: "plan-aogd-1", + name: "Vocabulary 99 or 98" + }, + { + code: "oa", + name: "Vocabulary 99 or 98" + }, + { + code: "plan-aogd-5", + name: "Vocabulary 99 or 98" + }, + { + code: "mofa-sl", + name: "Vocabulary 99 or 98" + }, + { + code: "c01", + name: "Vocabulary 99 or 98" + }, + { + code: "100", + name: "Vocabulary 99 or 98" + }, + { + code: "project-type-interventions", + name: "Vocabulary 99 or 98" + }, + { + code: "mofa-lop", + name: "Vocabulary 99 or 98" + }, + { + code: "26", + name: "Vocabulary 99 or 98" + }, + { + code: "23", + name: "Vocabulary 99 or 98" + }, + { + code: "24", + name: "Vocabulary 99 or 98" + }, + { + code: "25", + name: "Vocabulary 99 or 98" + }, + { + code: "dkt-rd-congo", + name: "Vocabulary 99 or 98" + }, + { + code: "mofa-bf", + name: "Vocabulary 99 or 98" + }, + { + code: "plan-aogd-2", + name: "Vocabulary 99 or 98" + }, + { + code: "plan-aogd-4", + name: "Vocabulary 99 or 98" + }, + { + code: "participatory-developmentgood-governance", + name: "Vocabulary 99 or 98" + }, + { + code: "plan-aogd-6", + name: "Vocabulary 99 or 98" + } +]; + +export const organisationTypeCodelist = [ + { + code: "10", + name: "Government" + }, + { + code: "11", + name: "Local Government" + }, + { + code: "15", + name: "Other Public Sector" + }, + { + code: "21", + name: "International NGO" + }, + { + code: "22", + name: "National NGO" + }, + { + code: "23", + name: "Regional NGO" + }, + { + code: "24", + name: "Partner Country based NGO" + }, + { + code: "30", + name: "Public Private Partnership" + }, + { + code: "40", + name: "Multilateral" + }, + { + code: "60", + name: "Foundation" + }, + { + code: "70", + name: "Private Sector" + }, + { + code: "71", + name: "Private Sector in Provider Country" + }, + { + code: "72", + name: "Private Sector in Aid Recipient Country" + }, + { + code: "73", + name: "Private Sector in Third Country" + }, + { + code: "80", + name: "Academic, Training and Research" + }, + { + code: "90", + name: "Other" + } +]; + +export const sectorVocabularyCodelist = [ + { + code: "1", + name: "OECD DAC CRS Purpose Codes (5 digit)" + }, + { + code: "2", + name: "OECD DAC CRS Purpose Codes (3 digit)" + }, + { + code: "3", + name: "Classification of the Functions of Government (UN)" + }, + { + code: "4", + name: + "Statistical classification of economic activities in the European Community" + }, + { + code: "5", + name: "National Taxonomy for Exempt Entities (USA)" + }, + { + code: "6", + name: "AidData" + }, + { + code: "7", + name: "SDG Goal" + }, + { + code: "8", + name: "SDG Target" + }, + { + code: "9", + name: "SDG Indicator" + }, + { + code: "10", + name: "Humanitarian Global Clusters (Inter-Agency Standing Committee)" + }, + { + code: "11", + name: "North American Industry Classification System (NAICS)" + }, + { + code: "12", + name: "UN System Function" + }, + { + code: "99", + name: "Reporting Organisation" + }, + { + code: "98", + name: "Reporting Organisation 2" + } +]; + +export const flowTypeCodelist = [ + { + code: "10", + name: "ODA" + }, + { + code: "20", + name: "OOF" + }, + { + code: "21", + name: "Non-export credit OOF" + }, + { + code: "22", + name: "Officially supported export credits" + }, + { + code: "30", + name: "Private Development Finance" + }, + { + code: "35", + name: "Private Market" + }, + { + code: "36", + name: "Private Foreign Direct Investment" + }, + { + code: "37", + name: "Other Private flows at market terms" + }, + { + code: "40", + name: "Non flow" + }, + { + code: "50", + name: "Other flows" + } +]; + +export const tiedStatusCodelist = [ + { + code: "3", + name: "Partially tied" + }, + { + code: "4", + name: "Tied" + }, + { + code: "5", + name: "Untied" + } +]; + +export const transactionTypeCodelist = [ + { + code: "1", + name: "Incoming Funds" + }, + { + code: "2", + name: "Outgoing Commitment" + }, + { + code: "3", + name: "Disbursement" + }, + { + code: "4", + name: "Expenditure" + }, + { + code: "5", + name: "Interest Payment" + }, + { + code: "6", + name: "Loan Repayment" + }, + { + code: "7", + name: "Reimbursement" + }, + { + code: "8", + name: "Purchase of Equity" + }, + { + code: "9", + name: "Sale of Equity" + }, + { + code: "10", + name: "Credit Guarantee" + }, + { + code: "11", + name: "Incoming Commitment" + }, + { + code: "12", + name: "Outgoing Pledge" + }, + { + code: "13", + name: "Incoming Pledge" + } +]; + +export const currencyCodelist = [ + { + code: "AED", + name: "UAE Dirham" + }, + { + code: "AFN", + name: "Afghani" + }, + { + code: "ALL", + name: "Lek" + }, + { + code: "AMD", + name: "Armenian Dram" + }, + { + code: "ANG", + name: "Netherlands Antillian Guilder" + }, + { + code: "AOA", + name: "Kwanza" + }, + { + code: "ARS", + name: "Argentine Peso" + }, + { + code: "AUD", + name: "Australian Dollar" + }, + { + code: "AWG", + name: "Aruban Guilder" + }, + { + code: "AZN", + name: "Azerbaijanian Manat" + }, + { + code: "BAM", + name: "Convertible Marks" + }, + { + code: "BBD", + name: "Barbados Dollar" + }, + { + code: "BDT", + name: "Taka" + }, + { + code: "BGN", + name: "Bulgarian Lev" + }, + { + code: "BHD", + name: "Bahraini Dinar" + }, + { + code: "BIF", + name: "Burundi Franc" + }, + { + code: "BMD", + name: "Bermudian Dollar" + }, + { + code: "BND", + name: "Brunei Dollar" + }, + { + code: "BOB", + name: "Boliviano" + }, + { + code: "BOV", + name: "Mvdol" + }, + { + code: "BRL", + name: "Brazilian Real" + }, + { + code: "BSD", + name: "Bahamian Dollar" + }, + { + code: "BTN", + name: "Ngultrum" + }, + { + code: "BWP", + name: "Pula" + }, + { + code: "BYR", + name: "Belarussian Ruble" + }, + { + code: "BYN", + name: "Belarussian Ruble" + }, + { + code: "BZD", + name: "Belize Dollar" + }, + { + code: "CAD", + name: "Canadian Dollar" + }, + { + code: "CDF", + name: "Congolese Franc" + }, + { + code: "CHF", + name: "Swiss Franc" + }, + { + code: "CLF", + name: "Unidades de fomento" + }, + { + code: "CLP", + name: "Chilean Peso" + }, + { + code: "CNY", + name: "Yuan Renminbi" + }, + { + code: "COP", + name: "Colombian Peso" + }, + { + code: "COU", + name: "Unidad de Valor Real" + }, + { + code: "CRC", + name: "Costa Rican Colon" + }, + { + code: "CUC", + name: "Peso Convertible" + }, + { + code: "CUP", + name: "Cuban Peso" + }, + { + code: "CVE", + name: "Cape Verde Escudo" + }, + { + code: "CZK", + name: "Czech Koruna" + }, + { + code: "DJF", + name: "Djibouti Franc" + }, + { + code: "DKK", + name: "Danish Krone" + }, + { + code: "DOP", + name: "Dominican Peso" + }, + { + code: "DZD", + name: "Algerian Dinar" + }, + { + code: "EEK", + name: "Kroon" + }, + { + code: "EGP", + name: "Egyptian Pound" + }, + { + code: "ERN", + name: "Nakfa" + }, + { + code: "ETB", + name: "Ethiopian Birr" + }, + { + code: "EUR", + name: "Euro" + }, + { + code: "FJD", + name: "Fiji Dollar" + }, + { + code: "FKP", + name: "Falkland Islands Pound" + }, + { + code: "GBP", + name: "Pound Sterling" + }, + { + code: "GEL", + name: "Lari" + }, + { + code: "GHS", + name: "Cedi" + }, + { + code: "GIP", + name: "Gibraltar Pound" + }, + { + code: "GMD", + name: "Dalasi" + }, + { + code: "GNF", + name: "Guinea Franc" + }, + { + code: "GTQ", + name: "Quetzal" + }, + { + code: "GYD", + name: "Guyana Dollar" + }, + { + code: "HKD", + name: "Hong Kong Dollar" + }, + { + code: "HNL", + name: "Lempira" + }, + { + code: "HRK", + name: "Kuna" + }, + { + code: "HTG", + name: "Gourde" + }, + { + code: "HUF", + name: "Forint" + }, + { + code: "IDR", + name: "Rupiah" + }, + { + code: "ILS", + name: "New Israeli Sheqel" + }, + { + code: "INR", + name: "Indian Rupee" + }, + { + code: "IQD", + name: "Iraqi Dinar" + }, + { + code: "IRR", + name: "Iranian Rial" + }, + { + code: "ISK", + name: "Iceland Krona" + }, + { + code: "JMD", + name: "Jamaican Dollar" + }, + { + code: "JOD", + name: "Jordanian Dinar" + }, + { + code: "JPY", + name: "Yen" + }, + { + code: "KES", + name: "Kenyan Shilling" + }, + { + code: "KGS", + name: "Som" + }, + { + code: "KHR", + name: "Riel" + }, + { + code: "KMF", + name: "Comoro Franc" + }, + { + code: "KPW", + name: "North Korean Won" + }, + { + code: "KRW", + name: "Won" + }, + { + code: "KWD", + name: "Kuwaiti Dinar" + }, + { + code: "KYD", + name: "Cayman Islands Dollar" + }, + { + code: "KZT", + name: "Tenge" + }, + { + code: "LAK", + name: "Kip" + }, + { + code: "LBP", + name: "Lebanese Pound" + }, + { + code: "LKR", + name: "Sri Lanka Rupee" + }, + { + code: "LRD", + name: "Liberian Dollar" + }, + { + code: "LSL", + name: "Loti" + }, + { + code: "LTL", + name: "Lithuanian Litas" + }, + { + code: "LVL", + name: "Latvian Lats" + }, + { + code: "LYD", + name: "Libyan Dinar" + }, + { + code: "MAD", + name: "Moroccan Dirham" + }, + { + code: "MDL", + name: "Moldovan Leu" + }, + { + code: "MGA", + name: "Malagasy Ariary" + }, + { + code: "MKD", + name: "Denar" + }, + { + code: "MMK", + name: "Kyat" + }, + { + code: "MNT", + name: "Tugrik" + }, + { + code: "MOP", + name: "Pataca" + }, + { + code: "MRO", + name: "Ouguiya" + }, + { + code: "MRU", + name: "Ouguiya" + }, + { + code: "MUR", + name: "Mauritius Rupee" + }, + { + code: "MVR", + name: "Rufiyaa" + }, + { + code: "MWK", + name: "Malawi Kwacha" + }, + { + code: "MXN", + name: "Mexican Peso" + }, + { + code: "MXV", + name: "Mexican Unidad de Inversion (UDI)" + }, + { + code: "MYR", + name: "Malaysian Ringgit" + }, + { + code: "MZN", + name: "Metical" + }, + { + code: "NAD", + name: "Namibia Dollar" + }, + { + code: "NGN", + name: "Naira" + }, + { + code: "NIO", + name: "Cordoba Oro" + }, + { + code: "NOK", + name: "Norwegian Krone" + }, + { + code: "NPR", + name: "Nepalese Rupee" + }, + { + code: "NZD", + name: "New Zealand Dollar" + }, + { + code: "OMR", + name: "Rial Omani" + }, + { + code: "PAB", + name: "Balboa" + }, + { + code: "PEN", + name: "Nuevo Sol" + }, + { + code: "PGK", + name: "Kina" + }, + { + code: "PHP", + name: "Philippine Peso" + }, + { + code: "PKR", + name: "Pakistan Rupee" + }, + { + code: "PLN", + name: "Zloty" + }, + { + code: "PYG", + name: "Guarani" + }, + { + code: "QAR", + name: "Qatari Rial" + }, + { + code: "RON", + name: "Romanian Leu" + }, + { + code: "RSD", + name: "Serbian Dinar" + }, + { + code: "RUB", + name: "Russian Ruble" + }, + { + code: "RWF", + name: "Rwanda Franc" + }, + { + code: "SAR", + name: "Saudi Riyal" + }, + { + code: "SBD", + name: "Solomon Islands Dollar" + }, + { + code: "SCR", + name: "Seychelles Rupee" + }, + { + code: "SDG", + name: "Sudanese Pound" + }, + { + code: "SEK", + name: "Swedish Krona" + }, + { + code: "SGD", + name: "Singapore Dollar" + }, + { + code: "SHP", + name: "Saint Helena Pound" + }, + { + code: "SLL", + name: "Leone" + }, + { + code: "SOS", + name: "Somali Shilling" + }, + { + code: "SSP", + name: "South Sudanese Pound" + }, + { + code: "SRD", + name: "Surinam Dollar" + }, + { + code: "STD", + name: "Dobra" + }, + { + code: "STN", + name: "Dobra" + }, + { + code: "SVC", + name: "El Salvador Colon" + }, + { + code: "SYP", + name: "Syrian Pound" + }, + { + code: "SZL", + name: "Lilangeni" + }, + { + code: "THB", + name: "Baht" + }, + { + code: "TJS", + name: "Somoni" + }, + { + code: "TMT", + name: "Manat" + }, + { + code: "TND", + name: "Tunisian Dinar" + }, + { + code: "TOP", + name: "Paanga" + }, + { + code: "TRY", + name: "Turkish Lira" + }, + { + code: "TTD", + name: "Trinidad and Tobago Dollar" + }, + { + code: "TWD", + name: "New Taiwan Dollar" + }, + { + code: "TZS", + name: "Tanzanian Shilling" + }, + { + code: "UAH", + name: "Hryvnia" + }, + { + code: "UGX", + name: "Uganda Shilling" + }, + { + code: "USD", + name: "US Dollar" + }, + { + code: "USN", + name: "US Dollar (Next day)" + }, + { + code: "USS", + name: "US Dollar (Same day)" + }, + { + code: "UYI", + name: "Uruguay Peso en Unidades Indexadas" + }, + { + code: "UYU", + name: "Peso Uruguayo" + }, + { + code: "UZS", + name: "Uzbekistan Sum" + }, + { + code: "VEF", + name: "Bolivar" + }, + { + code: "VES", + name: "Bolivar Soberano" + }, + { + code: "VND", + name: "Dong" + }, + { + code: "VUV", + name: "Vatu" + }, + { + code: "WST", + name: "Tala" + }, + { + code: "XAF", + name: "CFA Franc BEAC" + }, + { + code: "XBT", + name: "Bitcoin" + }, + { + code: "XCD", + name: "East Caribbean Dollar" + }, + { + code: "XDR", + name: "International Monetary Fund (IMF) Special Drawing Right (SDR)" + }, + { + code: "XOF", + name: "CFA Franc BCEAO" + }, + { + code: "XPF", + name: "CFP Franc" + }, + { + code: "YER", + name: "Yemeni Rial" + }, + { + code: "ZAR", + name: "Rand" + }, + { + code: "ZMK", + name: "Zambian Kwacha" + }, + { + code: "ZMW", + name: "Zambian Kwacha" + }, + { + code: "ZWL", + name: "Zimbabwe Dollar" + }, + { + code: "ATS", + name: "Austrian schilling" + }, + { + code: "DEM", + name: "Deutsche mark" + }, + { + code: "FIM", + name: "Finnish markka" + }, + { + code: "FRF", + name: "French franc" + }, + { + code: "GRD", + name: "Greek drachma" + }, + { + code: "ITL", + name: "Italian lira" + }, + { + code: "MTL", + name: "Maltese lira" + }, + { + code: "NLG", + name: "Netherlands guilder" + }, + { + code: "PTE", + name: "Portuguese escudo" + }, + { + code: "ESP", + name: "Spanish peseta" + }, + { + code: "VEB", + name: "Venezuelan bolivar" + }, + { + code: "IEP", + name: "Irish pound" + }, + { + code: "BEF", + name: "Belgian franc" + }, + { + code: "LUF", + name: "Luxembourg franc" + } +]; + +export const activityScopeCodelist = [ + { + code: "1", + name: "Global" + }, + { + code: "2", + name: "Regional" + }, + { + code: "3", + name: "Multi-national" + }, + { + code: "4", + name: "National" + }, + { + code: "5", + name: "Sub-national: Multi-first-level administrative areas" + }, + { + code: "6", + name: "Sub-national: Single first-level administrative area" + }, + { + code: "7", + name: "Sub-national: Single second-level administrative area" + }, + { + code: "8", + name: "Single location" + } +]; + +export const activityStatusCodelist = [ + { + code: "1", + name: "Pipeline/identification" + }, + { + code: "2", + name: "Implementation" + }, + { + code: "3", + name: "Finalisation" + }, + { + code: "4", + name: "Closed" + }, + { + code: "5", + name: "Cancelled" + }, + { + code: "6", + name: "Suspended" + } +]; + +export const collaborationTypeCodelist = [ + { + code: "1", + name: "Bilateral" + }, + { + code: "2", + name: "Multilateral (inflows)" + }, + { + code: "3", + name: + "Bilateral, core contributions to NGOs and other private bodies / PPPs" + }, + { + code: "4", + name: "Multilateral outflows" + }, + { + code: "6", + name: "Private Sector Outflows" + }, + { + code: "7", + name: + "Bilateral, ex-post reporting on NGOs’ activities funded through core contributions" + }, + { + code: "8", + name: "Bilateral, triangular co-operation." + } +]; + +export const defaultAidTypeCategoryCodelist = [ + { + code: "A", + name: "Budget support" + }, + { + code: "B", + name: "Core contributions and pooled programmes and funds" + }, + { + code: "C", + name: "Project-type interventions" + }, + { + code: "D", + name: "Experts and other technical assistance" + }, + { + code: "E", + name: "Scholarships and student costs in donor countries" + }, + { + code: "F", + name: "Debt relief" + }, + { + code: "G", + name: "Administrative costs not included elsewhere" + }, + { + code: "H", + name: "Other in-donor expenditures" + } +]; + +export const defaultAidTypyVocabularyCodelist = [ + { + code: "1", + name: "OECD DAC" + }, + { + code: "2", + name: "Earmarking Category" + }, + { + code: "3", + name: "Earmarking Modality" + }, + { + code: "4", + name: "Cash and Voucher Modalities" + } +]; + +export const defaultFinanceTypeCodelist = [ + { + code: "1", + name: "GNI: Gross National Income" + }, + { + code: "110", + name: "Standard grant" + }, + { + code: "1100", + name: "Guarantees/insurance" + }, + { + code: "111", + name: "Subsidies to national private investors" + }, + { + code: "2", + name: "ODA % GNI" + }, + { + code: "210", + name: "Interest subsidy" + }, + { + code: "211", + name: "Interest subsidy to national private exporters" + }, + { + code: "3", + name: "Total Flows % GNI" + }, + { + code: "310", + name: "Capital subscription on deposit basis" + }, + { + code: "311", + name: "Capital subscription on encashment basis" + }, + { + code: "4", + name: "Population" + }, + { + code: "410", + name: "Aid loan excluding debt reorganisation" + }, + { + code: "411", + name: "Investment-related loan to developing countries" + }, + { + code: "412", + name: "Loan in a joint venture with the recipient" + }, + { + code: "413", + name: "Loan to national private investor" + }, + { + code: "414", + name: "Loan to national private exporter" + }, + { + code: "421", + name: "Standard loan" + }, + { + code: "422", + name: "Reimbursable grant" + }, + { + code: "423", + name: "Bonds" + }, + { + code: "424", + name: "Asset-backed securities" + }, + { + code: "425", + name: "Other debt securities" + }, + { + code: "431", + name: "Subordinated loan" + }, + { + code: "432", + name: "Preferred equity" + }, + { + code: "433", + name: "Other hybrid instruments" + }, + { + code: "452", + name: "Non-banks non-guaranteed portions of guaranteed export credits" + }, + { + code: "453", + name: "Bank export credits" + }, + { + code: "510", + name: "Common equity" + }, + { + code: "511", + name: + "Acquisition of equity not part of joint venture in developing countries" + }, + { + code: "512", + name: "Other acquisition of equity" + }, + { + code: "520", + name: "Shares in collective investment vehicles" + }, + { + code: "530", + name: "Reinvested earnings" + }, + { + code: "610", + name: "Debt forgiveness: ODA claims (P)" + }, + { + code: "611", + name: "Debt forgiveness: ODA claims (I)" + }, + { + code: "612", + name: "Debt forgiveness: OOF claims (P)" + }, + { + code: "613", + name: "Debt forgiveness: OOF claims (I)" + }, + { + code: "614", + name: "Debt forgiveness: Private claims (P)" + }, + { + code: "615", + name: "Debt forgiveness: Private claims (I)" + }, + { + code: "616", + name: "Debt forgiveness: OOF claims (DSR)" + }, + { + code: "617", + name: "Debt forgiveness: Private claims (DSR)" + }, + { + code: "618", + name: "Debt forgiveness: Other" + }, + { + code: "620", + name: "Debt rescheduling: ODA claims (P)" + }, + { + code: "621", + name: "Debt rescheduling: ODA claims (I)" + }, + { + code: "622", + name: "Debt rescheduling: OOF claims (P)" + }, + { + code: "623", + name: "Debt rescheduling: OOF claims (I)" + }, + { + code: "624", + name: "Debt rescheduling: Private claims (P)" + }, + { + code: "625", + name: "Debt rescheduling: Private claims (I)" + }, + { + code: "626", + name: "Debt rescheduling: OOF claims (DSR)" + }, + { + code: "627", + name: "Debt rescheduling: Private claims (DSR)" + }, + { + code: "630", + name: "Debt rescheduling: OOF claim (DSR – original loan principal)" + }, + { + code: "631", + name: "Debt rescheduling: OOF claim (DSR – original loan interest)" + }, + { + code: "632", + name: "Debt rescheduling: Private claim (DSR – original loan principal)" + }, + { + code: "633", + name: "Debt forgiveness/conversion: export credit claims (P)" + }, + { + code: "634", + name: "Debt forgiveness/conversion: export credit claims (I)" + }, + { + code: "635", + name: "Debt forgiveness: export credit claims (DSR)" + }, + { + code: "636", + name: "Debt rescheduling: export credit claims (P)" + }, + { + code: "637", + name: "Debt rescheduling: export credit claims (I)" + }, + { + code: "638", + name: "Debt rescheduling: export credit claims (DSR)" + }, + { + code: "639", + name: + "Debt rescheduling: export credit claim (DSR – original loan principal)" + }, + { + code: "710", + name: + "Foreign direct investment, new capital outflow (includes reinvested earnings if separate identification not available)" + }, + { + code: "711", + name: "Other foreign direct investment, including reinvested earnings" + }, + { + code: "712", + name: "Foreign direct investment, reinvested earnings" + }, + { + code: "810", + name: "Bank bonds" + }, + { + code: "811", + name: "Non-bank bonds" + }, + { + code: "910", + name: "Other bank securities/claims" + }, + { + code: "911", + name: "Other non-bank securities/claims" + }, + { + code: "912", + name: "Purchase of securities from issuing agencies" + }, + { + code: "913", + name: + "Securities and other instruments originally issued by multilateral agencies" + } +]; + +export const defaultFlowTypeCodelist = [ + { + code: "10", + name: "ODA" + }, + { + code: "20", + name: "OOF" + }, + { + code: "21", + name: "Non-export credit OOF" + }, + { + code: "22", + name: "Officially supported export credits" + }, + { + code: "30", + name: "Private Development Finance" + }, + { + code: "35", + name: "Private Market" + }, + { + code: "36", + name: "Private Foreign Direct Investment" + }, + { + code: "37", + name: "Other Private flows at market terms" + }, + { + code: "40", + name: "Non flow" + }, + { + code: "50", + name: "Other flows" + } +]; + +export const documentLinkCategoryCodelist = [ + { + code: "A01", + name: "Pre- and post-project impact appraisal" + }, + { + code: "A02", + name: "Objectives / Purpose of activity" + }, + { + code: "A03", + name: "Intended ultimate beneficiaries" + }, + { + code: "A04", + name: "Conditions" + }, + { + code: "A05", + name: "Budget" + }, + { + code: "A06", + name: "Summary information about contract" + }, + { + code: "A07", + name: "Review of project performance and evaluation" + }, + { + code: "A08", + name: "Results, outcomes and outputs" + }, + { + code: "A09", + name: "Memorandum of understanding (If agreed by all parties)" + }, + { + code: "A10", + name: "Tender" + }, + { + code: "A11", + name: "Contract" + }, + { + code: "A12", + name: "Activity web page" + }, + { + code: "B01", + name: "Annual report" + }, + { + code: "B02", + name: "Institutional Strategy paper" + }, + { + code: "B03", + name: "Country strategy paper" + }, + { + code: "B04", + name: "Aid Allocation Policy" + }, + { + code: "B05", + name: "Procurement Policy and Procedure" + }, + { + code: "B06", + name: "Institutional Audit Report" + }, + { + code: "B07", + name: "Country Audit Report" + }, + { + code: "B08", + name: "Exclusions Policy" + }, + { + code: "B09", + name: "Institutional Evaluation Report" + }, + { + code: "B10", + name: "Country Evaluation Report" + }, + { + code: "B11", + name: "Sector strategy" + }, + { + code: "B12", + name: "Thematic strategy" + }, + { + code: "B13", + name: "Country-level Memorandum of Understanding" + }, + { + code: "B14", + name: "Evaluations policy" + }, + { + code: "B15", + name: "General Terms and Conditions" + }, + { + code: "B16", + name: "Organisation web page" + }, + { + code: "B17", + name: "Country/Region web page" + }, + { + code: "B18", + name: "Sector web page" + } +]; diff --git a/server/controllers/filter-api/utils/collaborationtype.ts b/server/controllers/filter-api/utils/collaborationtype.ts index 6bed0ca..f820a8c 100644 --- a/server/controllers/filter-api/utils/collaborationtype.ts +++ b/server/controllers/filter-api/utils/collaborationtype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_COLLABORATION_TYPE_CODE } from "../../../static/apiFilterFields"; +import { collaborationTypeCodelist } from "./codelists"; export function getCollaborationTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,36 +18,21 @@ export function getCollaborationTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = collaborationTypeCodelist; axios .get( - `${process.env.DS_REST_API}/codelists/CollaborationType/?format=json` + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` ) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/currency.ts b/server/controllers/filter-api/utils/currency.ts index 31a130c..f0144db 100644 --- a/server/controllers/filter-api/utils/currency.ts +++ b/server/controllers/filter-api/utils/currency.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_CURRENCY } from "../../../static/apiFilterFields"; +import { currencyCodelist } from "./codelists"; export function getCurrencyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getCurrencyOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = currencyCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/Currency/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/defaultaidtypecategory.ts b/server/controllers/filter-api/utils/defaultaidtypecategory.ts index 8ac6bf8..1a5665b 100644 --- a/server/controllers/filter-api/utils/defaultaidtypecategory.ts +++ b/server/controllers/filter-api/utils/defaultaidtypecategory.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_AID_TYPE_CATEGORY_CODE } from "../../../static/apiFilterFields"; +import { defaultAidTypeCategoryCodelist } from "./codelists"; export function getDefaultAidTypeCategoryOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getDefaultAidTypeCategoryOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = defaultAidTypeCategoryCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/AidType-category/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts b/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts index a4d0934..626c0b7 100644 --- a/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts +++ b/server/controllers/filter-api/utils/defaultaidtypevocabulary.ts @@ -3,7 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_AID_TYPE_VOCABULARY } from "../../../static/apiFilterFields"; - +import { defaultAidTypyVocabularyCodelist } from "./codelists"; export function getDefaultAidTypeVocabOptions(filterString = "*:*") { return new Promise((resolve, reject) => { const values = { @@ -17,36 +17,21 @@ export function getDefaultAidTypeVocabOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = defaultAidTypyVocabularyCodelist; axios .get( - `${process.env.DS_REST_API}/codelists/AidTypeVocabulary/?format=json` + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` ) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/defaultfinancetype.ts b/server/controllers/filter-api/utils/defaultfinancetype.ts index f347556..493b26a 100644 --- a/server/controllers/filter-api/utils/defaultfinancetype.ts +++ b/server/controllers/filter-api/utils/defaultfinancetype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_FINANCE_CODE } from "../../../static/apiFilterFields"; +import { defaultFinanceTypeCodelist } from "./codelists"; export function getDefaultFinanceTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getDefaultFinanceTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = defaultFinanceTypeCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/FinanceType/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/defaultflowtype.ts b/server/controllers/filter-api/utils/defaultflowtype.ts index 999d0b3..bae6884 100644 --- a/server/controllers/filter-api/utils/defaultflowtype.ts +++ b/server/controllers/filter-api/utils/defaultflowtype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_FLOW_TYPE_CODE } from "../../../static/apiFilterFields"; +import { defaultFlowTypeCodelist } from "./codelists"; export function getDefaultFlowTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getDefaultFlowTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = defaultFlowTypeCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/FlowType/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/defaulttiedstatus.ts b/server/controllers/filter-api/utils/defaulttiedstatus.ts index 967c231..4fb9b5c 100644 --- a/server/controllers/filter-api/utils/defaulttiedstatus.ts +++ b/server/controllers/filter-api/utils/defaulttiedstatus.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_TIED_STATUS_CODE } from "../../../static/apiFilterFields"; +import { tiedStatusCodelist } from "./codelists"; export function getDefaultTiedStatusOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getDefaultTiedStatusOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = tiedStatusCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/TiedStatus/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/documentlinkcategory.ts b/server/controllers/filter-api/utils/documentlinkcategory.ts index cc5d222..efa1c5d 100644 --- a/server/controllers/filter-api/utils/documentlinkcategory.ts +++ b/server/controllers/filter-api/utils/documentlinkcategory.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DOCUMENT_LINK_CATEGORY_CODE } from "../../../static/apiFilterFields"; +import { documentLinkCategoryCodelist } from "./codelists"; export function getDocumentLinkCategoryOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getDocumentLinkCategoryOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = documentLinkCategoryCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/DocumentCategory/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/donors.ts b/server/controllers/filter-api/utils/donors.ts index 83af78d..fa3aaa6 100644 --- a/server/controllers/filter-api/utils/donors.ts +++ b/server/controllers/filter-api/utils/donors.ts @@ -19,34 +19,18 @@ export function getDonorsOptions(filterString = "*:*") { }; axios .get( - `${process.env.DS_REST_API}/codelists/OrganisationIdentifier/?format=json` + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` ) - .then(codelistResponse => { - const orgsCodelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatOrganisationsOptions(actualData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatOrganisationsOptions(actualData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/hierarchy.ts b/server/controllers/filter-api/utils/hierarchy.ts index ef1c682..e154ac0 100644 --- a/server/controllers/filter-api/utils/hierarchy.ts +++ b/server/controllers/filter-api/utils/hierarchy.ts @@ -30,6 +30,7 @@ export function getHierarchyOptions(filterString = "*:*") { ) .then(callResponse => { const actualData = get(callResponse, "data.facets.items.buckets", []); + // TODO: This field does not have the name from the codelist, and therefore displays "1", "2" etc. resolve( orderBy( actualData.map((item: any) => ({ diff --git a/server/controllers/filter-api/utils/humscopevocab.ts b/server/controllers/filter-api/utils/humscopevocab.ts index 826acc6..7492df6 100644 --- a/server/controllers/filter-api/utils/humscopevocab.ts +++ b/server/controllers/filter-api/utils/humscopevocab.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_HUMANITARIAN_SCOPE_VOCABULARY } from "../../../static/apiFilterFields"; +import { humanitarianScopeVocabularyCodelist } from "./codelists"; export function getHumanitarianScopeVocabs(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,36 +18,21 @@ export function getHumanitarianScopeVocabs(filterString = "*:*") { }), rows: 0 }; + const codelistData = humanitarianScopeVocabularyCodelist; axios .get( - `${process.env.DS_REST_API}/codelists/HumanitarianScopeVocabulary/?format=json` + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` ) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/iativersion.ts b/server/controllers/filter-api/utils/iativersion.ts index 5c4615a..d44059f 100644 --- a/server/controllers/filter-api/utils/iativersion.ts +++ b/server/controllers/filter-api/utils/iativersion.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_IATI_VERSION } from "../../../static/apiFilterFields"; +import { versionCodelist } from "./codelists"; export function getIATIVersionOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getIATIVersionOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = versionCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/Version/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/language.ts b/server/controllers/filter-api/utils/language.ts index c357157..c1d8bd3 100644 --- a/server/controllers/filter-api/utils/language.ts +++ b/server/controllers/filter-api/utils/language.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_DEFAULT_LANG } from "../../../static/apiFilterFields"; +import { languageCodelist } from "./codelists"; export function getLanguageOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getLanguageOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = languageCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/Language/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/otheridentifiertype.ts b/server/controllers/filter-api/utils/otheridentifiertype.ts index 0f41102..84aec5c 100644 --- a/server/controllers/filter-api/utils/otheridentifiertype.ts +++ b/server/controllers/filter-api/utils/otheridentifiertype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_OTHER_IDENTIFIER_TYPE } from "../../../static/apiFilterFields"; +import { otherIdentifierCodelist } from "./codelists"; export function getOtherIdentifierTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,36 +18,21 @@ export function getOtherIdentifierTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = otherIdentifierCodelist; axios .get( - `${process.env.DS_REST_API}/codelists/OtherIdentifierType/?format=json` + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` ) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/policymarker.ts b/server/controllers/filter-api/utils/policymarker.ts index 8525174..552d5e8 100644 --- a/server/controllers/filter-api/utils/policymarker.ts +++ b/server/controllers/filter-api/utils/policymarker.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_POLICY_MARKER_CODE } from "../../../static/apiFilterFields"; +import { policyMarkerCodelist } from "./codelists"; export function getPolicyMarkerOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,41 +18,28 @@ export function getPolicyMarkerOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = policyMarkerCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/PolicyMarker/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve( + formatActivituStatusOptions(actualData, codelistData).map( + (item: any) => ({ + name: `${item.code} | ${item.name}`, + code: item.code + }) ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve( - formatActivituStatusOptions(actualData, codelistData).map( - (item: any) => ({ - name: `${item.code} | ${item.name}`, - code: item.code - }) - ) - ); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + ); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/reportingorgtype.ts b/server/controllers/filter-api/utils/reportingorgtype.ts index 6fe1edb..cf14cf5 100644 --- a/server/controllers/filter-api/utils/reportingorgtype.ts +++ b/server/controllers/filter-api/utils/reportingorgtype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import { formatOrgOptions } from "."; import querystring from "querystring"; import { AF_REPORTING_ORG_TYPE_CODE } from "../../../static/apiFilterFields"; +import { organisationTypeCodelist } from "./codelists"; export function getReportingOrgTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getReportingOrgTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = organisationTypeCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/OrganisationType/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatOrgOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatOrgOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/sectorvocab.ts b/server/controllers/filter-api/utils/sectorvocab.ts index 7f9cd34..cb86519 100644 --- a/server/controllers/filter-api/utils/sectorvocab.ts +++ b/server/controllers/filter-api/utils/sectorvocab.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_SECTOR_VOCABULARY } from "../../../static/apiFilterFields"; +import { sectorVocabularyCodelist } from "./codelists"; export function getSectorVocabularyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getSectorVocabularyOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = sectorVocabularyCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/SectorVocabulary/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/transactionflowtype.ts b/server/controllers/filter-api/utils/transactionflowtype.ts index 3acafe6..2b62efb 100644 --- a/server/controllers/filter-api/utils/transactionflowtype.ts +++ b/server/controllers/filter-api/utils/transactionflowtype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_TRANSACTION_FLOW_TYPE_CODE } from "../../../static/apiFilterFields"; +import { flowTypeCodelist } from "./codelists"; export function getTransactionFlowTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getTransactionFlowTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = flowTypeCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/FlowType/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/transactionreceiverorg.ts b/server/controllers/filter-api/utils/transactionreceiverorg.ts index d93cf47..af3886e 100644 --- a/server/controllers/filter-api/utils/transactionreceiverorg.ts +++ b/server/controllers/filter-api/utils/transactionreceiverorg.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import { formatOrgOptions } from "."; import querystring from "querystring"; import { AF_TRANSACTION_RECEIVER_ORG_REF } from "../../../static/apiFilterFields"; +import { organisationIdentifierCodelist } from "./codelists"; export function getTransactionReceiverOrgOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,36 +18,21 @@ export function getTransactionReceiverOrgOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = organisationIdentifierCodelist; axios .get( - `${process.env.DS_REST_API}/codelists/OrganisationIdentifier/?format=json` + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` ) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatOrgOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatOrgOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/transactiontiedstatus.ts b/server/controllers/filter-api/utils/transactiontiedstatus.ts index 0631650..60172e1 100644 --- a/server/controllers/filter-api/utils/transactiontiedstatus.ts +++ b/server/controllers/filter-api/utils/transactiontiedstatus.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_TRANSACTION_TIED_STATUS_CODE } from "../../../static/apiFilterFields"; +import { tiedStatusCodelist } from "./codelists"; export function getTransactionTiedStatusOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getTransactionTiedStatusOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = tiedStatusCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/TiedStatus/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/transactiontype.ts b/server/controllers/filter-api/utils/transactiontype.ts index 356a734..518ba51 100644 --- a/server/controllers/filter-api/utils/transactiontype.ts +++ b/server/controllers/filter-api/utils/transactiontype.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_TRANSACTION_TYPE_CODE } from "../../../static/apiFilterFields"; +import { transactionTypeCodelist } from "./codelists"; export function getTransactionTypeOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getTransactionTypeOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = transactionTypeCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/TransactionType/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; diff --git a/server/controllers/filter-api/utils/transactionvaluecurrency.ts b/server/controllers/filter-api/utils/transactionvaluecurrency.ts index 03ae99a..b206fcc 100644 --- a/server/controllers/filter-api/utils/transactionvaluecurrency.ts +++ b/server/controllers/filter-api/utils/transactionvaluecurrency.ts @@ -3,6 +3,7 @@ import get from "lodash/get"; import querystring from "querystring"; import { formatActivituStatusOptions } from "."; import { AF_TRANSACTION_VALUE_CURRENCY } from "../../../static/apiFilterFields"; +import { currencyCodelist } from "./codelists"; export function getTransactionValueCurrencyOptions(filterString = "*:*") { return new Promise((resolve, reject) => { @@ -17,34 +18,21 @@ export function getTransactionValueCurrencyOptions(filterString = "*:*") { }), rows: 0 }; + const codelistData = currencyCodelist; axios - .get(`${process.env.DS_REST_API}/codelists/Currency/?format=json`) - .then(codelistResponse => { - const codelistData = get(codelistResponse, "data", []); - axios - .get( - `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( - values, - "&", - "=", - { - encodeURIComponent: (str: string) => str - } - )}` - ) - .then(callResponse => { - const actualData = get( - callResponse, - "data.facets.items.buckets", - [] - ); - resolve(formatActivituStatusOptions(actualData, codelistData)); - }) - .catch(error => { - const _error = error.response ? error.response.data : error; - console.error(_error); - resolve([]); - }); + .get( + `${process.env.DS_SOLR_API}/activity/?${querystring.stringify( + values, + "&", + "=", + { + encodeURIComponent: (str: string) => str + } + )}` + ) + .then(callResponse => { + const actualData = get(callResponse, "data.facets.items.buckets", []); + resolve(formatActivituStatusOptions(actualData, codelistData)); }) .catch(error => { const _error = error.response ? error.response.data : error; From 628c9b25f7472eca87f50111f5aede5509be9ada Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Thu, 28 Jul 2022 15:19:32 +0200 Subject: [PATCH 5/7] fix: resolve missing dates --- .../controllers/detail-api/utils/activity.ts | 22 ++----------------- server/static/activityDetailConsts.ts | 4 ++++ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/server/controllers/detail-api/utils/activity.ts b/server/controllers/detail-api/utils/activity.ts index 25dbfd2..6a585ee 100644 --- a/server/controllers/detail-api/utils/activity.ts +++ b/server/controllers/detail-api/utils/activity.ts @@ -34,17 +34,7 @@ import { AF_BUDGET_TYPE_NAME, AF_BUDGET_VALUE, AF_BUDGET_VALUE_CURRENCY, - AF_CAPITAL_SPEND_PERCENTAGE, AF_COLLABORATION_TYPE_CODE, - AF_CONTACT_INFO_TYPE, - AF_CONTACT_INFO_TELEPHONE, - AF_CONTACT_INFO_EMAIL, - AF_CONTACT_INFO_WEBSITE, - AF_CONTACT_INFO_ORG_NARRATIVE, - AF_CONTACT_INFO_DEPARTMENT_NARRATIVE, - AF_CONTACT_INFO_PERSON_NAME_NARRATIVE, - AF_CONTACT_INFO_JOB_TITLE_NARRATIVE, - AF_CONTACT_INFO_MAILING_ADDRESS_NARRATIVE, AF_COUNTRY, AF_COUNTRY_NAME, AF_COUNTRY_PERCENTAGE, @@ -75,23 +65,15 @@ import { AF_SECTOR, AF_SECTOR_NAME, AF_SECTOR_PERCENTAGE, - AF_TAG_CODE, - AF_TAG_NARRATIVE, - AF_TAG_VOCABULARY, - AF_TAG_VOCABULARY_NAME, - AF_TRANSACTION_VALUE_CURRENCY, - AF_RELATED_ACTIVITY_REF, - AF_IATI_IDENTIFIER, AF_TRANSACTION_TYPE_CODE, AF_TRANSACTION_DATE_ISO_DATE, - AF_TRANSACTION_RECEIVER_ORG_NARRATIVE, - AF_TRANSACTION_PROVIDER_ORG_NARRATIVE, AF_TRANSACTION } from "../../../static/apiFilterFields"; function formatDate(dateStr: string): string { if (!dateStr) return dateStr; - return get(dateStr.split("T"), "[0]", dateStr); + let dateVal = get(dateStr.split("T"), "[0]", dateStr); + return new Date(dateVal).toLocaleDateString("en-GB"); } export function getDates(data: any) { diff --git a/server/static/activityDetailConsts.ts b/server/static/activityDetailConsts.ts index e70d4e1..b0a37b1 100644 --- a/server/static/activityDetailConsts.ts +++ b/server/static/activityDetailConsts.ts @@ -1,7 +1,9 @@ import { AF_ACTIVITY_DATE_END_ACTUAL, + AF_ACTIVITY_DATE_END_COMMON, AF_ACTIVITY_DATE_END_PLANNED, AF_ACTIVITY_DATE_START_ACTUAL, + AF_ACTIVITY_DATE_START_COMMON, AF_ACTIVITY_DATE_START_PLANNED, AF_ACTIVITY_SCOPE_CODE, AF_ACTIVITY_STATUS_CODE, @@ -127,8 +129,10 @@ ${AF_PARTICIPATING_ORG_REF_INDEX}, ${AF_PARTICIPATING_ORG_ROLE_INDEX}, ${AF_PARTICIPATING_ORG_TYPE_INDEX}, ${AF_ACTIVITY_DATE_START_PLANNED}, +${AF_ACTIVITY_DATE_END_COMMON}, ${AF_ACTIVITY_DATE_END_PLANNED}, ${AF_ACTIVITY_DATE_START_ACTUAL}, +${AF_ACTIVITY_DATE_START_COMMON}, ${AF_ACTIVITY_DATE_END_ACTUAL}, ${AF_CONTACT_INFO_TYPE}, ${AF_CONTACT_INFO_TELEPHONE}, From 3a2b954493ea83f628767cb4bda97f1437ee5023 Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Thu, 28 Jul 2022 16:08:52 +0200 Subject: [PATCH 6/7] fix: policy markers now correctly loading --- .../controllers/detail-api/utils/activity.ts | 48 ++++++++++++------- .../controllers/filter-api/utils/codelists.ts | 34 +++++++++++++ server/static/activityDetailConsts.ts | 2 + server/static/apiFilterFields.ts | 5 +- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/server/controllers/detail-api/utils/activity.ts b/server/controllers/detail-api/utils/activity.ts index 6a585ee..ab3efa3 100644 --- a/server/controllers/detail-api/utils/activity.ts +++ b/server/controllers/detail-api/utils/activity.ts @@ -16,6 +16,10 @@ import { defaultTiedStatusCodelist, tranlatedAidTypes } from "../../../static/codelists"; +import { + policyMarkerSignificanceCodelist, + policyMarkerVocabularyCodelist +} from "../../filter-api/utils/codelists"; import { orgTypesCodelist } from "../../../static/orgTypesCodelist"; import { sectorTranslations } from "../../../static/sectorTranslations"; import { orgMapping } from "../../../static/orgMapping"; @@ -55,7 +59,7 @@ import { AF_PARTICIPATING_ORG_ROLE_INDEX, AF_PARTICIPATING_ORG_TYPE_INDEX, AF_POLICY_MARKER_CODE, - AF_POLICY_MARKER_NAME, + AF_POLICY_MARKER_NARRATIVE, AF_POLICY_MARKER_SIGNIFICANCE, AF_POLICY_MARKER_VOCABULARY_NAME, AF_POLICY_MARKER_VOCABULARY_URI, @@ -529,7 +533,7 @@ export function getPolicyMarkers(data: any) { // data contains all the activity metadata. We need to extract the // expanded fields from it. const policy_marker_code = get(data, `["${AF_POLICY_MARKER_CODE}"]`, []); - const policy_marker_name = get(data, `["${AF_POLICY_MARKER_NAME}"]`, []); + const policy_marker_name = get(data, `["${AF_POLICY_MARKER_NARRATIVE}"]`, []); const policy_marker_significance = get( data, `["${AF_POLICY_MARKER_SIGNIFICANCE}"]`, @@ -547,15 +551,22 @@ export function getPolicyMarkers(data: any) { ); const result: any[] = []; policy_marker_code.forEach((code: any, index: number) => { - if ( - get(policy_marker_name, `[${index}]`, "").toLowerCase() !== "not targeted" - ) { + const name = get(policy_marker_name, `[${index}]`, ""); + const significance = + find(policyMarkerSignificanceCodelist, { + code: get(policy_marker_significance, `[${index}]`, "") + })?.name ?? "no data"; + const vocabulary = + find(policyMarkerVocabularyCodelist, { + code: get(policy_marker_vocabulary, `[${index}]`, "") + })?.name ?? "no data"; + if (significance.toLowerCase() !== "not targeted") { result.push({ - name: get(policy_marker_name, `[${index}]`, ""), + name, code, - significance: get(policy_marker_significance, `[${index}]`, ""), + significance, vocabulary_uri: get(policy_marker_vocabulary_uri, `[${index}]`, ""), - vocabulary: get(policy_marker_vocabulary, `[${index}]`, "") + vocabulary }); } }); @@ -767,16 +778,21 @@ export function getConditions(types: any, texts: any) { } export function getTransactions(data: any) { - const transactions = data.map((item: any) => ({ - date: item[AF_TRANSACTION_DATE_ISO_DATE].slice(0, 4), - type: item[AF_TRANSACTION_TYPE_CODE], - value: item[AF_TRANSACTION] - })); - + let transactions: any[] = []; + data.forEach((item: any) => { + const dates = item[AF_TRANSACTION_DATE_ISO_DATE]; + const types = item[AF_TRANSACTION_TYPE_CODE]; + const values = item[AF_TRANSACTION]; + values.forEach((value: number, index: number) => { + transactions.push({ + date: dates[index], + type: types[index], + value: value + }); + }); + }); const groupedYears = groupBy(transactions, "date"); - const result: any[] = []; - Object.keys(groupedYears).forEach((year: string) => { const disbursed = sumBy(filter(groupedYears[year], { type: "3" }), "value"); const commitment = sumBy( diff --git a/server/controllers/filter-api/utils/codelists.ts b/server/controllers/filter-api/utils/codelists.ts index 3b1e56e..e7b5569 100644 --- a/server/controllers/filter-api/utils/codelists.ts +++ b/server/controllers/filter-api/utils/codelists.ts @@ -3025,6 +3025,40 @@ export const policyMarkerCodelist = [ } ]; +export const policyMarkerVocabularyCodelist = [ + { + code: "1", + name: "OECD DAC CRS" + }, + { + code: "99", + name: "Reporting Organisation" + } +]; + +export const policyMarkerSignificanceCodelist = [ + { + code: "0", + name: "not targeted" + }, + { + code: "1", + name: "significant objective" + }, + { + code: "2", + name: "principal objective" + }, + { + code: "3", + name: "principal objective AND in support of an action programme" + }, + { + code: "4", + name: "Explicit primary objective" + } +]; + export const organisationTypeCodelist = [ { code: "10", diff --git a/server/static/activityDetailConsts.ts b/server/static/activityDetailConsts.ts index b0a37b1..df0b11a 100644 --- a/server/static/activityDetailConsts.ts +++ b/server/static/activityDetailConsts.ts @@ -50,6 +50,7 @@ import { AF_PARTICIPATING_ORG_TYPE_INDEX, AF_POLICY_MARKER_CODE, AF_POLICY_MARKER_NAME, + AF_POLICY_MARKER_NARRATIVE, AF_POLICY_MARKER_SIGNIFICANCE, AF_POLICY_MARKER_VOCABULARY_NAME, AF_POLICY_MARKER_VOCABULARY_URI, @@ -151,6 +152,7 @@ ${AF_SECTOR_NAME}, ${AF_SECTOR_PERCENTAGE}, ${AF_POLICY_MARKER_CODE}, ${AF_POLICY_MARKER_NAME}, +${AF_POLICY_MARKER_NARRATIVE}, ${AF_POLICY_MARKER_SIGNIFICANCE}, ${AF_POLICY_MARKER_VOCABULARY_NAME}, ${AF_POLICY_MARKER_VOCABULARY_URI}, diff --git a/server/static/apiFilterFields.ts b/server/static/apiFilterFields.ts index 29ec13b..327f2a4 100644 --- a/server/static/apiFilterFields.ts +++ b/server/static/apiFilterFields.ts @@ -140,8 +140,9 @@ export const AF_PARTICIPATING_ORG_TYPE_INDEX = "participating-org.type-index"; export const AF_POLICY_MARKER_CODE = "policy-marker.code"; export const AF_POLICY_MARKER_COMBINED = "policy-marker.combined"; export const AF_POLICY_MARKER_NAME = "policy-marker.name"; -export const AF_POLICY_MARKER_SIGNIFICANCE = "policy-marker.significance.name"; -export const AF_POLICY_MARKER_VOCABULARY_NAME = "policy-marker.vocabulary.name"; +export const AF_POLICY_MARKER_NARRATIVE = "policy-marker.narrative"; +export const AF_POLICY_MARKER_SIGNIFICANCE = "policy-marker.significance"; +export const AF_POLICY_MARKER_VOCABULARY_NAME = "policy-marker.vocabulary"; export const AF_POLICY_MARKER_VOCABULARY_URI = "policy-marker.vocabulary-uri"; export const AF_PLANNED_DISBURSEMENT_PERIOD_START_ISO_DATE = "planned-disbursement.period-start.iso-date"; From fc0e8f350037d3af7f6986900c6b71b5f0d24ce3 Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Fri, 29 Jul 2022 13:52:24 +0200 Subject: [PATCH 7/7] chore: fix org type name request on the detail pages --- server/controllers/detail-api/activity.ts | 11 ++++++++++- server/static/activityDetailConsts.ts | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/controllers/detail-api/activity.ts b/server/controllers/detail-api/activity.ts index 2caf963..d97ced7 100644 --- a/server/controllers/detail-api/activity.ts +++ b/server/controllers/detail-api/activity.ts @@ -1,5 +1,6 @@ import axios from "axios"; import get from "lodash/get"; +import find from "lodash/find"; import sumBy from "lodash/sumBy"; import querystring from "querystring"; import { genericError } from "../../utils/general"; @@ -25,6 +26,7 @@ import { AF_IATI_IDENTIFIER, AF_REPORTING_ORG_NARRATIVE, AF_REPORTING_ORG_REF, + AF_REPORTING_ORG_TYPE_CODE, AF_REPORTING_ORG_TYPE_NAME, AF_TITLE_NARRATIVE, AF_TITLE_NARRATIVE_LANG, @@ -34,6 +36,7 @@ import { AF_TRANSACTION_TYPE_CODE, AF_TRANSACTION_VALUE } from "../../static/apiFilterFields"; +import { organisationTypeCodelist } from "../filter-api/utils/codelists"; export function activityDetail(req: any, res: any) { const lang = req.body.lang || "en"; @@ -119,7 +122,13 @@ export function activityDetail(req: any, res: any) { reporting_org_type: get( activityMetaData, AF_REPORTING_ORG_TYPE_NAME, - "" + find(organisationTypeCodelist, { + code: get( + activityMetaData, + `["${AF_REPORTING_ORG_TYPE_CODE}"]`, + "" + ) + })?.name || "" ), title: getFieldValueLang( lang, diff --git a/server/static/activityDetailConsts.ts b/server/static/activityDetailConsts.ts index df0b11a..7d69471 100644 --- a/server/static/activityDetailConsts.ts +++ b/server/static/activityDetailConsts.ts @@ -60,6 +60,7 @@ import { AF_RELATED_ACTIVITY_REF, AF_RELATED_ACTIVITY_TYPE, AF_REPORTING_ORG_REF, + AF_REPORTING_ORG_TYPE_CODE, AF_REPORTING_ORG_TYPE_NAME, AF_SECTOR, AF_SECTOR_NAME, @@ -114,6 +115,7 @@ ${AF_IATI_IDENTIFIER}, ${AF_DEFAULT_FINANCE_CODE}, ${AF_DEFAULT_TIED_STATUS_CODE}, ${AF_DEFAULT_LANG}, +${AF_REPORTING_ORG_TYPE_CODE}, ${AF_REPORTING_ORG_TYPE_NAME}, ${AF_TITLE_NARRATIVE}, ${AF_TITLE_NARRATIVE_LANG},