diff --git a/modules/apis/src/main/java/com/axway/apim/apiimport/actions/RepublishToUpdateAPI.java b/modules/apis/src/main/java/com/axway/apim/apiimport/actions/RepublishToUpdateAPI.java index 5a8b0068c..8dbbd6dde 100644 --- a/modules/apis/src/main/java/com/axway/apim/apiimport/actions/RepublishToUpdateAPI.java +++ b/modules/apis/src/main/java/com/axway/apim/apiimport/actions/RepublishToUpdateAPI.java @@ -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; @@ -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 @@ -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 keepApplicationFromDevelopmentOrg(List applications, Organization developmentOrg) { + List applicationsToKeep = new ArrayList<>(); + for(ClientApplication app : applications) { + if(app.getOrganization().getName().equals(developmentOrg.getName())) { + applicationsToKeep.add(app); + } + } + return applicationsToKeep; + + } + private void mergeIntoList(List targetList, List source) { for (T element : source) { if (!targetList.contains(element)) { diff --git a/modules/apis/src/test/resources/com/axway/apim/test/files/basic/4_flexible-status-config.json b/modules/apis/src/test/resources/com/axway/apim/test/files/basic/4_flexible-status-config.json index e5c744900..d5438c524 100644 --- a/modules/apis/src/test/resources/com/axway/apim/test/files/basic/4_flexible-status-config.json +++ b/modules/apis/src/test/resources/com/axway/apim/test/files/basic/4_flexible-status-config.json @@ -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" - } - } - ] - } - ] -} \ No newline at end of file + "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}" + ] +}