Revision 57503
Added by Konstantina Galouni over 4 years ago
modules/uoa-monitor-service/trunk/src/main/resources/application.properties | ||
---|---|---|
1 |
#mongodb |
|
2 |
#beta |
|
3 |
#spring.data.mongodb.host=beta.services.openaire.eu |
|
4 |
#spring.data.mongodb.port=27017 |
|
5 |
#spring.data.mongodb.database=openairemonitor |
|
6 |
|
|
7 |
#production |
|
8 |
#spring.data.mongodb.host=localhost |
|
9 |
#spring.data.mongodb.port=27017 |
|
10 |
#spring.data.mongodb.database=openairemonitor |
|
11 |
#spring.data.mongodb.authentication-database=openairemonitor |
|
12 |
#spring.data.mongodb.username=dnet8480 |
|
13 |
#spring.data.mongodb.password=... |
|
14 |
|
|
15 |
|
|
16 |
#dev |
|
17 |
spring.data.mongodb.host=localhost |
|
18 |
spring.data.mongodb.port=27017 |
|
19 |
spring.data.mongodb.database=openaire_monitor |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/handlers/ExceptionsHandler.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.handlers; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.responses.ExceptionResponse; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.springframework.data.crossstore.ChangeSetPersister; |
|
6 |
import org.springframework.http.HttpStatus; |
|
7 |
import org.springframework.http.ResponseEntity; |
|
8 |
import org.springframework.web.bind.MissingServletRequestParameterException; |
|
9 |
import org.springframework.web.bind.annotation.ControllerAdvice; |
|
10 |
import org.springframework.web.bind.annotation.ExceptionHandler; |
|
11 |
import org.springframework.web.bind.annotation.RestController; |
|
12 |
|
|
13 |
@ControllerAdvice |
|
14 |
@RestController |
|
15 |
public class ExceptionsHandler { |
|
16 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
17 |
|
|
18 |
@ExceptionHandler(MissingServletRequestParameterException.class) |
|
19 |
public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) { |
|
20 |
ExceptionResponse response = new ExceptionResponse(); |
|
21 |
response.setErrorCode("Validation Error"); |
|
22 |
response.setErrorMessage("Invalid inputs."); |
|
23 |
response.setErrors(ex.getMessage()); |
|
24 |
response.setStatus(HttpStatus.BAD_REQUEST); |
|
25 |
log.debug("invalidInput exception"); |
|
26 |
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST); |
|
27 |
} |
|
28 |
|
|
29 |
@ExceptionHandler(NullPointerException.class) |
|
30 |
public ResponseEntity<ExceptionResponse> nullPointerException(Exception ex) { |
|
31 |
ExceptionResponse response = new ExceptionResponse(); |
|
32 |
response.setErrorCode("Null pointer Exception"); |
|
33 |
response.setErrorMessage("Null pointer Exception"); |
|
34 |
response.setErrors(ex.getMessage()); |
|
35 |
response.setStatus(HttpStatus.BAD_REQUEST); |
|
36 |
log.debug("nullPointerException exception"); |
|
37 |
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST); |
|
38 |
} |
|
39 |
|
|
40 |
@ExceptionHandler(ChangeSetPersister.NotFoundException.class) |
|
41 |
public ResponseEntity<ExceptionResponse> notFoundException(Exception ex) { |
|
42 |
ExceptionResponse response = new ExceptionResponse(); |
|
43 |
response.setErrorCode("Not found Exception"); |
|
44 |
response.setErrorMessage("Not found Exception"); |
|
45 |
response.setErrors(ex.getMessage()); |
|
46 |
response.setStatus(HttpStatus.NOT_FOUND); |
|
47 |
log.debug("notFoundException exception"); |
|
48 |
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND); |
|
49 |
} |
|
50 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/AuthorizationUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.handlers.utils; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
|
|
5 |
import javax.servlet.http.Cookie; |
|
6 |
import javax.servlet.http.HttpServletRequest; |
|
7 |
import java.io.BufferedReader; |
|
8 |
import java.io.InputStreamReader; |
|
9 |
import java.io.StringReader; |
|
10 |
import java.net.HttpURLConnection; |
|
11 |
import java.net.URL; |
|
12 |
import java.util.Enumeration; |
|
13 |
|
|
14 |
import com.google.gson.Gson; |
|
15 |
|
|
16 |
public class AuthorizationUtils { |
|
17 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
18 |
private String userInfoUrl = null; |
|
19 |
// private String communityAPI =""; |
|
20 |
// List<String> adminRoles = new ArrayList<String>(Arrays.asList("Super Administrator", "Portal Administrator")); |
|
21 |
private String originServer= null; |
|
22 |
public Boolean checkCookies(HttpServletRequest request){ |
|
23 |
Boolean valid = true; |
|
24 |
String cookieValue = this.getCookie(request,"AccessToken"); |
|
25 |
if(cookieValue == null || cookieValue.isEmpty()){ |
|
26 |
log.info("no cookie available "); |
|
27 |
valid = false; |
|
28 |
}else { |
|
29 |
String headerValue = this.getHeadersInfo(request, "x-xsrf-token"); |
|
30 |
if(headerValue == null || headerValue.isEmpty()){ |
|
31 |
log.info("no header available "); |
|
32 |
valid = false; |
|
33 |
}else{ |
|
34 |
if(!cookieValue.equals(headerValue)){ |
|
35 |
log.info("no proper header or cookie "); |
|
36 |
valid = false; |
|
37 |
}else if(!hasValidOrigin(this.getHeadersInfo(request, "origin"))){ |
|
38 |
log.info("no proper origin "); |
|
39 |
valid = false; |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
return valid; |
|
44 |
} |
|
45 |
public String getToken(HttpServletRequest request){ |
|
46 |
return this.getHeadersInfo(request, "x-xsrf-token"); |
|
47 |
} |
|
48 |
private String getCookie(HttpServletRequest request, String cookieName){ |
|
49 |
if(request.getCookies() == null){ |
|
50 |
return null; |
|
51 |
} |
|
52 |
for(Cookie c: request.getCookies()){ |
|
53 |
// log.debug("cookie "+ c.getName()+ " "+ c.getValue()); |
|
54 |
if(c.getName().equals(cookieName)){ |
|
55 |
return c.getValue(); |
|
56 |
} |
|
57 |
|
|
58 |
} |
|
59 |
return null; |
|
60 |
} |
|
61 |
private String getHeadersInfo(HttpServletRequest request, String name) { |
|
62 |
|
|
63 |
Enumeration headerNames = request.getHeaderNames(); |
|
64 |
while (headerNames.hasMoreElements()) { |
|
65 |
String key = (String) headerNames.nextElement(); |
|
66 |
String value = request.getHeader(key); |
|
67 |
// log.debug(" key: "+ key+" value: "+ value); |
|
68 |
if(name.equals(key)){ |
|
69 |
return value; |
|
70 |
} |
|
71 |
} |
|
72 |
return null; |
|
73 |
} |
|
74 |
public boolean hasValidOrigin(String origin) { |
|
75 |
if (origin != null && origin.indexOf(originServer)!=-1) { |
|
76 |
return true; |
|
77 |
} |
|
78 |
log.debug("Not valid origin. Origin server is \"" + origin + "\", but expected value is \"" + originServer + "\". If the expec cted value is not right, check properties file. "); |
|
79 |
return false; |
|
80 |
} |
|
81 |
public UserInfo getUserInfo(String accessToken){ |
|
82 |
String url=userInfoUrl+accessToken; |
|
83 |
URL obj = null; |
|
84 |
String responseStr=null; |
|
85 |
// log.debug("User info url is "+url); |
|
86 |
|
|
87 |
try { |
|
88 |
obj = new URL(url); |
|
89 |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
90 |
if (con.getResponseCode() != 200) { |
|
91 |
log.debug("User info response code is: " + con.getResponseCode()); |
|
92 |
return null; |
|
93 |
} |
|
94 |
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
95 |
StringBuffer response = new StringBuffer(); |
|
96 |
String inputLine; |
|
97 |
while ((inputLine = in.readLine()) != null) { |
|
98 |
response.append(inputLine).append("\n"); |
|
99 |
} |
|
100 |
in.close(); |
|
101 |
responseStr = response.toString(); |
|
102 |
}catch(Exception e){ |
|
103 |
log.error("An error occured while trying to fetch user info ",e); |
|
104 |
return null; |
|
105 |
} |
|
106 |
return json2UserInfo(responseStr); |
|
107 |
} |
|
108 |
private UserInfo json2UserInfo(String json) { |
|
109 |
|
|
110 |
// log.debug("Try to create userInfo class from json: "+json); |
|
111 |
if (json == null){ |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
BufferedReader br = new BufferedReader(new StringReader(json)); |
|
116 |
//convert the json string back to object |
|
117 |
Gson gson = new Gson(); |
|
118 |
UserInfo userInfo = null; |
|
119 |
try { |
|
120 |
userInfo = gson.fromJson(br, UserInfo.class); |
|
121 |
}catch(Exception e){ |
|
122 |
log.debug("Error in parsing json response. Given json is : "+json, e); |
|
123 |
return null; |
|
124 |
} |
|
125 |
|
|
126 |
// log.debug("Original response.........: "+userInfo.toString()); |
|
127 |
try { |
|
128 |
if(userInfo != null && userInfo.getEdu_person_entitlements() != null ) { |
|
129 |
|
|
130 |
for (int i = 0; i < userInfo.getEdu_person_entitlements().size(); i++) { |
|
131 |
String role = userInfo.getEdu_person_entitlements().get(i); |
|
132 |
// log.debug("AAI role: "+role); |
|
133 |
role = role.split(":")[role.split(":").length-1]; |
|
134 |
role = role.replace("+"," "); |
|
135 |
// log.debug("Adding parsed role : "+role); |
|
136 |
userInfo.getEdu_person_entitlements().set(i,role); |
|
137 |
} |
|
138 |
} |
|
139 |
}catch(Exception e){ |
|
140 |
log.debug("Error in parsing Edu_person_entitlements : ",e); |
|
141 |
return null; |
|
142 |
} |
|
143 |
// log.debug("After handling roles : "+userInfo.toString()); |
|
144 |
|
|
145 |
|
|
146 |
return userInfo; |
|
147 |
} |
|
148 |
public boolean isAuthorized(String token) { |
|
149 |
UserInfo userInfo = getUserInfo(token); |
|
150 |
if (userInfo != null ) { |
|
151 |
return true; |
|
152 |
} else { |
|
153 |
log.debug(" User has no Valid UserInfo"); |
|
154 |
return false; |
|
155 |
} |
|
156 |
|
|
157 |
} |
|
158 |
|
|
159 |
public String getUserInfoUrl() { |
|
160 |
return userInfoUrl; |
|
161 |
} |
|
162 |
|
|
163 |
public String getOriginServer() { |
|
164 |
return originServer; |
|
165 |
} |
|
166 |
|
|
167 |
public void setUserInfoUrl(String userInfoUrl) { |
|
168 |
this.userInfoUrl = userInfoUrl; |
|
169 |
} |
|
170 |
|
|
171 |
public void setOriginServer(String originServer) { |
|
172 |
this.originServer = originServer; |
|
173 |
} |
|
174 |
// private boolean hasRole(List<String> givenRoles, List<String> authorizedRoles) { |
|
175 |
// log.debug("It's registered with role " + givenRoles); |
|
176 |
// for (String gRole : givenRoles) { |
|
177 |
// if (authorizedRoles.indexOf(gRole) != -1) { |
|
178 |
// return true; |
|
179 |
// } |
|
180 |
// } |
|
181 |
// log.debug("Not Authorized. Authorized roles are" + authorizedRoles); |
|
182 |
// return false; |
|
183 |
// |
|
184 |
// } |
|
185 |
// private boolean isCommunityManager(String community, String email) { |
|
186 |
// |
|
187 |
// CommunityInfo communityInfo = getCommunityInfo(community); |
|
188 |
// if(communityInfo != null && communityInfo.getManagers() != null ) { |
|
189 |
// |
|
190 |
// for (int i = 0; i < communityInfo.getManagers().size(); i++) { |
|
191 |
// String manager = communityInfo.getManagers().get(i); |
|
192 |
// log.debug("Community manager: "+manager); |
|
193 |
// |
|
194 |
// } |
|
195 |
// } |
|
196 |
// return false; |
|
197 |
// |
|
198 |
// } |
|
199 |
// private CommunityInfo getCommunityInfo(String community) { |
|
200 |
// String url = userInfoUrl + community; |
|
201 |
// URL obj = null; |
|
202 |
// String responseStr = null; |
|
203 |
// log.debug("Community info url is " + url); |
|
204 |
// |
|
205 |
// try { |
|
206 |
// obj = new URL(url); |
|
207 |
// HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
208 |
// log.debug("User info response code is: " + con.getResponseCode()); |
|
209 |
// if (con.getResponseCode() != 200) { |
|
210 |
// return null; |
|
211 |
// } |
|
212 |
// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
213 |
// StringBuffer response = new StringBuffer(); |
|
214 |
// String inputLine; |
|
215 |
// while ((inputLine = in.readLine()) != null) { |
|
216 |
// response.append(inputLine).append("\n"); |
|
217 |
// } |
|
218 |
// in.close(); |
|
219 |
// responseStr = response.toString(); |
|
220 |
// } catch (Exception e) { |
|
221 |
// log.error("An error occured while trying to fetch user info ", e); |
|
222 |
// return null; |
|
223 |
// } |
|
224 |
// return json2CommunityInfo(community); |
|
225 |
// } |
|
226 |
// private CommunityInfo json2CommunityInfo(String json){ |
|
227 |
// |
|
228 |
// log.debug("Try to create CommunityInfo class from json: "+json); |
|
229 |
// if (json == null){ |
|
230 |
// return null; |
|
231 |
// } |
|
232 |
// |
|
233 |
// BufferedReader br = new BufferedReader(new StringReader(json)); |
|
234 |
// //convert the json string back to object |
|
235 |
// Gson gson = new Gson(); |
|
236 |
// CommunityInfo communityInfo = null; |
|
237 |
// try { |
|
238 |
// communityInfo = gson.fromJson(br, CommunityInfo.class); |
|
239 |
// }catch(Exception e){ |
|
240 |
// log.debug("Error in parsing json response. Given json is : "+json, e); |
|
241 |
// return null; |
|
242 |
// } |
|
243 |
// |
|
244 |
// log.debug("Original response.........: "+communityInfo.toString()); |
|
245 |
// |
|
246 |
// |
|
247 |
// |
|
248 |
// return communityInfo; |
|
249 |
// } |
|
250 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/UserInfo.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.handlers.utils; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
public class UserInfo { |
|
7 |
String name; |
|
8 |
String email; |
|
9 |
List<String> edu_person_entitlements = new ArrayList<String>(); |
|
10 |
|
|
11 |
@Override |
|
12 |
public String toString() { |
|
13 |
return "UserInfo{" + |
|
14 |
"name='" + name + '\'' + |
|
15 |
", email='" + email + '\'' + |
|
16 |
", edu_person_entitlements=" + edu_person_entitlements + |
|
17 |
'}'; |
|
18 |
} |
|
19 |
|
|
20 |
public String getName() { |
|
21 |
return name; |
|
22 |
} |
|
23 |
|
|
24 |
public void setName(String name) { |
|
25 |
this.name = name; |
|
26 |
} |
|
27 |
|
|
28 |
public String getEmail() { |
|
29 |
return email; |
|
30 |
} |
|
31 |
|
|
32 |
public void setEmail(String email) { |
|
33 |
this.email = email; |
|
34 |
} |
|
35 |
|
|
36 |
public List<String> getEdu_person_entitlements() { |
|
37 |
return edu_person_entitlements; |
|
38 |
} |
|
39 |
|
|
40 |
public void setEdu_person_entitlements(List<String> edu_person_entitlements) { |
|
41 |
this.edu_person_entitlements = edu_person_entitlements; |
|
42 |
} |
|
43 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/handlers/AuthorizationHandler.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.handlers; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.handlers.utils.AuthorizationUtils; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.springframework.beans.factory.annotation.Value; |
|
6 |
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
|
7 |
|
|
8 |
import javax.servlet.http.HttpServletRequest; |
|
9 |
import javax.servlet.http.HttpServletResponse; |
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
public class AuthorizationHandler extends HandlerInterceptorAdapter { |
|
13 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
14 |
private AuthorizationUtils helper = new AuthorizationUtils(); |
|
15 |
private List<String> allowedPostRequests; |
|
16 |
|
|
17 |
public AuthorizationHandler(String userInfoUrl, String originServer, List<String> allowedPostRequests){ |
|
18 |
helper.setOriginServer(originServer); |
|
19 |
helper.setUserInfoUrl(userInfoUrl); |
|
20 |
this.allowedPostRequests = allowedPostRequests; |
|
21 |
} |
|
22 |
@Override |
|
23 |
public boolean preHandle( |
|
24 |
HttpServletRequest request, |
|
25 |
HttpServletResponse response, |
|
26 |
Object handler) throws Exception { |
|
27 |
// log.debug("request method " + request.getRemoteHost()); |
|
28 |
log.debug("properties: " + helper.getOriginServer() + " "+ helper.getUserInfoUrl()); |
|
29 |
log.debug(allowedPostRequests); |
|
30 |
log.debug(allowedPostRequests.contains(request.getServletPath())); |
|
31 |
log.debug(request.getServletPath()); |
|
32 |
if((request.getMethod().equals("POST") || request.getMethod().equals("DELETE")) && |
|
33 |
!allowedPostRequests.contains(request.getServletPath())) { |
|
34 |
//TODO check domain & check user info |
|
35 |
if(!this.helper.checkCookies(request) || !helper.isAuthorized(helper.getToken(request))){ |
|
36 |
|
|
37 |
response.setHeader("Access-Control-Allow-Credentials","true"); |
|
38 |
response.setHeader("Access-Control-Allow-Origin","*"); |
|
39 |
response.setHeader("Vary","Origin"); |
|
40 |
|
|
41 |
response.setStatus(403); |
|
42 |
response.sendError(403, "Forbidden: You don't have permission to access. Maybe you are not registered."); |
|
43 |
return false; |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
return true; |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
// @Override |
|
52 |
// public void postHandle( |
|
53 |
// HttpServletRequest request, |
|
54 |
// HttpServletResponse response, |
|
55 |
// Object handler, |
|
56 |
// ModelAndView modelAndView) throws Exception { |
|
57 |
// log.info("I am here - postHandle "); |
|
58 |
// } |
|
59 |
// |
|
60 |
// @Override |
|
61 |
// public void afterCompletion( |
|
62 |
// HttpServletRequest request, |
|
63 |
// HttpServletResponse response, |
|
64 |
// Object handler, Exception ex) { |
|
65 |
// log.info("I am here - afterCompletion "); |
|
66 |
// } |
|
67 |
|
|
68 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/responses/ExceptionResponse.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.responses; |
|
2 |
|
|
3 |
import org.springframework.http.HttpStatus; |
|
4 |
|
|
5 |
public class ExceptionResponse { |
|
6 |
private HttpStatus status; |
|
7 |
private String errorCode; |
|
8 |
private String errorMessage; |
|
9 |
private String errors; |
|
10 |
|
|
11 |
public ExceptionResponse() {} |
|
12 |
|
|
13 |
public HttpStatus getStatus() { return status; } |
|
14 |
|
|
15 |
public void setStatus(HttpStatus status) { this.status = status; } |
|
16 |
|
|
17 |
public String getErrorCode() { |
|
18 |
return errorCode; |
|
19 |
} |
|
20 |
|
|
21 |
public void setErrorCode(String errorCode) { |
|
22 |
this.errorCode = errorCode; |
|
23 |
} |
|
24 |
|
|
25 |
public String getErrorMessage() { |
|
26 |
return errorMessage; |
|
27 |
} |
|
28 |
|
|
29 |
public void setErrorMessage(String errorMessage) { |
|
30 |
this.errorMessage = errorMessage; |
|
31 |
} |
|
32 |
|
|
33 |
public String getErrors() { |
|
34 |
return errors; |
|
35 |
} |
|
36 |
|
|
37 |
public void setErrors(String errors) { |
|
38 |
this.errors = errors; |
|
39 |
} |
|
40 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceApplication.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.configuration.properties.GoogleConfig; |
|
4 |
import eu.dnetlib.uoamonitorservice.configuration.properties.MailConfig; |
|
5 |
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig; |
|
6 |
import eu.dnetlib.uoamonitorservice.configuration.properties.SecurityConfig; |
|
7 |
import org.springframework.boot.SpringApplication; |
|
8 |
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|
9 |
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
10 |
import org.springframework.context.annotation.PropertySource; |
|
11 |
import org.springframework.context.annotation.PropertySources; |
|
12 |
|
|
13 |
@SpringBootApplication |
|
14 |
@PropertySources({ |
|
15 |
@PropertySource("classpath:monitorservice.properties"), |
|
16 |
@PropertySource(value = "file:/usr/share/tomcat7/lib/dnet-override.properties", ignoreResourceNotFound = true), |
|
17 |
@PropertySource(value = "file:/var/lib/tomcat_dnet/8380/lib/dnet-override.properties", ignoreResourceNotFound = true) |
|
18 |
|
|
19 |
}) |
|
20 |
|
|
21 |
@EnableConfigurationProperties({SecurityConfig.class, MailConfig.class, GoogleConfig.class, MongoConfig.class}) |
|
22 |
|
|
23 |
public class UoaMonitorServiceApplication { |
|
24 |
public static void main(String[] args) { |
|
25 |
SpringApplication.run(UoaMonitorServiceApplication.class, args); |
|
26 |
} |
|
27 |
|
|
28 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; |
|
4 |
import org.springframework.data.mongodb.repository.MongoRepository; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
public interface MongoDBStakeholderDAO extends StakeholderDAO, MongoRepository<Stakeholder, String> { |
|
9 |
List<Stakeholder> findAll(); |
|
10 |
List<Stakeholder> findByType(String type); |
|
11 |
|
|
12 |
List<Stakeholder> findByIsDefaultProfile(boolean isDefaultProfile); |
|
13 |
List<Stakeholder> findByIsDefaultProfileAndType(boolean isDefaultProfile, String type); |
|
14 |
|
|
15 |
Stakeholder save(Stakeholder stakeholder); |
|
16 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public interface StakeholderDAO { |
|
8 |
List<Stakeholder> findAll(); |
|
9 |
List<Stakeholder> findByType(String type); |
|
10 |
|
|
11 |
List<Stakeholder> findByIsDefaultProfile(boolean isDefaultProfile); |
|
12 |
List<Stakeholder> findByIsDefaultProfileAndType(boolean isDefaultProfile, String type); |
|
13 |
|
|
14 |
Stakeholder save(Stakeholder stakeholder); |
|
15 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.annotation.JsonProperty; |
|
4 |
import org.springframework.data.annotation.Id; |
|
5 |
|
|
6 |
import java.util.Date; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
|
|
10 |
enum StakeholderType |
|
11 |
{ |
|
12 |
// Do not rename or remove existring values. This may cause problems with already stored values in DB |
|
13 |
funder, ri, project, organization; |
|
14 |
} |
|
15 |
|
|
16 |
|
|
17 |
public class Stakeholder { |
|
18 |
@Id |
|
19 |
@JsonProperty("_id") |
|
20 |
private String id; |
|
21 |
|
|
22 |
private StakeholderType type; // private StakeholderType type; |
|
23 |
private String index_id; |
|
24 |
private String index_name; |
|
25 |
private String index_shortName; |
|
26 |
private String alias; |
|
27 |
private boolean isDefaultProfile; |
|
28 |
private boolean isActive; |
|
29 |
private boolean isPublic; |
|
30 |
private Date creationDate; |
|
31 |
private Date updateDate; |
|
32 |
private List<String> managers; |
|
33 |
|
|
34 |
private List<Topic> topics; |
|
35 |
|
|
36 |
public String getId() { |
|
37 |
return id; |
|
38 |
} |
|
39 |
|
|
40 |
public void setId(String id) { |
|
41 |
this.id = id; |
|
42 |
} |
|
43 |
|
|
44 |
public StakeholderType getType() { |
|
45 |
return type; |
|
46 |
} |
|
47 |
|
|
48 |
public void setType(StakeholderType type) { |
|
49 |
this.type = type; |
|
50 |
} |
|
51 |
|
|
52 |
public String getIndex_id() { |
|
53 |
return index_id; |
|
54 |
} |
|
55 |
|
|
56 |
public void setIndex_id(String index_id) { |
|
57 |
this.index_id = index_id; |
|
58 |
} |
|
59 |
|
|
60 |
public String getIndex_name() { |
|
61 |
return index_name; |
|
62 |
} |
|
63 |
|
|
64 |
public void setIndex_name(String index_name) { |
|
65 |
this.index_name = index_name; |
|
66 |
} |
|
67 |
|
|
68 |
public String getIndex_shortName() { |
|
69 |
return index_shortName; |
|
70 |
} |
|
71 |
|
|
72 |
public void setIndex_shortName(String index_shortName) { |
|
73 |
this.index_shortName = index_shortName; |
|
74 |
} |
|
75 |
|
|
76 |
public String getAlias() { |
|
77 |
return alias; |
|
78 |
} |
|
79 |
|
|
80 |
public void setAlias(String alias) { |
|
81 |
this.alias = alias; |
|
82 |
} |
|
83 |
|
|
84 |
public boolean isDefaultProfile() { |
|
85 |
return isDefaultProfile; |
|
86 |
} |
|
87 |
|
|
88 |
public void setDefaultProfile(boolean defaultProfile) { |
|
89 |
isDefaultProfile = defaultProfile; |
|
90 |
} |
|
91 |
|
|
92 |
public boolean isActive() { |
|
93 |
return isActive; |
|
94 |
} |
|
95 |
|
|
96 |
public void setActive(boolean active) { |
|
97 |
isActive = active; |
|
98 |
} |
|
99 |
|
|
100 |
public boolean isPublic() { |
|
101 |
return isPublic; |
|
102 |
} |
|
103 |
|
|
104 |
public void setPublic(boolean aPublic) { |
|
105 |
isPublic = aPublic; |
|
106 |
} |
|
107 |
|
|
108 |
public Date getCreationDate() { |
|
109 |
return creationDate; |
|
110 |
} |
|
111 |
|
|
112 |
public void setCreationDate(Date creationDate) { |
|
113 |
this.creationDate = creationDate; |
|
114 |
} |
|
115 |
|
|
116 |
public Date getUpdateDate() { |
|
117 |
return updateDate; |
|
118 |
} |
|
119 |
|
|
120 |
public void setUpdateDate(Date updateDate) { |
|
121 |
this.updateDate = updateDate; |
|
122 |
} |
|
123 |
|
|
124 |
public List<String> getManagers() { |
|
125 |
return managers; |
|
126 |
} |
|
127 |
|
|
128 |
public void setManagers(List<String> managers) { |
|
129 |
this.managers = managers; |
|
130 |
} |
|
131 |
|
|
132 |
public List<Topic> getTopics() { |
|
133 |
return topics; |
|
134 |
} |
|
135 |
|
|
136 |
public void setTopics(List<Topic> topics) { |
|
137 |
this.topics = topics; |
|
138 |
} |
|
139 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/SubCategory.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class SubCategory { |
|
6 |
private String name; |
|
7 |
private String alias; |
|
8 |
private String description; |
|
9 |
private boolean isActive; |
|
10 |
private boolean isPublic; |
|
11 |
private List<Indicator> charts; |
|
12 |
private List<Indicator> numbers; |
|
13 |
|
|
14 |
public String getName() { |
|
15 |
return name; |
|
16 |
} |
|
17 |
|
|
18 |
public void setName(String name) { |
|
19 |
this.name = name; |
|
20 |
} |
|
21 |
|
|
22 |
public String getAlias() { |
|
23 |
return alias; |
|
24 |
} |
|
25 |
|
|
26 |
public void setAlias(String alias) { |
|
27 |
this.alias = alias; |
|
28 |
} |
|
29 |
|
|
30 |
public String getDescription() { |
|
31 |
return description; |
|
32 |
} |
|
33 |
|
|
34 |
public void setDescription(String description) { |
|
35 |
this.description = description; |
|
36 |
} |
|
37 |
|
|
38 |
public boolean isActive() { |
|
39 |
return isActive; |
|
40 |
} |
|
41 |
|
|
42 |
public void setActive(boolean active) { |
|
43 |
isActive = active; |
|
44 |
} |
|
45 |
|
|
46 |
public boolean isPublic() { |
|
47 |
return isPublic; |
|
48 |
} |
|
49 |
|
|
50 |
public void setPublic(boolean aPublic) { |
|
51 |
isPublic = aPublic; |
|
52 |
} |
|
53 |
|
|
54 |
public List<Indicator> getCharts() { |
|
55 |
return charts; |
|
56 |
} |
|
57 |
|
|
58 |
public void setCharts(List<Indicator> charts) { |
|
59 |
this.charts = charts; |
|
60 |
} |
|
61 |
|
|
62 |
public List<Indicator> getNumbers() { |
|
63 |
return numbers; |
|
64 |
} |
|
65 |
|
|
66 |
public void setNumbers(List<Indicator> numbers) { |
|
67 |
this.numbers = numbers; |
|
68 |
} |
|
69 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
enum IndicatorPathType { |
|
6 |
// Do not rename or remove existring values. This may cause problems with already stored values in DB |
|
7 |
table, bar, column; |
|
8 |
} |
|
9 |
|
|
10 |
public class IndicatorPath { |
|
11 |
private IndicatorPathType type; // for charts is type of chart {table, bar, column, etc} |
|
12 |
private String source; // for numbers is the service {statistics, search, metrics} for charts is the tool {stats-tool,old,metrics, fake} |
|
13 |
private String url; |
|
14 |
private List<String> jsonPath; |
|
15 |
|
|
16 |
public IndicatorPathType getType() { |
|
17 |
return type; |
|
18 |
} |
|
19 |
|
|
20 |
public void setType(IndicatorPathType type) { |
|
21 |
this.type = type; |
|
22 |
} |
|
23 |
|
|
24 |
public String getSource() { |
|
25 |
return source; |
|
26 |
} |
|
27 |
|
|
28 |
public void setSource(String source) { |
|
29 |
this.source = source; |
|
30 |
} |
|
31 |
|
|
32 |
public String getUrl() { |
|
33 |
return url; |
|
34 |
} |
|
35 |
|
|
36 |
public void setUrl(String url) { |
|
37 |
this.url = url; |
|
38 |
} |
|
39 |
|
|
40 |
public List<String> getJsonPath() { |
|
41 |
return jsonPath; |
|
42 |
} |
|
43 |
|
|
44 |
public void setJsonPath(List<String> jsonPath) { |
|
45 |
this.jsonPath = jsonPath; |
|
46 |
} |
|
47 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.annotation.JsonProperty; |
|
4 |
import org.springframework.data.annotation.Id; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
enum IndicatorType { |
|
9 |
// Do not rename or remove existring values. This may cause problems with already stored values in DB |
|
10 |
number, chart; |
|
11 |
} |
|
12 |
|
|
13 |
enum IndicatorWidth { |
|
14 |
// Do not rename or remove existring values. This may cause problems with already stored values in DB |
|
15 |
small, medium, large; |
|
16 |
} |
|
17 |
|
|
18 |
public class Indicator { |
|
19 |
@Id |
|
20 |
@JsonProperty("_id") |
|
21 |
private String id; |
|
22 |
|
|
23 |
private String name; |
|
24 |
private String description; |
|
25 |
private IndicatorType type; //number,chart |
|
26 |
private IndicatorWidth width; //small,medium,large |
|
27 |
private List<String> tags; |
|
28 |
private boolean isActive; |
|
29 |
private boolean isPublic; |
|
30 |
private List<IndicatorPath> indicatorPaths; |
|
31 |
|
|
32 |
public String getId() { |
|
33 |
return id; |
|
34 |
} |
|
35 |
|
|
36 |
public void setId(String id) { |
|
37 |
this.id = id; |
|
38 |
} |
|
39 |
|
|
40 |
public String getName() { |
|
41 |
return name; |
|
42 |
} |
|
43 |
|
|
44 |
public void setName(String name) { |
|
45 |
this.name = name; |
|
46 |
} |
|
47 |
|
|
48 |
public String getDescription() { |
|
49 |
return description; |
|
50 |
} |
|
51 |
|
|
52 |
public void setDescription(String description) { |
|
53 |
this.description = description; |
|
54 |
} |
|
55 |
|
|
56 |
public IndicatorType getType() { |
|
57 |
return type; |
|
58 |
} |
|
59 |
|
|
60 |
public void setType(IndicatorType type) { |
|
61 |
this.type = type; |
|
62 |
} |
|
63 |
|
|
64 |
public IndicatorWidth getWidth() { |
|
65 |
return width; |
|
66 |
} |
|
67 |
|
|
68 |
public void setWidth(IndicatorWidth width) { |
|
69 |
this.width = width; |
|
70 |
} |
|
71 |
|
|
72 |
public List<String> getTags() { |
|
73 |
return tags; |
|
74 |
} |
|
75 |
|
|
76 |
public void setTags(List<String> tags) { |
|
77 |
this.tags = tags; |
|
78 |
} |
|
79 |
|
|
80 |
public boolean isActive() { |
|
81 |
return isActive; |
|
82 |
} |
|
83 |
|
|
84 |
public void setActive(boolean isActive) { |
|
85 |
this.isActive = isActive; |
|
86 |
} |
|
87 |
|
|
88 |
public boolean isPublic() { |
|
89 |
return isPublic; |
|
90 |
} |
|
91 |
|
|
92 |
public void setPublic(boolean isPublic) { |
|
93 |
this.isPublic = isPublic; |
|
94 |
} |
|
95 |
|
|
96 |
public List<IndicatorPath> getNdicatorPaths() { |
|
97 |
return indicatorPaths; |
|
98 |
} |
|
99 |
|
|
100 |
public void setNdicatorPaths(List<IndicatorPath> ndicatorPaths) { |
|
101 |
this.indicatorPaths = ndicatorPaths; |
|
102 |
} |
|
103 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Category.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class Category { |
|
6 |
private String name; |
|
7 |
private String alias; |
|
8 |
private String description; |
|
9 |
private boolean isActive; |
|
10 |
private boolean isPublic; |
|
11 |
private boolean isOverview; |
|
12 |
private List<SubCategory> subCategories; |
|
13 |
|
|
14 |
public String getName() { |
|
15 |
return name; |
|
16 |
} |
|
17 |
|
|
18 |
public void setName(String name) { |
|
19 |
this.name = name; |
|
20 |
} |
|
21 |
|
|
22 |
public String getAlias() { |
|
23 |
return alias; |
|
24 |
} |
|
25 |
|
|
26 |
public void setAlias(String alias) { |
|
27 |
this.alias = alias; |
|
28 |
} |
|
29 |
|
|
30 |
public String getDescription() { |
|
31 |
return description; |
|
32 |
} |
|
33 |
|
|
34 |
public void setDescription(String description) { |
|
35 |
this.description = description; |
|
36 |
} |
|
37 |
|
|
38 |
public boolean isActive() { |
|
39 |
return isActive; |
|
40 |
} |
|
41 |
|
|
42 |
public void setActive(boolean active) { |
|
43 |
isActive = active; |
|
44 |
} |
|
45 |
|
|
46 |
public boolean isPublic() { |
|
47 |
return isPublic; |
|
48 |
} |
|
49 |
|
|
50 |
public void setPublic(boolean aPublic) { |
|
51 |
isPublic = aPublic; |
|
52 |
} |
|
53 |
|
|
54 |
public boolean isOverview() { |
|
55 |
return isOverview; |
|
56 |
} |
|
57 |
|
|
58 |
public void setOverview(boolean overview) { |
|
59 |
isOverview = overview; |
|
60 |
} |
|
61 |
|
|
62 |
public List<SubCategory> getSubCategories() { |
|
63 |
return subCategories; |
|
64 |
} |
|
65 |
|
|
66 |
public void setSubCategories(List<SubCategory> subCategories) { |
|
67 |
this.subCategories = subCategories; |
|
68 |
} |
|
69 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Topic.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class Topic { |
|
6 |
private String name; |
|
7 |
private String alias; |
|
8 |
private String description; |
|
9 |
private boolean isActive; |
|
10 |
private boolean isPublic; |
|
11 |
private List<Category> categories; |
|
12 |
|
|
13 |
public String getName() { |
|
14 |
return name; |
|
15 |
} |
|
16 |
|
|
17 |
public void setName(String name) { |
|
18 |
this.name = name; |
|
19 |
} |
|
20 |
|
|
21 |
public String getAlias() { |
|
22 |
return alias; |
|
23 |
} |
|
24 |
|
|
25 |
public void setAlias(String alias) { |
|
26 |
this.alias = alias; |
|
27 |
} |
|
28 |
|
|
29 |
public String getDescription() { |
|
30 |
return description; |
|
31 |
} |
|
32 |
|
|
33 |
public void setDescription(String description) { |
|
34 |
this.description = description; |
|
35 |
} |
|
36 |
|
|
37 |
public boolean isActive() { |
|
38 |
return isActive; |
|
39 |
} |
|
40 |
|
|
41 |
public void setActive(boolean active) { |
|
42 |
isActive = active; |
|
43 |
} |
|
44 |
|
|
45 |
public boolean isPublic() { |
|
46 |
return isPublic; |
|
47 |
} |
|
48 |
|
|
49 |
public void setPublic(boolean aPublic) { |
|
50 |
isPublic = aPublic; |
|
51 |
} |
|
52 |
|
|
53 |
public List<Category> getCategories() { |
|
54 |
return categories; |
|
55 |
} |
|
56 |
|
|
57 |
public void setCategories(List<Category> categories) { |
|
58 |
this.categories = categories; |
|
59 |
} |
|
60 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceConfiguration.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.configuration.properties.SecurityConfig; |
|
4 |
import eu.dnetlib.uoamonitorservice.handlers.AuthorizationHandler; |
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.context.annotation.Bean; |
|
8 |
import org.springframework.context.annotation.Configuration; |
|
9 |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; |
|
10 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|
11 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
|
12 |
|
|
13 |
@Configuration |
|
14 |
public class UoaMonitorServiceConfiguration extends WebMvcConfigurerAdapter { |
|
15 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
16 |
|
|
17 |
@Autowired |
|
18 |
private SecurityConfig securityConfig; |
|
19 |
|
|
20 |
|
|
21 |
@Bean |
|
22 |
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { |
|
23 |
return new PropertySourcesPlaceholderConfigurer(); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public void addInterceptors(InterceptorRegistry registry) { |
|
28 |
registry.addInterceptor(new AuthorizationHandler(securityConfig.getUserInfoUrl(), securityConfig.getOriginServer(), securityConfig.getPostsAllowed())) |
|
29 |
.addPathPatterns("/**"); |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.controllers; |
|
2 |
|
|
3 |
|
|
4 |
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO; |
|
5 |
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; |
|
6 |
import org.apache.log4j.Logger; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.web.bind.annotation.*; |
|
9 |
|
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
@RestController |
|
13 |
@CrossOrigin(origins = "*") |
|
14 |
public class TestController { |
|
15 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
16 |
|
|
17 |
@Autowired |
|
18 |
private StakeholderDAO stakeholderDAO; |
|
19 |
|
|
20 |
@RequestMapping("/") |
|
21 |
public String index() { |
|
22 |
return "Greetings from Spring Boot!"; |
|
23 |
} |
|
24 |
|
|
25 |
// Check ExceptionHandler |
|
26 |
@RequestMapping(value = "/test-error1", method = RequestMethod.GET) |
|
27 |
public Stakeholder getFirstStakeholder() { |
|
28 |
List<Stakeholder> stakeholders; |
|
29 |
stakeholders = stakeholderDAO.findAll(); |
|
30 |
|
|
31 |
return stakeholders.get(0); |
|
32 |
} |
|
33 |
|
|
34 |
@RequestMapping(value = "/test-error2", method = RequestMethod.GET) |
|
35 |
public String getParam(@RequestParam() String param) { |
|
36 |
return param; |
|
37 |
} |
|
38 |
|
|
39 |
@RequestMapping(value = "/test-error3", method = RequestMethod.GET) |
|
40 |
public String getSubstringOfNull() { |
|
41 |
String str = null; |
|
42 |
return str.substring(2); |
|
43 |
} |
|
44 |
|
|
45 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO; |
|
4 |
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; |
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.web.bind.annotation.*; |
|
8 |
|
|
9 |
import java.text.SimpleDateFormat; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.Date; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
@RestController |
|
15 |
@CrossOrigin(origins = "*") |
|
16 |
public class StakeholderController { |
|
17 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private StakeholderDAO stakeholderDAO; |
|
21 |
|
|
22 |
@RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET) |
|
23 |
public List<Stakeholder> getAllStakeholders(@RequestParam(required = false) String type) { |
|
24 |
List<Stakeholder> stakeholders; |
|
25 |
if(type == null) { |
|
26 |
stakeholders = stakeholderDAO.findAll(); |
|
27 |
} else { |
|
28 |
stakeholders = stakeholderDAO.findByType(type); |
|
29 |
} |
|
30 |
return stakeholders; |
|
31 |
} |
|
32 |
|
|
33 |
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET) |
|
34 |
public List<Stakeholder> getAllDefaultStakeholders(@RequestParam(required = false) String type) { |
|
35 |
List<Stakeholder> stakeholders; |
|
36 |
if(type == null) { |
|
37 |
stakeholders = stakeholderDAO.findByIsDefaultProfile(true); |
|
38 |
} else { |
|
39 |
stakeholders = stakeholderDAO.findByIsDefaultProfileAndType(true, type); |
|
40 |
} |
|
41 |
return stakeholders; |
|
42 |
} |
|
43 |
|
|
44 |
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET) |
|
45 |
public List<Stakeholder> getAllRealStakeholders(@RequestParam(required = false) String type) { |
|
46 |
List<Stakeholder> stakeholders; |
|
47 |
if(type == null) { |
|
48 |
stakeholders = stakeholderDAO.findByIsDefaultProfile(false); |
|
49 |
} else { |
|
50 |
stakeholders = stakeholderDAO.findByIsDefaultProfileAndType(false, type); |
|
51 |
} |
|
52 |
log.debug(new Date()); |
|
53 |
|
|
54 |
return stakeholders; |
|
55 |
} |
|
56 |
|
|
57 |
@RequestMapping(value = "/stakeholder/dates", method = RequestMethod.GET) |
|
58 |
public List<Date> getAllStakeholderDates() { |
|
59 |
List<Stakeholder> profiles = stakeholderDAO.findAll(); |
|
60 |
List<Date> profileDates = new ArrayList<>(); |
|
61 |
|
|
62 |
int i=0; |
|
63 |
for(Stakeholder profile : profiles) { |
|
64 |
log.debug(profile.getCreationDate()); |
|
65 |
profileDates.add(profile.getCreationDate()); |
|
66 |
log.debug(profileDates.get(i)); |
|
67 |
i++; |
|
68 |
} |
|
69 |
return profileDates; |
|
70 |
} |
|
71 |
|
|
72 |
@RequestMapping(value = "/stakeholder/dates1", method = RequestMethod.GET) |
|
73 |
public List<String> getAllStakeholderDates1() { |
|
74 |
List<Stakeholder> profiles = stakeholderDAO.findAll(); |
|
75 |
List<String> profileDates = new ArrayList<>(); |
|
76 |
|
|
77 |
for(Stakeholder profile : profiles) { |
|
78 |
log.debug(profile.getCreationDate().toString()); |
|
79 |
profileDates.add(profile.getCreationDate().toString()); |
|
80 |
} |
|
81 |
return profileDates; |
|
82 |
} |
|
83 |
|
|
84 |
@RequestMapping(value = "/stakeholder/dates2", method = RequestMethod.GET) |
|
85 |
public List<String> getAllStakeholderDates2() { |
|
86 |
List<Stakeholder> profiles = stakeholderDAO.findAll(); |
|
87 |
List<String> profileDates = new ArrayList<>(); |
|
88 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
89 |
|
|
90 |
for(Stakeholder profile : profiles) { |
|
91 |
log.debug(format.format(profile.getCreationDate())); |
|
92 |
profileDates.add(format.format(profile.getCreationDate())); |
|
93 |
} |
|
94 |
return profileDates; |
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
@RequestMapping(value = "/stakeholder/save", method = RequestMethod.POST) |
|
99 |
public Stakeholder insertStakeholder(@RequestBody Stakeholder stakeholder) { |
|
100 |
//Stakeholder stakeholder = new Stakeholder(); |
|
101 |
|
|
102 |
Stakeholder stakeholderSaved = stakeholderDAO.save(stakeholder); |
|
103 |
|
|
104 |
return stakeholderSaved; |
|
105 |
} |
|
106 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.configuration.mongo; |
|
2 |
|
|
3 |
import com.mongodb.MongoClient; |
|
4 |
import com.mongodb.MongoCredential; |
|
5 |
import com.mongodb.ServerAddress; |
|
6 |
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.context.annotation.Bean; |
|
9 |
import org.springframework.context.annotation.Configuration; |
|
10 |
import org.springframework.context.annotation.Primary; |
|
11 |
import org.springframework.data.mongodb.MongoDbFactory; |
|
12 |
import org.springframework.data.mongodb.core.MongoTemplate; |
|
13 |
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; |
|
14 |
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; |
|
15 |
|
|
16 |
import java.util.Collections; |
|
17 |
|
|
18 |
@Configuration |
|
19 |
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoamonitorservice.dao"}) |
|
20 |
public class MongoConnection { |
|
21 |
|
|
22 |
@Autowired |
|
23 |
private MongoConfig mongoConfig; |
|
24 |
|
|
25 |
@Bean |
|
26 |
@Primary |
|
27 |
public MongoDbFactory mongoDbFactory() { |
|
28 |
return new SimpleMongoDbFactory(getMongoClient(), mongoConfig.getDatabase()); |
|
29 |
} |
|
30 |
|
|
31 |
@Bean(name = "mongoTemplate") |
|
32 |
@Primary |
|
33 |
public MongoTemplate getMongoTemplate() { |
|
34 |
return new MongoTemplate(mongoDbFactory()); |
|
35 |
} |
|
36 |
|
|
37 |
private MongoClient getMongoClient() { |
|
38 |
if(mongoConfig.getUsername() != null && mongoConfig.getPassword() != null){ |
|
39 |
return new MongoClient(Collections.singletonList( |
|
40 |
new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort())), |
|
41 |
Collections.singletonList(MongoCredential.createCredential(mongoConfig.getUsername(), mongoConfig.getDatabase(), mongoConfig.getPassword().toCharArray()))); |
|
42 |
} else { |
|
43 |
return new MongoClient(Collections.singletonList(new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort()))); |
|
44 |
} |
|
45 |
} |
|
46 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/GoogleConfig.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.configuration.properties; |
|
2 |
|
|
3 |
import org.springframework.boot.context.properties.ConfigurationProperties; |
|
4 |
|
|
5 |
@ConfigurationProperties("monitorservice.google") |
|
6 |
public class GoogleConfig { |
|
7 |
|
|
8 |
private String secret; |
|
9 |
|
|
10 |
public String getSecret() { |
|
11 |
return secret; |
|
12 |
} |
|
13 |
|
|
14 |
public void setSecret(String secret) { |
|
15 |
this.secret = secret; |
|
16 |
} |
|
17 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MongoConfig.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.configuration.properties; |
|
2 |
|
|
3 |
import org.springframework.boot.context.properties.ConfigurationProperties; |
|
4 |
|
|
5 |
@ConfigurationProperties("monitorservice.mongodb") |
|
6 |
public class MongoConfig { |
|
7 |
|
|
8 |
private String host; |
|
9 |
private String database; |
|
10 |
private String username; |
|
11 |
private String password; |
|
12 |
private int port; |
|
13 |
|
|
14 |
|
|
15 |
public String getHost() { |
|
16 |
return host; |
|
17 |
} |
|
18 |
|
|
19 |
public void setHost(String host) { |
|
20 |
this.host = host; |
|
21 |
} |
|
22 |
|
|
23 |
public String getDatabase() { |
|
24 |
return database; |
|
25 |
} |
|
26 |
|
|
27 |
public void setDatabase(String database) { |
|
28 |
this.database = database; |
|
29 |
} |
|
30 |
|
|
31 |
public String getUsername() { |
|
32 |
return username; |
|
33 |
} |
|
34 |
|
|
35 |
public void setUsername(String username) { |
|
36 |
this.username = username; |
|
37 |
} |
|
38 |
|
|
39 |
public String getPassword() { |
|
40 |
return password; |
|
41 |
} |
|
42 |
|
|
43 |
public void setPassword(String password) { |
|
44 |
this.password = password; |
|
45 |
} |
|
46 |
|
|
47 |
public int getPort() { |
|
48 |
return port; |
|
49 |
} |
|
50 |
|
|
51 |
public void setPort(int port) { |
|
52 |
this.port = port; |
|
53 |
} |
|
54 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MailConfig.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.configuration.properties; |
|
2 |
|
|
3 |
import org.springframework.boot.context.properties.ConfigurationProperties; |
|
4 |
|
|
5 |
@ConfigurationProperties("monitorservice.mail") |
|
6 |
public class MailConfig { |
|
7 |
|
|
8 |
private String host; |
|
9 |
private String port; |
|
10 |
private String auth; |
|
11 |
private String from; |
|
12 |
private String username; |
|
13 |
private String password; |
|
14 |
|
|
15 |
|
|
16 |
public void setHost(String host) { |
|
17 |
this.host = host; |
|
18 |
} |
|
19 |
|
|
20 |
public void setPort(String port) { |
|
21 |
this.port = port; |
|
22 |
} |
|
23 |
|
|
24 |
public void setAuth(String auth) { |
|
25 |
this.auth = auth; |
|
26 |
} |
|
27 |
|
|
28 |
public void setFrom(String from) { |
|
29 |
this.from = from; |
|
30 |
} |
|
31 |
|
|
32 |
public void setUsername(String username) { |
|
33 |
this.username = username; |
|
34 |
} |
|
35 |
|
|
36 |
public void setPassword(String password) { |
|
37 |
this.password = password; |
|
38 |
} |
|
39 |
|
|
40 |
public String getHost() { |
|
41 |
return host; |
|
42 |
} |
|
43 |
|
|
44 |
public String getPort() { |
|
45 |
return port; |
|
46 |
} |
|
47 |
|
|
48 |
public String getAuth() { |
|
49 |
return auth; |
|
50 |
} |
|
51 |
|
|
52 |
public String getFrom() { |
|
53 |
return from; |
|
54 |
} |
|
55 |
|
|
56 |
public String getUsername() { |
|
57 |
return username; |
|
58 |
} |
|
59 |
|
|
60 |
public String getPassword() { |
|
61 |
return password; |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/SecurityConfig.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.configuration.properties; |
|
2 |
|
Also available in: Unified diff
Initial commit for monitor-service.