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
use monitordb;
243

    
244
// 29-09-2020 - 22-10-2020
245
//upperCaseEnumValues();
246
addHeightInIndicators();
247
addVisibility();
248
removeIsActiveAndIsPublic();
249

    
250
addAdminToolsCollections();
251
// addPortals();
252

    
253
uniqueIndexes();
(2-2/2)