Skip to content

Commit

Permalink
- Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 24, 2024
1 parent e3abd8d commit 6393a81
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public String getVersion(APIFilter apiFilter) {
}

private List<API> filterAPIs(APIFilter filter) throws IOException {
List<API> apis = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<List<API>>() {
List<API> apis = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() {
});
apis.removeIf(filter::filter);

Expand All @@ -226,7 +226,7 @@ private List<API> filterAPIs(APIFilter filter) throws IOException {
* Translates the methodIds of the given api. The operations are loaded from the API-Manager based on the apiId
*
* @param api in which the methods should be translated
* @param apiId the methods are loaded based on this API-ID (this might be an another referenced API)
* @param apiId the methods are loaded based on this API-ID (this might be a referenced API)
* @param mode translation direction
* @throws AppException when something goes wrong
*/
Expand Down Expand Up @@ -297,9 +297,7 @@ private void addRemoteHost(API api, boolean includeRemoteHost) throws AppExcepti
RemoteHost remoteHost = APIManagerAdapter.getInstance().getRemoteHostsAdapter().getRemoteHost(url.getHost(), url.getPort());
api.setRemotehost(remoteHost);
} catch (Exception e) {
if (LOG.isDebugEnabled()) {
LOG.error("Error setting remote host for API based on backendBasePath: " + backendBasePath, e);
}
LOG.error("Error setting remote host for API based on backendBasePath: {}", backendBasePath, e);
}
}

Expand Down Expand Up @@ -343,8 +341,8 @@ public void updateAPIImage(API api, Image image) throws AppException {
}
}

private <ProfileType> void translateMethodIds(Map<String, ProfileType> profiles, METHOD_TRANSLATION mode, List<String> apiIds) throws AppException {
Map<String, ProfileType> updatedEntries = new HashMap<>();
private <T> void translateMethodIds(Map<String, T> profiles, METHOD_TRANSLATION mode, List<String> apiIds) throws AppException {
Map<String, T> updatedEntries = new HashMap<>();
if (profiles != null) {
Iterator<String> keys = profiles.keySet().iterator();
while (keys.hasNext()) {
Expand All @@ -359,7 +357,7 @@ private <ProfileType> void translateMethodIds(Map<String, ProfileType> profiles,
}
if (method != null) break;
}
ProfileType profileWithType = profiles.get(key);
T profileWithType = profiles.get(key);
Profile profile = (Profile) profileWithType;
if (profile instanceof OutboundProfile) {
if (method != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -26,7 +25,6 @@ public void updateApiMethods(String frontendApiId, List<APIMethod> actualApiMeth
if (!desiredApiMethods.isEmpty()) {
APIManagerAPIMethodAdapter apiManagerAPIMethodAdapter = apiManager.getMethodAdapter();
List<APIMethod> apiMethods = apiManagerAPIMethodAdapter.getAllMethodsForAPI(frontendApiId);
List<String> updatedMethodNames = new ArrayList<>();
for (APIMethod apiMethod : desiredApiMethods) {
for (APIMethod method : apiMethods) {
String operationName = method.getName();
Expand All @@ -37,7 +35,6 @@ public void updateApiMethods(String frontendApiId, List<APIMethod> actualApiMeth
apiMethod.setVirtualizedApiId(method.getVirtualizedApiId());
apiMethod.setApiMethodId(method.getApiMethodId());
apiManagerAPIMethodAdapter.updateApiMethod(apiMethod);
updatedMethodNames.add(operationName);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void execute(APIChangeState changes) throws AppException {
// If a proxy update is required
if (changes.isProxyUpdateRequired()) {
// Handle vhost
if(desiredAPI.getVhost() == null || desiredAPI.getVhost().isEmpty()){
if (desiredAPI.getVhost() == null || desiredAPI.getVhost().isEmpty()) {
actualAPI.setVhost(null);
}
// Update the proxy
Expand Down Expand Up @@ -81,14 +81,7 @@ public void execute(APIChangeState changes) throws AppException {
new ManageClientOrganization(desiredAPI, actualAPI).execute(false);
// Handle subscription to applications
new ManageClientApps(desiredAPI, actualAPI, null).execute(false);
if (actualAPI.getState().equals(API.STATE_DELETED)) {
LOG.info("Successfully deleted API: {} {} (ID: {})", actualAPI.getName(), actualAPI.getVersion(), actualAPI.getId());
} else {
LOG.info("Successfully updated {} API: {} {} (ID: {})", actualAPI.getState(), actualAPI.getName(), actualAPI.getVersion(), actualAPI.getId());
}
if (!changes.waiting4Approval().isEmpty() && LOG.isInfoEnabled()) {
LOG.info("{}", changes.waiting4Approval());
}
logStatus(actualAPI, changes);
} catch (Exception e) {
LOG.error("Error updating existing API", e);
throw new AppException("Error updating existing API", ErrorCode.BREAKING_CHANGE_DETECTED);
Expand All @@ -97,4 +90,14 @@ public void execute(APIChangeState changes) throws AppException {
}
}

private void logStatus(API actualAPI, APIChangeState changes) throws AppException {
if (actualAPI.getState().equals(API.STATE_DELETED)) {
LOG.info("Successfully deleted API: {} {} (ID: {})", actualAPI.getName(), actualAPI.getVersion(), actualAPI.getId());
} else {
LOG.info("Successfully updated {} API: {} {} (ID: {})", actualAPI.getState(), actualAPI.getName(), actualAPI.getVersion(), actualAPI.getId());
}
if (!changes.waiting4Approval().isEmpty() && LOG.isInfoEnabled()) {
LOG.info("{}", changes.waiting4Approval());
}
}
}

0 comments on commit 6393a81

Please sign in to comment.