Revision 60959
Added by Konstantina Galouni almost 3 years ago
modules/uoa-orcid-service/trunk/update_db.js | ||
---|---|---|
1 |
//version compatibility: 1.0.0-SNAPSHOT |
|
2 |
print("here"); |
|
3 |
|
|
4 |
function setUserTokenCreationDate(){ |
|
5 |
print("\n\n setUserTokenCreationDate \n\n"); |
|
6 |
|
|
7 |
works = db.work.aggregate( |
|
8 |
[ |
|
9 |
{ $sort: { orcid: 1, creationDate: 1 } }, |
|
10 |
{ |
|
11 |
$group: |
|
12 |
{ |
|
13 |
_id: "$orcid", |
|
14 |
creationDate: { $first: "$creationDate" } |
|
15 |
} |
|
16 |
} |
|
17 |
] |
|
18 |
); |
|
19 |
|
|
20 |
while (works.hasNext()) { |
|
21 |
var work = works.next(); |
|
22 |
print("\n\n"); |
|
23 |
print("DATE OF FIRST WORK FOR ORCID: ",tojson(work)); |
|
24 |
userTokens = db.userTokens.find({"orcid": work['_id']}).map(function (userToken) { return userToken; }); |
|
25 |
|
|
26 |
for(var i=0; i<userTokens.length; i++) { |
|
27 |
var userToken = userTokens[i]; |
|
28 |
// print("OLD userToken: ",tojson(userToken)); |
|
29 |
|
|
30 |
userToken['creationDate'] = work['creationDate']; |
|
31 |
|
|
32 |
print(tojson(userToken)); |
|
33 |
db.userTokens.save(userToken); |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
function setDashboardInWorks() { |
|
40 |
print("\n\n setDashboardInWorks \n\n"); |
|
41 |
var works = db.work.find().map(function (work) { return work; }); |
|
42 |
|
|
43 |
for(var i=0; i<works.length; i++) { |
|
44 |
var current_work = works[i]; |
|
45 |
current_work['dashboard'] = "production_explore"; |
|
46 |
db.work.save(current_work); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
use openaire_orcid; |
|
51 |
|
|
52 |
// 29-03-2021 - 20-04-2021 |
|
53 |
// setUserTokenCreationDate(); |
|
54 |
// setDashboardInWorks(); |
modules/uoa-orcid-service/trunk/src/main/java/eu/dnetlib/uoaorcidservice/services/UserTokensService.java | ||
---|---|---|
21 | 21 |
import java.security.InvalidKeyException; |
22 | 22 |
import java.security.NoSuchAlgorithmException; |
23 | 23 |
import java.security.spec.InvalidKeySpecException; |
24 |
import java.util.Date; |
|
24 | 25 |
import java.util.List; |
25 | 26 |
|
26 | 27 |
@Service |
... | ... | |
97 | 98 |
} |
98 | 99 |
|
99 | 100 |
public void saveUserTokens(UserTokens userTokens) throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IOException { |
101 |
userTokens.setCreationDate(new Date()); |
|
100 | 102 |
userTokens.setAaiId(rolesUtils.getAaiId()); |
101 | 103 |
userTokens = encryptTokens(userTokens); |
102 | 104 |
|
modules/uoa-orcid-service/trunk/src/main/java/eu/dnetlib/uoaorcidservice/entities/ResultIdAndWork.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaorcidservice.entities; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
5 | 3 |
public class ResultIdAndWork { |
4 |
private String dashboard = "production_explore"; |
|
6 | 5 |
String[] pids; |
7 | 6 |
Object work; |
8 | 7 |
|
8 |
public String getDashboard() { |
|
9 |
return dashboard; |
|
10 |
} |
|
11 |
|
|
12 |
public void setDashboard(String dashboard) { |
|
13 |
this.dashboard = dashboard; |
|
14 |
} |
|
15 |
|
|
9 | 16 |
public String[] getPids() { |
10 | 17 |
return pids; |
11 | 18 |
} |
modules/uoa-orcid-service/trunk/src/main/java/eu/dnetlib/uoaorcidservice/entities/UserTokens.java | ||
---|---|---|
3 | 3 |
import com.fasterxml.jackson.annotation.JsonProperty; |
4 | 4 |
import org.springframework.data.annotation.Id; |
5 | 5 |
|
6 |
import java.util.Date; |
|
7 |
|
|
6 | 8 |
public class UserTokens { |
7 | 9 |
@Id |
8 | 10 |
//@JsonProperty("_id") |
... | ... | |
16 | 18 |
private String refresh_token; |
17 | 19 |
private String expires_in; |
18 | 20 |
private String scope; |
21 |
private Date creationDate; |
|
19 | 22 |
|
20 | 23 |
|
21 | 24 |
// public String getId() { |
... | ... | |
89 | 92 |
public void setName(String name) { |
90 | 93 |
this.name = name; |
91 | 94 |
} |
95 |
|
|
96 |
public Date getCreationDate() { |
|
97 |
return creationDate; |
|
98 |
} |
|
99 |
|
|
100 |
public void setCreationDate(Date creationDate) { |
|
101 |
this.creationDate = creationDate; |
|
102 |
} |
|
92 | 103 |
} |
modules/uoa-orcid-service/trunk/src/main/java/eu/dnetlib/uoaorcidservice/entities/Work.java | ||
---|---|---|
15 | 15 |
private String orcid; |
16 | 16 |
private Date creationDate; |
17 | 17 |
private Date updateDate; |
18 |
private String dashboard; |
|
18 | 19 |
|
19 | 20 |
public String getId() { |
20 | 21 |
return id; |
... | ... | |
63 | 64 |
public void setUpdateDate(Date updateDate) { |
64 | 65 |
this.updateDate = updateDate; |
65 | 66 |
} |
67 |
|
|
68 |
public String getDashboard() { |
|
69 |
return dashboard; |
|
70 |
} |
|
71 |
|
|
72 |
public void setDashboard(String dashboard) { |
|
73 |
this.dashboard = dashboard; |
|
74 |
} |
|
66 | 75 |
} |
modules/uoa-orcid-service/trunk/src/main/java/eu/dnetlib/uoaorcidservice/controllers/OrcidServiceCheckDeployController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaorcidservice.controllers; |
|
2 |
|
|
3 |
import com.mongodb.BasicDBObject; |
|
4 |
import com.mongodb.CommandResult; |
|
5 |
import com.mongodb.DBObject; |
|
6 |
import eu.dnetlib.uoaorcidservice.configuration.mongo.MongoConnection; |
|
7 |
import eu.dnetlib.uoaorcidservice.configuration.properties.MongoConfig; |
|
8 |
import eu.dnetlib.uoaorcidservice.configuration.properties.OrcidConfig; |
|
9 |
import eu.dnetlib.uoaorcidservice.handlers.utils.AESUtils; |
|
10 |
import org.apache.log4j.Logger; |
|
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
12 |
import org.springframework.data.mongodb.core.MongoTemplate; |
|
13 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
14 |
import org.springframework.web.bind.annotation.CrossOrigin; |
|
15 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
16 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
17 |
import org.springframework.web.bind.annotation.RestController; |
|
18 |
|
|
19 |
import java.util.HashMap; |
|
20 |
import java.util.Map; |
|
21 |
|
|
22 |
@RestController |
|
23 |
@CrossOrigin(origins = "*") |
|
24 |
public class OrcidServiceCheckDeployController { |
|
25 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private MongoConnection mongoConnection; |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private MongoConfig mongoConfig; |
|
32 |
|
|
33 |
@Autowired |
|
34 |
private OrcidConfig orcidConfig; |
|
35 |
|
|
36 |
@Autowired |
|
37 |
private AESUtils aesUtils; |
|
38 |
|
|
39 |
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET) |
|
40 |
public String hello() { |
|
41 |
log.debug("Hello from uoa-orcid-service!"); |
|
42 |
return "Hello from uoa-orcid-service!"; |
|
43 |
} |
|
44 |
|
|
45 |
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") |
|
46 |
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET) |
|
47 |
public Map<String, String> checkEverything() { |
|
48 |
Map<String, String> response = new HashMap<>(); |
|
49 |
|
|
50 |
MongoTemplate mt = mongoConnection.getMongoTemplate(); |
|
51 |
DBObject ping = new BasicDBObject("ping", "1"); |
|
52 |
try { |
|
53 |
CommandResult answer = mt.getDb().command(ping); |
|
54 |
response.put("Mongo try: error", answer.getErrorMessage()); |
|
55 |
} catch (Exception e) { |
|
56 |
response.put("Mongo catch: error", e.getMessage()); |
|
57 |
} |
|
58 |
|
|
59 |
response.put("orcidservice.mongodb.database", mongoConfig.getDatabase()); |
|
60 |
response.put("orcidservice.mongodb.host", mongoConfig.getHost()); |
|
61 |
response.put("orcidservice.mongodb.port", mongoConfig.getPort()+""); |
|
62 |
response.put("orcidservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]"); |
|
63 |
response.put("orcidservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]"); |
|
64 |
|
|
65 |
response.put("orcidservice.orcid.apiURL", orcidConfig.getApiURL()); |
|
66 |
response.put("orcidservice.orcid.tokenURL", orcidConfig.getTokenURL()); |
|
67 |
response.put("orcidservice.orcid.clientId", orcidConfig.getClientId() == null ? null : "[unexposed value]"); |
|
68 |
response.put("orcidservice.orcid.clientSecret", orcidConfig.getClientSecret() == null ? null : "[unexposed value]"); |
|
69 |
|
|
70 |
response.put("orcidservice.encryption.password", aesUtils.getPassword() == null ? null : "[unexposed value]"); |
|
71 |
|
|
72 |
return response; |
|
73 |
} |
|
74 |
} |
modules/uoa-orcid-service/trunk/src/main/java/eu/dnetlib/uoaorcidservice/controllers/WorkController.java | ||
---|---|---|
7 | 7 |
import eu.dnetlib.uoaorcidservice.entities.UserTokens; |
8 | 8 |
import eu.dnetlib.uoaorcidservice.entities.Work; |
9 | 9 |
import eu.dnetlib.uoaorcidservice.handlers.ConflictException; |
10 |
import eu.dnetlib.uoaorcidservice.handlers.ForbiddenException; |
|
11 | 10 |
import eu.dnetlib.uoaorcidservice.services.UserTokensService; |
12 | 11 |
import eu.dnetlib.uoaorcidservice.services.WorkService; |
13 | 12 |
import org.apache.log4j.Logger; |
14 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
15 |
import org.springframework.data.util.Pair; |
|
16 | 14 |
import org.springframework.http.*; |
17 |
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; |
|
18 |
import org.springframework.security.access.AccessDeniedException; |
|
19 | 15 |
import org.springframework.security.access.AuthorizationServiceException; |
20 | 16 |
import org.springframework.security.access.prepost.PreAuthorize; |
21 | 17 |
import org.springframework.web.bind.annotation.*; |
... | ... | |
34 | 30 |
import java.util.*; |
35 | 31 |
|
36 | 32 |
@RestController |
37 |
//@RequestMapping("/orcid") |
|
38 | 33 |
@PreAuthorize("isAuthenticated()") |
39 | 34 |
@CrossOrigin(origins = "*") |
40 | 35 |
public class WorkController { |
... | ... | |
167 | 162 |
workToSave.setOrcid(userOrcid); |
168 | 163 |
workToSave.setCreationDate(date); |
169 | 164 |
workToSave.setUpdateDate(date); |
165 |
workToSave.setDashboard(result.getDashboard()); |
|
170 | 166 |
|
171 | 167 |
HttpHeaders responseHeaders = response.getHeaders(); |
172 | 168 |
String locationPath = responseHeaders.getLocation().toString(); |
Also available in: Unified diff
[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").