Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/AccountType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/**
* Type of cardholder account used for the transaction. Allows a cardholder to select the type of
Expand All @@ -37,6 +38,8 @@ public enum AccountType {

UNIVERSAL("Universal");

private static final Logger LOG = Logger.getLogger(AccountType.class.getName());

private String value;

AccountType(String value) {
Expand All @@ -60,6 +63,12 @@ public static AccountType fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but could we use String templating here using String.format?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 11 doesn't have String.formatted() (that's Java 15+), but String.format() works. However, looking at the code more carefully, the concatenation in LOG.warning(...) is the pattern you're pointing at.
The idiomatic Java way for Java 11 would be String.format(...). That said, the concatenation here is fairly readable and there's no performance concern since it only runs on the unexpected-value path.

Looks like we could use String.format(...)., but readability seems not to be an issue. However this change will involve updating the Mustache templates and regenerate all models. Still to be considerred? WDYT @thomasc-adyen

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this, I see now the comment "Approach for centralizing unknown enum handling" 😁

"AccountType: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(AccountType.values()));
return null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change, right? In the past this would have failed and now it will return null - will we update the release notes to document the difference?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, the nexo AccountType uses gson that implements a similar approach, without throwing an exception when the enum is unknown

  public static AccountType fromValue(String v) {
    return Arrays.stream(values()).filter(s -> s.value.equals(v)).findFirst().orElse(null);
  }

Did you mean this change? or am I missing something?

}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/Alignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets Alignment */
public enum Alignment {
Expand All @@ -25,6 +26,8 @@ public enum Alignment {

RIGHT("Right");

private static final Logger LOG = Logger.getLogger(Alignment.class.getName());

private String value;

Alignment(String value) {
Expand All @@ -48,6 +51,12 @@ public static Alignment fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gcatanese if this is not generated, rather than doing this per enum, it would be cleaner to make a generic fromValue helper class that handles this globally for all enums

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we are repeating this across all enums, so centralizing it in one class will help with maintainability and consistency longer-term

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also remove the Logger from enum classes, which feels beneficial although I can't articulate why 😆

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tapi is using the same templates as all other APIs, so we would need to update the templates and re-generate all models. Maybe could be an improvement to follow up?

I think the Logger is necessary because the application doesn't get a value for the enum (only null), the Logger is the only way to avoid this happening silently (in an ideal world we would never do that, but rather throw an exception). This helps merchant to figure our what happens.
An alternative is to move the serialization/deserialization code outside the enum (in a supporting class?), again adjusting templates and regenerating.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this, I see now the comment below 😁

"Alignment: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(Alignment.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/CharacterHeight.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets CharacterHeight */
public enum CharacterHeight {
Expand All @@ -23,6 +24,8 @@ public enum CharacterHeight {

SINGLE_HEIGHT("SingleHeight");

private static final Logger LOG = Logger.getLogger(CharacterHeight.class.getName());

private String value;

CharacterHeight(String value) {
Expand All @@ -46,6 +49,12 @@ public static CharacterHeight fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"CharacterHeight: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(CharacterHeight.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/CharacterStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets CharacterStyle */
public enum CharacterStyle {
Expand All @@ -25,6 +26,8 @@ public enum CharacterStyle {

UNDERLINE("Underline");

private static final Logger LOG = Logger.getLogger(CharacterStyle.class.getName());

private String value;

CharacterStyle(String value) {
Expand All @@ -48,6 +51,12 @@ public static CharacterStyle fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"CharacterStyle: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(CharacterStyle.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/CharacterWidth.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets CharacterWidth */
public enum CharacterWidth {
DOUBLE_WIDTH("DoubleWidth"),

SINGLE_WIDTH("SingleWidth");

private static final Logger LOG = Logger.getLogger(CharacterWidth.class.getName());

private String value;

CharacterWidth(String value) {
Expand All @@ -44,6 +47,12 @@ public static CharacterWidth fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"CharacterWidth: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(CharacterWidth.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets Device */
public enum Device {
Expand All @@ -25,6 +26,8 @@ public enum Device {

CUSTOMER_INPUT("CustomerInput");

private static final Logger LOG = Logger.getLogger(Device.class.getName());

private String value;

Device(String value) {
Expand All @@ -48,6 +51,12 @@ public static Device fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"Device: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(Device.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/DocumentQualifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets DocumentQualifier */
public enum DocumentQualifier {
Expand All @@ -29,6 +30,8 @@ public enum DocumentQualifier {

VOUCHER("Voucher");

private static final Logger LOG = Logger.getLogger(DocumentQualifier.class.getName());

private String value;

DocumentQualifier(String value) {
Expand All @@ -52,6 +55,12 @@ public static DocumentQualifier fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"DocumentQualifier: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(DocumentQualifier.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/ErrorCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets ErrorCondition */
public enum ErrorCondition {
Expand Down Expand Up @@ -51,6 +52,8 @@ public enum ErrorCondition {

WRONG_PIN("WrongPIN");

private static final Logger LOG = Logger.getLogger(ErrorCondition.class.getName());

private String value;

ErrorCondition(String value) {
Expand All @@ -74,6 +77,12 @@ public static ErrorCondition fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"ErrorCondition: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(ErrorCondition.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/EventToNotify.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/**
* Event the POI notifies to the Sale System. Possible values: * **Abort** * **BeginMaintenance** *
Expand Down Expand Up @@ -59,6 +60,8 @@ public enum EventToNotify {

USE_ANOTHER_CARD_FOR_PREAUTH("UseAnotherCardForPreauth");

private static final Logger LOG = Logger.getLogger(EventToNotify.class.getName());

private String value;

EventToNotify(String value) {
Expand All @@ -82,6 +85,12 @@ public static EventToNotify fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"EventToNotify: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(EventToNotify.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/GlobalStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets GlobalStatus */
public enum GlobalStatus {
Expand All @@ -25,6 +26,8 @@ public enum GlobalStatus {

UNREACHABLE("Unreachable");

private static final Logger LOG = Logger.getLogger(GlobalStatus.class.getName());

private String value;

GlobalStatus(String value) {
Expand All @@ -48,6 +51,12 @@ public static GlobalStatus fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"GlobalStatus: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(GlobalStatus.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/IdentificationSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/**
* Support of the loyalty account identification. Allows knowing where and how you have found the
Expand All @@ -29,6 +30,8 @@ public enum IdentificationSupport {

NO_CARD("NoCard");

private static final Logger LOG = Logger.getLogger(IdentificationSupport.class.getName());

private String value;

IdentificationSupport(String value) {
Expand All @@ -52,6 +55,12 @@ public static IdentificationSupport fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"IdentificationSupport: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(IdentificationSupport.values()));
return null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/adyen/model/tapi/IdentificationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.*;
import java.util.logging.Logger;

/** Gets or Sets IdentificationType */
public enum IdentificationType {
Expand All @@ -27,6 +28,8 @@ public enum IdentificationType {

PHONE_NUMBER("PhoneNumber");

private static final Logger LOG = Logger.getLogger(IdentificationType.class.getName());

private String value;

IdentificationType(String value) {
Expand All @@ -50,6 +53,12 @@ public static IdentificationType fromValue(String value) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
// handling unexpected value
LOG.warning(
"IdentificationType: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(IdentificationType.values()));
return null;
}
}
Loading