Project

General

Profile

1
//version compatibility: 1.0.0-SNAPSHOT
2

    
3
//use openaire_monitor;
4

    
5
function upperCaseEnumValues() {
6
  stakeholders = db.stakeholder.find().map(function (stakeholders) {
7
    return stakeholders;
8
  });
9
  for(var i=0; i<stakeholders.length; i++) {
10
    stakeholder = stakeholders[i];
11

    
12
    stakeholderType = stakeholder.type;
13
    stakeholder.type = stakeholderType.toUpperCase();
14
    db.stakeholder.save(stakeholder);
15
  }
16
  print("Uppercase enum values for Stakeholder types");
17

    
18
  sections = db.section.find().map(function (sections) {
19
    return sections;
20
  });
21
  for(var i=0; i<sections.length; i++) {
22
    section = sections[i];
23

    
24
    sectionType = section.type;
25
    section.type = sectionType.toUpperCase();
26
    db.section.save(section);
27
  }
28
  print("Uppercase enum values for Section types");
29

    
30
  indicators = db.indicator.find().map(function (indicators) {
31
    return indicators;
32
  });
33
  for(var i=0; i<indicators.length; i++) {
34
    indicator = indicators[i];
35

    
36
    indicatorType = indicator.type;
37
    indicator.type = indicatorType.toUpperCase();
38
    indicatorWidth = indicator.width;
39
    indicator.width = indicatorWidth.toUpperCase();
40

    
41
    indicatorPaths = indicator.indicatorPaths;
42
    for(var j=0; j<indicatorPaths.lenght; j++) {
43
      indicatorPath = indicatorPaths[j];
44

    
45
      indicatorPathType = indicatorPath.type;
46
      indicatorPath.type = indicatorPathType.toUpperCase();
47
      indicatorPathSource = indicatorPath.source;
48
      indicatorPath.source = indicatorPathSource.toUpperCase();
49
    }
50

    
51
    db.indicator.save(indicator);
52
  }
53
  print("Uppercase enum values for Indicator types and width");
54
  print("Uppercase enum values for Indicator path types and source");
55
}
56

    
57
function addHeightInIndicators() {
58
  indicators = db.indicator.find().map(function (indicators) {
59
    return indicators;
60
  });
61
  for(var i=0; i<indicators.length; i++) {
62
    indicator = indicators[i];
63

    
64
    if(indicator.type == "chart" || indicator.type == "CHART") {
65
      indicator['height'] = "MEDIUM";
66
    } else {
67
      indicator['height'] = "SMALL";
68
    }
69
    db.indicator.save(indicator);
70
  }
71
  print("Height field added in Indicators");
72
}
73

    
74

    
75
function addVisibility() {
76
  stakeholders = db.stakeholder.find().map(function (stakeholders) {
77
    return stakeholders;
78
  });
79
  for (var i = 0; i < stakeholders.length; i++) {
80
    stakeholder = stakeholders[i];
81

    
82
    if (stakeholder.isActive) {
83
      if (stakeholder.isPublic) {
84
        stakeholder['visibility'] = "PUBLIC";
85
      } else {
86
        stakeholder['visibility'] = "RESTRICTED";
87
      }
88
    } else {
89
      stakeholder['visibility'] = "PRIVATE";
90
    }
91

    
92
    db.stakeholder.save(stakeholder);
93
  }
94
  print("Add visibility field for Stakeholders");
95

    
96
  topics = db.topic.find().map(function (topics) {
97
    return topics;
98
  });
99
  for (var i = 0; i < topics.length; i++) {
100
    topic = topics[i];
101

    
102
    topicVisibility = "PRIVATE";
103
    if (topic.isActive) {
104
      if (topic.isPublic) {
105
        topicVisibility = "PUBLIC";
106
      } else {
107
        topicVisibility = "RESTRICTED";
108
      }
109
    }
110

    
111
    topic['visibility'] = topicVisibility;
112
    db.topic.save(topic);
113
  }
114
  print("Add visibility field for Topics");
115

    
116
  categories = db.category.find().map(function (categories) {
117
    return categories;
118
  });
119
  for (var i = 0; i < categories.length; i++) {
120
    category = categories[i];
121

    
122
    if (category.isActive) {
123
      if (category.isPublic) {
124
        category['visibility'] = "PUBLIC";
125
      } else {
126
        category['visibility'] = "RESTRICTED";
127
      }
128
    } else {
129
      category['visibility'] = "PRIVATE";
130
    }
131

    
132
    db.category.save(category);
133
  }
134
  print("Add visibility field for Categories");
135

    
136
  subCategories = db.subCategory.find().map(function (subCategories) {
137
    return subCategories;
138
  });
139
  for (var i = 0; i < subCategories.length; i++) {
140
    subCategory = subCategories[i];
141

    
142
    if (subCategory.isActive) {
143
      if (subCategory.isPublic) {
144
        subCategory['visibility'] = "PUBLIC";
145
      } else {
146
        subCategory['visibility'] = "RESTRICTED";
147
      }
148
    } else {
149
      subCategory['visibility'] = "PRIVATE";
150
    }
151

    
152
    db.subCategory.save(subCategory);
153
  }
154
  print("Add visibility field for SubCategories");
155

    
156
  indicators = db.indicator.find().map(function (indicators) {
157
    return indicators;
158
  });
159
  for (var i = 0; i < indicators.length; i++) {
160
    indicator = indicators[i];
161

    
162
    if (indicator.isActive) {
163
      if (indicator.isPublic) {
164
        indicator['visibility'] = "PUBLIC";
165
      } else {
166
        indicator['visibility'] = "RESTRICTED";
167
      }
168
    } else {
169
      indicator['visibility'] = "PRIVATE";
170
    }
171

    
172
    db.indicator.save(indicator);
173
  }
174
  print("Add visibility field for Indicators");
175
}
176

    
177
function removeIsActiveAndIsPublic() {
178
  stakeholders = db.stakeholder.find().map(function (stakeholders) {
179
    return stakeholders;
180
  });
181
  for(var i=0; i<stakeholders.length; i++) {
182
    stakeholder = stakeholders[i];
183

    
184
    db.stakeholder.update({"_id": stakeholder._id}, {$unset: {isPublic: "", isActive: ""}});
185
  }
186

    
187
  topics = db.topic.find().map(function (topics) {
188
    return topics;
189
  });
190
  for(var i=0; i<topics.length; i++) {
191
    topic = topics[i];
192

    
193
    db.topic.update({"_id": topic._id}, {$unset: {isPublic: "", isActive: ""}});
194
  }
195

    
196
  categories = db.category.find().map(function (categories) {
197
    return categories;
198
  });
199
  for(var i=0; i<categories.length; i++) {
200
    category = categories[i];
201

    
202
    db.category.update({"_id": category._id}, {$unset: {isPublic: "", isActive: ""}});
203
  }
204

    
205
  subCategories = db.subCategory.find().map(function (subCategories) {
206
    return subCategories;
207
  });
208
  for(var i=0; i<subCategories.length; i++) {
209
    subCategory = subCategories[i];
210

    
211
    db.subCategory.update({"_id": subCategory._id}, {$unset: {isPublic: "", isActive: ""}});
212
  }
213

    
214
  indicators = db.indicator.find().map(function (indicators) {
215
    return indicators;
216
  });
217
  for(var i=0; i<indicators.length; i++) {
218
    indicator = indicators[i];
219

    
220
    db.indicator.update({"_id": indicator._id}, {$unset: {isPublic: "", isActive: ""}});
221
  }
222
}
223

    
224
function addAdminToolsCollections () {
225
  db.createCollection("portal");
226
  db.createCollection("entity");
227
  db.createCollection("page");
228
  db.createCollection("pageHelpContent");
229
  db.createCollection("divId");
230
  db.createCollection("divHelpContent");
231
}
232

    
233
function addPortals() {
234
  db.portal.save({"pid": "monitor", "name": "Monitor", "type": "monitor", "piwik": null, "pages": {}, "entities": {}});
235
}
236

    
237
function uniqueIndexes() {
238
  db.portal.createIndex( { "pid": 1 }, { unique: true } );
239
  db.stakeholder.createIndex( { "alias": 1 }, { unique: true } );
240
}
241

    
242

    
243
function addFooterDivIdForPortalType(portalType) {
244
  homePageID = db.page.find({"portalType": portalType, "route": "/"}).map( function(portal) { return portal._id.str; } ).toString();
245
  db.divId.save({ "name" : "footer", "pages" : [ homePageID ], "portalType" : portalType });
246
  print("divId 'footer' added for "+portalType+" (home page id: "+homePageID + ")");
247
}
248

    
249
function addHomePageInPortalType(portalType) {
250
  homePageID = db.page.insertOne({ "route" : "/", "name" : "Home", "type" : "other", "entities" : [ ], "portalType" : portalType, "top" : false, "bottom" : false, "left" : false, "right" : false }).insertedId.str;
251
  print("Creating Home page with id " + homePageID);
252
  portals = db.portal.find({"type": portalType}).map( function(portal) { return portal; } );
253
  for (var i = 0; i < portals.length; i++) {
254
    portal_pages = portals[i].pages;
255

    
256
    portal_pages[homePageID] = true;
257

    
258
    portal_pid = portals[i].pid;
259
    db.portal.update({ "pid" : portal_pid },{$set: { "pages": portal_pages}});
260
    print("Add home page with id " + homePageID + " on " + portalType + " " + portal_pid);
261
  }
262
}
263

    
264
function addFooterHelpTextForPortalType(portalType) {
265
  footerDivIdID = db.divId.find({"portalType": portalType, "name": "footer"}).map( function(divId) { return divId._id.str; } ).toString();
266

    
267
  portals = db.portal.find({"type": portalType}).map( function(portal) { return portal; } );
268
  for (var j = 0; j < portals.length; j++) {
269
    portal = portals[j];
270

    
271
    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";
272

    
273
    if(portal.pid == "egi") {
274
      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";
275

    
276
    } else if(portal.pid == "risis") {
277

    
278
      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";
279

    
280
    } else if(portal.pid == "sobigdata") {
281

    
282
      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";
283
    }
284

    
285
    db.divHelpContent.save(
286
      { "divId" : footerDivIdID,
287
        "portal" : portal._id.str,
288
        "content" : "<p class=\"uk-margin-remove-bottom\"><span style=\"font-size:8pt\">"+content+"</span></p>",
289
        "isActive" : true
290
      }
291
    );
292

    
293
    print("div help text for divId 'footer' added for "+portalType +" (id: "+ portal._id + " - pid: " + portal.pid + " - footer divId id: "+footerDivIdID + ")");
294
  }
295
}
296

    
297

    
298
use monitordb;
299
// use 1_openaire-mongodb-beta; // dev db
300

    
301
// 29-09-2020 - 22-10-2020
302
//upperCaseEnumValues();
303
// addHeightInIndicators();
304
// addVisibility();
305
// removeIsActiveAndIsPublic();
306
//
307
// addAdminToolsCollections();
308
// // addPortals();
309
//
310
// uniqueIndexes();
311

    
312
// 04-06-2021
313
addHomePageInPortalType("funder");
314
addFooterDivIdForPortalType("funder");
315
addFooterHelpTextForPortalType("funder");
316
addHomePageInPortalType("ri");
317
addFooterDivIdForPortalType("ri");
318
addFooterHelpTextForPortalType("ri");
319
addHomePageInPortalType("organization");
320
addFooterDivIdForPortalType("organization");
321
addFooterHelpTextForPortalType("organization");
(2-2/2)