[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").
This commit is contained in:
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;
|
||||
}
|
||||
}
|
|
@ -7,15 +7,11 @@ import eu.dnetlib.uoaorcidservice.entities.ResultIdAndWork;
|
|||
import eu.dnetlib.uoaorcidservice.entities.UserTokens;
|
||||
import eu.dnetlib.uoaorcidservice.entities.Work;
|
||||
import eu.dnetlib.uoaorcidservice.handlers.ConflictException;
|
||||
import eu.dnetlib.uoaorcidservice.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoaorcidservice.services.UserTokensService;
|
||||
import eu.dnetlib.uoaorcidservice.services.WorkService;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.access.AuthorizationServiceException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -34,7 +30,6 @@ import java.security.spec.InvalidKeySpecException;
|
|||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
//@RequestMapping("/orcid")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class WorkController {
|
||||
|
@ -167,6 +162,7 @@ public class WorkController {
|
|||
workToSave.setOrcid(userOrcid);
|
||||
workToSave.setCreationDate(date);
|
||||
workToSave.setUpdateDate(date);
|
||||
workToSave.setDashboard(result.getDashboard());
|
||||
|
||||
HttpHeaders responseHeaders = response.getHeaders();
|
||||
String locationPath = responseHeaders.getLocation().toString();
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
package eu.dnetlib.uoaorcidservice.entities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ResultIdAndWork {
|
||||
private String dashboard = "production_explore";
|
||||
String[] pids;
|
||||
Object work;
|
||||
|
||||
public String getDashboard() {
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
public void setDashboard(String dashboard) {
|
||||
this.dashboard = dashboard;
|
||||
}
|
||||
|
||||
public String[] getPids() {
|
||||
return pids;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package eu.dnetlib.uoaorcidservice.entities;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class UserTokens {
|
||||
@Id
|
||||
//@JsonProperty("_id")
|
||||
|
@ -16,6 +18,7 @@ public class UserTokens {
|
|||
private String refresh_token;
|
||||
private String expires_in;
|
||||
private String scope;
|
||||
private Date creationDate;
|
||||
|
||||
|
||||
// public String getId() {
|
||||
|
@ -89,4 +92,12 @@ public class UserTokens {
|
|||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(Date creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public class Work {
|
|||
private String orcid;
|
||||
private Date creationDate;
|
||||
private Date updateDate;
|
||||
private String dashboard;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -63,4 +64,12 @@ public class Work {
|
|||
public void setUpdateDate(Date updateDate) {
|
||||
this.updateDate = updateDate;
|
||||
}
|
||||
|
||||
public String getDashboard() {
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
public void setDashboard(String dashboard) {
|
||||
this.dashboard = dashboard;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.security.InvalidAlgorithmParameterException;
|
|||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
@ -97,6 +98,7 @@ public class UserTokensService {
|
|||
}
|
||||
|
||||
public void saveUserTokens(UserTokens userTokens) throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IOException {
|
||||
userTokens.setCreationDate(new Date());
|
||||
userTokens.setAaiId(rolesUtils.getAaiId());
|
||||
userTokens = encryptTokens(userTokens);
|
||||
|
||||
|
|
|
@ -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