Search in sources :

Example 6 with APICorsConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APICorsConfigurationDTO in project carbon-apimgt by wso2.

the class MappingUtil method toAPIDto.

/**
 * This method converts the API Object from models into APIDTO object.
 *
 * @param api API object
 * @return APIDTO object with provided API object
 */
public static APIDTO toAPIDto(API api) throws IOException {
    APIDTO apidto = new APIDTO();
    apidto.setId(api.getId());
    apidto.setName(api.getName());
    apidto.version(api.getVersion());
    apidto.setContext(api.getContext());
    apidto.setDescription(api.getDescription());
    apidto.setIsDefaultVersion(api.isDefaultVersion());
    apidto.setVisibility(APIDTO.VisibilityEnum.valueOf(api.getVisibility().toString()));
    apidto.setResponseCaching(Boolean.toString(api.isResponseCachingEnabled()));
    apidto.setCacheTimeout(api.getCacheTimeout());
    apidto.setVisibleRoles(new ArrayList<>(api.getVisibleRoles()));
    apidto.setProvider(api.getProvider());
    apidto.setPermission(api.getApiPermission());
    apidto.setLifeCycleStatus(api.getLifeCycleStatus());
    apidto.setWorkflowStatus(api.getWorkflowStatus());
    apidto.setTags(new ArrayList<>(api.getTags()));
    apidto.hasOwnGateway(api.hasOwnGateway());
    apidto.setLabels(new ArrayList<>(api.getLabels()));
    apidto.setTransport(new ArrayList<>(api.getTransport()));
    apidto.setUserPermissionsForApi(api.getUserSpecificApiPermissions());
    apidto.setSecurityScheme(mapSecuritySchemeIntToList(api.getSecurityScheme()));
    for (Policy policy : api.getPolicies()) {
        apidto.addPoliciesItem(policy.getPolicyName());
    }
    apidto.setScopes(api.getScopes());
    BusinessInformation businessInformation = api.getBusinessInformation();
    API_businessInformationDTO apiBusinessInformationDTO = new API_businessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(businessInformation.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(businessInformation.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(businessInformation.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(businessInformation.getTechnicalOwnerEmail());
    apidto.setBusinessInformation(apiBusinessInformationDTO);
    CorsConfiguration corsConfiguration = api.getCorsConfiguration();
    API_corsConfigurationDTO apiCorsConfigurationDTO = new API_corsConfigurationDTO();
    apiCorsConfigurationDTO.setAccessControlAllowCredentials(corsConfiguration.isAllowCredentials());
    apiCorsConfigurationDTO.setAccessControlAllowHeaders(corsConfiguration.getAllowHeaders());
    apiCorsConfigurationDTO.setAccessControlAllowMethods(corsConfiguration.getAllowMethods());
    apiCorsConfigurationDTO.setAccessControlAllowOrigins(corsConfiguration.getAllowOrigins());
    apiCorsConfigurationDTO.setCorsConfigurationEnabled(corsConfiguration.isEnabled());
    apidto.setCorsConfiguration(apiCorsConfigurationDTO);
    apidto.setEndpoint(fromEndpointToList(api.getEndpoint()));
    for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
        API_operationsDTO apiOperationsDTO = new API_operationsDTO();
        apiOperationsDTO.setId(uriTemplate.getTemplateId());
        apiOperationsDTO.setUritemplate(uriTemplate.getUriTemplate());
        apiOperationsDTO.setAuthType(uriTemplate.getAuthType());
        apiOperationsDTO.setEndpoint(fromEndpointToList(uriTemplate.getEndpoint()));
        apiOperationsDTO.setHttpVerb(uriTemplate.getHttpVerb());
        apiOperationsDTO.setPolicy(uriTemplate.getPolicy().getPolicyName());
        apiOperationsDTO.setScopes(uriTemplate.getScopes());
        apidto.addOperationsItem(apiOperationsDTO);
    }
    if (api.getApiPolicy() != null) {
        apidto.setApiPolicy(api.getApiPolicy().getPolicyName());
    }
    apidto.setCreatedTime(api.getCreatedTime().toString());
    apidto.setLastUpdatedTime(api.getLastUpdatedTime().toString());
    if (api.getThreatProtectionPolicies() != null) {
        List<String> policyIdList = new ArrayList<>(api.getThreatProtectionPolicies());
        List<API_threatProtectionPolicies_listDTO> listDTOS = new ArrayList<>();
        for (String policyId : policyIdList) {
            API_threatProtectionPolicies_listDTO threatProtectionPoliciesListDTO = new API_threatProtectionPolicies_listDTO();
            threatProtectionPoliciesListDTO.setPolicyId(policyId);
            // set priority when implementing
            // threatProtectionPoliciesListDTO.setPriority(10);
            listDTOS.add(threatProtectionPoliciesListDTO);
        }
        API_threatProtectionPoliciesDTO threatProtectionPoliciesDTO = new API_threatProtectionPoliciesDTO();
        threatProtectionPoliciesDTO.setList(listDTOS);
        apidto.setThreatProtectionPolicies(threatProtectionPoliciesDTO);
    }
    return apidto;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) ArrayList(java.util.ArrayList) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) API_threatProtectionPolicies_listDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_threatProtectionPolicies_listDTO) API_operationsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_operationsDTO) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) API_threatProtectionPoliciesDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_threatProtectionPoliciesDTO) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) API_businessInformationDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_businessInformationDTO) API_corsConfigurationDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_corsConfigurationDTO)

Example 7 with APICorsConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APICorsConfigurationDTO in project product-microgateway by wso2.

the class CmdUtils method getDefaultCorsConfig.

public static APICorsConfigurationDTO getDefaultCorsConfig() {
    APICorsConfigurationDTO corsConfigurationDTO = new APICorsConfigurationDTO();
    corsConfigurationDTO.setCorsConfigurationEnabled(true);
    corsConfigurationDTO.setAccessControlAllowOrigins(CliConstants.ACCESS_CONTROL_ALLOW_ORIGINS);
    corsConfigurationDTO.setAccessControlAllowMethods(CliConstants.ACCESS_CONTROL_ALLOW_METHODS);
    corsConfigurationDTO.setAccessControlAllowHeaders(CliConstants.ACCESS_CONTROL_ALLOW_HEADERS);
    corsConfigurationDTO.setAccessControlAllowCredentials(CliConstants.ACCESS_CONTROL_ALLOW_CREDENTIALS);
    return corsConfigurationDTO;
}
Also used : APICorsConfigurationDTO(org.wso2.apimgt.gateway.cli.model.rest.APICorsConfigurationDTO)

Aggregations

ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 CORSConfiguration (org.wso2.carbon.apimgt.api.model.CORSConfiguration)4 Tier (org.wso2.carbon.apimgt.api.model.Tier)4 APICorsConfigurationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APICorsConfigurationDTO)4 APIInfoAdditionalPropertiesDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoAdditionalPropertiesDTO)4 APIOperationsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO)4 HashSet (java.util.HashSet)3 JSONObject (org.json.simple.JSONObject)3 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)3 APIInfoAdditionalPropertiesMapDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoAdditionalPropertiesMapDTO)3 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 LinkedHashSet (java.util.LinkedHashSet)2 JSONParser (org.json.simple.parser.JSONParser)2 ParseException (org.json.simple.parser.ParseException)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 APICategory (org.wso2.carbon.apimgt.api.model.APICategory)2 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)2