[Trunk | Orcid Service]:
1. OrcidServiceCheckDeployController.java: [NEW] Controller added and a. "hello()" method (@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)) which just prints and returns a greeting message. b. "checkEverything()" method @RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET) only accessible by PORTAL ADMINS which checks connection with db and prints properties. 2. ResultIdAndWork.java & Work.java: Added field "dashboard" (in ResultInWork class, default value is "production_explpre") and its getters and setters. 3. UserTokens.java: Added field "creationDate" and its getters and setters. 4. UserTokensService.java: Call setCreationDate() method with current Date in "saveUserTokens()" method. 5. WorkController.java: Call setDashboard() method with dashboard value from parameter of type ResultIdAndWork in "saveWork()" method. 6. update_db.js: Script with methods "setUserTokenCreationDate()" (use date of first work for this orcid) and "setDashboardInWorks()" (set all to "production_explore").master
parent
69f9eb6df6
commit
56eb48686d
@ -0,0 +1,74 @@
|
|||||||
|
package eu.dnetlib.uoaorcidservice.controllers;
|
||||||
|
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.CommandResult;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import eu.dnetlib.uoaorcidservice.configuration.mongo.MongoConnection;
|
||||||
|
import eu.dnetlib.uoaorcidservice.configuration.properties.MongoConfig;
|
||||||
|
import eu.dnetlib.uoaorcidservice.configuration.properties.OrcidConfig;
|
||||||
|
import eu.dnetlib.uoaorcidservice.handlers.utils.AESUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class OrcidServiceCheckDeployController {
|
||||||
|
private final Logger log = Logger.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MongoConnection mongoConnection;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MongoConfig mongoConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrcidConfig orcidConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AESUtils aesUtils;
|
||||||
|
|
||||||
|
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
||||||
|
public String hello() {
|
||||||
|
log.debug("Hello from uoa-orcid-service!");
|
||||||
|
return "Hello from uoa-orcid-service!";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
||||||
|
public Map<String, String> checkEverything() {
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
|
||||||
|
MongoTemplate mt = mongoConnection.getMongoTemplate();
|
||||||
|
DBObject ping = new BasicDBObject("ping", "1");
|
||||||
|
try {
|
||||||
|
CommandResult answer = mt.getDb().command(ping);
|
||||||
|
response.put("Mongo try: error", answer.getErrorMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
response.put("Mongo catch: error", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
response.put("orcidservice.mongodb.database", mongoConfig.getDatabase());
|
||||||
|
response.put("orcidservice.mongodb.host", mongoConfig.getHost());
|
||||||
|
response.put("orcidservice.mongodb.port", mongoConfig.getPort()+"");
|
||||||
|
response.put("orcidservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
|
||||||
|
response.put("orcidservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
|
||||||
|
|
||||||
|
response.put("orcidservice.orcid.apiURL", orcidConfig.getApiURL());
|
||||||
|
response.put("orcidservice.orcid.tokenURL", orcidConfig.getTokenURL());
|
||||||
|
response.put("orcidservice.orcid.clientId", orcidConfig.getClientId() == null ? null : "[unexposed value]");
|
||||||
|
response.put("orcidservice.orcid.clientSecret", orcidConfig.getClientSecret() == null ? null : "[unexposed value]");
|
||||||
|
|
||||||
|
response.put("orcidservice.encryption.password", aesUtils.getPassword() == null ? null : "[unexposed value]");
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
//version compatibility: 1.0.0-SNAPSHOT
|
||||||
|
print("here");
|
||||||
|
|
||||||
|
function setUserTokenCreationDate(){
|
||||||
|
print("\n\n setUserTokenCreationDate \n\n");
|
||||||
|
|
||||||
|
works = db.work.aggregate(
|
||||||
|
[
|
||||||
|
{ $sort: { orcid: 1, creationDate: 1 } },
|
||||||
|
{
|
||||||
|
$group:
|
||||||
|
{
|
||||||
|
_id: "$orcid",
|
||||||
|
creationDate: { $first: "$creationDate" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
while (works.hasNext()) {
|
||||||
|
var work = works.next();
|
||||||
|
print("\n\n");
|
||||||
|
print("DATE OF FIRST WORK FOR ORCID: ",tojson(work));
|
||||||
|
userTokens = db.userTokens.find({"orcid": work['_id']}).map(function (userToken) { return userToken; });
|
||||||
|
|
||||||
|
for(var i=0; i<userTokens.length; i++) {
|
||||||
|
var userToken = userTokens[i];
|
||||||
|
// print("OLD userToken: ",tojson(userToken));
|
||||||
|
|
||||||
|
userToken['creationDate'] = work['creationDate'];
|
||||||
|
|
||||||
|
print(tojson(userToken));
|
||||||
|
db.userTokens.save(userToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDashboardInWorks() {
|
||||||
|
print("\n\n setDashboardInWorks \n\n");
|
||||||
|
var works = db.work.find().map(function (work) { return work; });
|
||||||
|
|
||||||
|
for(var i=0; i<works.length; i++) {
|
||||||
|
var current_work = works[i];
|
||||||
|
current_work['dashboard'] = "production_explore";
|
||||||
|
db.work.save(current_work);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use openaire_orcid;
|
||||||
|
|
||||||
|
// 29-03-2021 - 20-04-2021
|
||||||
|
// setUserTokenCreationDate();
|
||||||
|
// setDashboardInWorks();
|
Loading…
Reference in New Issue