From ace24e5fcc20106680e8f68dca511dc39c5a96bd Mon Sep 17 00:00:00 2001 From: rathnapandi Date: Tue, 14 Nov 2023 21:43:48 -0700 Subject: [PATCH] - Code cleanup --- modules/apim-adapter/pom.xml | 2 +- .../axway/apim/adapter/APIManagerAdapter.java | 7 ------ .../jackson/OrganizationDeserializer.java | 24 ++++--------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/modules/apim-adapter/pom.xml b/modules/apim-adapter/pom.xml index 62dda4ef3..d02c975e3 100644 --- a/modules/apim-adapter/pom.xml +++ b/modules/apim-adapter/pom.xml @@ -108,7 +108,7 @@ com.jayway.jsonpath json-path - 2.7.0 + 2.8.0 test diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java index b4d3a7d4c..6aabff9f5 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java @@ -72,7 +72,6 @@ public class APIManagerAdapter { private static APIManagerAdapter instance; private String apiManagerVersion = null; private String apiManagerName = null; - private boolean initialized; public static final ObjectMapper mapper = new ObjectMapper(); private static final Map clientCredentialToAppMap = new HashMap<>(); private boolean usingOrgAdmin = false; @@ -122,7 +121,6 @@ public synchronized void deleteInstance() { instance = null; APIMHttpClient.deleteInstances(); } - initialized = false; } private void setApiManagerVersion() throws AppException { @@ -152,11 +150,6 @@ private APIManagerAdapter() { this.oauthClientAdapter = new APIManagerOAuthClientProfilesAdapter(this); this.appAdapter = new APIMgrAppsAdapter(this); this.userAdapter = new APIManagerUserAdapter(this); - initialized = true; - } - - public boolean isInitialized() { - return initialized; } public APIMCLICacheManager getCacheManager() { diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/OrganizationDeserializer.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/OrganizationDeserializer.java index 1b7d12991..5461af556 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/OrganizationDeserializer.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/OrganizationDeserializer.java @@ -16,40 +16,24 @@ public class OrganizationDeserializer extends StdDeserializer { private static final long serialVersionUID = 1L; - public OrganizationDeserializer() { - this(null); - } - public OrganizationDeserializer(Class organization) { super(organization); } @Override - public Organization deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException { + public Organization deserialize(JsonParser jp, DeserializationContext context) + throws IOException { APIManagerAdapter apiManagerAdapter = APIManagerAdapter.getInstance(); APIManagerOrganizationAdapter organizationAdapter = apiManagerAdapter.getOrgAdapter(); JsonNode node = jp.getCodec().readTree(jp); // Deserialization depends on the direction if ("organizationId".equals(jp.currentName())) { - // APIManagerAdapter is not yet initialized - if (!apiManagerAdapter.isInitialized()) { - Organization organization = new Organization(); - organization.setId(node.asText()); - return organization; - } // organizationId is given by API-Manager return organizationAdapter.getOrgForId(node.asText()); } else { - // APIManagerAdapter is not yet initialized - if (!apiManagerAdapter.isInitialized()) { - Organization organization = new Organization(); - organization.setName(node.asText()); - return organization; - } // Otherwise make sure the organization exists and try to load it - Organization organization =organizationAdapter.getOrgForName(node.asText()); - if (organization == null && validateOrganization(ctxt)) { + Organization organization = organizationAdapter.getOrgForName(node.asText()); + if (organization == null && validateOrganization(context)) { throw new AppException("The given organization: '" + node.asText() + "' is unknown.", ErrorCode.UNKNOWN_ORGANIZATION); } return organization;