rewritten endpoint parsing
This commit is contained in:
parent
775b3b042d
commit
5eb12c6526
BIN
Calculator-1.0.0.zip
Normal file
BIN
Calculator-1.0.0.zip
Normal file
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
package cz.trask.migration.impl.v45;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -103,11 +104,11 @@ public class ExportToWso2FromV32 extends AbstractProcess {
|
||||
byte[] data = prepareApiZipFile32to45(client, ver, ref);
|
||||
String fileName = api.getName() + "-" + ver.getVersion() + ".zip";
|
||||
|
||||
// FileOutputStream fos = new FileOutputStream(fileName);
|
||||
// fos.write(data);
|
||||
// fos.flush();
|
||||
// fos.close();
|
||||
// System.exit(0);
|
||||
FileOutputStream fos = new FileOutputStream(fileName);
|
||||
fos.write(data);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
//System.exit(0);
|
||||
|
||||
if (data != null && data.length > 0 && fileName != null && !fileName.isEmpty()) {
|
||||
int responseCode = publishApiToWso2(fileName, data, tokenResponse);
|
||||
@ -185,12 +186,12 @@ public class ExportToWso2FromV32 extends AbstractProcess {
|
||||
addGenericPolicyMetadata(zos, baseDir + subDir, specialName.replace(".j2", ".yaml"), r);
|
||||
} else if (FileType.POLICY_OUT.toString().equals(amd.getGroupId())) {
|
||||
subDir = "Policies/";
|
||||
specialName = r.getName().replace(".xml", "_v1_common.j2");
|
||||
specialName = r.getName().replace(".xml", "_v1_api.j2");
|
||||
content = convertSequenceToPolicy(content);
|
||||
addGenericPolicyMetadata(zos, baseDir + subDir, specialName.replace(".j2", ".yaml"), r);
|
||||
} else if (FileType.POLICY_FAULT.toString().equals(amd.getGroupId())) {
|
||||
subDir = "Policies/";
|
||||
specialName = r.getName().replace(".xml", "_v1_common.j2");
|
||||
specialName = r.getName().replace(".xml", "_v1_api.j2");
|
||||
content = convertSequenceToPolicy(content);
|
||||
addGenericPolicyMetadata(zos, baseDir + subDir, specialName.replace(".j2", ".yaml"), r);
|
||||
} else if (FileType.OPENAPI.toString().equals(amd.getGroupId())) {
|
||||
|
||||
@ -3,12 +3,12 @@ package cz.trask.migration.mapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import cz.trask.migration.AbstractProcess;
|
||||
@ -17,7 +17,6 @@ import cz.trask.migration.model.v45.ApiDefinition45;
|
||||
import cz.trask.migration.model.v45.ApiDefinition45.ApiPolicies;
|
||||
import cz.trask.migration.model.v45.ApiDefinition45.Operation;
|
||||
import cz.trask.migration.model.v45.ApiDefinition45.OperationPolicies;
|
||||
import cz.trask.migration.util.CredentialsDecoder;
|
||||
|
||||
public class ApiDefinitionMapper32to45 {
|
||||
|
||||
@ -100,7 +99,7 @@ public class ApiDefinitionMapper32to45 {
|
||||
data.setCorsConfiguration(mapCors(oldApi.getCorsConfiguration()));
|
||||
|
||||
// ---------- endpoint ----------
|
||||
data.setEndpointConfig(mapEndpointConfig(oldApi.getEndpointConfig()));
|
||||
data.setEndpointConfig(oldApi.getEndpointConfig());
|
||||
data.setEndpointImplementationType(oldApi.getImplementation());
|
||||
|
||||
// ---------- API policies ----------
|
||||
@ -124,9 +123,15 @@ public class ApiDefinitionMapper32to45 {
|
||||
data.setGatewayType("wso2/synapse");
|
||||
|
||||
// ---------- business & monetization ----------
|
||||
data.setBusinessInformation(oldApi.getMonetizationProperties());
|
||||
data.setAdditionalProperties(Collections.emptyList());
|
||||
data.setAdditionalPropertiesMap(oldApi.getAdditionalProperties());
|
||||
data.setBusinessInformation(new HashMap<>());
|
||||
data.getBusinessInformation().put("businessOwner", oldApi.getBusinessOwner());
|
||||
data.getBusinessInformation().put("businessOwnerEmail", oldApi.getBusinessOwnerEmail());
|
||||
data.getBusinessInformation().put("technicalOwner", oldApi.getTechnicalOwner());
|
||||
data.getBusinessInformation().put("technicalOwnerEmail", oldApi.getTechnicalOwnerEmail());
|
||||
|
||||
// ---------- additional properties ----------
|
||||
data.setAdditionalProperties(mapAdditionalProperties(oldApi.getAdditionalProperties()));
|
||||
data.setAdditionalPropertiesMap(mapAdditionalPropertiesMap(oldApi.getAdditionalProperties()));
|
||||
|
||||
// ---------- subscription ----------
|
||||
data.setSubscriptionAvailability(oldApi.getSubscriptionAvailability().toUpperCase());
|
||||
@ -146,6 +151,36 @@ public class ApiDefinitionMapper32to45 {
|
||||
return newApi;
|
||||
}
|
||||
|
||||
private static List<Object> mapAdditionalProperties(Map<String, Object> additionalProperties) {
|
||||
if (additionalProperties != null && !additionalProperties.isEmpty()) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : additionalProperties.entrySet()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", entry.getKey());
|
||||
map.put("value", entry.getValue());
|
||||
map.put("display", "false");
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Map<String, Object> mapAdditionalPropertiesMap(Map<String, Object> additionalProperties) {
|
||||
if (additionalProperties != null && !additionalProperties.isEmpty()) {
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : additionalProperties.entrySet()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", entry.getKey());
|
||||
map.put("value", entry.getValue());
|
||||
map.put("display", "false");
|
||||
res.put(entry.getKey(), map);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ApiPolicies mapApiPolicies(ApiDefinition32 oldApi) {
|
||||
ApiDefinition45.ApiPolicies apiPolicies = new ApiDefinition45.ApiPolicies();
|
||||
// ---------- request policies ----------
|
||||
@ -197,73 +232,73 @@ public class ApiDefinitionMapper32to45 {
|
||||
return cors;
|
||||
}
|
||||
|
||||
private static ApiDefinition45.EndpointConfig mapEndpointConfig(ApiDefinition32.EndpointConfig oldEndpoint) {
|
||||
if (oldEndpoint == null)
|
||||
return null;
|
||||
|
||||
ApiDefinition45.EndpointConfig newEndpoint = new ApiDefinition45.EndpointConfig();
|
||||
newEndpoint.setEndpoint_type(oldEndpoint.getEndpointType());
|
||||
|
||||
if (oldEndpoint.getSandboxEndpoints() != null) {
|
||||
ApiDefinition45.EndpointGroup sandbox = new ApiDefinition45.EndpointGroup();
|
||||
sandbox.setUrl(oldEndpoint.getSandboxEndpoints().getUrl());
|
||||
newEndpoint.setSandbox_endpoints(sandbox);
|
||||
}
|
||||
|
||||
if (oldEndpoint.getProductionEndpoints() != null) {
|
||||
ApiDefinition45.EndpointGroup production = new ApiDefinition45.EndpointGroup();
|
||||
production.setUrl(oldEndpoint.getProductionEndpoints().getUrl());
|
||||
newEndpoint.setProduction_endpoints(production);
|
||||
}
|
||||
|
||||
if (oldEndpoint.getEndpointSecurity() != null) {
|
||||
ApiDefinition45.EndpointSecurity security = new ApiDefinition45.EndpointSecurity();
|
||||
security.setSandbox(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getSandbox()));
|
||||
security.setProduction(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getProduction()));
|
||||
newEndpoint.setEndpoint_security(security);
|
||||
}
|
||||
|
||||
return newEndpoint;
|
||||
}
|
||||
|
||||
private static ApiDefinition45.SecurityEnv mapSecurityEnv(ApiDefinition32.SecurityEnvironment oldSec) {
|
||||
if (oldSec == null)
|
||||
return null;
|
||||
|
||||
ApiDefinition45.SecurityEnv newSec = new ApiDefinition45.SecurityEnv();
|
||||
newSec.setType(oldSec.getType());
|
||||
newSec.setTokenUrl(oldSec.getTokenUrl());
|
||||
newSec.setClientId(oldSec.getClientId());
|
||||
newSec.setClientSecret(
|
||||
CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(), AbstractProcess.PRIVATE_KEY_APIM_32));
|
||||
newSec.setUsername(oldSec.getUsername());
|
||||
newSec.setPassword(oldSec.getPassword());
|
||||
newSec.setGrantType(oldSec.getGrantType());
|
||||
newSec.setEnabled(oldSec.isEnabled());
|
||||
newSec.setConnectionTimeoutDuration(0);
|
||||
newSec.setSocketTimeoutDuration(0);
|
||||
newSec.setConnectionRequestTimeoutDuration(0);
|
||||
newSec.setProxyConfigs(new ApiDefinition45.ProxyConfigs());
|
||||
|
||||
// ---------- parse customParameters JSON string ----------
|
||||
if (oldSec.getCustomParameters() != null && !oldSec.getCustomParameters().isEmpty()) {
|
||||
try {
|
||||
Map<String, Object> map = AbstractProcess.mapperYaml.readValue(oldSec.getCustomParameters(),
|
||||
new TypeReference<>() {
|
||||
});
|
||||
newSec.setCustomParameters(map);
|
||||
} catch (Exception e) {
|
||||
newSec.setCustomParameters(Collections.emptyMap());
|
||||
}
|
||||
} else {
|
||||
newSec.setCustomParameters(Collections.emptyMap());
|
||||
}
|
||||
|
||||
// ---------- parse additionalProperties JSON string ----------
|
||||
newSec.setAdditionalProperties(Collections.emptyMap());
|
||||
|
||||
return newSec;
|
||||
}
|
||||
// private static ApiDefinition45.EndpointConfig mapEndpointConfig(ApiDefinition32.EndpointConfig oldEndpoint) {
|
||||
// if (oldEndpoint == null)
|
||||
// return null;
|
||||
//
|
||||
// ApiDefinition45.EndpointConfig newEndpoint = new ApiDefinition45.EndpointConfig();
|
||||
// newEndpoint.setEndpoint_type(oldEndpoint.getEndpointType());
|
||||
//
|
||||
// if (oldEndpoint.getSandboxEndpoints() != null) {
|
||||
// ApiDefinition45.EndpointGroup sandbox = new ApiDefinition45.EndpointGroup();
|
||||
// sandbox.setUrl(oldEndpoint.getSandboxEndpoints().getUrl());
|
||||
// newEndpoint.setSandbox_endpoints(sandbox);
|
||||
// }
|
||||
//
|
||||
// if (oldEndpoint.getProductionEndpoints() != null) {
|
||||
// ApiDefinition45.EndpointGroup production = new ApiDefinition45.EndpointGroup();
|
||||
// production.setUrl(oldEndpoint.getProductionEndpoints().getUrl());
|
||||
// newEndpoint.setProduction_endpoints(production);
|
||||
// }
|
||||
//
|
||||
// if (oldEndpoint.getEndpointSecurity() != null) {
|
||||
// ApiDefinition45.EndpointSecurity security = new ApiDefinition45.EndpointSecurity();
|
||||
// security.setSandbox(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getSandbox()));
|
||||
// security.setProduction(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getProduction()));
|
||||
// newEndpoint.setEndpoint_security(security);
|
||||
// }
|
||||
//
|
||||
// return newEndpoint;
|
||||
// }
|
||||
//
|
||||
// private static ApiDefinition45.SecurityEnv mapSecurityEnv(ApiDefinition32.SecurityEnvironment oldSec) {
|
||||
// if (oldSec == null)
|
||||
// return null;
|
||||
//
|
||||
// ApiDefinition45.SecurityEnv newSec = new ApiDefinition45.SecurityEnv();
|
||||
// newSec.setType(oldSec.getType());
|
||||
// newSec.setTokenUrl(oldSec.getTokenUrl());
|
||||
// newSec.setClientId(oldSec.getClientId());
|
||||
// newSec.setClientSecret(
|
||||
// CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(), AbstractProcess.PRIVATE_KEY_APIM_32));
|
||||
// newSec.setUsername(oldSec.getUsername());
|
||||
// newSec.setPassword(oldSec.getPassword());
|
||||
// newSec.setGrantType(oldSec.getGrantType());
|
||||
// newSec.setEnabled(oldSec.isEnabled());
|
||||
// newSec.setConnectionTimeoutDuration(0);
|
||||
// newSec.setSocketTimeoutDuration(0);
|
||||
// newSec.setConnectionRequestTimeoutDuration(0);
|
||||
// newSec.setProxyConfigs(new ApiDefinition45.ProxyConfigs());
|
||||
//
|
||||
// // ---------- parse customParameters JSON string ----------
|
||||
// if (oldSec.getCustomParameters() != null && !oldSec.getCustomParameters().isEmpty()) {
|
||||
// try {
|
||||
// Map<String, Object> map = AbstractProcess.mapperYaml.readValue(oldSec.getCustomParameters(),
|
||||
// new TypeReference<>() {
|
||||
// });
|
||||
// newSec.setCustomParameters(map);
|
||||
// } catch (Exception e) {
|
||||
// newSec.setCustomParameters(Collections.emptyMap());
|
||||
// }
|
||||
// } else {
|
||||
// newSec.setCustomParameters(Collections.emptyMap());
|
||||
// }
|
||||
//
|
||||
// // ---------- parse additionalProperties JSON string ----------
|
||||
// newSec.setAdditionalProperties(Collections.emptyMap());
|
||||
//
|
||||
// return newSec;
|
||||
// }
|
||||
|
||||
public static List<Operation> mapOperations(String swaggerYamlString) throws Exception {
|
||||
JsonNode root = AbstractProcess.mapperYaml.readTree(swaggerYamlString);
|
||||
|
||||
@ -5,7 +5,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
@ -18,12 +17,12 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ApiDefinition32 {
|
||||
|
||||
public static class EndpointConfigDeserializer extends JsonDeserializer<EndpointConfig> {
|
||||
public static class EndpointConfigDeserializer extends JsonDeserializer<Map> {
|
||||
@Override
|
||||
public EndpointConfig deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
public Map deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
String json = p.getValueAsString();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(json, EndpointConfig.class);
|
||||
return mapper.readValue(json, Map.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +55,7 @@ public class ApiDefinition32 {
|
||||
private String subscriptionAvailability;
|
||||
private CorsConfiguration corsConfiguration;
|
||||
@JsonDeserialize(using = EndpointConfigDeserializer.class)
|
||||
private EndpointConfig endpointConfig;
|
||||
private Map endpointConfig;
|
||||
private String responseCache;
|
||||
private int cacheTimeout;
|
||||
private String implementation;
|
||||
@ -79,6 +78,10 @@ public class ApiDefinition32 {
|
||||
private String accessControl;
|
||||
private double rating;
|
||||
private boolean isLatest;
|
||||
private String businessOwner;
|
||||
private String businessOwnerEmail;
|
||||
private String technicalOwner;
|
||||
private String technicalOwnerEmail;
|
||||
|
||||
// -------------------- inner classes --------------------
|
||||
|
||||
@ -115,51 +118,6 @@ public class ApiDefinition32 {
|
||||
private List<String> accessControlAllowMethods;
|
||||
}
|
||||
|
||||
// ----------- typový objekt endpointConfig -----------
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class EndpointConfig {
|
||||
@JsonProperty("endpoint_type")
|
||||
private String endpointType;
|
||||
|
||||
@JsonProperty("sandbox_endpoints")
|
||||
private Endpoint sandboxEndpoints;
|
||||
|
||||
@JsonProperty("production_endpoints")
|
||||
private Endpoint productionEndpoints;
|
||||
|
||||
@JsonProperty("endpoint_security")
|
||||
private EndpointSecurity endpointSecurity;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Endpoint {
|
||||
private String url;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class EndpointSecurity {
|
||||
private SecurityEnvironment sandbox;
|
||||
private SecurityEnvironment production;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class SecurityEnvironment {
|
||||
private String tokenUrl;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String password;
|
||||
private String username;
|
||||
private String type;
|
||||
private String grantType;
|
||||
private boolean enabled;
|
||||
private String customParameters;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ProxyConfigs {
|
||||
|
||||
@ -63,7 +63,7 @@ public class ApiDefinition45 {
|
||||
private String createdTime;
|
||||
private String lastUpdatedTimestamp;
|
||||
private String lastUpdatedTime;
|
||||
private EndpointConfig endpointConfig;
|
||||
private Map endpointConfig;
|
||||
private String endpointImplementationType;
|
||||
private SubtypeConfiguration subtypeConfiguration;
|
||||
private List<Object> scopes;
|
||||
@ -115,47 +115,6 @@ public class ApiDefinition45 {
|
||||
private String signatureHeader;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class EndpointConfig {
|
||||
private String endpoint_type;
|
||||
private EndpointGroup sandbox_endpoints;
|
||||
private EndpointGroup production_endpoints;
|
||||
private EndpointSecurity endpoint_security;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class EndpointGroup {
|
||||
private String url;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class EndpointSecurity {
|
||||
private SecurityEnv sandbox;
|
||||
private SecurityEnv production;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class SecurityEnv {
|
||||
private String tokenUrl;
|
||||
private String clientId;
|
||||
private int connectionTimeoutDuration;
|
||||
private String type;
|
||||
private int socketTimeoutDuration;
|
||||
private boolean enabled;
|
||||
private ProxyConfigs proxyConfigs;
|
||||
private String password;
|
||||
private String clientSecret;
|
||||
private Map<String, Object> customParameters;
|
||||
private Map<String, Object> additionalProperties;
|
||||
private String grantType;
|
||||
private int connectionRequestTimeoutDuration;
|
||||
private String username;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ProxyConfigs {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user