Skip to content

Commit

Permalink
#193 Resolve IDE warnings in java source code (#196)
Browse files Browse the repository at this point in the history
* #193 Resolve IDE warnings in java source code

* #193 Bump release version & remove unused enum type
  • Loading branch information
conorheffron authored Dec 30, 2024
1 parent b468576 commit 7f0f3d5
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>conorheffron</groupId>
<artifactId>ironoc</artifactId>
<version>5.5.2</version>
<version>5.5.3</version>
<packaging>war</packaging>

<distributionManagement>
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/net/ironoc/portfolio/aws/AwsSecretManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ public class AwsSecretManager extends AbstractLogger implements SecretManager {
@Override
public String getGitSecret() {
Region region = Region.of(REGION);
SecretsManagerClient client = SecretsManagerClient.builder()
String secret = "";
try (SecretsManagerClient client = SecretsManagerClient.builder()
.region(region)
.build();
GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder()
.secretId(SECRET_NAME_GIT_TOKEN)
.build();
.build()) {
GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder()
.secretId(SECRET_NAME_GIT_TOKEN)
.build();

String secret = "";
try {
GetSecretValueResponse getSecretValueResponse = client.getSecretValue(getSecretValueRequest);
String json = getSecretValueResponse.secretString();

Expand Down
15 changes: 7 additions & 8 deletions src/main/java/net/ironoc/portfolio/client/GitClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import javax.net.ssl.HttpsURLConnection;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -58,7 +58,6 @@ public <T> List<T> callGitHubApi(String apiUri, String uri, Class<T> type, Strin
inputStream = this.readInputStream(conn);
Map<String, List<String>> map = conn.getHeaderFields();
List<String> linkHeader = map.get("Link");
Map<String, String> linkHeaders = new HashMap<>();
if (linkHeader != null && !linkHeader.isEmpty()) {
info("Link.Header: {}", linkHeader);
}
Expand All @@ -80,13 +79,13 @@ public <T> List<T> callGitHubApi(String apiUri, String uri, Class<T> type, Strin
}

private <T> List<T> readJsonResponse(InputStream inputStream, Class<T> type) throws Exception {
List<T> dtos = new ArrayList<>();
List<T> items;
String jsonResponse = convertInputStreamToString(inputStream);
CollectionType listType = objectMapper.getTypeFactory()
.constructCollectionType(ArrayList.class, type);
dtos = objectMapper.readValue(jsonResponse, listType);
debug("List.of(DTO)={}", dtos);
return dtos;
items = objectMapper.readValue(jsonResponse, listType);
debug("List.of(DTO)={}", items);
return items;
}

@Override
Expand All @@ -106,7 +105,7 @@ public HttpsURLConnection createConn(String url, String baseUrl, String httpMeth
conn.setRequestProperty("Authorization", token);
}
conn.setRequestMethod(httpMethod);
conn.setFollowRedirects(propertyConfig.getGitFollowRedirects());
HttpURLConnection.setFollowRedirects(propertyConfig.getGitFollowRedirects());
conn.setConnectTimeout(propertyConfig.getGitTimeoutConnect());
conn.setReadTimeout(propertyConfig.getGitTimeoutRead());
conn.setInstanceFollowRedirects(propertyConfig.getGitInstanceFollowRedirects());
Expand All @@ -123,7 +122,7 @@ public void closeConn(InputStream inputStream) throws IOException {
inputStream.close();
}

String convertInputStreamToString(InputStream inputStream) throws Exception {
protected String convertInputStreamToString(InputStream inputStream) throws Exception {
return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public List<String> getGitApiEndpointProjectsCache() {
return extractValues(projects);
}

@Override
public boolean isCacheJobEnabled() {
return Boolean.parseBoolean(environment.getRequiredProperty(propertyKey.isCacheJobEnabled()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ private ResponseEntity<List<RepositoryIssueDomain>> getIssuesByUsernameAndRepo(H
String username,
String repository) {
// user & repo name validation (must contain only letters, numbers and/or dash chars)
String userId = "";
String repo = "";
String userId;
String repo;
if (!StringUtils.isNoneBlank(username, repository)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Collections.emptyList());
} else if (!StringUtils.isAlphanumericSpace(sanitizeValue(username)
Expand Down Expand Up @@ -103,7 +103,7 @@ private ResponseEntity<List<RepositoryIssueDomain>> getIssuesByUsernameAndRepo(H
private ResponseEntity<List<RepositoryDetailDomain>> getReposByUsername(HttpServletRequest request,
String username) {
// username validation (must contain only letters, numbers and/or dash chars)
String userId = "";
String userId;
if (StringUtils.isBlank(username)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Collections.emptyList());
} else if (!StringUtils.isAlphanumericSpace(sanitizeValue(username)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@
@Getter
public class RepositoryDetailDomain {

@Schema(name= "name", description = "Name of GitHub Repository.", example = "ironoc-db", required = true)
@Schema(name= "name", description = "Name of GitHub Repository.", example = "ironoc-db",
requiredMode = Schema.RequiredMode.REQUIRED)
private String name;

@Schema(name= "fullName", description = "Full Name of GitHub Repository (Format is: username/project_name).",
example = "conorheffron/ironoc-db", required = true)
example = "conorheffron/ironoc-db", requiredMode = Schema.RequiredMode.REQUIRED)
private String fullName;

@Schema(name= "description", description = "Description of GitHub project.", example = "Personal Portfolio Website.",
required = false)
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String description;

@Schema(name= "appHome", description = "Normally this value is the link to the project/app home page.",
example = "http://ironoc.com", required = false)
example = "http://ironoc.com", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String appHome;

@Schema(name = "repoUrl", description = "This is the home page URL of the project.",
example = "https://github.com/conorheffron/ironoc-db", required = true)
example = "https://github.com/conorheffron/ironoc-db", requiredMode = Schema.RequiredMode.REQUIRED)
private String repoUrl;

@Schema(name = "topics", description = "Labels or topics associated with the GitHub repository project.",
example = "[aws, jdk21, maven, personal, portfolio, spring-boot-3]", required = false)
example = "[aws, jdk21, maven, personal, portfolio, spring-boot-3]", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String topics;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
public class RepositoryIssueDomain {

@Schema(name= "number", description = "Project Issue Number.",
example = "45", required = true)
example = "45", requiredMode = Schema.RequiredMode.REQUIRED)
private String number;

@Schema(name= "title", description = "Issue Title Text.",
example = "The UI is not rendering the GitHub Repo Details View", required = true)
example = "The UI is not rendering the GitHub Repo Details View", requiredMode = Schema.RequiredMode.REQUIRED)
private String title;

@Schema(name= "body", description = "Issue Content & Description.",
example = "The app crashes when I visit the Repo Details View", required = false)
example = "The app crashes when I visit the Repo Details View", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String body;
}
2 changes: 1 addition & 1 deletion src/main/java/net/ironoc/portfolio/dto/OwnerDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Data
@NoArgsConstructor
@ToString(includeFieldNames = true)
@ToString()
@Builder
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void run() {

for(String project : getProjects()) {
List<RepositoryIssueDto> issuesDtos = gitDetails.getIssues(userId, project);
info("Running GIT details job for userIds={}, project={}, repositoryDetailDtos={}", userId,
info("Running GIT details job for userIds={}, project={}, issuesDtos={}", userId,
project, issuesDtos);
if (issuesDtos != null && !issuesDtos.isEmpty()) {
gitProjectCache.remove(userId + project);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ironoc.portfolio.resolver;

import org.springframework.lang.Nullable;
import net.ironoc.portfolio.logger.AbstractLogger;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.core.io.ClassPathResource;
Expand Down Expand Up @@ -27,14 +28,14 @@ public PushStateResourceResolver(List<String> handledExtensions, List<String> ig
}

@Override
public Resource resolveResource(HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain) {
public Resource resolveResource(@Nullable HttpServletRequest request, @Nullable String requestPath,
@Nullable List<? extends Resource> locations, @Nullable ResourceResolverChain chain) {
return resolve(requestPath, locations);
}

@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations,
ResourceResolverChain chain) {
public String resolveUrlPath(@Nullable String resourcePath, @Nullable List<? extends Resource> locations,
@Nullable ResourceResolverChain chain) {
Resource resolvedResource = resolve(resourcePath, locations);
if (resolvedResource == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public GitDetailsService(PropertyConfigI propertyConfig,
this.urlUtils = urlUtils;
this.gitRepoCache = gitRepoCache;
this.gitProjectCache = gitProjectCache;
; }
}

@Override
public List<RepositoryDetailDto> getRepoDetails(String username) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/ironoc/portfolio/utils/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import net.ironoc.portfolio.logger.AbstractLogger;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.net.URL;

@Component
public class UrlUtils extends AbstractLogger {

public boolean isValidURL(String urlString) {
try {
URL url = new URL(urlString);
URL url = URI.create(urlString).toURL();
url.toURI();
return true;
} catch (Exception e) {
Expand Down

0 comments on commit 7f0f3d5

Please sign in to comment.