Skip to content

Commit

Permalink
Add logging to debug caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhave committed Nov 5, 2024
1 parent 395f8f3 commit 8f57f4f
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/main/java/io/spring/projectapi/github/GithubOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import io.spring.projectapi.github.ProjectDocumentation.Status;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.annotation.Cacheable;
Expand Down Expand Up @@ -78,6 +80,8 @@ public class GithubOperations {

private final String branch;

private static final Logger logger = LoggerFactory.getLogger(GithubOperations.class);

public GithubOperations(RestTemplateBuilder restTemplateBuilder, ObjectMapper objectMapper, String token,
String branch) {
this.restTemplate = restTemplateBuilder.rootUri(GITHUB_URI)
Expand All @@ -95,13 +99,6 @@ private static int compare(ProjectDocumentation o1, ProjectDocumentation o2) {
return -version1.compareTo(version2);
}

@Cacheable(value = "documentation", key = "#projectSlug")
public List<ProjectDocumentation> getProjectDocumentations(String projectSlug) {
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "documentation.json");
String content = getFileContents(response);
return convertToProjectDocumentation(content);
}

public void addProjectDocumentation(String projectSlug, ProjectDocumentation documentation) {
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "documentation.json");
List<ProjectDocumentation> documentations = new ArrayList<>();
Expand Down Expand Up @@ -212,13 +209,15 @@ public void deleteDocumentation(String projectSlug, String version) {
}

private ResponseEntity<Map<String, Object>> getFile(String projectSlug, String fileName) {
logger.info("****In private getFile for project " + projectSlug);
RequestEntity<Void> request = RequestEntity
.get("/project/{projectSlug}/{fileName}?ref=" + this.branch, projectSlug, fileName)
.build();
try {
return this.restTemplate.exchange(request, STRING_OBJECT_MAP);
}
catch (HttpClientErrorException ex) {
logger.info("****In private getFile for project with exception " + projectSlug);
HttpStatusCode statusCode = ex.getStatusCode();
if (statusCode.value() == 404) {
throwIfProjectDoesNotExist(projectSlug);
Expand Down Expand Up @@ -256,6 +255,7 @@ private String getFileSha(ResponseEntity<Map<String, Object>> exchange) {
public List<Project> getProjects() {
List<Project> projects = new ArrayList<>();
try {
logger.info("****In getProjects");
RequestEntity<Void> request = RequestEntity.get("/project?ref=" + this.branch).build();
ResponseEntity<List<Map<String, Object>>> exchange = this.restTemplate.exchange(request,
STRING_OBJECT_MAP_LIST);
Expand All @@ -279,6 +279,7 @@ public List<Project> getProjects() {

@Cacheable(value = "project", key = "#projectSlug")
public Project getProject(String projectSlug) {
logger.info("****In getProject with project " + projectSlug);
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "index.md");
String contents = getFileContents(response);
Map<String, String> frontMatter = MarkdownUtils.getFrontMatter(contents);
Expand All @@ -287,8 +288,17 @@ public Project getProject(String projectSlug) {
return this.objectMapper.convertValue(frontMatter, Project.class);
}

@Cacheable(value = "documentation", key = "#projectSlug")
public List<ProjectDocumentation> getProjectDocumentations(String projectSlug) {
logger.info("****In getProjectDocumentations with project " + projectSlug);
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "documentation.json");
String content = getFileContents(response);
return convertToProjectDocumentation(content);
}

@Cacheable(value = "support", key = "#projectSlug")
public List<ProjectSupport> getProjectSupports(String projectSlug) {
logger.info("****In getProjectSupports with project " + projectSlug);
ResponseEntity<Map<String, Object>> response = getFile(projectSlug, "support.json");
if (response == null) {
return Collections.emptyList();
Expand All @@ -306,6 +316,7 @@ public List<ProjectSupport> getProjectSupports(String projectSlug) {

@Cacheable(value = "support_policy", key = "#projectSlug")
public String getProjectSupportPolicy(String projectSlug) {
logger.info("****In getProjectSupportPolicy with project " + projectSlug);
ResponseEntity<Map<String, Object>> indexResponse = getFile(projectSlug, "index.md");
String indexContents = getFileContents(indexResponse);
Map<String, String> frontMatter = MarkdownUtils.getFrontMatter(indexContents);
Expand Down

0 comments on commit 8f57f4f

Please sign in to comment.