Revision 58394
Added by Konstantina Galouni almost 4 years ago
update_db.js | ||
---|---|---|
1429 | 1429 |
softwareId = db.entity.find( { pid: "software" }).map( function(entity) { return entity._id.str; } ).toString() |
1430 | 1430 |
orpId = db.entity.find( { pid: "orp" }).map( function(entity) { return entity._id.str; } ).toString(); |
1431 | 1431 |
|
1432 |
searchResearchOutcomesId = db.page.insertOne({"name" : "Search Research Outcomes", "route" : "/search/find/research-outcomes", "type" : "search", "connect":false,"openaire":true, "communities": true, "entities" : [publicationId, datasetId, softwareId, orpId]}).insertedId.str; |
|
1433 |
avancedSearchResearchOutcomesId = db.page.insertOne({"name" : "Advanced Search Research Outcomes", "route" : "/search/advanced/research-outcomes", "type" : "search", "connect":false,"openaire":true, "communities": true, "entities" : [publicationId, datasetId, softwareId, orpId]}).insertedId.str; |
|
1432 |
searchResearchOutcomesId = db.page.insertOne({"name" : "Search Research Outcomes", "route" : "/search/find/research-outcomes", "type" : "search", "connect":false,"openaire":true, "communities": true, "entities" : [publicationId, datasetId, softwareId, orpId], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str;
|
|
1433 |
avancedSearchResearchOutcomesId = db.page.insertOne({"name" : "Advanced Search Research Outcomes", "route" : "/search/advanced/research-outcomes", "type" : "search", "connect":false,"openaire":true, "communities": true, "entities" : [publicationId, datasetId, softwareId, orpId], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str;
|
|
1434 | 1434 |
|
1435 | 1435 |
print("Creating Search Research Outcomes page with id " + searchResearchOutcomesId); |
1436 | 1436 |
print("Creating Advanced Search Research Outcomes page with id " + avancedSearchResearchOutcomesId); |
1437 | 1437 |
|
1438 | 1438 |
communities = db.community.find().map( function(community) { return community; } ); |
1439 | 1439 |
for (var i = 0; i < communities.length; i++) { |
1440 |
community_pages = communities[i].pages;
|
|
1440 |
community_pages = communities[i].pages; |
|
1441 | 1441 |
|
1442 |
community_pages[searchResearchOutcomesId] = true;
|
|
1443 |
community_pages[avancedSearchResearchOutcomesId] = true;
|
|
1442 |
community_pages[searchResearchOutcomesId] = true; |
|
1443 |
community_pages[avancedSearchResearchOutcomesId] = true; |
|
1444 | 1444 |
|
1445 |
community_pid = communities[i].pid;
|
|
1446 |
db.community.update({ "pid" : community_pid },{$set: { "pages": community_pages}});
|
|
1447 |
print("Add Search Research Outcomes page with id " + searchResearchOutcomesId + " on community " + community_pid);
|
|
1448 |
print("Add Advanced Search Research Outcomes page with id " + avancedSearchResearchOutcomesId + " on community " + community_pid);
|
|
1445 |
community_pid = communities[i].pid; |
|
1446 |
db.community.update({ "pid" : community_pid },{$set: { "pages": community_pages}}); |
|
1447 |
print("Add Search Research Outcomes page with id " + searchResearchOutcomesId + " on community " + community_pid); |
|
1448 |
print("Add Advanced Search Research Outcomes page with id " + avancedSearchResearchOutcomesId + " on community " + community_pid); |
|
1449 | 1449 |
} |
1450 | 1450 |
} |
1451 | 1451 |
|
1452 |
use openaire_admin; |
|
1452 |
function addPortalType() { |
|
1453 |
communities = db.community.find().map( function(community) { return community; } ); |
|
1454 |
for (var i = 0; i < communities.length; i++) { |
|
1455 |
community = communities[i]; |
|
1456 |
if(community.pid == "openaire") { |
|
1457 |
community['type'] = "explore"; |
|
1458 |
} else if(community.pid == "connect") { |
|
1459 |
community['type'] = "connect"; |
|
1460 |
} else { |
|
1461 |
community['type'] = "community"; |
|
1462 |
} |
|
1463 |
db.community.save(community); |
|
1464 |
} |
|
1465 |
} |
|
1453 | 1466 |
|
1467 |
function createPagesForEachPortalType() { |
|
1468 |
pages = db.page.find().map( function(page) { return page; } ); |
|
1469 |
for (var i = 0; i < pages.length; i++) { |
|
1470 |
page = pages[i]; |
|
1471 |
|
|
1472 |
print("createPagesForEachPortalType: page["+i+"] = "+page.name + " ( "+page._id.str+" ) -> openaire: "+page.openaire+" - connect: "+page.connect + " - communities: "+page.communities); |
|
1473 |
|
|
1474 |
if(page.openaire == false) { // do not include this page in portal profile |
|
1475 |
communityOpenaire = db.community.findOne({pid: "openaire"}); |
|
1476 |
removePageFromPortal(communityOpenaire, page._id, communityOpenaire.pages); |
|
1477 |
} |
|
1478 |
if(page.connect == false) { // do not include this page in portal profile |
|
1479 |
communityConnect = db.community.findOne({pid: "connect"}); |
|
1480 |
removePageFromPortal(communityConnect, page._id, communityConnect.pages); |
|
1481 |
} |
|
1482 |
if(page.communities == false) { |
|
1483 |
communities = db.community.find({ "type" : "community" }).map( function(community) { return community; } ); |
|
1484 |
for (var j = 0; j < communities.length; j++) { |
|
1485 |
removePageFromPortal(communities[j], page._id, communities[j].pages); |
|
1486 |
} |
|
1487 |
} |
|
1488 |
|
|
1489 |
if(page.openaire == true && page.connect == true && page.communities == true) { |
|
1490 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "community", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1491 |
print("Keep for communities"); |
|
1492 |
|
|
1493 |
createAndUpdatePageAndContentsForPortal(page, "openaire", "explore"); |
|
1494 |
//print("Delete and create other for explore"); |
|
1495 |
|
|
1496 |
createAndUpdatePageAndContentsForPortal(page, "connect", "connect"); |
|
1497 |
//print("Delete and create other for connect"); |
|
1498 |
|
|
1499 |
} else if(page.openaire == true && page.connect == true) { |
|
1500 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "connect", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1501 |
print("Keep for connect"); |
|
1502 |
|
|
1503 |
createAndUpdatePageAndContentsForPortal(page, "openaire", "explore"); |
|
1504 |
//print("Delete and create other for explore"); |
|
1505 |
|
|
1506 |
} else if(page.openaire == true && page.communities == true) { |
|
1507 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "community", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1508 |
print("Keep for community"); |
|
1509 |
|
|
1510 |
createAndUpdatePageAndContentsForPortal(page, "openaire", "explore"); |
|
1511 |
//print("Delete and create other for explore"); |
|
1512 |
|
|
1513 |
} else if(page.connect == true && page.communities == true) { |
|
1514 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "community", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1515 |
print("Keep for community"); |
|
1516 |
|
|
1517 |
createAndUpdatePageAndContentsForPortal(page, "connect", "connect"); |
|
1518 |
//print("Delete and create other for connect"); |
|
1519 |
|
|
1520 |
} else if(page.openaire == true) { |
|
1521 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "explore", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1522 |
print("Keep for explore"); |
|
1523 |
|
|
1524 |
} else if(page.connect == true) { |
|
1525 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "connect", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1526 |
print("Keep for connect"); |
|
1527 |
|
|
1528 |
} else if(page.communities == true) { |
|
1529 |
db.page.save({"_id": page._id, "name" : page.name, "route" : page.route, "type" : page.type, "portalType": "community", "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1530 |
print("Keep for community"); |
|
1531 |
|
|
1532 |
} |
|
1533 |
} |
|
1534 |
} |
|
1535 |
|
|
1536 |
function createAndUpdatePageAndContentsForPortal(page, pid, portalType) { |
|
1537 |
db.page.save({"name" : page.name, "route" : page.route, "type" : page.type, "portalType": portalType, "entities" : page.entities, "top":page.top, "bottom":page.bottom, "right":page.right,"left":page.left}); |
|
1538 |
pageIdForPortalType = db.page.find({portalType: portalType, "route" : page.route}).map(function (page) { return page._id.str; }).toString(); |
|
1539 |
print("portalType: "+ portalType + " --> new page id: "+ pageIdForPortalType); |
|
1540 |
|
|
1541 |
community = db.community.findOne({pid: pid}); |
|
1542 |
|
|
1543 |
community_pages = community.pages; |
|
1544 |
community_pages[pageIdForPortalType] = community_pages[page._id.str]; |
|
1545 |
removePageFromPortal(community, page._id, community_pages); |
|
1546 |
if(portalType == "explore") { |
|
1547 |
print(" Delete page: "+page._id.str + " = (should be null) "+community.pages[page._id.str] |
|
1548 |
+ " - new page: "+pageIdForPortalType+" = "+community.pages[pageIdForPortalType]); |
|
1549 |
} |
|
1550 |
|
|
1551 |
updatePageHelpContentsForPortalPage(page._id.str, pageIdForPortalType, community._id.str); |
|
1552 |
} |
|
1553 |
|
|
1554 |
function removePageFromPortal(community, pageId, community_pages) { |
|
1555 |
//community_pages = community.pages; |
|
1556 |
//print(community.name+": Delete page: "+pageId.str); |
|
1557 |
delete community_pages[pageId.str]; |
|
1558 |
db.community.update({"pid": community.pid}, {$set: {"pages": community_pages}}); |
|
1559 |
} |
|
1560 |
|
|
1561 |
function updatePageHelpContentsForPortalPage(pageId, newPageId, communityId) { |
|
1562 |
pageHelpContents = db.pageHelpContent.find({"page" : pageId, "community" : communityId,}).map( function(pageHelpContent) { return pageHelpContent; } ); |
|
1563 |
for (var i = 0; i < pageHelpContents.length; i++) { |
|
1564 |
pageHelpContent = pageHelpContents[i]; |
|
1565 |
db.pageHelpContent.save({ |
|
1566 |
"_id": pageHelpContent._id, |
|
1567 |
"page": newPageId, |
|
1568 |
"community": communityId, |
|
1569 |
"placement": pageHelpContent.placement, |
|
1570 |
"order": pageHelpContent.order, |
|
1571 |
"content": pageHelpContent.content, |
|
1572 |
"isActive": pageHelpContent.isActive, |
|
1573 |
"isPriorTo": pageHelpContent.isPriorTo |
|
1574 |
}); |
|
1575 |
} |
|
1576 |
} |
|
1577 |
|
|
1578 |
function createDivIdsForEachPortalType() { |
|
1579 |
divIds = db.divId.find().map( function(divId) { return divId; } ); |
|
1580 |
for (var i = 0; i < divIds.length; i++) { |
|
1581 |
divId = divIds[i]; |
|
1582 |
|
|
1583 |
print("createDivIdsForEachPortalType: divId["+i+"] = "+divId.name + " -> openaire: "+divId.openaire+" - connect: "+divId.connect + " - communities: "+divId.communities); |
|
1584 |
|
|
1585 |
if(divId.openaire == true && divId.connect == true && divId.communities == true) { |
|
1586 |
//var pages = updateDivIdPages(divId.pages, "community"); |
|
1587 |
//db.divId.save({"_id": divId._id, "name": divId.name, "pages": pages, "portalType": "community"}); |
|
1588 |
//createAndUpdateDivId(divId, "community", false); |
|
1589 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "community", false); |
|
1590 |
|
|
1591 |
createAndUpdateDivIdAndContentsForPortal(divId, "openaire", "explore", true); |
|
1592 |
createAndUpdateDivIdAndContentsForPortal(divId, "connect", "connect", true); |
|
1593 |
|
|
1594 |
} else if(divId.openaire == true && divId.connect == true) { |
|
1595 |
//var pages = updateDivIdPages(divId.pages, "connect"); |
|
1596 |
//db.divId.save({"_id": divId._id, "name": divId.name, "pages": pages, "portalType": "connect"}); |
|
1597 |
//createAndUpdateDivId(divId, "connect", false); |
|
1598 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "connect", false); |
|
1599 |
|
|
1600 |
createAndUpdateDivIdAndContentsForPortal(divId, "openaire", "explore", true); |
|
1601 |
|
|
1602 |
} else if(divId.openaire == true && divId.communities == true) { |
|
1603 |
//var pages = updateDivIdPages(divId.pages, "community"); |
|
1604 |
//db.divId.save({ "_id": divId._id, "name" : divId.name, "pages" : pages, "portalType": "community"}); |
|
1605 |
//createAndUpdateDivId(divId, "community", false); |
|
1606 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "community", false); |
|
1607 |
|
|
1608 |
createAndUpdateDivIdAndContentsForPortal(divId, "openaire", "explore", true); |
|
1609 |
|
|
1610 |
} else if(divId.connect == true && divId.communities == true) { |
|
1611 |
//var pages = updateDivIdPages(divId.pages, "community"); |
|
1612 |
//db.divId.save({ "_id": divId._id, "name" : divId.name, "pages" : pages, "portalType": "community"}); |
|
1613 |
//createAndUpdateDivId(divId, "community", false); |
|
1614 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "community", false); |
|
1615 |
|
|
1616 |
createAndUpdateDivIdAndContentsForPortal(divId, "connect", "connect", true); |
|
1617 |
|
|
1618 |
} else if(divId.openaire == true) { |
|
1619 |
//var pages = updateDivIdPages(divId.pages, "explore"); |
|
1620 |
//db.divId.save({ "_id": divId._id, "name" : divId.name, "pages" : pages, "portalType": "explore"}); |
|
1621 |
//createAndUpdateDivId(divId, "explore", false); |
|
1622 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "explore", false); |
|
1623 |
|
|
1624 |
} else if(divId.connect == true) { |
|
1625 |
//var pages = updateDivIdPages(divId.pages, "connect"); |
|
1626 |
//db.divId.save({ "_id": divId._id, "name" : divId.name, "pages" : pages, "portalType": "connect"}); |
|
1627 |
//createAndUpdateDivId(divId, "connect", false); |
|
1628 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "connect", false); |
|
1629 |
|
|
1630 |
} else if(divId.communities == true) { |
|
1631 |
//var pages = updateDivIdPages(divId.pages, "community"); |
|
1632 |
//db.divId.save({ "_id": divId._id, "name" : divId.name, "pages" : pages, "portalType": "community"}); |
|
1633 |
//createAndUpdateDivId(divId, "community", false); |
|
1634 |
createAndUpdateDivIdAndContentsForPortal(divId, null, "community", false); |
|
1635 |
} |
|
1636 |
} |
|
1637 |
} |
|
1638 |
|
|
1639 |
function updateDivIdPages(pages, portalType) { |
|
1640 |
var newPages = []; |
|
1641 |
for (var i = 0; i < pages.length; i++) { |
|
1642 |
page = db.page.findOne({"_id": ObjectId(pages[i])}); |
|
1643 |
pageForPortalType = db.page.findOne({portalType: portalType, "route" : page.route}); |
|
1644 |
if(pageForPortalType) { |
|
1645 |
print("page in divId: "+pages[i] + " will be replaced with "+pageForPortalType._id.str); |
|
1646 |
newPages.push(pageForPortalType._id.str); |
|
1647 |
} else { |
|
1648 |
print("page in divId: "+pages[i] + " will be not be replaced. pageForPortalType: "+pageForPortalType); |
|
1649 |
} |
|
1650 |
} |
|
1651 |
return newPages; |
|
1652 |
} |
|
1653 |
|
|
1654 |
// function createAndUpdateDivId(divId, portalType, create) { |
|
1655 |
// var pages = updateDivIdPages(divId.pages, portalType); |
|
1656 |
// if(pages.length == 0) { |
|
1657 |
// db.divId.remove({"_id": divId._id}); |
|
1658 |
// communities = db.community.find({ "type" : portalType }).map( function(community) { return community; } ); |
|
1659 |
// for (var j = 0; j < communities.length; j++) { |
|
1660 |
// db.divHelpContent.remove({"divId": divId._id.str, "community": communities[j]._id.str}); |
|
1661 |
// } |
|
1662 |
// } else { |
|
1663 |
// if (create) { |
|
1664 |
// db.divId.save({"name": divId.name, "pages": pages, "portalType": portalType}); |
|
1665 |
// } else { |
|
1666 |
// db.divId.save({"_id": divId._id, "name": divId.name, "pages": pages, "portalType": portalType}); |
|
1667 |
// } |
|
1668 |
// } |
|
1669 |
// } |
|
1670 |
|
|
1671 |
function createAndUpdateDivIdAndContentsForPortal(divId, pid, portalType, create) { |
|
1672 |
//var pages = updateDivIdPages(divId.pages, portalType); |
|
1673 |
//db.divId.save({ "name" : divId.name, "pages" : pages, "portalType": portalType}); |
|
1674 |
|
|
1675 |
var pages = updateDivIdPages(divId.pages, portalType); |
|
1676 |
if(pages.length == 0) { |
|
1677 |
db.divId.remove({"_id": divId._id}); |
|
1678 |
communities = db.community.find({ "type" : portalType }).map( function(community) { return community; } ); |
|
1679 |
for (var j = 0; j < communities.length; j++) { |
|
1680 |
db.divHelpContent.remove({"divId": divId._id.str, "community": communities[j]._id.str}); |
|
1681 |
} |
|
1682 |
} else { |
|
1683 |
if (create) { |
|
1684 |
db.divId.save({"name": divId.name, "pages": pages, "portalType": portalType}); |
|
1685 |
|
|
1686 |
divIdForPortalType = db.divId.find({portalType: portalType, "name" : divId.name}).map(function (divId) { return divId._id.str; }).toString(); |
|
1687 |
|
|
1688 |
communityId = db.community.find({pid: pid}).map(function (community) { return community._id.str; }).toString(); |
|
1689 |
|
|
1690 |
updateDivIdHelpContentsForPortalPage(divId._id.str, divIdForPortalType, communityId); |
|
1691 |
} else { |
|
1692 |
db.divId.save({"_id": divId._id, "name": divId.name, "pages": pages, "portalType": portalType}); |
|
1693 |
} |
|
1694 |
} |
|
1695 |
} |
|
1696 |
|
|
1697 |
function updateDivIdHelpContentsForPortalPage(divIdId, newDivIdId, communityId) { |
|
1698 |
divHelpContents = db.divHelpContent.find({"divId" : divIdId, "community" : communityId,}).map( function(divHelpContent) { return divHelpContent; } ); |
|
1699 |
for (var i = 0; i < divHelpContents.length; i++) { |
|
1700 |
divHelpContent = divHelpContents[i]; |
|
1701 |
|
|
1702 |
db.divHelpContent.save({ |
|
1703 |
"_id": divHelpContent._id, |
|
1704 |
"divId" : newDivIdId, |
|
1705 |
"community" : communityId, |
|
1706 |
"content" : divHelpContent.content, |
|
1707 |
"isActive" : divHelpContent.isActive |
|
1708 |
}); |
|
1709 |
} |
|
1710 |
} |
|
1711 |
|
|
1712 |
function renameCollectionAndFields() { |
|
1713 |
db.community.renameCollection("portal"); |
|
1714 |
db.communitySubscribers.renameCollection("portalSubscribers"); |
|
1715 |
|
|
1716 |
db.divHelpContent.update({"community": {$exists: true}}, {$rename:{"community":"portal"}}, false, true); |
|
1717 |
db.pageHelpContent.update({"community": {$exists: true}}, {$rename:{"community":"portal"}}, false, true); |
|
1718 |
db.notifications.update({"communityPid": {$exists: true}}, {$rename:{"communityPid":"portalPid"}}, false, true); |
|
1719 |
} |
|
1720 |
|
|
1721 |
function addPortalPidInLayoutRecords() { |
|
1722 |
communities = db.portal.find().map( function(community) { return community; } ); |
|
1723 |
for (var j = 0; j < communities.length; j++) { |
|
1724 |
community = communities[j]; |
|
1725 |
if(community.layout) { |
|
1726 |
layout = db.layout.findOne({"_id": ObjectId(community.layout)}); |
|
1727 |
db.layout.save({ |
|
1728 |
"_id": layout._id, |
|
1729 |
"mainColor": layout.mainColor, |
|
1730 |
"secondaryColor": layout.secondaryColor, |
|
1731 |
"panel": layout.panel, |
|
1732 |
"box": layout.box, |
|
1733 |
"links": layout.links, |
|
1734 |
"buttons": layout.buttons, |
|
1735 |
"portalPid": community.pid |
|
1736 |
}) |
|
1737 |
|
|
1738 |
db.portal.update({"_id": community._id}, {$unset: {layout:""}}); |
|
1739 |
} |
|
1740 |
} |
|
1741 |
} |
|
1742 |
|
|
1743 |
use openaire_admin_beta_20191105; |
|
1744 |
|
|
1454 | 1745 |
//updatePages(); |
1455 | 1746 |
|
1456 | 1747 |
//updateTypeOfLandingPages(); |
... | ... | |
1513 | 1804 |
// removeOldLayouts(); |
1514 | 1805 |
|
1515 | 1806 |
// 13-03-2020 |
1516 |
addSearchResearchOutcomesPages(); |
|
1807 |
//addSearchResearchOutcomesPages(); |
|
1808 |
|
|
1809 |
// 02-02-2020 - 19-03-2020 |
|
1810 |
addPortalType(); |
|
1811 |
createPagesForEachPortalType(); |
|
1812 |
createDivIdsForEachPortalType(); |
|
1813 |
renameCollectionAndFields(); |
|
1814 |
addPortalPidInLayoutRecords(); |
Also available in: Unified diff
[use-UoaAdminToolsLibrary | Admin Tools Service]:
REMINDER NOTE: change war name and properties (e.g. in MongoConfig.java) when merging to trunk.
1. Move MongoDBDAOs to folder /dao/MongoDBDAOs.
2. Move entities for Subscriber to folder /entities/subscriber.
3. Move entities for Curator to folder /entities/curator.
4. Add services for Layout, Statistics and Subscribers (to be called by controllers).
5. Rename "CommunitySubscribers" to "PortalSubscribers", "CommunitySubscribersController" to "PortalSubscribersController" and "CommunitySubscribersDAO" to "PortalSubscribersDAO".
6. Update all files to import appropriate files (from library or locally).
7. Create "ConnectController", "ExploreController" and update "CommunityController".
8. UoaAdminToolsApplication.java: scanBasePackages = {"eu.dnetlib.uoaadmintools", "eu.dnetlib.uoaadmintoolslibrary"}
9. MongoConnection.java: basePackages = {"eu.dnetlib.uoaadmintools.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"}
10. Update update_db.js for changing db collections and entries according to new schema.