Readjust scripts structure and add script to update RPOs.
This commit is contained in:
parent
9f5b087587
commit
d20f1611c5
|
@ -0,0 +1,5 @@
|
|||
load('library/initialize.js');
|
||||
|
||||
initializeRPOs(removeDuplicateIds(rpos, 'id'));
|
||||
initializeRFOs(removeDuplicateIds(rfos, 'funder_id'));
|
||||
initializeDatasources(removeDuplicateIds(datasources, 'openaire_id'));
|
|
@ -0,0 +1,37 @@
|
|||
load('library/initialize.js');
|
||||
|
||||
var aliasWithRole = ["met-eireann","mary-immaculate-college","technological-university-dublin","sport-ireland","dcu","irel","nda","ucd","rcsi","sfi","health-service-executive","hib","atu","ul","deptecc","tusla---child-and-family-agency","tcd","galway","maynooth","heanet","i-form-advanced-manufacturing-research-centre","rotunda-hospital","ucc","department-of-children-and-youth-affairs","dublin","marine-institute","seai","cit","setu","esri1","department-of-agriculture-food-and-the-marine","iph"];
|
||||
|
||||
function keepRPOsWithRole(aliasWithRole) {
|
||||
var stakeholders = db.stakeholder.find({ alias: { $in: aliasWithRole } });
|
||||
rpos = removeDuplicateIds(rpos, 'id');
|
||||
var canContinue = true;
|
||||
stakeholders.forEach(stakeholder => {
|
||||
if(rpos.find(rpo => !!rpo.id && rpo.id === stakeholder.index_id) == null) {
|
||||
print('Stakeholder with alias: ' + stakeholder.alias + ' has invalid id. Checking by name...');
|
||||
var newRPO = rpos.find(rpo => !!rpo.name && rpo.name === stakeholder.index_name);
|
||||
if(newRPO != null) {
|
||||
print('Name is found. Updating the id from: ' + stakeholder.index_id + ' to: ' + newRPO.id);
|
||||
stakeholder.index_id = newRPO.id;
|
||||
db.stakeholder.save(stakeholder);
|
||||
} else {
|
||||
newRPO = rpos.find(rpo => !!rpo.shortname && rpo.shortname === stakeholder.index_shortname);
|
||||
if (newRPO != null) {
|
||||
print('Shortname is found. Updating the id from: ' + stakeholder.index_id + ' to: ' + newRPO.id);
|
||||
stakeholder.index_id = newRPO.id;
|
||||
db.stakeholder.save(stakeholder);
|
||||
} else {
|
||||
print('Resolve stakeholder with alias: ' + stakeholder.alias + ' to continue.');
|
||||
canContinue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return canContinue;
|
||||
}
|
||||
|
||||
if(keepRPOsWithRole(aliasWithRole)) {
|
||||
print('Deleting old profiles');
|
||||
db.stakeholder.deleteMany({ alias: { $nin: aliasWithRole }, defaultId: { $ne: null } });
|
||||
initializeRPOs(rpos);
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
//load('organization.js')
|
||||
//load('funder.js')
|
||||
//load('datasource.js')
|
||||
|
||||
function initializeRPOs(rpos) {
|
||||
var defaultRPO = db.stakeholder.findOne({"alias": "default-rpo"});
|
||||
rpos.forEach(rpo => {
|
||||
let name = rpo.shortname != 'NULL'?rpo.shortname:rpo.name;
|
||||
let alias = name.toLowerCase().replace(/\s+/g, "-");
|
||||
i = 1;
|
||||
while(db.stakeholder.findOne({"alias": alias}) != null) {
|
||||
alias = alias + i.toString();
|
||||
i++;
|
||||
}
|
||||
var stakeholder = {
|
||||
"_class": "eu.dnetlib.uoamonitorservice.entities.Stakeholder",
|
||||
"type": "organization",
|
||||
"index_id": rpo.id,
|
||||
"index_name": rpo.name,
|
||||
"index_shortName": rpo.shortname,
|
||||
"statsProfile": "ie_monitor",
|
||||
"isUpload": false,
|
||||
"name": rpo.name,
|
||||
"alias": alias,
|
||||
"locale": "EN",
|
||||
"visibility": "PUBLIC",
|
||||
"topics": [],
|
||||
"defaultId": defaultRPO._id.valueOf()
|
||||
}
|
||||
db.stakeholder.save(stakeholder);
|
||||
});
|
||||
print(rpos.length + ' RPOs has been created');
|
||||
}
|
||||
|
||||
function initializeRFOs(rfos) {
|
||||
var defaultRFO = db.stakeholder.findOne({"alias": "default-rfo"});
|
||||
rfos.forEach(rfo => {
|
||||
let name = rfo.funder_shortname != ''?rfo.funder_shortname:rfo.funder_name;
|
||||
let alias = name.toLowerCase().replace(/\s+/g, "-");
|
||||
i = 1;
|
||||
while(db.stakeholder.findOne({"alias": alias}) != null) {
|
||||
alias = alias + i.toString();
|
||||
i++;
|
||||
}
|
||||
var stakeholder = {
|
||||
"_class": "eu.dnetlib.uoamonitorservice.entities.Stakeholder",
|
||||
"type": "funder",
|
||||
"index_id": rfo.funder_id,
|
||||
"index_name": rfo.funder_name,
|
||||
"index_shortName": rfo.funder_shortname,
|
||||
"statsProfile": "ie_monitor",
|
||||
"isUpload": false,
|
||||
"name": rfo.funder_name,
|
||||
"alias": alias,
|
||||
"locale": "EN",
|
||||
"visibility": "PUBLIC",
|
||||
"topics": [],
|
||||
"defaultId": defaultRFO._id.valueOf()
|
||||
}
|
||||
db.stakeholder.save(stakeholder);
|
||||
});
|
||||
print(rfos.length + ' RFOs has been created');
|
||||
}
|
||||
|
||||
function initializeDatasources(datasources) {
|
||||
var defaultRepo = db.stakeholder.findOne({"alias": "default-repo"});
|
||||
datasources.forEach(datasource => {
|
||||
let name = datasource.official_name;
|
||||
let alias = name.toLowerCase().replace(/\s+/g, "-");
|
||||
i = 1;
|
||||
while(db.stakeholder.findOne({"alias": alias}) != null) {
|
||||
alias = alias + i.toString();
|
||||
i++;
|
||||
}
|
||||
var stakeholder = {
|
||||
"_class": "eu.dnetlib.uoamonitorservice.entities.Stakeholder",
|
||||
"type": "datasource",
|
||||
"index_id": datasource.openaire_id,
|
||||
"index_name": datasource.official_name,
|
||||
"index_shortName": datasource.official_name,
|
||||
"statsProfile": "ie_monitor",
|
||||
"isUpload": false,
|
||||
"name": datasource.official_name,
|
||||
"alias": alias,
|
||||
"locale": "EN",
|
||||
"visibility": "PUBLIC",
|
||||
"topics": [],
|
||||
"defaultId": defaultRepo._id.valueOf()
|
||||
}
|
||||
db.stakeholder.save(stakeholder);
|
||||
});
|
||||
print(datasources.length + ' repositories has been created');
|
||||
}
|
||||
|
||||
use irishdb;
|
||||
|
||||
initializeRPOs(rpos);
|
||||
initializeRFOs(rfos);
|
||||
initializeDatasources(datasources);
|
|
@ -0,0 +1,122 @@
|
|||
load('library/organization.js')
|
||||
load('library/funder.js')
|
||||
load('library/datasource.js')
|
||||
|
||||
function generateAlias(name) {
|
||||
// Step 1: Convert to lower case
|
||||
let alias = name.toLowerCase();
|
||||
|
||||
// Step 2: Replace all invalid characters with a hyphen
|
||||
alias = alias.replace(/[^a-z0-9-]/g, '-');
|
||||
|
||||
// Step 3: Replace multiple consecutive hyphens with a single hyphen
|
||||
alias = alias.replace(/-+/g, '-');
|
||||
|
||||
// Step 4: Remove leading or trailing hyphens
|
||||
alias = alias.replace(/^-+|-+$/g, '');
|
||||
|
||||
/* Find duplicates */
|
||||
let duplicate = alias.toString();
|
||||
var i = 1;
|
||||
while(db.stakeholder.findOne({"alias": duplicate}) != null) {
|
||||
duplicate = alias + i.toString();
|
||||
i++;
|
||||
}
|
||||
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
function removeDuplicateIds(array, fieldId) {
|
||||
let seenIds = {}; // Object to store encountered ids
|
||||
let uniqueArray = [];
|
||||
|
||||
array.forEach(obj => {
|
||||
if (!seenIds[obj[fieldId]]) { // If id is not encountered yet
|
||||
seenIds[obj[fieldId]] = true; // Mark id as encountered
|
||||
uniqueArray.push(obj); // Add object to unique array
|
||||
}
|
||||
});
|
||||
|
||||
return uniqueArray;
|
||||
}
|
||||
|
||||
function initializeRPOs(rpos) {
|
||||
var defaultRPO = db.stakeholder.findOne({"alias": "default-rpo"});
|
||||
var count = 0;
|
||||
var found = 0;
|
||||
rpos.forEach(rpo => {
|
||||
if(db.stakeholder.findOne({"index_id": rpo.id}) == null) {
|
||||
let alias = generateAlias(!!rpo.shortname && rpo.shortname != 'NULL'?rpo.shortname:rpo.name);
|
||||
var stakeholder = {
|
||||
"_class": "eu.dnetlib.uoamonitorservice.entities.Stakeholder",
|
||||
"type": "organization",
|
||||
"index_id": rpo.id,
|
||||
"index_name": rpo.name,
|
||||
"index_shortName": rpo.shortname,
|
||||
"statsProfile": "ie_monitor",
|
||||
"isUpload": false,
|
||||
"name": rpo.name,
|
||||
"alias": alias,
|
||||
"locale": "EN",
|
||||
"visibility": "PUBLIC",
|
||||
"topics": [],
|
||||
"copy": false,
|
||||
"defaultId": defaultRPO._id.valueOf()
|
||||
}
|
||||
db.stakeholder.save(stakeholder);
|
||||
count++;
|
||||
} else {
|
||||
found++;
|
||||
}
|
||||
});
|
||||
print(count + ' RPOs has been created and ' + found + ' already exist');
|
||||
}
|
||||
|
||||
function initializeRFOs(rfos) {
|
||||
var defaultRFO = db.stakeholder.findOne({"alias": "default-rfo"});
|
||||
rfos.forEach(rfo => {
|
||||
let alias = generateAlias(rfo.funder_shortname != ''?rfo.funder_shortname:rfo.funder_name);
|
||||
var stakeholder = {
|
||||
"_class": "eu.dnetlib.uoamonitorservice.entities.Stakeholder",
|
||||
"type": "funder",
|
||||
"index_id": rfo.funder_id,
|
||||
"index_name": rfo.funder_name,
|
||||
"index_shortName": rfo.funder_shortname,
|
||||
"statsProfile": "ie_monitor",
|
||||
"isUpload": false,
|
||||
"name": rfo.funder_name,
|
||||
"alias": alias,
|
||||
"locale": "EN",
|
||||
"visibility": "PUBLIC",
|
||||
"topics": [],
|
||||
"copy": false,
|
||||
"defaultId": defaultRFO._id.valueOf()
|
||||
}
|
||||
db.stakeholder.save(stakeholder);
|
||||
});
|
||||
print(rfos.length + ' RFOs has been created');
|
||||
}
|
||||
|
||||
function initializeDatasources(datasources) {
|
||||
var defaultRepo = db.stakeholder.findOne({"alias": "default-repo"});
|
||||
datasources.forEach(datasource => {
|
||||
let alias = generateAlias(datasource.official_name);
|
||||
var stakeholder = {
|
||||
"_class": "eu.dnetlib.uoamonitorservice.entities.Stakeholder",
|
||||
"type": "datasource",
|
||||
"index_id": datasource.openaire_id,
|
||||
"index_name": datasource.official_name,
|
||||
"index_shortName": datasource.official_name,
|
||||
"statsProfile": "ie_monitor",
|
||||
"isUpload": false,
|
||||
"name": datasource.official_name,
|
||||
"alias": alias,
|
||||
"locale": "EN",
|
||||
"visibility": "PUBLIC",
|
||||
"topics": [],
|
||||
"defaultId": defaultRepo._id.valueOf()
|
||||
}
|
||||
db.stakeholder.save(stakeholder);
|
||||
});
|
||||
print(datasources.length + ' repositories has been created');
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue