[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.
This commit is contained in:
parent
1a784f29bd
commit
479e2c0aeb
|
@ -0,0 +1,64 @@
|
||||||
|
package eu.dnetlib.uoamonitorservice.controllers;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value={"/monitor", "/funder", "/project", "/ri"})
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class MonitorController {
|
||||||
|
private final Logger log = Logger.getLogger(this.getClass());
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private LayoutService layoutService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PortalService portalService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||||
|
public PortalResponse updatePortal(@RequestBody Portal portal) {
|
||||||
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
||||||
|
|
||||||
|
// String old_pid = portalResponse.getPid();
|
||||||
|
// String new_pid = portal.getPid();
|
||||||
|
// if(!old_pid.equals(new_pid)) {
|
||||||
|
// layoutService.updatePid(old_pid, new_pid);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return portalResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||||
|
public PortalResponse insertPortal(@RequestBody Portal portal) {
|
||||||
|
PortalResponse portalResponse = portalService.insertPortal(portal);
|
||||||
|
return portalResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
|
public Boolean deletePortals(@RequestBody List<String> portals) {
|
||||||
|
for (String id: portals) {
|
||||||
|
String pid = portalService.deletePortal(id);
|
||||||
|
// layoutService.deleteByPid(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
||||||
|
// public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
||||||
|
// return layoutService.findByPid(pid);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
||||||
|
// public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
||||||
|
// return layoutService.save(layout);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,253 @@
|
||||||
|
//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 } );
|
||||||
|
}
|
||||||
|
|
||||||
|
use monitordb;
|
||||||
|
|
||||||
|
// 29-09-2020 - 22-10-2020
|
||||||
|
//upperCaseEnumValues();
|
||||||
|
addHeightInIndicators();
|
||||||
|
addVisibility();
|
||||||
|
removeIsActiveAndIsPublic();
|
||||||
|
|
||||||
|
addAdminToolsCollections();
|
||||||
|
// addPortals();
|
||||||
|
|
||||||
|
uniqueIndexes();
|
Loading…
Reference in New Issue