From ca01fb657f92aeafd5f61cd1921ba94902f72925 Mon Sep 17 00:00:00 2001 From: Radek Davidek Date: Wed, 1 Oct 2025 18:00:27 +0200 Subject: [PATCH] big refactor --- .../cz/trask/apioperator/impl/Import.java | 544 +++++++++--------- 1 file changed, 283 insertions(+), 261 deletions(-) diff --git a/src/main/java/cz/trask/apioperator/impl/Import.java b/src/main/java/cz/trask/apioperator/impl/Import.java index 9723827..94e9acd 100644 --- a/src/main/java/cz/trask/apioperator/impl/Import.java +++ b/src/main/java/cz/trask/apioperator/impl/Import.java @@ -1,20 +1,25 @@ package cz.trask.apioperator.impl; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; import cz.trask.apioperator.AbstractProcess; import cz.trask.apioperator.model.APIInfo; @@ -32,335 +37,352 @@ import io.apicurio.registry.rest.v2.beans.ArtifactMetaData; import io.apicurio.registry.rest.v2.beans.ArtifactReference; import io.apicurio.registry.rest.v2.beans.EditableMetaData; import io.apicurio.registry.rest.v2.beans.Rule; -import io.apicurio.registry.rest.v2.beans.VersionMetaData; import io.apicurio.registry.rest.v2.beans.VersionSearchResults; import io.apicurio.registry.types.RuleType; +/** + * Import class – reads APIs from WSO2 APIM and publishes them to Apicurio. + * + *

+ * All major improvements from the original code: + *

+ *

+ */ public class Import extends AbstractProcess { - private static Logger log = LogManager.getLogger(Import.class); + private static final Logger log = LogManager.getLogger(Import.class); - StartParameters sp; - RegistryClient client; - static int i = 1; + private final AtomicInteger apiCounter = new AtomicInteger(1); + private final Gson gson = new Gson(); + + private final StartParameters sp; + private final RegistryClient client; public Import(StartParameters sp) throws Exception { this.sp = sp; - client = RegistryClientFactory.create(config.getApicurioApiUrl()); + this.client = RegistryClientFactory.create(config.getApicurioApiUrl()); } /** - * Process Export API - * - * @throws Exception - all exceptions in the code are thrown for handling in - * CICD purpose + * Main entry point for the import process. + * + * @throws RuntimeException if any error occurs */ - public void process() throws Exception { - log.info("exporting APIs..."); + public void process() { try { - log.info("Register user for calling Admins APIs..."); - RegisterResponse registerResponse = register(config.getSourceRegistrationApiUrl(), - config.getSourceWso2User()); - log.info("Registered with clientId: " + registerResponse.getClientId()); + log.info("Starting API export…"); - log.info("Getting token for clientId:" + registerResponse.getClientId()); - TokenResponse tokenResponse = getToken(config.getSourcePublisherTokenUrl(), config.getSourceWso2User(), - registerResponse, - "apim:api_view apim:api_create apim:api_manage apim:api_delete apim:api_publish apim:subscription_view apim:subscription_block apim:subscription_manage apim:external_services_discover apim:threat_protection_policy_create apim:threat_protection_policy_manage apim:document_create apim:document_manage apim:mediation_policy_view apim:mediation_policy_create apim:mediation_policy_manage apim:client_certificates_view apim:client_certificates_add apim:client_certificates_update apim:ep_certificates_view apim:ep_certificates_add apim:ep_certificates_update apim:publisher_settings apim:pub_alert_manage apim:shared_scope_manage apim:app_import_export apim:api_import_export apim:api_product_import_export apim:api_generate_key apim:common_operation_policy_view apim:common_operation_policy_manage apim:comment_write apim:comment_view apim:admin"); - log.debug("Token for clientId is: " + tokenResponse.getAccess_token()); + RegisterResponse register = register(config.getSourceRegistrationApiUrl(), config.getSourceWso2User()); - log.info("Getting list of APIs ..."); - APIList apis = getList(config.getSourcePublisherApiUrl(), tokenResponse); + String clientId = register.getClientId(); + log.info("Registered with clientId: {}", clientId); + TokenResponse token = getToken(config.getSourcePublisherTokenUrl(), config.getSourceWso2User(), register, + "apim:api_view apim:api_create apim:api_manage apim:api_delete apim:api_publish " + + "apim:subscription_view apim:subscription_block apim:subscription_manage apim:external_services_discover " + + "apim:threat_protection_policy_create apim:threat_protection_policy_manage apim:document_create apim:document_manage " + + "apim:mediation_policy_view apim:mediation_policy_create apim:mediation_policy_manage apim:client_certificates_view " + + "apim:client_certificates_add apim:client_certificates_update apim:ep_certificates_view apim:ep_certificates_add " + + "apim:ep_certificates_update apim:publisher_settings apim:pub_alert_manage apim:shared_scope_manage apim:app_import_export " + + "apim:api_import_export apim:api_product_import_export apim:api_generate_key apim:common_operation_policy_view " + + "apim:common_operation_policy_manage apim:comment_write apim:comment_view apim:admin"); + + log.debug("Access token received – {}", token.getAccess_token()); + + APIList apis = getList(config.getSourcePublisherApiUrl(), token); if (apis == null || apis.getList() == null || apis.getList().length == 0) { - throw new Exception( - "There is no APIs to export that meets yours criteria! Please, check the name of API you want to export and try again!"); + throw new IllegalStateException( + "No APIs to export that match your criteria! Check the name of the API you want to export."); } - log.info("Found " + apis.getCount() + " APIs"); + log.info("Found {} APIs", apis.getCount()); int maxThreads = config.getMaxThreads(); - log.info("Starting API processing with " + maxThreads + " threads"); ExecutorService executor = Executors.newFixedThreadPool(maxThreads); + for (APIInfo api : apis.getList()) { - executor.execute(new Runnable() { - @Override - public void run() { - processApi(api, tokenResponse, i++, apis.getCount()); - } - }); + final int index = apiCounter.getAndIncrement(); + executor.submit(() -> processApi(api, token, index, apis.getCount())); } + executor.shutdown(); - while (!executor.isTerminated()) { - Thread.sleep(500); + if (!executor.awaitTermination(10, TimeUnit.MINUTES)) { + log.warn("Timeout waiting for API import tasks to finish"); } log.info("Finished processing APIs."); } catch (Exception e) { - log.error("Error while exporting APIs. ", e); - throw new Exception("Error while exporting APIs!"); + log.error("Error while exporting APIs.", e); + throw new RuntimeException("Export failed", e); } } - private void processApi(APIInfo api, TokenResponse tokenResponse, int i, int apiCount) { + /** + * Process a single API – fetches the data, creates or updates the corresponding + * artifact in Apicurio. + */ + private void processApi(APIInfo api, TokenResponse tokenResponse, int index, int total) { long start = System.currentTimeMillis(); - String apiStatus = api.getLifeCycleStatus(); - if (!apiStatus.contains("PUBLISHED") && !apiStatus.contains("DEPRECATED")) { - log.info("Skipping API " + i + " of " + apiCount + "with ID " + api.getId() - + " because it is not published."); + String status = api.getLifeCycleStatus(); + + if (!status.contains("PUBLISHED") && !status.contains("DEPRECATED")) { + log.info("Skipping API {} of {} – not published (ID={})", index, total, api.getId()); return; } + try { - log.info("Processing API " + i + " of " + apiCount); + log.info("Processing API {} of {}", index, total); - Map httpHeaders = new HashMap<>(); - Map params = new HashMap<>(); + Map httpHeaders = Collections.singletonMap("Authorization", + "Bearer " + tokenResponse.getAccess_token()); - httpHeaders.put("Authorization", "Bearer ".concat(tokenResponse.getAccess_token())); + String type = mapApiType(api.getType()); - String type = api.getType(); + // 1) Retrieve basic information + HttpResponse apiInfoResp = makeRequest("GET", config.getSourceDevportalApiUrl() + "/apis/" + api.getId(), + httpHeaders, Collections.emptyMap()); - switch (type) { - case "HTTP": - type = "OPENAPI"; - break; - case "GRAPHQL": - type = "GRAPHQL"; - break; - case "WS": - type = "ASYNCAPI"; - break; - case "SOAP": - type = "WSDL"; - break; - default: + HttpResponse subsResp = makeRequest("GET", + config.getSourcePublisherApiUrl() + "/subscriptions?apiId=" + api.getId(), httpHeaders, + Collections.emptyMap()); + + HttpResponse swaggerResp = makeRequest("GET", + config.getSourcePublisherApiUrl() + "/apis/" + api.getId() + "/swagger", httpHeaders, + Collections.emptyMap()); + + // 2) Export the API as a zip + HttpResponse exportedZip = makeRequest("GET", + config.getSourcePublisherApiUrl() + "/apis/export?apiId=" + api.getId(), httpHeaders, + Collections.emptyMap(), true); + + List zipEntries = ZipExtractor.extractFilesFromZip(exportedZip.getResponseBytes()); + + // 3) Deserialize JSON responses + TypeToken> mapType = new TypeToken<>() { + }; + Map apiMap = gson.fromJson(apiInfoResp.getResponse(), mapType.getType()); + Map subsMap = gson.fromJson(subsResp.getResponse(), mapType.getType()); + + @SuppressWarnings("unchecked") + List tagsList = (List) apiMap.get("tags"); + + // 4) Build the properties map + Map props = new LinkedHashMap<>(); + props.put("version", api.getVersion()); + props.put("status", status); + addSubscriptionsToProps(props, subsMap); + addEndpointsToProps(props, apiMap); + addTagsToProps(props, tagsList); + + // 5) Build the description that contains the publisher & devportal URLs + String baseDesc = api.getDescription() != null ? api.getDescription() : ""; + String pubUrl = config.getPublisherUrlPattern().replace("{API_ID}", api.getId()); + String devPortUrl = config.getDevportalUrlPattern().replace("{API_ID}", api.getId()); + + String fullDesc = baseDesc + " ***** PUBLISHER URL ***** " + pubUrl + " ***** DEVPORTAL URL ***** " + + devPortUrl; + + // 6) Update the swagger with the description and servers + JsonObject swaggerObj = JsonParser.parseString(swaggerResp.getResponse()).getAsJsonObject(); + updateSwagger(swaggerObj, apiMap, fullDesc); + + // 7) Prepare artifact creation/update + String group = config.getDefaultApiGroup(); + String mainArtifactId = api.getName() + api.getContext(); + + VersionSearchResults existingArtifacts; + try { + existingArtifacts = client.listArtifactVersions(group, mainArtifactId, 0, Integer.MAX_VALUE); + } catch (Exception e) { + log.debug("No API {} exists – will create it", api.getContext()); + existingArtifacts = null; } - try { - HttpResponse responseApi = makeRequest("GET", - config.getSourceDevportalApiUrl().concat(String.format("/apis/%s", api.getId())), httpHeaders, - params); - HttpResponse responseSubs = makeRequest("GET", - config.getSourcePublisherApiUrl().concat(String.format("/subscriptions?apiId=%s", api.getId())), - httpHeaders, params); - HttpResponse responseApiSwagger = makeRequest("GET", - config.getSourcePublisherApiUrl().concat(String.format("/apis/%s/swagger", api.getId())), - httpHeaders, params); + if (existingArtifacts == null) { + // Create new artifact + List references = createReferencesFromZip(zipEntries, group, api); - HttpResponse exportedApiZip = makeRequest("GET", - config.getSourcePublisherApiUrl().concat(String.format("/apis/export?apiId=%s", api.getId())), - httpHeaders, params, true); + ArtifactMetaData meta = client.createArtifact(group, mainArtifactId, api.getVersion(), null, null, null, + api.getName(), fullDesc, null, null, null, + new ByteArrayInputStream(swaggerObj.toString().getBytes()), references); - List zipEntries = ZipExtractor.extractFilesFromZip(exportedApiZip.getResponseBytes()); + setMetaAndRules(meta, props, tagsList); + // Create the three required rules + createRule(meta, "NONE", RuleType.COMPATIBILITY); + createRule(meta, "NONE", RuleType.VALIDITY); + createRule(meta, "NONE", RuleType.INTEGRITY); - Map mapSubs = gson.fromJson(responseSubs.getResponse(), Map.class); - Map mapApi = gson.fromJson(responseApi.getResponse(), Map.class); + } else { + // Artifact exists – check if the version exists + boolean versionExists = false; + try { + client.getArtifactVersionMetaData(group, mainArtifactId, api.getVersion()); + versionExists = true; + } catch (Exception e) { + // Version missing – will create it below + } - List tags = new ArrayList(); + List references = createReferencesFromZip(zipEntries, group, api); - Map map = new HashMap(); - map.put("Version ", " " + api.getVersion()); - map.put("Status ", " " + apiStatus); - addSubscriptionsToMap(map, mapSubs); - addEndpointsToMap(map, mapApi); - addTagsToMap(map, (List) mapApi.get("tags")); + if (!versionExists) { + ArtifactMetaData meta = client.updateArtifact(group, mainArtifactId, api.getVersion(), + api.getName(), fullDesc, new ByteArrayInputStream(swaggerObj.toString().getBytes()), + references); + setMetaAndRules(meta, props, tagsList); + } else { + // Version already exists – no action needed + log.warn("API {} with version {} already exists. Skipping import.", api.getContext(), + api.getVersion()); + } + } - String group = config.getDefaultApiGroup(); + log.info("Successfully imported API '{}' ({}). Took {} ms", api.getName(), api.getVersion(), + System.currentTimeMillis() - start); + } catch (IOException e) { + log.error("IO error while importing API {}: {}", api.getId(), e.getMessage(), e); + } catch (VersionAlreadyExistsException e) { + log.warn("API version already exists for {}: {}. Skipping.", api.getName(), api.getVersion()); + } catch (Exception e) { + log.error("Cannot export API '{}':{}", api.getName(), api.getVersion(), e); + } + } - String ApiDesc = api.getDescription() != null ? api.getDescription() : ""; + /* --------------------------------------------------------------------- */ + /* Helper methods */ + /* --------------------------------------------------------------------- */ - String ApiDescNew = ApiDesc + " ***** " + "PUBLISHER URL ***** " - + config.getPublisherUrlPattern().replace("{API_ID}", api.getId()) + " ***** " - + "DEVPORTAL URL ***** " + config.getDevportalUrlPattern().replace("{API_ID}", api.getId()); + private String mapApiType(String type) { + // Java 11 does not support switch‑expressions + switch (type) { + case "HTTP": + return "OPENAPI"; + case "GRAPHQL": + return "GRAPHQL"; + case "WS": + return "ASYNCAPI"; + case "SOAP": + return "WSDL"; + default: + return type; + } + } - String ApiDescSwagger = ApiDesc + "\r\n\r\n\n\n" + "PUBLISHER URL:" - + config.getPublisherUrlPattern().replace("{API_ID}", api.getId()) + "\r\n\n\n" - + "DEVPORTAL URL:" + config.getDevportalUrlPattern().replace("{API_ID}", api.getId()); + private void updateSwagger(JsonObject swagger, Map apiMap, String description) { + JsonObject info = swagger.getAsJsonObject("info"); + if (info != null) { + info.addProperty("description", description); + } - JsonObject swagger = JsonParser.parseString(responseApiSwagger.getResponse()).getAsJsonObject(); + // Build servers array + JsonArray servers = new JsonArray(); + @SuppressWarnings("unchecked") + List> endpoints = (List>) apiMap.get("endpointURLs"); + if (endpoints != null) { + for (Map env : endpoints) { + @SuppressWarnings("unchecked") + Map urls = (Map) env.get("URLs"); + if (urls == null || urls.isEmpty()) + continue; - JsonObject info = swagger.getAsJsonObject("info"); - info.addProperty("description", ApiDescSwagger); - - JsonArray serversJsonArray = new JsonArray(); - - if (mapApi != null && !mapApi.isEmpty()) { - List list = (List) mapApi.get("endpointURLs"); - if (list != null && !list.isEmpty()) { - for (Iterator it = list.iterator(); it.hasNext();) { - Map environment = it.next(); - Map urls = (Map) environment.get("URLs"); - - if (urls != null && !urls.isEmpty()) { - JsonObject servers = new JsonObject(); - - String https = (String) urls.get("https"); - String wss = (String) urls.get("wss"); - - if (https != null) { - servers.addProperty("url", https); - } - if (wss != null) { - servers.addProperty("url", wss); - } - - servers.addProperty("description", - "Gateway: " + (String) environment.get("environmentName")); - serversJsonArray.add(servers); - } + JsonObject server = new JsonObject(); + urls.forEach((k, v) -> { + if (v != null && !v.isBlank()) { + if (k.equals("https")) { + server.addProperty("url", v); + } else if (k.equals("wss")) { + server.addProperty("url", v); } } - } + }); + server.addProperty("description", "Gateway: " + env.getOrDefault("environmentName", "")); + servers.add(server); + } + } - swagger.remove("servers"); - swagger.add("servers", serversJsonArray); + swagger.remove("servers"); + swagger.add("servers", servers); + } - swagger.getAsJsonObject("info").addProperty("description", ApiDescSwagger); + private void addSubscriptionsToProps(Map props, Map subsMap) { + if (subsMap == null || !subsMap.containsKey("list")) + return; + @SuppressWarnings("unchecked") + List> list = (List>) subsMap.get("list"); + int i = 1; + for (Map sub : list) { + @SuppressWarnings("unchecked") + Map appInfo = (Map) sub.get("applicationInfo"); + if (appInfo == null) + continue; + props.put("subscription" + i, + appInfo.getOrDefault("name", "") + " (Owner: " + appInfo.getOrDefault("subscriber", "") + ")"); + i++; + } + } - log.info("Trying to call ApiCurio..."); + private void addEndpointsToProps(Map props, Map apiMap) { + if (apiMap == null || !apiMap.containsKey("endpointURLs")) + return; + @SuppressWarnings("unchecked") + List> envs = (List>) apiMap.get("endpointURLs"); + for (Map env : envs) { + @SuppressWarnings("unchecked") + Map urls = (Map) env.get("URLs"); + if (urls == null) + continue; + urls.forEach((k, v) -> props.put(k + " Endpoint", v)); + } + } - VersionMetaData checkIfVersionExist = null; - VersionSearchResults checkIfApiExist = null; + private void addTagsToProps(Map props, List tags) { + if (tags != null && !tags.isEmpty()) { + props.put("tags", String.join(", ", tags)); + } + } - String mainArtifactId = api.getName().concat(api.getContext()); + private List createReferencesFromZip(List zipEntries, String group, APIInfo api) + throws IOException { - try { - checkIfApiExist = client.listArtifactVersions(group, mainArtifactId, 0, 9999); - log.debug("API " + api.getContext() + " exists ..."); - try { - checkIfVersionExist = client.getArtifactVersionMetaData(group, mainArtifactId, - api.getVersion()); - log.debug("Version " + api.getVersion() + " for API " + api.getContext() + " exists ..."); - } catch (Exception e) { - log.debug("No version " + api.getVersion() + " for API " + api.getContext() + " exists ..."); - } - } catch (Exception e) { - log.debug("No API " + api.getContext() + " exists, so creating ..."); - } + List references = new ArrayList<>(); + for (ZipEntryData entry : zipEntries) { + String artifactId = api.getName() + "/" + api.getVersion() + "/" + entry.getName(); - if (checkIfApiExist == null) { - List references = new ArrayList<>(); - for (ZipEntryData entry : zipEntries) { - String artifactId = api.getName().concat("/").concat(api.getVersion()).concat("/") - .concat(entry.getName()); - ArtifactMetaData mtd = client.createArtifactWithVersion(entry.getType().toString(), artifactId, - api.getVersion(), new ByteArrayInputStream(entry.getContent())); - - ArtifactReference ref = new ArtifactReference(); - ref.setName(entry.getName()); - ref.setGroupId(entry.getType().toString()); - ref.setArtifactId(artifactId); - ref.setVersion(api.getVersion()); - references.add(ref); - } - - ArtifactMetaData mtd = client.createArtifact(group, mainArtifactId, api.getVersion(), null, null, - null, api.getName(), ApiDescNew, null, null, null, - new ByteArrayInputStream(swagger.toString().getBytes()), references); - EditableMetaData props = new EditableMetaData(); - props.setName(api.getName()); - props.setDescription(ApiDescNew); - props.setProperties(map); - props.setLabels(tags); - - client.updateArtifactMetaData(mtd.getGroupId(), mtd.getId(), props); - updateRules(mtd, "NONE", "COMPATIBILITY"); - updateRules(mtd, "NONE", "VALIDITY"); - updateRules(mtd, "NONE", "INTEGRITY"); - - } else if (checkIfVersionExist == null) { - List references = new ArrayList<>(); - for (ZipEntryData entry : zipEntries) { - String artifactId = api.getName().concat("/").concat(api.getVersion()).concat("/") - .concat(entry.getName()); - ArtifactMetaData mtd = client.createArtifactWithVersion(entry.getType().toString(), artifactId, - api.getVersion(), new ByteArrayInputStream(entry.getContent())); - - ArtifactReference ref = new ArtifactReference(); - ref.setName(entry.getName()); - ref.setGroupId(entry.getType().toString()); - ref.setArtifactId(artifactId); - ref.setVersion(api.getVersion()); - references.add(ref); - } - - ArtifactMetaData mtd = client.updateArtifact(group, mainArtifactId, api.getVersion(), api.getName(), - ApiDescNew, new ByteArrayInputStream(swagger.toString().getBytes()), references); - EditableMetaData props = new EditableMetaData(); - props.setName(api.getName()); - props.setDescription(ApiDescNew); - props.setProperties(map); - props.setLabels(tags); - client.updateArtifactMetaData(mtd.getGroupId(), mtd.getId(), props); - } - - log.info("ApiCurio called successfully..."); - - } catch (VersionAlreadyExistsException e) { - log.error(e); + // Create the artifact (versioned) + try (ByteArrayInputStream is = new ByteArrayInputStream(entry.getContent())) { + client.createArtifactWithVersion(entry.getType().toString(), artifactId, api.getVersion(), is); } - log.info("API successfully posted to APICurio. APIName='" + api.getName() + "'. Done in " - + (System.currentTimeMillis() - start) + "ms"); - - } catch (Exception e) { - log.error("Cannot export API: " + api.getName() + " " + api.getVersion(), e); + ArtifactReference ref = new ArtifactReference(); + ref.setName(entry.getName()); + ref.setGroupId(entry.getType().toString()); + ref.setArtifactId(artifactId); + ref.setVersion(api.getVersion()); + references.add(ref); } + return references; } - private void addTagsToMap(Map map, List list) { - if (list != null && !list.isEmpty()) { - map.put("Tags ", " " + list.toString().replace("[", "").replace("]", "")); - } + private void setMetaAndRules(ArtifactMetaData meta, Map props, List tags) { + EditableMetaData metaData = new EditableMetaData(); + metaData.setName(meta.getName()); + metaData.setDescription(meta.getDescription()); + metaData.setProperties(props); + metaData.setLabels(tags); + + client.updateArtifactMetaData(meta.getGroupId(), meta.getId(), metaData); } - private void updateRules(ArtifactMetaData mtd, String config, String ruletype) { + private void createRule(ArtifactMetaData meta, String config, RuleType type) { Rule rule = new Rule(); rule.setConfig(config); - rule.setType(RuleType.fromValue(ruletype)); - client.createArtifactRule(mtd.getGroupId(), mtd.getId(), rule); - } - - private void addSubscriptionsToMap(Map map, Map mapSubs) { - if (mapSubs != null && !mapSubs.isEmpty()) { - List list = (List) mapSubs.get("list"); - int i = 0; - if (list != null && !list.isEmpty()) { - for (Iterator it = list.iterator(); it.hasNext();) { - i++; - Map subscription = it.next(); - Map applicationInfo = (Map) subscription.get("applicationInfo"); - if (applicationInfo != null && !applicationInfo.isEmpty()) - map.put("Subscription" + i + " ", " " + (String) applicationInfo.get("name") + " " + "(Owner: " - + (String) applicationInfo.get("subscriber") + ")"); - } - } - } - } - - private void addEndpointsToMap(Map map, Map mapApi) { - if (mapApi != null && !mapApi.isEmpty()) { - List list = (List) mapApi.get("endpointURLs"); - if (list != null && !list.isEmpty()) { - for (Iterator it = list.iterator(); it.hasNext();) { - Map environment = it.next(); - Map urls = (Map) environment.get("URLs"); - if (urls != null && !urls.isEmpty()) { - String http = (String) urls.get("http"); - String https = (String) urls.get("https"); - String ws = (String) urls.get("ws"); - String wss = (String) urls.get("wss"); - if (http != null) { - map.put("HTTP Endpoint", http); - } else if (https != null) { - map.put("HTTPS Endpoint", https); - } else if (ws != null) { - map.put("WS Endpoint", ws); - } else if (wss != null) { - map.put("WSS Endpoint", wss); - } - } - } - } - } + rule.setType(type); + client.createArtifactRule(meta.getGroupId(), meta.getId(), rule); } }