2020-07-03 12:09:22 +02:00
|
|
|
package eu.dnetlib.organizations.controller;
|
|
|
|
|
2021-11-19 12:14:42 +01:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2020-11-23 12:02:33 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2021-11-19 12:14:42 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2020-11-23 12:02:33 +01:00
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.env.Profiles;
|
|
|
|
import org.springframework.security.core.Authentication;
|
2020-07-03 12:09:22 +02:00
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
2020-11-23 12:02:33 +01:00
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
2022-09-26 14:50:23 +02:00
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
2020-07-03 12:09:22 +02:00
|
|
|
|
2021-11-19 12:14:42 +01:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
2021-01-27 12:17:38 +01:00
|
|
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
2021-09-28 16:05:21 +02:00
|
|
|
import eu.dnetlib.organizations.model.SystemConfiguration;
|
|
|
|
import eu.dnetlib.organizations.repository.SystemConfigurationRepository;
|
2021-01-27 12:17:38 +01:00
|
|
|
|
2020-07-03 12:09:22 +02:00
|
|
|
@Controller
|
2021-01-27 12:17:38 +01:00
|
|
|
public class HomeController extends AbstractDnetController {
|
2020-07-03 12:09:22 +02:00
|
|
|
|
2020-11-23 12:02:33 +01:00
|
|
|
@Autowired
|
|
|
|
private Environment env;
|
|
|
|
|
2021-09-28 16:05:21 +02:00
|
|
|
@Autowired
|
|
|
|
private SystemConfigurationRepository systemConfigurationRepository;
|
|
|
|
|
2022-09-26 14:50:23 +02:00
|
|
|
@Value("${openaire.explore.organization.baseurl}")
|
|
|
|
private String openaireBaseUrl;
|
|
|
|
|
2021-11-19 12:14:42 +01:00
|
|
|
@Value("${openorgs.support.pages}")
|
|
|
|
private String supportPagesJson;
|
|
|
|
|
|
|
|
private Map<String, String> supportPages;
|
|
|
|
|
2020-07-03 12:09:22 +02:00
|
|
|
@GetMapping("/")
|
|
|
|
public String home() {
|
2020-11-23 12:02:33 +01:00
|
|
|
return env.acceptsProfiles(Profiles.of("dev")) ? "redirect:main" : "home";
|
2020-07-03 12:09:22 +02:00
|
|
|
}
|
|
|
|
|
2022-09-26 14:50:23 +02:00
|
|
|
@GetMapping("/redirect/oa/{orgId}")
|
|
|
|
public String openaireUrl(@PathVariable final String orgId) {
|
|
|
|
return "redirect:" + String.format(openaireBaseUrl, orgId);
|
|
|
|
}
|
|
|
|
|
2020-11-04 15:06:34 +01:00
|
|
|
@GetMapping("/main")
|
|
|
|
public String main() {
|
|
|
|
return "main";
|
|
|
|
}
|
|
|
|
|
2020-07-03 12:09:22 +02:00
|
|
|
@GetMapping("/login")
|
|
|
|
public String login() {
|
|
|
|
return "login";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/authorizationRequest")
|
|
|
|
public String authorizationRequest() {
|
|
|
|
return "authorizationRequest";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/alreadyRegistered")
|
|
|
|
public String alreadyRegistered() {
|
|
|
|
return "alreadyRegistered";
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:02:33 +01:00
|
|
|
@ModelAttribute("email")
|
|
|
|
public String getUserEmail(final Authentication authentication) {
|
|
|
|
return authentication != null ? UserInfo.getEmail(authentication) : null;
|
|
|
|
}
|
|
|
|
|
2022-09-21 10:25:48 +02:00
|
|
|
@ModelAttribute("role")
|
|
|
|
public UserRole getUserRole(final Authentication authentication) {
|
|
|
|
return authentication != null ? UserInfo.findRole(authentication) : null;
|
|
|
|
}
|
|
|
|
|
2022-09-19 14:33:22 +02:00
|
|
|
@ModelAttribute("fullname")
|
|
|
|
public String getUserFullname(final Authentication authentication) {
|
2022-09-22 13:53:21 +02:00
|
|
|
return authentication != null ? UserInfo.getFullname(authentication) : "unknown";
|
2022-09-19 14:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@ModelAttribute("organization")
|
|
|
|
public String getUserOrganization(final Authentication authentication) {
|
2022-09-22 13:53:21 +02:00
|
|
|
return authentication != null ? UserInfo.getOrganization(authentication) : "unknown";
|
2022-09-19 14:33:22 +02:00
|
|
|
}
|
|
|
|
|
2021-09-28 16:05:21 +02:00
|
|
|
@ModelAttribute("sysconf")
|
|
|
|
public SystemConfiguration getSysConf(final Authentication authentication) {
|
|
|
|
return systemConfigurationRepository.findById(SystemConfiguration.DEFAULT_ID).get();
|
|
|
|
}
|
|
|
|
|
2021-11-19 12:14:42 +01:00
|
|
|
@ModelAttribute("supportPages")
|
|
|
|
public Map<String, String> supportPages(final Authentication authentication) throws JsonMappingException, JsonProcessingException {
|
|
|
|
if (supportPages == null) {
|
|
|
|
final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
final TypeReference<LinkedHashMap<String, String>> typeRef = new TypeReference<LinkedHashMap<String, String>>() {};
|
|
|
|
this.supportPages = mapper.readValue(supportPagesJson, typeRef);
|
|
|
|
}
|
|
|
|
return supportPages;
|
|
|
|
}
|
|
|
|
|
2020-09-28 16:53:20 +02:00
|
|
|
@GetMapping({
|
2022-08-26 09:39:45 +02:00
|
|
|
"apidoc", "api-doc", "/doc", "/swagger"
|
2020-09-28 16:53:20 +02:00
|
|
|
})
|
2020-07-03 12:09:22 +02:00
|
|
|
public String apiDoc() {
|
2022-08-26 09:39:45 +02:00
|
|
|
return "redirect:swagger-ui/index.html";
|
2020-07-03 12:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|