Enhance code readability by improving comments, formatting, and aligning annotations across classes.
This commit is contained in:
@@ -34,7 +34,7 @@ abstract class CfBasicHttpClient {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
CfBasicHttpClient(String baseUrl, String authEmail, String authKey)
|
||||
throws IllegalArgumentException {
|
||||
throws IllegalArgumentException {
|
||||
if (authEmail == null || authEmail.isBlank()) {
|
||||
throw new IllegalArgumentException("Authentication email must not be null or blank!");
|
||||
}
|
||||
@@ -60,12 +60,12 @@ abstract class CfBasicHttpClient {
|
||||
|
||||
private <T extends AbstractResponse> T executeRequest(ClassicHttpRequest request,
|
||||
Class<T> responseType)
|
||||
throws CloudflareApiException {
|
||||
throws CloudflareApiException {
|
||||
String logUri = null;
|
||||
try (CloseableHttpClient client = createHttpClient()) {
|
||||
ResultWrapper result = client.execute(request,
|
||||
(ClassicHttpResponse response) -> new ResultWrapper(response.getCode(),
|
||||
EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)));
|
||||
(ClassicHttpResponse response) -> new ResultWrapper(response.getCode(),
|
||||
EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)));
|
||||
|
||||
|
||||
T respObj = objectMapper.readValue(result.responseBody, responseType);
|
||||
@@ -79,9 +79,9 @@ abstract class CfBasicHttpClient {
|
||||
return respObj;
|
||||
} else {
|
||||
log.error("{} request failed for URL {}: Status {}", request.getMethod(), request.getUri(),
|
||||
result.statusCode);
|
||||
result.statusCode);
|
||||
throw new CloudflareApiException(
|
||||
request.getMethod() + " request failed with status code: " + result.statusCode);
|
||||
request.getMethod() + " request failed with status code: " + result.statusCode);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("JSON parsing error for request to {}", logUri, e);
|
||||
@@ -95,7 +95,7 @@ abstract class CfBasicHttpClient {
|
||||
* Sends a GET request to the given endpoint and maps the response.
|
||||
*/
|
||||
<T extends AbstractResponse> T getRequest(String endpoint, Class<T> responseType)
|
||||
throws CloudflareApiException {
|
||||
throws CloudflareApiException {
|
||||
HttpGet request = new HttpGet(buildUrl(endpoint));
|
||||
return executeRequest(request, responseType);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ abstract class CfBasicHttpClient {
|
||||
<T extends AbstractResponse> T postRequest(String endpoint,
|
||||
Object requestPayload,
|
||||
Class<T> responseType)
|
||||
throws CloudflareApiException {
|
||||
throws CloudflareApiException {
|
||||
HttpPost request = new HttpPost(buildUrl(endpoint));
|
||||
setRequestPayload(request, requestPayload);
|
||||
return executeRequest(request, responseType);
|
||||
@@ -127,7 +127,7 @@ abstract class CfBasicHttpClient {
|
||||
<T extends AbstractResponse> T putRequest(String endpoint,
|
||||
Object requestPayload,
|
||||
Class<T> responseType)
|
||||
throws CloudflareApiException {
|
||||
throws CloudflareApiException {
|
||||
HttpPut request = new HttpPut(buildUrl(endpoint));
|
||||
setRequestPayload(request, requestPayload);
|
||||
return executeRequest(request, responseType);
|
||||
@@ -138,7 +138,7 @@ abstract class CfBasicHttpClient {
|
||||
*/
|
||||
<T extends AbstractResponse> T patchRequest(String endpoint,
|
||||
Object requestPayload)
|
||||
throws CloudflareApiException {
|
||||
throws CloudflareApiException {
|
||||
HttpPatch request = new HttpPatch(buildUrl(endpoint));
|
||||
setRequestPayload(request, requestPayload);
|
||||
return executeRequest(request, (Class<T>) codes.thischwa.cf.model.RecordSingleResponse.class);
|
||||
@@ -149,12 +149,12 @@ abstract class CfBasicHttpClient {
|
||||
*/
|
||||
private void setRequestPayload(BasicClassicHttpRequest request,
|
||||
Object requestPayload)
|
||||
throws CloudflareApiException {
|
||||
throws CloudflareApiException {
|
||||
try {
|
||||
String jsonPayload = objectMapper.writeValueAsString(requestPayload);
|
||||
log.debug("Request payload: {}", jsonPayload);
|
||||
request.setEntity(new StringEntity(jsonPayload,
|
||||
ContentType.APPLICATION_JSON));
|
||||
ContentType.APPLICATION_JSON));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new CloudflareApiException("Error serializing JSON payload", e);
|
||||
}
|
||||
|
||||
@@ -106,6 +106,10 @@ public class CfDnsClient extends CfBasicHttpClient {
|
||||
this.responseValidator = new ResponseValidator(emptyResultThrowsException);
|
||||
}
|
||||
|
||||
private static String buildFqdn(ZoneEntity zone, String sld) {
|
||||
return sld + "." + zone.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of all zones from the Cloudflare API.
|
||||
*
|
||||
@@ -376,10 +380,6 @@ public class CfDnsClient extends CfBasicHttpClient {
|
||||
checkResponse(resp);
|
||||
}
|
||||
|
||||
private static String buildFqdn(ZoneEntity zone, String sld) {
|
||||
return sld + "." + zone.getName();
|
||||
}
|
||||
|
||||
private void checkResponse(AbstractResponse resp) throws CloudflareApiException {
|
||||
checkResponse(resp, false);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum CfRequest {
|
||||
|
||||
/** Represents the API endpoint path for retrieving the list of DNS zones. */
|
||||
/**
|
||||
* Represents the API endpoint path for retrieving the list of DNS zones.
|
||||
*/
|
||||
ZONE_LIST("/zones"),
|
||||
/**
|
||||
* Represents the API endpoint path for retrieving information about a specific DNS zone by its
|
||||
@@ -69,7 +71,7 @@ public enum CfRequest {
|
||||
* arguments.
|
||||
*
|
||||
* @param vars the arguments to format the path string with; these are typically specific
|
||||
* identifiers or parameters required by the API endpoint.
|
||||
* identifiers or parameters required by the API endpoint.
|
||||
* @return the fully constructed API endpoint path as a string.
|
||||
*/
|
||||
String buildPath(Object... vars) {
|
||||
|
||||
@@ -7,7 +7,8 @@ import java.io.Serial;
|
||||
*/
|
||||
public class CloudflareApiException extends Exception {
|
||||
|
||||
@Serial private static final long serialVersionUID = 1L;
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructs a new CloudflareApiException with the specified detail message.
|
||||
@@ -22,9 +23,9 @@ public class CloudflareApiException extends Exception {
|
||||
* Constructs a new CloudflareApiException with the specified detail message and cause.
|
||||
*
|
||||
* @param message the detail message, which provides additional context or information about the
|
||||
* exception.
|
||||
* @param cause the cause of this exception, which is the underlying throwable that triggered this
|
||||
* exception.
|
||||
* exception.
|
||||
* @param cause the cause of this exception, which is the underlying throwable that triggered this
|
||||
* exception.
|
||||
*/
|
||||
public CloudflareApiException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
||||
@@ -13,7 +13,7 @@ public class CloudflareNotFoundException extends CloudflareApiException {
|
||||
* Constructs a new CloudflareNotFoundException with the specified detail message.
|
||||
*
|
||||
* @param message the detail message, which provides additional context about the "not found"
|
||||
* error encountered during interaction with the Cloudflare API.
|
||||
* error encountered during interaction with the Cloudflare API.
|
||||
*/
|
||||
public CloudflareNotFoundException(String message) {
|
||||
super(message);
|
||||
@@ -23,9 +23,9 @@ public class CloudflareNotFoundException extends CloudflareApiException {
|
||||
* Constructs a new CloudflareNotFoundException with the specified detail message and cause.
|
||||
*
|
||||
* @param message the detail message, which provides additional context about the "not found"
|
||||
* error encountered during interaction with the Cloudflare API.
|
||||
* @param cause the cause of this exception, which is the underlying throwable that triggered this
|
||||
* exception.
|
||||
* error encountered during interaction with the Cloudflare API.
|
||||
* @param cause the cause of this exception, which is the underlying throwable that triggered this
|
||||
* exception.
|
||||
*/
|
||||
public CloudflareNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
||||
@@ -24,7 +24,7 @@ import lombok.EqualsAndHashCode;
|
||||
* <p>Subclasses can be created by specifying the entity type that the response should handle.
|
||||
*
|
||||
* @param <T> Represents the type of entities contained within the response. For this class, it is
|
||||
* expected to be {@code ResponseEntity}.
|
||||
* expected to be {@code ResponseEntity}.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
package codes.thischwa.cf.model;
|
||||
|
||||
/**
|
||||
* Represents a response that contains a single {@link BatchEntry} as the result.
|
||||
*
|
||||
* <p>This class is used for API responses where the primary result is a batch entry,
|
||||
* which includes collections of operations such as patches, posts, puts, and deletes
|
||||
* performed on DNS record entities.
|
||||
*
|
||||
* <p>Extends {@code AbstractSingleResponse} with {@code BatchEntry} as the generic type,
|
||||
* ensuring that the response result is a batch of operations.
|
||||
*/
|
||||
public class BatchResponse extends AbstractSingleResponse<BatchEntry> {
|
||||
|
||||
BatchResponse() {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PagingRequest {
|
||||
/**
|
||||
* Creates a new {@code PagingRequest} instance with the specified page number and items per page.
|
||||
*
|
||||
* @param page the page number to be requested
|
||||
* @param page the page number to be requested
|
||||
* @param perPage the number of items to be included per page
|
||||
* @return a new {@code PagingRequest} instance with the provided parameters
|
||||
*/
|
||||
|
||||
@@ -34,10 +34,14 @@ public class RecordEntity extends AbstractEntity {
|
||||
private Boolean proxied;
|
||||
private Integer ttl;
|
||||
private Boolean locked;
|
||||
@Nullable private String zoneId;
|
||||
@Nullable private String zoneName;
|
||||
@Nullable private LocalDateTime modifiedOn;
|
||||
@Nullable private LocalDateTime createdOn;
|
||||
@Nullable
|
||||
private String zoneId;
|
||||
@Nullable
|
||||
private String zoneName;
|
||||
@Nullable
|
||||
private LocalDateTime modifiedOn;
|
||||
@Nullable
|
||||
private LocalDateTime createdOn;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the RecordEntity class and invokes the parent constructor from
|
||||
@@ -52,9 +56,9 @@ public class RecordEntity extends AbstractEntity {
|
||||
/**
|
||||
* Builds and returns a {@link RecordEntity} instance with the specified attributes.
|
||||
*
|
||||
* @param name the name of the DNS record
|
||||
* @param type the {@link RecordType} of the DNS record
|
||||
* @param ttl the time-to-live (TTL) value for the DNS record
|
||||
* @param name the name of the DNS record
|
||||
* @param type the {@link RecordType} of the DNS record
|
||||
* @param ttl the time-to-live (TTL) value for the DNS record
|
||||
* @param content the content of the DNS record, typically an IP address
|
||||
* @return a {@link RecordEntity} populated with the provided attributes
|
||||
*/
|
||||
@@ -81,6 +85,16 @@ public class RecordEntity extends AbstractEntity {
|
||||
return rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link RecordEntity} instance with the specified attributes.
|
||||
*
|
||||
* @param id the unique identifier for the DNS record
|
||||
* @param name the name of the DNS record
|
||||
* @param type the type of the DNS record, represented as a string (e.g., "A", "CNAME")
|
||||
* @param ttl the time-to-live (TTL) value for the DNS record
|
||||
* @param content the content of the DNS record, typically an IP address or other record data
|
||||
* @return a {@link RecordEntity} populated with the provided attributes
|
||||
*/
|
||||
public static RecordEntity build(String id, String name, String type, Integer ttl, String content) {
|
||||
RecordEntity rec = build(name, RecordType.valueOf(type), ttl, content);
|
||||
rec.setId(id);
|
||||
|
||||
@@ -21,14 +21,34 @@ public class ResponseResultInfo {
|
||||
private List<Error> errors;
|
||||
private List<String> messages;
|
||||
|
||||
/**
|
||||
* Represents an error with a specific code and message.
|
||||
*
|
||||
* <p>This class is used to encapsulate error information, including a numerical error code
|
||||
* and a corresponding descriptive message. It is often used as part of a collection of errors
|
||||
* to provide detailed diagnostics for failed operations or processes.
|
||||
*/
|
||||
@Data
|
||||
public static class Error {
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the {@code Error} class with default values for its properties.
|
||||
*
|
||||
* <p>This no-argument constructor initializes an {@code Error} object without setting
|
||||
* specific values for the error code or message. It is primarily used when an error needs to
|
||||
* be created and set up later, or when default values are acceptable.
|
||||
*/
|
||||
public Error() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of the {@code Error} class with a specified error code and message.
|
||||
*
|
||||
* @param code the numerical code representing the error
|
||||
* @param message the descriptive message providing details about the error
|
||||
*/
|
||||
public Error(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package codes.thischwa.cf.model;
|
||||
|
||||
/** Represents a response model that contains multiple {@link ZoneEntity} instances. */
|
||||
/**
|
||||
* Represents a response model that contains multiple {@link ZoneEntity} instances.
|
||||
*/
|
||||
public class ZoneMultipleResponse extends AbstractMultipleResponse<ZoneEntity> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
/** The model of CloudflareDNS-java. */
|
||||
/**
|
||||
* The model of CloudflareDNS-java.
|
||||
*/
|
||||
|
||||
package codes.thischwa.cf.model;
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
/** The base package of CloudflareDNS-java. */
|
||||
/**
|
||||
* The base package of CloudflareDNS-java.
|
||||
*/
|
||||
|
||||
package codes.thischwa.cf;
|
||||
Reference in New Issue
Block a user