Skip to content

Commit ed2c806

Browse files
author
rathnapandi
committed
Code clean up
1 parent 3e1c21d commit ed2c806

File tree

14 files changed

+27
-107
lines changed

14 files changed

+27
-107
lines changed

modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public synchronized void deleteInstance() {
126126
}
127127

128128
private void setApiManagerVersion() throws AppException {
129-
Config config = configAdapter.getConfig(false);
129+
Config config = configAdapter.getConfig();
130130
apiManagerVersion = config.getProductVersion();
131131
if (usingOrgAdmin)
132132
LOG.info("Organization Administrator Self Service Enabled : {}", config.getOadminSelfServiceEnabled());
@@ -539,15 +539,15 @@ public String getApiManagerVersion() throws AppException {
539539
if (apiManagerVersion != null) {
540540
return apiManagerVersion;
541541
}
542-
apiManagerVersion = APIManagerAdapter.getInstance().configAdapter.getConfig(false).getProductVersion();
542+
apiManagerVersion = APIManagerAdapter.getInstance().configAdapter.getConfig().getProductVersion();
543543
return apiManagerVersion;
544544
}
545545

546546
public String getApiManagerName() throws AppException {
547547
if (apiManagerName != null) {
548548
return apiManagerName;
549549
}
550-
apiManagerName = APIManagerAdapter.getInstance().configAdapter.getConfig(false).getPortalName();
550+
apiManagerName = APIManagerAdapter.getInstance().configAdapter.getConfig().getPortalName();
551551
return apiManagerName;
552552
}
553553

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerConfigAdapter.java

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
import com.fasterxml.jackson.annotation.JsonInclude.Include;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
1414
import com.fasterxml.jackson.databind.module.SimpleModule;
15-
import com.fasterxml.jackson.databind.ser.FilterProvider;
16-
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
17-
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
18-
import org.apache.commons.lang3.ArrayUtils;
1915
import org.apache.http.HttpEntity;
2016
import org.apache.http.client.methods.CloseableHttpResponse;
2117
import org.apache.http.client.utils.URIBuilder;
@@ -28,8 +24,6 @@
2824
import java.io.IOException;
2925
import java.net.URI;
3026
import java.net.URISyntaxException;
31-
import java.util.HashMap;
32-
import java.util.Map;
3327

3428
public class APIManagerConfigAdapter {
3529

@@ -43,50 +37,7 @@ public APIManagerConfigAdapter() {
4337
cmd = CoreParameters.getInstance();
4438
}
4539

46-
Map<Boolean, String> apiManagerResponse = new HashMap<>();
47-
48-
Map<Boolean, Config> managerConfig = new HashMap<>();
49-
50-
51-
/**
52-
* Config fields that were introduced with a certain API-Manager version.
53-
* This list is mainly used to filter out fields, when using an older API-Manager version.
54-
*/
55-
protected enum ConfigFields {
56-
VERSION_7720200130("7.7.20200530", new String[]{"apiImportTimeout", "apiImportMimeValidation", "apiImportEditable", "lockUserAccount"}),
57-
VERSION_77("7.7.0", new String[]{
58-
"userNameRegex", "changePasswordOnFirstLogin", "passwordExpiryEnabled", "passwordLifetimeDays",
59-
"applicationScopeRestrictions", "strictCertificateChecking", "serverCertificateVerification", "advisoryBannerEnabled", "advisoryBannerText"
60-
});
61-
62-
private final String[] ignoreFields;
63-
private final String managerVersion;
64-
65-
ConfigFields(String managerVersion, String[] ignoreFields) {
66-
this.ignoreFields = ignoreFields;
67-
this.managerVersion = managerVersion;
68-
}
69-
70-
public String getManagerVersion() {
71-
return managerVersion;
72-
}
73-
74-
public static String[] getIgnoredFields() {
75-
String[] restrictedFields = new String[]{};
76-
for (ConfigFields fields : values()) {
77-
// Add all ignore fields until we reached the used API-Manager version
78-
if (APIManagerAdapter.hasAPIManagerVersion(fields.getManagerVersion())) {
79-
break;
80-
}
81-
restrictedFields = ArrayUtils.addAll(restrictedFields, fields.ignoreFields);
82-
}
83-
return restrictedFields;
84-
}
85-
86-
}
87-
88-
private void readConfigFromAPIManager(boolean useAdmin) throws AppException {
89-
if (apiManagerResponse.get(useAdmin) != null) return;
40+
public Config getConfig() throws AppException {
9041
try {
9142
URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/config").build();
9243
RestAPICall getRequest = new GETRequest(uri);
@@ -97,22 +48,10 @@ private void readConfigFromAPIManager(boolean useAdmin) throws AppException {
9748
LOG.error("Error loading configuration from API-Manager. Response-Code: {} Got response: {}", statusCode, response);
9849
throw new AppException("Error loading configuration from API-Manager. Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION);
9950
}
100-
apiManagerResponse.put(useAdmin, response);
51+
return mapper.readValue(response, Config.class);
10152
}
10253
} catch (Exception e) {
103-
throw new AppException("Can't read configuration from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
104-
}
105-
}
106-
107-
public Config getConfig(boolean useAdmin) throws AppException {
108-
if (managerConfig.get(useAdmin) != null) return managerConfig.get(useAdmin);
109-
readConfigFromAPIManager(useAdmin);
110-
try {
111-
Config config = mapper.readValue(apiManagerResponse.get(useAdmin), Config.class);
112-
managerConfig.put(useAdmin, config);
113-
return config;
114-
} catch (IOException e) {
115-
throw new AppException("Error parsing API-Manager configuration", ErrorCode.API_MANAGER_COMMUNICATION_ERR, e);
54+
throw new AppException("Can't read configuration from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION_ERR, e);
11655
}
11756
}
11857

@@ -122,9 +61,6 @@ public void updateConfiguration(Config desiredConfig) throws AppException {
12261
throw new AppException("An Admin Account is required to update the API-Manager configuration.", ErrorCode.NO_ADMIN_ROLE_USER);
12362
}
12463
URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/config").build();
125-
FilterProvider filter = new SimpleFilterProvider().setDefaultFilter(
126-
SimpleBeanPropertyFilter.serializeAllExcept(ConfigFields.getIgnoredFields()));
127-
mapper.setFilterProvider(filter);
12864
mapper.registerModule(new SimpleModule().setSerializerModifier(new PolicySerializerModifier(false)));
12965
mapper.setSerializationInclusion(Include.NON_NULL);
13066
RestAPICall request;

modules/apim-adapter/src/main/java/com/axway/apim/adapter/client/apps/APIMgrAppsAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.net.URI;
3434
import java.net.URISyntaxException;
3535
import java.util.*;
36+
import java.util.concurrent.ConcurrentHashMap;
3637

3738
public class APIMgrAppsAdapter {
3839

@@ -44,8 +45,8 @@ public class APIMgrAppsAdapter {
4445
public static final String API_KEY = "apiKey";
4546
public static final String CREDENTIAL_TYPE = "credentialType";
4647

47-
Map<ClientAppFilter, String> apiManagerResponse = new HashMap<>();
48-
Map<String, String> subscribedAppAPIManagerResponse = new HashMap<>();
48+
Map<ClientAppFilter, String> apiManagerResponse = new ConcurrentHashMap<>();
49+
Map<String, String> subscribedAppAPIManagerResponse = new ConcurrentHashMap<>();
4950
CoreParameters cmd = CoreParameters.getInstance();
5051
ObjectMapper mapper = APIManagerAdapter.mapper;
5152
Cache<String, String> applicationsCache;

modules/apim-adapter/src/main/java/com/axway/apim/lib/utils/Utils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ public static void validateCustomProperties(Map<String, String> customProperties
267267
}
268268
}
269269

270+
/**
271+
* Read custom properties from payload and create in a different format.
272+
* @param entities api, app, org and user
273+
* @param json raw json message
274+
* @param filter filter
275+
* @throws IOException
276+
*/
277+
270278
public static void addCustomPropertiesForEntity(List<? extends CustomPropertiesEntity> entities, String json, CustomPropertiesFilter filter) throws IOException {
271279
ObjectMapper mapper = new ObjectMapper();
272280
// Custom-Properties will be added depending on the given Properties in the filter

modules/apim-adapter/src/test/java/com/axway/apim/adapter/apis/APIManagerConfigAdapterTest.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,12 @@ public void close() {
3939
super.close();
4040
}
4141

42-
@Test
43-
public void testCorrectFieldsAreIgnored() throws AppException {
44-
apiManagerAdapter.setApiManagerVersion("7.7.20200930");
45-
String[] ignoreFields = APIManagerConfigAdapter.ConfigFields.getIgnoredFields();
46-
// No field should be ignored for the Sept-Release
47-
Assert.assertNotNull(ignoreFields);
48-
Assert.assertEquals(ignoreFields.length, 0);
49-
50-
apiManagerAdapter.setApiManagerVersion("7.7.20200730");
51-
ignoreFields = APIManagerConfigAdapter.ConfigFields.getIgnoredFields();
52-
// Same for July, as fields have been added in January release
53-
Assert.assertNotNull(ignoreFields);
54-
Assert.assertEquals(ignoreFields.length, 0);
5542

56-
apiManagerAdapter.setApiManagerVersion("7.7.20200331");
57-
ignoreFields = APIManagerConfigAdapter.ConfigFields.getIgnoredFields();
58-
// March release doesn't support new parameters introduced with the May release
59-
Assert.assertNotNull(ignoreFields);
60-
Assert.assertEquals(ignoreFields.length, 4);
61-
62-
apiManagerAdapter.setApiManagerVersion("7.7.0");
63-
ignoreFields = APIManagerConfigAdapter.ConfigFields.getIgnoredFields();
64-
// 7.7.0 plain already supports some new settings
65-
Assert.assertNotNull(ignoreFields);
66-
Assert.assertEquals(ignoreFields.length, 4); // Only brand new fields are returned to be ignored
67-
}
6843

6944
@Test
7045
public void updateConfiguration() {
7146
try {
72-
Config config = apiManagerConfigAdapter.getConfig(true);
47+
Config config = apiManagerConfigAdapter.getConfig();
7348
config.setApiPortalHostname("api.axway.com");
7449
apiManagerConfigAdapter.updateConfiguration(config);
7550
}catch (AppException e){

modules/apis/src/main/java/com/axway/apim/APIImportApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public int importAPI(APIImportParams params) {
6868
// If we don't have an AdminAccount available, we ignore published APIs - For OrgAdmins
6969
// the unpublished or pending APIs become the actual API
7070
boolean isAdminAccount = APIManagerAdapter.getInstance().hasAdminAccount();
71-
boolean orgAdminSelfService = APIManagerAdapter.getInstance().getConfigAdapter().getConfig(isAdminAccount).getOadminSelfServiceEnabled();
71+
boolean orgAdminSelfService = APIManagerAdapter.getInstance().getConfigAdapter().getConfig().getOadminSelfServiceEnabled();
7272
if (!isAdminAccount && !orgAdminSelfService) {
7373
filters.add(new BasicNameValuePair("field", "state"));
7474
filters.add(new BasicNameValuePair("op", "ne"));

modules/apis/src/main/java/com/axway/apim/apiimport/APIChangeState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public APIImportParams getApiImportParams() {
298298

299299

300300
public boolean isAdminAccountNeeded() throws AppException {
301-
boolean orgAdminSelfServiceEnabled = APIManagerAdapter.getInstance().getConfigAdapter().getConfig(APIManagerAdapter.getInstance().hasAdminAccount()).getOadminSelfServiceEnabled();
301+
boolean orgAdminSelfServiceEnabled = APIManagerAdapter.getInstance().getConfigAdapter().getConfig().getOadminSelfServiceEnabled();
302302
if (orgAdminSelfServiceEnabled) return false;
303303
return (!getDesiredAPI().getState().equals(Constants.API_UNPUBLISHED) && !getDesiredAPI().getState().equals(Constants.API_DELETED)) ||
304304
(getActualAPI() != null && !getActualAPI().getState().equals(Constants.API_UNPUBLISHED));

modules/apis/src/main/java/com/axway/apim/apiimport/APIImportConfigAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ private void handleOutboundSSLAuthN(AuthenticationProfile authnProfile) throws A
705705
private void validateHasQueryStringKey(API importApi) throws AppException {
706706
if (importApi.getApiRoutingKey() == null) return; // Nothing to check
707707
if (APIManagerAdapter.getInstance().hasAdminAccount()) {
708-
boolean apiRoutingKeyEnabled = APIManagerAdapter.getInstance().getConfigAdapter().getConfig(true).getApiRoutingKeyEnabled();
708+
boolean apiRoutingKeyEnabled = APIManagerAdapter.getInstance().getConfigAdapter().getConfig().getApiRoutingKeyEnabled();
709709
if (!apiRoutingKeyEnabled) {
710710
throw new AppException("API-Manager Query-String Routing option is disabled. Please turn it on to use apiRoutingKey.", ErrorCode.QUERY_STRING_ROUTING_DISABLED);
711711
}

modules/apis/src/main/java/com/axway/apim/apiimport/APIImportManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class APIImportManager {
2828
*/
2929
public void applyChanges(APIChangeState changeState, boolean forceUpdate, boolean updateOnly) throws AppException {
3030
boolean enforceBreakingChange = CoreParameters.getInstance().isForce();
31-
boolean orgAdminSelfService = APIManagerAdapter.getInstance().getConfigAdapter().getConfig(APIManagerAdapter.getInstance().hasAdminAccount()).getOadminSelfServiceEnabled();
31+
boolean orgAdminSelfService = APIManagerAdapter.getInstance().getConfigAdapter().getConfig().getOadminSelfServiceEnabled();
3232
if (!APIManagerAdapter.getInstance().hasAdminAccount() && changeState.isAdminAccountNeeded()) {
3333
if (orgAdminSelfService) {
3434
LOG.info("Desired API-State set to published using OrgAdmin account only. Going to create a publish request.");

modules/settings/src/main/java/com/axway/apim/setup/APIManagerSettingsApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private ExportResult exportAPIManagerSetup(APIManagerSetupExportParams params, R
105105
APIManagerSetupResultHandler exporter = APIManagerSetupResultHandler.create(exportImpl, params, result);
106106
APIManagerConfig apiManagerConfig = new APIManagerConfig();
107107
if (params.isExportConfig()) {
108-
apiManagerConfig.setConfig(adapter.getConfigAdapter().getConfig(APIManagerAdapter.getInstance().hasAdminAccount()));
108+
apiManagerConfig.setConfig(adapter.getConfigAdapter().getConfig());
109109
}
110110
if (params.isExportAlerts()) {
111111
apiManagerConfig.setAlerts(adapter.getAlertsAdapter().getAlerts());

0 commit comments

Comments
 (0)