Search in sources :

Example 16 with CorsConfiguration

use of org.wso2.carbon.apimgt.core.models.CorsConfiguration in project carbon-apimgt by wso2.

the class ApiDAOImpl method addAPIRelatedInformation.

/**
 * Method for adding API related information
 *
 * @param connection DB Connection
 * @param statement  PreparedStatement
 * @param api        API object
 * @throws SQLException if error occurs while accessing data layer
 */
private void addAPIRelatedInformation(Connection connection, PreparedStatement statement, final API api) throws SQLException, org.wso2.carbon.apimgt.core.exception.APIMgtDAOException {
    String apiPrimaryKey = api.getId();
    statement.setString(1, api.getProvider());
    statement.setString(2, api.getName());
    statement.setString(3, api.getContext());
    statement.setString(4, api.getVersion());
    statement.setBoolean(5, api.isDefaultVersion());
    statement.setString(6, api.getDescription());
    statement.setString(7, api.getVisibility().toString());
    statement.setBoolean(8, api.isResponseCachingEnabled());
    statement.setBoolean(9, api.hasOwnGateway());
    statement.setInt(10, api.getCacheTimeout());
    statement.setString(11, apiPrimaryKey);
    BusinessInformation businessInformation = api.getBusinessInformation();
    statement.setString(12, businessInformation.getTechnicalOwner());
    statement.setString(13, businessInformation.getTechnicalOwnerEmail());
    statement.setString(14, businessInformation.getBusinessOwner());
    statement.setString(15, businessInformation.getBusinessOwnerEmail());
    statement.setString(16, api.getLifecycleInstanceId());
    statement.setString(17, api.getLifeCycleStatus());
    CorsConfiguration corsConfiguration = api.getCorsConfiguration();
    statement.setBoolean(18, corsConfiguration.isEnabled());
    statement.setString(19, String.join(",", corsConfiguration.getAllowOrigins()));
    statement.setBoolean(20, corsConfiguration.isAllowCredentials());
    statement.setString(21, String.join(",", corsConfiguration.getAllowHeaders()));
    statement.setString(22, String.join(",", corsConfiguration.getAllowMethods()));
    statement.setInt(23, getApiTypeId(connection, ApiType.STANDARD));
    statement.setString(24, api.getCreatedBy());
    statement.setTimestamp(25, Timestamp.valueOf(LocalDateTime.now()));
    statement.setTimestamp(26, Timestamp.valueOf(LocalDateTime.now()));
    statement.setString(27, api.getCopiedFromApiId());
    statement.setString(28, api.getUpdatedBy());
    statement.setString(29, APILCWorkflowStatus.APPROVED.toString());
    statement.setInt(30, api.getSecurityScheme());
    statement.execute();
    if (API.Visibility.RESTRICTED == api.getVisibility()) {
        addVisibleRole(connection, apiPrimaryKey, api.getVisibleRoles());
    }
    addTagsMapping(connection, apiPrimaryKey, api.getTags());
    addLabelMapping(connection, apiPrimaryKey, api.getLabels());
    addGatewayConfig(connection, apiPrimaryKey, api.getGatewayConfig(), api.getCreatedBy());
    addTransports(connection, apiPrimaryKey, api.getTransport());
    addUrlMappings(connection, api.getUriTemplates().values(), apiPrimaryKey);
    addSubscriptionPolicies(connection, api.getPolicies(), apiPrimaryKey);
    addEndPointsForApi(connection, apiPrimaryKey, api.getEndpoint());
    addAPIDefinition(connection, apiPrimaryKey, api.getApiDefinition(), api.getCreatedBy());
    addAPIPermission(connection, api.getPermissionMap(), apiPrimaryKey);
    if (api.getThreatProtectionPolicies() != null) {
        addThreatProtectionPolicies(connection, apiPrimaryKey, api.getThreatProtectionPolicies());
    }
    if (api.getApiPolicy() != null) {
        addApiPolicy(connection, api.getApiPolicy().getUuid(), apiPrimaryKey);
    }
}
Also used : BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration)

Example 17 with CorsConfiguration

use of org.wso2.carbon.apimgt.core.models.CorsConfiguration 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)

Aggregations

CorsConfiguration (org.wso2.carbon.apimgt.core.models.CorsConfiguration)17 BusinessInformation (org.wso2.carbon.apimgt.core.models.BusinessInformation)16 API (org.wso2.carbon.apimgt.core.models.API)13 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 HashSet (java.util.HashSet)12 HashMap (java.util.HashMap)10 Map (java.util.Map)9 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)7 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)7 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)6 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)5 ArrayList (java.util.ArrayList)4 HashedMap (org.apache.commons.collections.map.HashedMap)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 IOException (java.io.IOException)2 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)2 API_businessInformationDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.API_businessInformationDTO)2