use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class SearchResultMappingUtil method fromDocumentationToProductDocumentResultDTO.
public static DocumentSearchResultDTO fromDocumentationToProductDocumentResultDTO(Documentation document, APIProduct apiProduct) throws APIManagementException {
DocumentSearchResultDTO docResultDTO = new DocumentSearchResultDTO();
docResultDTO.setId(document.getId());
docResultDTO.setName(document.getName());
docResultDTO.setDocType(DocumentSearchResultDTO.DocTypeEnum.valueOf(document.getType().toString()));
docResultDTO.setType(SearchResultDTO.TypeEnum.DOC);
docResultDTO.associatedType(APIConstants.AuditLogConstants.API_PRODUCT);
docResultDTO.setSummary(document.getSummary());
docResultDTO.setVisibility(mapVisibilityFromDocumentToDTO(document.getVisibility()));
docResultDTO.setSourceType(mapSourceTypeFromDocumentToDTO(document.getSourceType()));
docResultDTO.setOtherTypeName(document.getOtherTypeName());
APIProductIdentifier apiId = apiProduct.getId();
docResultDTO.setApiName(apiId.getName());
docResultDTO.setApiVersion(apiId.getVersion());
docResultDTO.setApiProvider(APIUtil.replaceEmailDomainBack(apiId.getProviderName()));
docResultDTO.setApiUUID(apiProduct.getUuid());
return docResultDTO;
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class APITemplateBuilderImpl method getConfigStringForTemplate.
@Override
public String getConfigStringForTemplate(Environment environment) throws APITemplateException {
StringWriter writer = new StringWriter();
try {
// build the context for template and apply the necessary decorators
ConfigContext configcontext = null;
if (api != null) {
configcontext = createConfigContext(api, environment);
} else {
// API Product scenario
configcontext = createConfigContext(apiProduct, environment);
}
// @todo: this validation might be better to do when the builder is initialized.
configcontext.validate();
VelocityContext context = configcontext.getContext();
context.internalGetKeys();
/* first, initialize velocity engine */
VelocityEngine velocityengine = new VelocityEngine();
APIUtil.initializeVelocityContext(velocityengine);
velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
initVelocityEngine(velocityengine);
Template t = null;
if (api != null) {
t = velocityengine.getTemplate(getTemplatePath());
if (APIConstants.APITransportType.WS.toString().equals(api.getType())) {
context.put("topicMappings", this.api.getWebSocketTopicMappingConfiguration().getMappings());
} else if (APIConstants.APITransportType.WEBSUB.toString().equals(api.getType())) {
String signingAlgorithm = api.getWebsubSubscriptionConfiguration().getSigningAlgorithm();
context.put("signingAlgorithm", signingAlgorithm.toLowerCase() + "=");
context.put("secret", api.getWebsubSubscriptionConfiguration().getSecret());
context.put("hmacSignatureGenerationAlgorithm", "Hmac" + signingAlgorithm);
context.put("signatureHeader", api.getWebsubSubscriptionConfiguration().getSignatureHeader());
context.put("isSecurityEnabled", !StringUtils.isEmpty(api.getWebsubSubscriptionConfiguration().getSecret()));
} else if (APIConstants.GRAPHQL_API.equals(api.getType())) {
boolean isSubscriptionAvailable = false;
if (api.getWebSocketTopicMappingConfiguration() != null) {
isSubscriptionAvailable = true;
context.put(APIConstants.VELOCITY_API_WEBSOCKET_TOPIC_MAPPINGS, this.api.getWebSocketTopicMappingConfiguration().getMappings());
}
context.put(APIConstants.VELOCITY_GRAPHQL_API_SUBSCRIPTION_AVAILABLE, isSubscriptionAvailable);
}
} else {
t = velocityengine.getTemplate(getApiProductTemplatePath());
}
t.merge(context, writer);
} catch (Exception e) {
log.error("Velocity Error", e);
throw new APITemplateException("Velocity Error", e);
}
return writer.toString();
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveSequence.
private static GatewayContentDTO retrieveSequence(APIProduct apiProduct, String pathToAchieve, List<MediationPolicyDTO> mediationPolicies, String type, API api) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = apiProduct.getId();
MediationPolicyDTO mediationPolicyDTO = null;
for (MediationPolicyDTO mediationPolicy : mediationPolicies) {
if (type.equalsIgnoreCase(mediationPolicy.getType())) {
mediationPolicyDTO = mediationPolicy;
break;
}
}
if (mediationPolicyDTO != null) {
GatewayContentDTO sequenceContentDto = new GatewayContentDTO();
String sequenceContent = ImportUtils.retrieveSequenceContent(pathToAchieve, !mediationPolicyDTO.isShared(), type.toLowerCase(), mediationPolicyDTO.getName());
if (StringUtils.isNotEmpty(sequenceContent)) {
try {
OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(sequenceContent.getBytes()));
if (omElement != null) {
String seqExt = APIUtil.getSequenceExtensionName(apiProductIdentifier.getName(), apiProductIdentifier.getVersion()).concat("--").concat(api.getUuid());
if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_OUT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_IN_EXT;
}
if (omElement.getAttribute(new QName("name")) != null) {
omElement.getAttribute(new QName("name")).setAttributeValue(seqExt);
}
sequenceContentDto.setName(seqExt);
sequenceContentDto.setContent(APIUtil.convertOMtoString(omElement));
return sequenceContentDto;
}
} catch (Exception e) {
throw new APIManagementException(e);
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIProduct 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()));
}
}
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class APIControllerUtil method injectEnvParamsToAPIProduct.
/**
* This method will be used to add extracted environment parameters to the imported API Product DTO object.
*
* @param importedApiProductDto API Product DTO object to be imported
* @param envParams Env params object with required parameters
* @return APIProductDTO Updated API Product DTO Object
*/
public static APIProductDTO injectEnvParamsToAPIProduct(APIProductDTO importedApiProductDto, JsonObject envParams, String pathToArchive) throws APIManagementException {
if (envParams == null || envParams.isJsonNull()) {
return importedApiProductDto;
}
APIProduct importedApiProduct = APIMappingUtil.fromDTOtoAPIProduct(importedApiProductDto, importedApiProductDto.getProvider());
// handle mutualSSL certificates
handleMutualSslCertificates(envParams, null, importedApiProductDto, importedApiProduct.getId(), pathToArchive);
// handle available subscription policies
JsonElement policies = envParams.get(ImportExportConstants.POLICIES_FIELD);
if (policies != null && !policies.isJsonNull()) {
handleSubscriptionPolicies(policies, null, importedApiProductDto);
}
return importedApiProductDto;
}
Aggregations