use of org.wso2.carbon.apimgt.internal.service.dto.APIDTO in project carbon-apimgt by wso2.
the class ExportUtils method addDependentAPIsToArchive.
/**
* Retrieve dependent APIs by checking the resources of the API Product and store those in the archive directory.
*
* @param archivePath Temp location to save the API artifacts
* @param apiProductDtoToReturn API Product DTO which the resources should be considered
* @param userName User name of the requester
* @param provider API Product Provider
* @param exportFormat Export format of the API meta data, could be yaml or json
* @param isStatusPreserved Whether API status is preserved while export
* @param organization Organization
* @throws APIImportExportException If an error occurs while creating the directory or extracting the archive
* @throws APIManagementException If an error occurs while retrieving API related resources
*/
public static void addDependentAPIsToArchive(String archivePath, APIProductDTO apiProductDtoToReturn, ExportFormat exportFormat, APIProvider provider, String userName, Boolean isStatusPreserved, boolean preserveDocs, boolean preserveCredentials, String organization) throws APIImportExportException, APIManagementException {
String apisDirectoryPath = archivePath + File.separator + ImportExportConstants.APIS_DIRECTORY;
CommonUtil.createDirectory(apisDirectoryPath);
List<ProductAPIDTO> apisList = apiProductDtoToReturn.getApis();
for (ProductAPIDTO productAPIDTO : apisList) {
String apiProductRequesterDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
API api = provider.getAPIbyUUID(productAPIDTO.getApiId(), apiProductRequesterDomain);
APIDTO apiDtoToReturn = APIMappingUtil.fromAPItoDTO(api, preserveCredentials, null);
File dependentAPI = exportApi(provider, api.getId(), apiDtoToReturn, api, userName, exportFormat, isStatusPreserved, preserveDocs, StringUtils.EMPTY, organization);
CommonUtil.extractArchive(dependentAPI, apisDirectoryPath);
}
}
use of org.wso2.carbon.apimgt.internal.service.dto.APIDTO in project carbon-apimgt by wso2.
the class ExportUtils method addEndpointCertificatesToArchive.
/**
* Retrieve the endpoint certificates and store those in the archive directory.
*
* @param archivePath File path to export the endpoint certificates
* @param apiDto API DTO to be exported
* @param tenantId Tenant id of the user
* @param exportFormat Export format of file
* @throws APIImportExportException If an error occurs while exporting endpoint certificates
*/
public static void addEndpointCertificatesToArchive(String archivePath, APIDTO apiDto, int tenantId, ExportFormat exportFormat) throws APIImportExportException {
List<String> productionEndpoints;
List<String> sandboxEndpoints;
List<String> productionFailovers;
List<String> sandboxFailovers;
Set<String> uniqueEndpointURLs = new HashSet<>();
JsonArray endpointCertificatesDetails = new JsonArray();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String endpointConfigString = gson.toJson(apiDto.getEndpointConfig());
String endpointCertsDirectoryPath = archivePath + File.separator + ImportExportConstants.ENDPOINT_CERTIFICATES_DIRECTORY;
CommonUtil.createDirectory(endpointCertsDirectoryPath);
if (StringUtils.isEmpty(endpointConfigString) || "null".equals(endpointConfigString)) {
if (log.isDebugEnabled()) {
log.debug("Endpoint Details are empty for API: " + apiDto.getName() + StringUtils.SPACE + APIConstants.API_DATA_VERSION + ": " + apiDto.getVersion());
}
return;
}
try {
JSONTokener tokener = new JSONTokener(endpointConfigString);
JSONObject endpointConfig = new JSONObject(tokener);
productionEndpoints = getEndpointURLs(endpointConfig, API_DATA_PRODUCTION_ENDPOINTS, apiDto.getName());
sandboxEndpoints = getEndpointURLs(endpointConfig, API_DATA_SANDBOX_ENDPOINTS, apiDto.getName());
productionFailovers = getEndpointURLs(endpointConfig, APIConstants.ENDPOINT_PRODUCTION_FAILOVERS, apiDto.getName());
sandboxFailovers = getEndpointURLs(endpointConfig, APIConstants.ENDPOINT_SANDBOX_FAILOVERS, apiDto.getName());
// Remove duplicate and append result
uniqueEndpointURLs.addAll(productionEndpoints);
uniqueEndpointURLs.addAll(sandboxEndpoints);
uniqueEndpointURLs.addAll(productionFailovers);
uniqueEndpointURLs.addAll(sandboxFailovers);
for (String url : uniqueEndpointURLs) {
JsonArray certificateListOfUrl = getEndpointCertificateContentAndMetaData(tenantId, url, endpointCertsDirectoryPath);
endpointCertificatesDetails.addAll(certificateListOfUrl);
}
if (endpointCertificatesDetails.size() > 0) {
CommonUtil.writeDtoToFile(endpointCertsDirectoryPath + ImportExportConstants.ENDPOINTS_CERTIFICATE_FILE, exportFormat, ImportExportConstants.TYPE_ENDPOINT_CERTIFICATES, endpointCertificatesDetails);
} else if (log.isDebugEnabled()) {
log.debug("No endpoint certificates available for API: " + apiDto.getName() + StringUtils.SPACE + APIConstants.API_DATA_VERSION + ": " + apiDto.getVersion() + ". Skipping certificate export.");
}
} catch (JSONException e) {
throw new APIImportExportException("Error in converting Endpoint config to JSON object in API: " + apiDto.getName(), e);
} catch (IOException e) {
throw new APIImportExportException("Error while retrieving saving endpoint certificate details for API: " + apiDto.getName() + " as YAML", e);
}
}
use of org.wso2.carbon.apimgt.internal.service.dto.APIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method addWebsocketTopicMappings.
private static void addWebsocketTopicMappings(API api, APIDTO apidto) {
org.json.JSONObject endpointConfiguration = new org.json.JSONObject(api.getEndpointConfig());
String sandboxEndpointUrl = !endpointConfiguration.isNull(APIConstants.API_DATA_SANDBOX_ENDPOINTS) ? endpointConfiguration.getJSONObject(APIConstants.API_DATA_SANDBOX_ENDPOINTS).getString("url") : null;
String productionEndpointUrl = !endpointConfiguration.isNull(APIConstants.API_DATA_PRODUCTION_ENDPOINTS) ? endpointConfiguration.getJSONObject(APIConstants.API_DATA_PRODUCTION_ENDPOINTS).getString("url") : null;
Map<String, Map<String, String>> perTopicMappings = new HashMap<>();
for (APIOperationsDTO operation : apidto.getOperations()) {
String key = operation.getTarget();
String mapping = operation.getUriMapping() == null ? "" : Paths.get("/", operation.getUriMapping()).toString();
Map<String, String> endpoints = new HashMap<>();
if (sandboxEndpointUrl != null) {
endpoints.put(APIConstants.GATEWAY_ENV_TYPE_SANDBOX, sandboxEndpointUrl + mapping);
}
if (productionEndpointUrl != null) {
endpoints.put(APIConstants.GATEWAY_ENV_TYPE_PRODUCTION, productionEndpointUrl + mapping);
}
perTopicMappings.put(key, endpoints);
}
api.setWebSocketTopicMappingConfiguration(new WebSocketTopicMappingConfiguration(perTopicMappings));
addWebsocketTopicResourceKeys(api);
}
use of org.wso2.carbon.apimgt.internal.service.dto.APIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setAPIFaultSequencesToBeAdded.
private static void setAPIFaultSequencesToBeAdded(API api, GatewayAPIDTO gatewayAPIDTO, String extractedPath, APIDTO apidto) throws APIManagementException {
String faultSeqExt = APIUtil.getSequenceExtensionName(api) + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
if (!APIConstants.APITransportType.HTTP.toString().equals(api.getType())) {
gatewayAPIDTO.setSequencesToBeRemove(GatewayUtils.addStringToList(faultSeqExt, gatewayAPIDTO.getSequencesToBeRemove()));
List<MediationPolicyDTO> mediationPolicies = apidto.getMediationPolicies();
GatewayContentDTO faultSequenceContent = retrieveSequence(extractedPath, mediationPolicies, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, api);
if (faultSequenceContent != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(faultSequenceContent, gatewayAPIDTO.getSequenceToBeAdd()));
}
}
gatewayAPIDTO.setSequencesToBeRemove(GatewayUtils.addStringToList(faultSeqExt, gatewayAPIDTO.getSequencesToBeRemove()));
}
use of org.wso2.carbon.apimgt.internal.service.dto.APIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setCustomSequencesToBeAdded.
private static void setCustomSequencesToBeAdded(APIProduct apiProduct, API api, GatewayAPIDTO gatewayAPIDTO, String extractedPath, APIDTO apidto) throws APIManagementException {
if (APIConstants.APITransportType.HTTP.toString().equals(api.getType())) {
GatewayContentDTO gatewayInContentDTO = retrieveOperationPolicySequenceForProducts(apiProduct, api, extractedPath, APIConstants.OPERATION_SEQUENCE_TYPE_REQUEST);
if (gatewayInContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayInContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayOutContentDTO = retrieveOperationPolicySequenceForProducts(apiProduct, api, extractedPath, APIConstants.OPERATION_SEQUENCE_TYPE_RESPONSE);
if (gatewayOutContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayOutContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayFaultContentDTO = retrieveOperationPolicySequenceForProducts(apiProduct, api, extractedPath, APIConstants.OPERATION_SEQUENCE_TYPE_FAULT);
if (gatewayFaultContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayFaultContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
} else {
GatewayContentDTO gatewayInContentDTO = retrieveSequence(apiProduct, extractedPath, apidto.getMediationPolicies(), APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, api);
if (gatewayInContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayInContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
GatewayContentDTO gatewayOutContentDTO = retrieveSequence(apiProduct, extractedPath, apidto.getMediationPolicies(), APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, api);
if (gatewayOutContentDTO != null) {
gatewayAPIDTO.setSequenceToBeAdd(addGatewayContentToList(gatewayOutContentDTO, gatewayAPIDTO.getSequenceToBeAdd()));
}
}
}
Aggregations