Skip to content

Commit

Permalink
- Fix integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 23, 2024
1 parent 42c4fe4 commit 0fc97ff
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.axway.apim.adapter.APIStatusManager;
import com.axway.apim.api.API;
import com.axway.apim.api.model.Organization;
import com.axway.apim.api.model.apps.ClientApplication;
import com.axway.apim.apiimport.APIChangeState;
import com.axway.apim.lib.CoreParameters;
import com.axway.apim.lib.CoreParameters.Mode;
import com.axway.apim.lib.error.AppException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,23 +20,21 @@ public class RepublishToUpdateAPI {
public void execute(APIChangeState changes) throws AppException {

API actualAPI = changes.getActualAPI();
Mode clientAppsMode = CoreParameters.getInstance().getClientAppsMode();
Mode clientOrgsMode = CoreParameters.getInstance().getClientOrgsMode();
CoreParameters.Mode clientAppsMode = CoreParameters.getInstance().getClientAppsMode();
CoreParameters.Mode clientOrgsMode = CoreParameters.getInstance().getClientOrgsMode();
// Get existing Orgs and Apps, as they will be lost when the API gets unpublished
if (clientAppsMode == Mode.add && actualAPI.getApplications() != null) {
if (clientAppsMode == CoreParameters.Mode.add && actualAPI.getApplications() != null) {
if (changes.getDesiredAPI().getApplications() == null)
changes.getDesiredAPI().setApplications(new ArrayList<>());
mergeIntoList(changes.getDesiredAPI().getApplications(), actualAPI.getApplications());
// Reset the applications to have them re-created based the desired Apps
actualAPI.setApplications(new ArrayList<>());
}
if (clientOrgsMode == Mode.add && actualAPI.getClientOrganizations() != null) {
if (clientOrgsMode == CoreParameters.Mode.add && actualAPI.getClientOrganizations() != null) {
if (changes.getDesiredAPI().getClientOrganizations() == null)
changes.getDesiredAPI().setClientOrganizations(new ArrayList<>());
// Take over existing organizations
mergeIntoList(changes.getDesiredAPI().getClientOrganizations(), actualAPI.getClientOrganizations());
// Delete them, so that they are re-created based on the desired orgs
actualAPI.setClientOrganizations(new ArrayList<>());
}
// 1. Create BE- and FE-API (API-Proxy) / Including updating all belonging props!
// This also includes all CONFIGURED application subscriptions and client-orgs
Expand All @@ -50,12 +49,23 @@ public void execute(APIChangeState changes) throws AppException {
APIStatusManager statusManager = new APIStatusManager();
statusManager.update(actualAPI, API.STATE_UNPUBLISHED, true);
actualAPI.setClientOrganizations(new ArrayList<>()); // remove all client organizations
actualAPI.setApplications(new ArrayList<>()); // remove all consumer applications
actualAPI.setApplications(keepApplicationFromDevelopmentOrg(actualAPI.getApplications(), actualAPI.getOrganization())); // remove all consumer applications
UpdateExistingAPI updateExistingAPI = new UpdateExistingAPI();
updateExistingAPI.execute(changes);
LOG.debug("Existing API successfully updated: {} (ID: {})", actualAPI.getName(), actualAPI.getId());
}

public List<ClientApplication> keepApplicationFromDevelopmentOrg(List<ClientApplication> applications, Organization developmentOrg) {
List<ClientApplication> applicationsToKeep = new ArrayList<>();
for(ClientApplication app : applications) {
if(app.getOrganization().getName().equals(developmentOrg.getName())) {
applicationsToKeep.add(app);
}
}
return applicationsToKeep;

}

private <T> void mergeIntoList(List<T> targetList, List<T> source) {
for (T element : source) {
if (!targetList.contains(element)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@

{
"name": "${apiName}",
"path": "${apiPath}",
"state": "${state}",
"version": "${version}",
"organization": "API Development ${orgNumber}",
"inboundProfiles": {
"_default": {
"securityProfile": "_default",
"corsProfile": "_default",
"monitorAPI": true,
"monitorSubject": "authentication.subject.id"
}
},
"securityProfiles": [
{
"name": "_default",
"isDefault": true,
"devices": [
{
"name": "API Key",
"type": "apiKey",
"order": 0,
"properties": {
"apiKeyFieldName": "KeyId",
"takeFrom": "QUERY",
"removeCredentialsOnSuccess": "false"
}
}
]
}
]
}
"name": "${apiName}",
"path": "${apiPath}",
"state": "${state}",
"version": "${version}",
"organization": "API Development ${orgNumber}",
"inboundProfiles": {
"_default": {
"securityProfile": "_default",
"corsProfile": "_default",
"monitorAPI": true,
"monitorSubject": "authentication.subject.id"
}
},
"securityProfiles": [
{
"name": "_default",
"isDefault": true,
"devices": [
{
"name": "API Key",
"type": "apiKey",
"order": 0,
"properties": {
"apiKeyFieldName": "KeyId",
"takeFrom": "QUERY",
"removeCredentialsOnSuccess": "false"
}
}
]
}
],
"clientOrganizations": [
"${orgName2}"
]
}

0 comments on commit 0fc97ff

Please sign in to comment.