Search in sources :

Example 96 with APIProduct

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;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) DocumentSearchResultDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentSearchResultDTO)

Example 97 with APIProduct

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();
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) APITemplateException(org.wso2.carbon.apimgt.impl.template.APITemplateException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.api.RegistryException) APITemplateException(org.wso2.carbon.apimgt.impl.template.APITemplateException) Template(org.apache.velocity.Template)

Example 98 with APIProduct

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;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO) JSONException(org.json.JSONException) XMLStreamException(javax.xml.stream.XMLStreamException) CertificateManagementException(org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) APITemplateException(org.wso2.carbon.apimgt.impl.template.APITemplateException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MediationPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationPolicyDTO)

Example 99 with APIProduct

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()));
        }
    }
}
Also used : GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)

Example 100 with APIProduct

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;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) JsonElement(com.google.gson.JsonElement)

Aggregations

APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)71 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)52 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)51 API (org.wso2.carbon.apimgt.api.model.API)37 ArrayList (java.util.ArrayList)31 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)22 PublisherAPIProduct (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct)22 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)21 Tier (org.wso2.carbon.apimgt.api.model.Tier)21 HashMap (java.util.HashMap)19 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)19 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)18 JSONObject (org.json.simple.JSONObject)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)16 HashSet (java.util.HashSet)15 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)15 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)14 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)14 ParseException (org.json.simple.parser.ParseException)12