506 lines
17 KiB
JavaScript
506 lines
17 KiB
JavaScript
//version compatibility: 1.0.0-SNAPSHOT
|
|
|
|
//use openaire_monitor;
|
|
|
|
function upperCaseEnumValues() {
|
|
stakeholders = db.stakeholder.find().map(function (stakeholders) {
|
|
return stakeholders;
|
|
});
|
|
for(var i=0; i<stakeholders.length; i++) {
|
|
stakeholder = stakeholders[i];
|
|
|
|
stakeholderType = stakeholder.type;
|
|
stakeholder.type = stakeholderType.toUpperCase();
|
|
db.stakeholder.save(stakeholder);
|
|
}
|
|
print("Uppercase enum values for Stakeholder types");
|
|
|
|
sections = db.section.find().map(function (sections) {
|
|
return sections;
|
|
});
|
|
for(var i=0; i<sections.length; i++) {
|
|
section = sections[i];
|
|
|
|
sectionType = section.type;
|
|
section.type = sectionType.toUpperCase();
|
|
db.section.save(section);
|
|
}
|
|
print("Uppercase enum values for Section types");
|
|
|
|
indicators = db.indicator.find().map(function (indicators) {
|
|
return indicators;
|
|
});
|
|
for(var i=0; i<indicators.length; i++) {
|
|
indicator = indicators[i];
|
|
|
|
indicatorType = indicator.type;
|
|
indicator.type = indicatorType.toUpperCase();
|
|
indicatorWidth = indicator.width;
|
|
indicator.width = indicatorWidth.toUpperCase();
|
|
|
|
indicatorPaths = indicator.indicatorPaths;
|
|
for(var j=0; j<indicatorPaths.lenght; j++) {
|
|
indicatorPath = indicatorPaths[j];
|
|
|
|
indicatorPathType = indicatorPath.type;
|
|
indicatorPath.type = indicatorPathType.toUpperCase();
|
|
indicatorPathSource = indicatorPath.source;
|
|
indicatorPath.source = indicatorPathSource.toUpperCase();
|
|
}
|
|
|
|
db.indicator.save(indicator);
|
|
}
|
|
print("Uppercase enum values for Indicator types and width");
|
|
print("Uppercase enum values for Indicator path types and source");
|
|
}
|
|
|
|
function addHeightInIndicators() {
|
|
indicators = db.indicator.find().map(function (indicators) {
|
|
return indicators;
|
|
});
|
|
for(var i=0; i<indicators.length; i++) {
|
|
indicator = indicators[i];
|
|
|
|
if(indicator.type == "chart" || indicator.type == "CHART") {
|
|
indicator['height'] = "MEDIUM";
|
|
} else {
|
|
indicator['height'] = "SMALL";
|
|
}
|
|
db.indicator.save(indicator);
|
|
}
|
|
print("Height field added in Indicators");
|
|
}
|
|
|
|
|
|
function addVisibility() {
|
|
stakeholders = db.stakeholder.find().map(function (stakeholders) {
|
|
return stakeholders;
|
|
});
|
|
for (var i = 0; i < stakeholders.length; i++) {
|
|
stakeholder = stakeholders[i];
|
|
|
|
if (stakeholder.isActive) {
|
|
if (stakeholder.isPublic) {
|
|
stakeholder['visibility'] = "PUBLIC";
|
|
} else {
|
|
stakeholder['visibility'] = "RESTRICTED";
|
|
}
|
|
} else {
|
|
stakeholder['visibility'] = "PRIVATE";
|
|
}
|
|
|
|
db.stakeholder.save(stakeholder);
|
|
}
|
|
print("Add visibility field for Stakeholders");
|
|
|
|
topics = db.topic.find().map(function (topics) {
|
|
return topics;
|
|
});
|
|
for (var i = 0; i < topics.length; i++) {
|
|
topic = topics[i];
|
|
|
|
topicVisibility = "PRIVATE";
|
|
if (topic.isActive) {
|
|
if (topic.isPublic) {
|
|
topicVisibility = "PUBLIC";
|
|
} else {
|
|
topicVisibility = "RESTRICTED";
|
|
}
|
|
}
|
|
|
|
topic['visibility'] = topicVisibility;
|
|
db.topic.save(topic);
|
|
}
|
|
print("Add visibility field for Topics");
|
|
|
|
categories = db.category.find().map(function (categories) {
|
|
return categories;
|
|
});
|
|
for (var i = 0; i < categories.length; i++) {
|
|
category = categories[i];
|
|
|
|
if (category.isActive) {
|
|
if (category.isPublic) {
|
|
category['visibility'] = "PUBLIC";
|
|
} else {
|
|
category['visibility'] = "RESTRICTED";
|
|
}
|
|
} else {
|
|
category['visibility'] = "PRIVATE";
|
|
}
|
|
|
|
db.category.save(category);
|
|
}
|
|
print("Add visibility field for Categories");
|
|
|
|
subCategories = db.subCategory.find().map(function (subCategories) {
|
|
return subCategories;
|
|
});
|
|
for (var i = 0; i < subCategories.length; i++) {
|
|
subCategory = subCategories[i];
|
|
|
|
if (subCategory.isActive) {
|
|
if (subCategory.isPublic) {
|
|
subCategory['visibility'] = "PUBLIC";
|
|
} else {
|
|
subCategory['visibility'] = "RESTRICTED";
|
|
}
|
|
} else {
|
|
subCategory['visibility'] = "PRIVATE";
|
|
}
|
|
|
|
db.subCategory.save(subCategory);
|
|
}
|
|
print("Add visibility field for SubCategories");
|
|
|
|
indicators = db.indicator.find().map(function (indicators) {
|
|
return indicators;
|
|
});
|
|
for (var i = 0; i < indicators.length; i++) {
|
|
indicator = indicators[i];
|
|
|
|
if (indicator.isActive) {
|
|
if (indicator.isPublic) {
|
|
indicator['visibility'] = "PUBLIC";
|
|
} else {
|
|
indicator['visibility'] = "RESTRICTED";
|
|
}
|
|
} else {
|
|
indicator['visibility'] = "PRIVATE";
|
|
}
|
|
|
|
db.indicator.save(indicator);
|
|
}
|
|
print("Add visibility field for Indicators");
|
|
}
|
|
|
|
function removeIsActiveAndIsPublic() {
|
|
stakeholders = db.stakeholder.find().map(function (stakeholders) {
|
|
return stakeholders;
|
|
});
|
|
for(var i=0; i<stakeholders.length; i++) {
|
|
stakeholder = stakeholders[i];
|
|
|
|
db.stakeholder.update({"_id": stakeholder._id}, {$unset: {isPublic: "", isActive: ""}});
|
|
}
|
|
|
|
topics = db.topic.find().map(function (topics) {
|
|
return topics;
|
|
});
|
|
for(var i=0; i<topics.length; i++) {
|
|
topic = topics[i];
|
|
|
|
db.topic.update({"_id": topic._id}, {$unset: {isPublic: "", isActive: ""}});
|
|
}
|
|
|
|
categories = db.category.find().map(function (categories) {
|
|
return categories;
|
|
});
|
|
for(var i=0; i<categories.length; i++) {
|
|
category = categories[i];
|
|
|
|
db.category.update({"_id": category._id}, {$unset: {isPublic: "", isActive: ""}});
|
|
}
|
|
|
|
subCategories = db.subCategory.find().map(function (subCategories) {
|
|
return subCategories;
|
|
});
|
|
for(var i=0; i<subCategories.length; i++) {
|
|
subCategory = subCategories[i];
|
|
|
|
db.subCategory.update({"_id": subCategory._id}, {$unset: {isPublic: "", isActive: ""}});
|
|
}
|
|
|
|
indicators = db.indicator.find().map(function (indicators) {
|
|
return indicators;
|
|
});
|
|
for(var i=0; i<indicators.length; i++) {
|
|
indicator = indicators[i];
|
|
|
|
db.indicator.update({"_id": indicator._id}, {$unset: {isPublic: "", isActive: ""}});
|
|
}
|
|
}
|
|
|
|
function addAdminToolsCollections () {
|
|
db.createCollection("portal");
|
|
db.createCollection("entity");
|
|
db.createCollection("page");
|
|
db.createCollection("pageHelpContent");
|
|
db.createCollection("divId");
|
|
db.createCollection("divHelpContent");
|
|
}
|
|
|
|
function addPortals() {
|
|
db.portal.save({"pid": "monitor", "name": "Monitor", "type": "monitor", "piwik": null, "pages": {}, "entities": {}});
|
|
}
|
|
|
|
function uniqueIndexes() {
|
|
db.portal.createIndex( { "pid": 1 }, { unique: true } );
|
|
db.stakeholder.createIndex( { "alias": 1 }, { unique: true } );
|
|
}
|
|
|
|
|
|
function addFooterDivIdForPortalType(portalType) {
|
|
homePageID = db.page.find({"portalType": portalType, "route": "/"}).map( function(portal) { return portal._id.str; } ).toString();
|
|
db.divId.save({ "name" : "footer", "pages" : [ homePageID ], "portalType" : portalType });
|
|
print("divId 'footer' added for "+portalType+" (home page id: "+homePageID + ")");
|
|
}
|
|
|
|
function addHomePageInPortalType(portalType) {
|
|
homePageID = db.page.insertOne({ "route" : "/", "name" : "Home", "type" : "other", "entities" : [ ], "portalType" : portalType, "top" : false, "bottom" : false, "left" : false, "right" : false }).insertedId.str;
|
|
print("Creating Home page with id " + homePageID);
|
|
portals = db.portal.find({"type": portalType}).map( function(portal) { return portal; } );
|
|
for (var i = 0; i < portals.length; i++) {
|
|
portal_pages = portals[i].pages;
|
|
|
|
portal_pages[homePageID] = true;
|
|
|
|
portal_pid = portals[i].pid;
|
|
db.portal.update({ "pid" : portal_pid },{$set: { "pages": portal_pages}});
|
|
print("Add home page with id " + homePageID + " on " + portalType + " " + portal_pid);
|
|
}
|
|
}
|
|
|
|
function addFooterHelpTextForPortalType(portalType) {
|
|
footerDivIdID = db.divId.find({"portalType": portalType, "name": "footer"}).map( function(divId) { return divId._id.str; } ).toString();
|
|
|
|
portals = db.portal.find({"type": portalType}).map( function(portal) { return portal; } );
|
|
for (var j = 0; j < portals.length; j++) {
|
|
portal = portals[j];
|
|
|
|
var content = "This OpenAIRE MONITOR dashboard is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541 and 101017452";
|
|
|
|
if(portal.pid == "egi") {
|
|
content = "This OpenAIRE MONITOR dashboard is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541 and 101017452";
|
|
|
|
} else if(portal.pid == "risis") {
|
|
|
|
content = "This OpenAIRE MONITOR dashboard is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541 and 101017452 and 824091";
|
|
|
|
} else if(portal.pid == "sobigdata") {
|
|
|
|
content = "This OpenAIRE MONITOR dashboard is part of a project that has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No. 777541 and 101017452 and 871042";
|
|
}
|
|
|
|
db.divHelpContent.save(
|
|
{ "divId" : footerDivIdID,
|
|
"portal" : portal._id.str,
|
|
"content" : "<p class=\"uk-margin-remove-bottom\"><span style=\"font-size:8pt\">"+content+"</span></p>",
|
|
"isActive" : true
|
|
}
|
|
);
|
|
|
|
print("div help text for divId 'footer' added for "+portalType +" (id: "+ portal._id + " - pid: " + portal.pid + " - footer divId id: "+footerDivIdID + ")");
|
|
}
|
|
}
|
|
|
|
function statsProfileOfIndicatorsAsVariable() {
|
|
print("statsProfileOfIndicatorsAsVariable");
|
|
|
|
numOfNumbers = 0;
|
|
numOfCharts = 0;
|
|
numOfNonMonitorProfiles = 0;
|
|
numOfMonitorProfiles = 0;
|
|
numOfNoProfiles = 0;
|
|
differentProfiles = new Set();
|
|
|
|
// indicators = db.indicator.find({"type": "chart"}).map(function (indicator) {
|
|
// indicators = db.indicator.find({"type": "number"}).map(function (indicator) {
|
|
indicators = db.indicator.find().map(function (indicator) {
|
|
return indicator;
|
|
});
|
|
|
|
print(indicators.length);
|
|
|
|
for (var i = 0; i < indicators.length; i++) {
|
|
indicator = indicators[i];
|
|
|
|
indicatorPaths = indicator.indicatorPaths;
|
|
if(indicatorPaths) {
|
|
for (var j = 0; j < indicatorPaths.length; j++) {
|
|
indicatorPath = indicatorPaths[j];
|
|
chartObjectStr = "";
|
|
// if(indicator.type == "chart") {
|
|
chartObjectStr = indicatorPath.chartObject;
|
|
// chartObject = JSON.parse(chartObjectStr);
|
|
if(indicator.type == "chart") {
|
|
numOfCharts++;
|
|
} else {
|
|
numOfNumbers++;
|
|
}
|
|
|
|
// if(i==0) {
|
|
// if(chartObject.chartDescription != null && chartObject.chartDescription.queries != null) {
|
|
// print(chartObject.chartDescription.queries.length);
|
|
// for(var z = 0; z < chartObject.chartDescription.queries.length; z++) {
|
|
// query = chartObject.chartDescription.queries[z].query;
|
|
// print(query.profile);
|
|
// query.profile = "((__statsProfile__))";
|
|
// }
|
|
// }
|
|
// indicatorPath.chartObject = JSON.stringify(chartObject);
|
|
|
|
if(chartObjectStr != null) {
|
|
var included = chartObjectStr.includes('"profile":"monitor"');
|
|
if (!included) {
|
|
numOfNonMonitorProfiles++;
|
|
print("Indicator with id: " + indicator._id + " has not monitor profile.");
|
|
} else {
|
|
numOfMonitorProfiles++;
|
|
}
|
|
|
|
splitted = chartObjectStr.split('"profile":"');
|
|
if (splitted.length == 1) {
|
|
numOfNoProfiles++;
|
|
}
|
|
for (var z = 1; z < splitted.length; z = z + 2) {
|
|
prof = splitted[z].split('"')[0];
|
|
differentProfiles.add(prof);
|
|
}
|
|
|
|
chartObjectStr = chartObjectStr.split('"profile":"monitor"').join('"profile":"((__profile__))"');
|
|
chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE All-inclusive"').join('"profile":"((__profile__))"');
|
|
chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE Monitor"').join('"profile":"((__profile__))"');
|
|
indicatorPath.chartObject = chartObjectStr;
|
|
} else {
|
|
print("Indicator with id: " + indicator._id + " has no chartObject");
|
|
}
|
|
}
|
|
}
|
|
|
|
// save indicator
|
|
db.indicator.save(indicator);
|
|
}
|
|
print("\n");
|
|
print("numOfNumbers: "+numOfNumbers);
|
|
print("numOfCharts: "+numOfCharts);
|
|
print("numOfMonitorProfiles: "+numOfMonitorProfiles);
|
|
print("numOfNonMonitorProfiles: "+numOfNonMonitorProfiles);
|
|
print("numOfNoProfiles: "+numOfNoProfiles);
|
|
print("Different profiles are: ");
|
|
for (var item of differentProfiles) {
|
|
print(item);
|
|
}
|
|
}
|
|
|
|
function addFundingLevelInFilters(filter) {
|
|
if(filter.groupFilters && filter.groupFilters.length > 0) {
|
|
var index = filter.groupFilters.findIndex(filter => filter.field.includes('project'));
|
|
if(index !== -1) {
|
|
print('before: ' + JSON.stringify(filter));
|
|
var prefix = filter.groupFilters[index].field.substring(0, filter.groupFilters[index].field.indexOf('project'));
|
|
if(!filter.groupFilters.find(filter => filter.field === prefix + "project.funding level 1")) {
|
|
filter.groupFilters.push({
|
|
"field": prefix + "project.funding level 1",
|
|
"type": "contains",
|
|
"values": [
|
|
'((__index_shortName__))'
|
|
]
|
|
});
|
|
print('after: ' + JSON.stringify(filter));
|
|
} else {
|
|
print('Already added');
|
|
}
|
|
}
|
|
return filter;
|
|
}
|
|
}
|
|
|
|
function addFundingStreamInDefaultMSCA() {
|
|
print("addFundingStreamInDefaultMSCA")
|
|
|
|
var stakeholder = db.stakeholder.findOne({"alias": "default-fl1"});
|
|
if(stakeholder) {
|
|
stakeholder.topics.forEach((topic) => {
|
|
var topicObj = db.topic.findOne({"_id": ObjectId(topic)});
|
|
topicObj.categories.forEach((category) => {
|
|
var categoryObj = db.category.findOne({"_id": ObjectId(category)});
|
|
categoryObj.subCategories.forEach((subCategory) => {
|
|
var subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)});
|
|
subCategoryObj.numbers.forEach((number) => {
|
|
var section = db.section.findOne({"_id": ObjectId(number)});
|
|
section.indicators.forEach((indicator) => {
|
|
var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)});
|
|
if(indicatorObject.indicatorPaths[0].parameters) {
|
|
indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase();
|
|
if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) {
|
|
var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject);
|
|
if(json.series && json.series.length > 0) {
|
|
json.series.forEach(query => {
|
|
if(query.query && query.query.filters && query.query.filters.length > 0) {
|
|
query.query.filters.forEach(filter => {
|
|
filter = addFundingLevelInFilters(filter);
|
|
});
|
|
}
|
|
});
|
|
indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json);
|
|
db.indicator.save(indicatorObject);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
subCategoryObj.charts.forEach((chart) => {
|
|
var section = db.section.findOne({"_id": ObjectId(chart)});
|
|
section.indicators.forEach((indicator) => {
|
|
var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)});
|
|
if(indicatorObject.indicatorPaths[0].parameters) {
|
|
indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase();
|
|
if (indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) {
|
|
var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject);
|
|
if (json.chartDescription && json.chartDescription.queries && json.chartDescription.queries.length > 0) {
|
|
json.chartDescription.queries.forEach(query => {
|
|
if (query.query && query.query.filters && query.query.filters.length > 0) {
|
|
query.query.filters.forEach(filter => {
|
|
filter = addFundingLevelInFilters(filter);
|
|
});
|
|
}
|
|
});
|
|
indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json);
|
|
db.indicator.save(indicatorObject);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
});
|
|
} else {
|
|
print("Profile doesn't exist")
|
|
}
|
|
|
|
}
|
|
|
|
|
|
use monitordb;
|
|
// use 1_openaire-mongodb-beta; // dev db
|
|
|
|
// 29-09-2020 - 22-10-2020
|
|
//upperCaseEnumValues();
|
|
// addHeightInIndicators();
|
|
// addVisibility();
|
|
// removeIsActiveAndIsPublic();
|
|
//
|
|
// addAdminToolsCollections();
|
|
// // addPortals();
|
|
//
|
|
// uniqueIndexes();
|
|
|
|
// 04-06-2021 - 24-06-2021
|
|
// addHomePageInPortalType("funder");
|
|
// addFooterDivIdForPortalType("funder");
|
|
// addFooterHelpTextForPortalType("funder");
|
|
// addHomePageInPortalType("ri");
|
|
// addFooterDivIdForPortalType("ri");
|
|
// addFooterHelpTextForPortalType("ri");
|
|
// addHomePageInPortalType("organization");
|
|
// addFooterDivIdForPortalType("organization");
|
|
// addFooterHelpTextForPortalType("organization");
|
|
|
|
// 11-04-2023
|
|
statsProfileOfIndicatorsAsVariable();
|
|
// 30-05-2023
|
|
addFundingStreamInDefaultMSCA();
|