[Trunk | Admin Tools Service]:
1. admintools.properties & UoaAdminToolsApplication.java: Uncomment admintools.properties and ignore if @PropertySource for dnet-override.properties not found, to let tests runs. 2. Subscriber.java: Add default constructor and constructor with email parameter. 3. CommunitySubscribersController.java: a. Autowire SecurityConfig to let methods get UserInfo via token. b. Add GET method "getNumberOfSubscribersPerCommunity()" (/community/{pid}/subscribers/count). c. Add GET methos "getIsSubscribedToCommunity()" (/community/{pid}/is-subscriber): Return true/ false and gets user email via token in @RequestHeader("X-XSRF-TOKEN"). d. Method "addSubscriberInCommunity()" renamed to "addSubscriberInCommunityByEmail()" | Method "deleteSubscriberFromCommunity()" renamed to "deleteSubscriberFromCommunityByEmail()". e. Add POST methods "addSubscriberInCommunity()" (/community/{pid}/subscriber) and "deleteSubscriberFromCommunity()" (/community/{pid}/subscriber/delete): Return true/ false and get user email via token in @RequestHeader("X-XSRF-TOKEN"). f. Method getCommunitiesPerSubcriber(@RequestParam(value="email", required = true) String email) --> getCommunitiesPerSubcriber(@RequestHeader("X-XSRF-TOKEN") String token): Get user email via token in @RequestHeader("X-XSRF-TOKEN"). 4. update_db.js: a. Add method "createNewPagesForConnect()": adds page "/publications" for connect (enabled). b. Add method "createNewPagesForCommunities()": adds pages "/content" (enabled), "/projects" (disabled), "/national-bulletins" (disabled), "/subjects"(disabled) for communities. c. Add method "removeContentPolicyPageAndAddHelpTextInCommunitiesSourcesPage()": remove old "/content" connect page and move its contents to new "/content" for every community (NOT connect & openaire).
This commit is contained in:
parent
3e494fd665
commit
04d9e7a91f
|
@ -13,7 +13,7 @@ import org.springframework.context.annotation.PropertySources;
|
|||
@SpringBootApplication
|
||||
@PropertySources({
|
||||
@PropertySource("classpath:admintools.properties"),
|
||||
@PropertySource("classpath:dnet-override.properties")
|
||||
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
|
||||
})
|
||||
@EnableConfigurationProperties({SecurityConfig.class, MailConfig.class, GoogleConfig.class, MongoConfig.class})
|
||||
public class UoaAdminToolsApplication {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.dnetlib.uoaadmintools.controllers;
|
||||
|
||||
import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
|
||||
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
||||
import eu.dnetlib.uoaadmintools.dao.CommunitySubscribersDAO;
|
||||
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
||||
|
@ -7,11 +8,14 @@ import eu.dnetlib.uoaadmintools.entities.Community;
|
|||
import eu.dnetlib.uoaadmintools.entities.CommunitySubscribers;
|
||||
import eu.dnetlib.uoaadmintools.entities.Subscriber;
|
||||
import eu.dnetlib.uoaadmintools.handlers.ContentNotFoundException;
|
||||
import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils;
|
||||
import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +31,9 @@ public class CommunitySubscribersController {
|
|||
@Autowired
|
||||
CommunityDAO communityDAO;
|
||||
|
||||
@Autowired
|
||||
private SecurityConfig securityConfig;
|
||||
|
||||
private final Logger log = Logger.getLogger(this.getClass());
|
||||
@RequestMapping(value = "/community/subscribers", method = RequestMethod.GET)
|
||||
public List<CommunitySubscribers> getAllCommunitySubscribers(){
|
||||
|
@ -43,8 +50,112 @@ public class CommunitySubscribersController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{pid}/subscribers/count", method = RequestMethod.GET)
|
||||
public Integer getNumberOfSubscribersPerCommunity(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if(communitySubscribers != null){
|
||||
if(communitySubscribers.getSubscribers() != null) {
|
||||
return communitySubscribers.getSubscribers().size();
|
||||
}
|
||||
}else{
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
|
||||
public Boolean getIsSubscribedToCommunity(@PathVariable(value="pid", required = true) String pid,
|
||||
//@RequestBody String email,
|
||||
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
||||
AuthorizationUtils helper = new AuthorizationUtils();
|
||||
helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
||||
UserInfo userInfo = helper.getUserInfo(token);
|
||||
|
||||
if(userInfo != null) {
|
||||
String email = userInfo.getEmail();
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if (communitySubscribers != null) {
|
||||
if (communitySubscribers.getSubscribers() != null) {
|
||||
for (Subscriber subscriber : communitySubscribers.getSubscribers()) {
|
||||
if (subscriber.getEmail().equals(email)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST)
|
||||
public Boolean addSubscriberInCommunity(@PathVariable(value="pid", required = true) String pid,
|
||||
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
||||
AuthorizationUtils helper = new AuthorizationUtils();
|
||||
helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
||||
UserInfo userInfo = helper.getUserInfo(token);
|
||||
|
||||
if(userInfo != null) {
|
||||
String email = userInfo.getEmail();
|
||||
Subscriber subscriber = new Subscriber(email);
|
||||
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if (communitySubscribers == null) {
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
}
|
||||
|
||||
Subscriber savedSubscriber = subscriberDAO.findByEmail(email);
|
||||
if (savedSubscriber == null) {
|
||||
savedSubscriber = subscriberDAO.save(subscriber);
|
||||
}
|
||||
for (Subscriber sub : communitySubscribers.getSubscribers()) {
|
||||
if (sub.getEmail().equals(subscriber.getEmail())) {
|
||||
//already subscribed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//not subscribed yet
|
||||
communitySubscribers.getSubscribers().add(savedSubscriber);
|
||||
communitySubscriberDAO.save(communitySubscribers);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
@RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST)
|
||||
public Boolean deleteSubscriberFromCommunity(@PathVariable(value="pid", required = true) String pid,
|
||||
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
||||
AuthorizationUtils helper = new AuthorizationUtils();
|
||||
helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
||||
UserInfo userInfo = helper.getUserInfo(token);
|
||||
|
||||
if(userInfo != null) {
|
||||
String email = userInfo.getEmail();
|
||||
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if (communitySubscribers == null) {
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
}
|
||||
|
||||
Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator();
|
||||
while(subscriberIterator.hasNext()) {
|
||||
Subscriber subscriber = subscriberIterator.next();
|
||||
if(subscriber.getEmail().equals(email)) {
|
||||
subscriberIterator.remove();
|
||||
communitySubscriberDAO.save(communitySubscribers);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST)
|
||||
public CommunitySubscribers addSubscriberInCommunity(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
|
||||
public CommunitySubscribers addSubscriberInCommunityByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if(communitySubscribers == null){
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
|
@ -66,7 +177,7 @@ public class CommunitySubscribersController {
|
|||
|
||||
}
|
||||
@RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST)
|
||||
public CommunitySubscribers deleteSubscriberFromCommunity(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
|
||||
public CommunitySubscribers deleteSubscriberFromCommunityByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if(communitySubscribers == null){
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
|
@ -82,14 +193,24 @@ public class CommunitySubscribersController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET)
|
||||
public List<String> getCommunitiesPerSubcriber(@RequestParam(value="email", required = true) String email) {
|
||||
List<CommunitySubscribers> communitySubscribers = communitySubscriberDAO.findAll();
|
||||
public List<String> getCommunitiesPerSubcriber(//@RequestParam(value="email", required = true) String email,
|
||||
@RequestHeader("X-XSRF-TOKEN") String token) {
|
||||
AuthorizationUtils helper = new AuthorizationUtils();
|
||||
helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
||||
UserInfo userInfo = helper.getUserInfo(token);
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
for(CommunitySubscribers s:communitySubscribers){
|
||||
for(Subscriber sub:s.getSubscribers()) {
|
||||
if (sub.getEmail().equals(email)) {
|
||||
list.add(s.getPid());
|
||||
break;
|
||||
|
||||
if (userInfo != null) {
|
||||
String email = userInfo.getEmail();
|
||||
List<CommunitySubscribers> communitySubscribers = communitySubscriberDAO.findAll();
|
||||
|
||||
for (CommunitySubscribers s : communitySubscribers) {
|
||||
for (Subscriber sub : s.getSubscribers()) {
|
||||
if (sub.getEmail().equals(email)) {
|
||||
list.add(s.getPid());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@ public class Subscriber {
|
|||
|
||||
private String email;
|
||||
|
||||
public Subscriber() {}
|
||||
public Subscriber(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#dev
|
||||
#admintool.security.userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
||||
#admintool.security.originServer = .di.uoa.gr
|
||||
#admintool.security.postsAllowed = /contact,/contact/
|
||||
#admintool.mail.host = smtp.gmail.com
|
||||
#admintool.mail.port = 587
|
||||
#admintool.mail.auth = true
|
||||
#admintool.mail.from = openaire.test@gmail.com
|
||||
#admintool.mail.username = openaire.test@gmail.com
|
||||
#admintool.mail.password =
|
||||
#admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
|
||||
#admintool.mongodb.host=localhost
|
||||
#admintool.mongodb.port=27017
|
||||
#admintool.mongodb.database=openaire_admin
|
||||
admintool.security.userInfoUrl = http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=
|
||||
admintool.security.originServer = .di.uoa.gr
|
||||
admintool.security.postsAllowed = /contact,/contact/
|
||||
admintool.mail.host = smtp.gmail.com
|
||||
admintool.mail.port = 587
|
||||
admintool.mail.auth = true
|
||||
admintool.mail.from = openaire.test@gmail.com
|
||||
admintool.mail.username = openaire.test@gmail.com
|
||||
admintool.mail.password =
|
||||
admintool.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
|
||||
admintool.mongodb.host=localhost
|
||||
admintool.mongodb.port=27017
|
||||
admintool.mongodb.database=openaire_admin
|
||||
|
||||
#beta
|
||||
#admintool.security.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
|
||||
|
|
117
update_db.js
117
update_db.js
|
@ -1449,6 +1449,116 @@ function addSearchResearchOutcomesPages() {
|
|||
}
|
||||
}
|
||||
|
||||
function createNewPagesForConnect() {
|
||||
// Connect pages
|
||||
publicationsId = db.page.insertOne({
|
||||
"name": "Publications",
|
||||
"route": "/publications",
|
||||
"type": "other",
|
||||
"connect": true,
|
||||
"openaire": false,
|
||||
"communities": false,
|
||||
"entities": [],
|
||||
"top": true,
|
||||
"bottom": false,
|
||||
"right": false,
|
||||
"left": false
|
||||
}).insertedId.str;
|
||||
print("Connect: Creating Publications page with id " + publicationsId);
|
||||
|
||||
var connectCommunity = db.community.findOne({pid: "connect"});
|
||||
connect_pages = connectCommunity.pages;
|
||||
connect_pages[publicationsId] = true;
|
||||
db.community.update({"pid": "connect"}, {$set: {"pages": connect_pages}});
|
||||
print("Add Publications page with id " + publicationsId + " on community connect");
|
||||
}
|
||||
|
||||
function createNewPagesForCommunities() {
|
||||
// Community pages
|
||||
sourcesId = db.page.insertOne({"name" : "Sources and methology", "route" : "/content", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str;
|
||||
print("Communities: Creating Sources and methology page with id " + sourcesId);
|
||||
|
||||
projectsId = db.page.insertOne({"name" : "Projects and funding opportunities", "route" : "/projects", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str;
|
||||
print("Communities: Creating Projects page with id " + projectsId);
|
||||
|
||||
nationalBulletinsId = db.page.insertOne({"name" : "National Bulletins", "route" : "/national-bulletins", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":false,"right":false,"left":false}).insertedId.str;
|
||||
print("Communities: Creating National Bulletins page with id " + nationalBulletinsId);
|
||||
|
||||
subjectsId = db.page.insertOne({"name" : "Subjects", "route" : "/subjects", "type" : "other", "connect":false,"openaire":false, "communities": true, "entities" : [], "top":true,"bottom":true,"right":false,"left":false}).insertedId.str;
|
||||
print("Communities: Creating Subjects page with id " + subjectsId);
|
||||
|
||||
communities = db.community.find().map( function(community) { return community; } );
|
||||
for (var i = 0; i < communities.length; i++) {
|
||||
community_pages = communities[i].pages;
|
||||
|
||||
community_pages[sourcesId] = true;
|
||||
community_pages[projectsId] = false;
|
||||
community_pages[nationalBulletinsId] = false;
|
||||
community_pages[subjectsId] = false;
|
||||
|
||||
community_pid = communities[i].pid;
|
||||
db.community.update({ "pid" : community_pid },{$set: { "pages": community_pages}});
|
||||
print("Add Sources and methology page with id " + sourcesId + " on community " + community_pid);
|
||||
print("Add Projects page with id " + projectsId + " on community " + community_pid);
|
||||
print("Add National Bulletins page with id " + nationalBulletinsId + " on community " + community_pid);
|
||||
print("Add Subjects page with id " + subjectsId + " on community " + community_pid);
|
||||
}
|
||||
}
|
||||
|
||||
function removeContentPolicyPageAndAddHelpTextInCommunitiesSourcesPage() {
|
||||
contentId = db.page.find({route: "/content", "connect": true}).map(function (page) {
|
||||
return page._id.str;
|
||||
}).toString();
|
||||
db.page.remove({"route": "/content", "connect": true});
|
||||
print("Remove Content Policy page with id " + contentId + " and connect: true");
|
||||
|
||||
var connectCommunity = db.community.findOne({pid: "connect"});
|
||||
// connect_pages = connectCommunity.pages;
|
||||
// delete connect_pages[contentId];
|
||||
// db.community.update({"pid": "connect"}, {$set: {"pages": connect_pages}});
|
||||
// print("Remove Content Policy page with id " + contentId + " on community: connect");
|
||||
|
||||
communities_contentId = db.page.find({route: "/content", "communities": true}).map(function (page) {
|
||||
return page._id.str;
|
||||
}).toString();
|
||||
communities = db.community.find().map(function (community) {
|
||||
return community;
|
||||
});
|
||||
for (var i = 0; i < communities.length; i++) {
|
||||
community_pages = communities[i].pages;
|
||||
delete community_pages[contentId];
|
||||
db.community.update({"pid": communities[i].pid}, {$set: {"pages": community_pages}});
|
||||
print("Remove Content Policy page with id " + contentId + " on community: "+communities[i].pid);
|
||||
|
||||
db.pageHelpContent.find({
|
||||
community: connectCommunity._id.str,
|
||||
page: contentId
|
||||
}).forEach(function (pageHelpContentForContentPolicy) {
|
||||
if(communities[i].pid != "openaire" && communities[i].pid != "connect") {
|
||||
newCommunityPageHelpContent = db.pageHelpContent.save({
|
||||
"page": communities_contentId, "community": communities[i]._id.str,
|
||||
"content": pageHelpContentForContentPolicy.content,
|
||||
"placement": pageHelpContentForContentPolicy.placement, "order": pageHelpContentForContentPolicy.order,
|
||||
"isActive": pageHelpContentForContentPolicy.isActive, "isPriorTo": pageHelpContentForContentPolicy.isPriorTo
|
||||
});
|
||||
|
||||
print("Add pageHelpContent on community " + communities[i].pid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pageHelpContentsForContentPolicy = db.pageHelpContent.find({
|
||||
community: connectCommunity._id.str,
|
||||
page: contentId
|
||||
}).map(function (pageHelpContent) {
|
||||
return pageHelpContent;
|
||||
});
|
||||
for (var i = 0; i < pageHelpContentsForContentPolicy.length; i++) {
|
||||
db.pageHelpContent.remove({"_id": pageHelpContentsForContentPolicy[i]._id});
|
||||
print("Removed pageHelpContent with id " + pageHelpContentsForContentPolicy[i]._id.str + " from community: connect");
|
||||
}
|
||||
}
|
||||
|
||||
use openaire_admin;
|
||||
|
||||
//updatePages();
|
||||
|
@ -1513,4 +1623,9 @@ use openaire_admin;
|
|||
// removeOldLayouts();
|
||||
|
||||
// 13-03-2020
|
||||
addSearchResearchOutcomesPages();
|
||||
//addSearchResearchOutcomesPages();
|
||||
|
||||
// 10-04-2020
|
||||
createNewPagesForConnect();
|
||||
createNewPagesForCommunities();
|
||||
removeContentPolicyPageAndAddHelpTextInCommunitiesSourcesPage();
|
Loading…
Reference in New Issue