Project

General

Profile

« Previous | Next » 

Revision 59815

[Trunk | Monitor Service]:
1. MonitorController.java: new class for admin tools functionalities (to be updated, when admin tools UI will be redesigned).
2. update_db.js: Update script added for mongo db updates.

View differences:

modules/uoa-monitor-service/trunk/update_db.js
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();
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
1
package eu.dnetlib.uoamonitorservice.controllers;
2

  
3
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
5
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
6
import org.apache.log4j.Logger;
7
import org.springframework.web.bind.annotation.*;
8
import org.springframework.beans.factory.annotation.Autowired;
9

  
10
import java.util.*;
11

  
12
@RestController
13
@RequestMapping(value={"/monitor", "/funder", "/project", "/ri"})
14
@CrossOrigin(origins = "*")
15
public class MonitorController {
16
    private final Logger log = Logger.getLogger(this.getClass());
17
//
18
//    @Autowired
19
//    private LayoutService layoutService;
20

  
21
    @Autowired
22
    private PortalService portalService;
23

  
24
    @RequestMapping(value = "/update", method = RequestMethod.POST)
25
    public PortalResponse updatePortal(@RequestBody Portal portal) {
26
        PortalResponse portalResponse = portalService.updatePortal(portal);
27

  
28
//        String old_pid = portalResponse.getPid();
29
//        String new_pid = portal.getPid();
30
//        if(!old_pid.equals(new_pid)) {
31
//            layoutService.updatePid(old_pid, new_pid);
32
//        }
33

  
34
        return portalResponse;
35
    }
36

  
37
    @RequestMapping(value = "/save", method = RequestMethod.POST)
38
    public PortalResponse insertPortal(@RequestBody Portal portal) {
39
        PortalResponse portalResponse = portalService.insertPortal(portal);
40
        return portalResponse;
41
    }
42

  
43
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
44
    public Boolean deletePortals(@RequestBody List<String> portals) {
45
        for (String id: portals) {
46
            String pid = portalService.deletePortal(id);
47
//            layoutService.deleteByPid(pid);
48
        }
49

  
50
        return true;
51
    }
52

  
53
//    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
54
//    public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
55
//        return layoutService.findByPid(pid);
56
//    }
57
//
58
//    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
59
//    public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
60
//        return layoutService.save(layout);
61
//    }
62

  
63
}
64

  

Also available in: Unified diff