-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestResource.java
More file actions
71 lines (61 loc) · 2.94 KB
/
RequestResource.java
File metadata and controls
71 lines (61 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package de.tum.cit.aet.dataProcessing.web;
import de.tum.cit.aet.core.security.CryptoService;
import de.tum.cit.aet.dataProcessing.service.RequestService;
import de.tum.cit.aet.repositoryProcessing.dto.TeamRepositoryDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("api/requestResource/")
@Slf4j
public class RequestResource {
private final RequestService requestService;
private final CryptoService cryptoService;
@Autowired
public RequestResource(RequestService requestService, CryptoService cryptoService) {
this.requestService = requestService;
this.cryptoService = cryptoService;
}
/**
* GET endpoint to fetch and clone all repositories.
* Triggers the fetching of participations from Artemis and clones/pulls all repositories.
*
* @param jwtToken The JWT token from the cookie
* @param serverUrl The Artemis server URL from the cookie
* @param username The Artemis username from the cookie (optional)
* @param encryptedPassword The encrypted Artemis password from the cookie (optional)
* @return ResponseEntity containing the list of TeamRepositoryDTO
*/
@GetMapping("fetchAndCloneRepositories")
public ResponseEntity<List<TeamRepositoryDTO>> fetchAndCloneRepositories(
@CookieValue(value = "jwt", required = false) String jwtToken,
@CookieValue(value = "artemis_server_url", required = false) String serverUrl,
@CookieValue(value = "artemis_username", required = false) String username,
@CookieValue(value = "artemis_password", required = false) String encryptedPassword
) {
log.info("GET request received: fetchAndCloneRepositories");
List<TeamRepositoryDTO> repositories;
if (jwtToken != null && serverUrl != null) {
log.info("Using dynamic credentials from cookies");
String password = null;
if (encryptedPassword != null) {
try {
password = cryptoService.decrypt(encryptedPassword);
} catch (Exception e) {
log.error("Failed to decrypt password from cookie", e);
}
}
repositories = requestService.fetchAndCloneRepositories(serverUrl, jwtToken, username, password);
} else {
log.warn("No credentials found in cookies. Authentication required.");
return ResponseEntity.status(401).build();
}
log.info("Successfully fetched and cloned {} repositories", repositories.size());
return ResponseEntity.ok(repositories);
}
}