Search in sources :

Example 16 with BusinessInformation

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

the class TestUtil method createApi.

protected static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
    Set<String> transport = new HashSet<>();
    transport.add("http");
    Set<Policy> policies = new HashSet<>();
    policies.add(new SubscriptionPolicy("Silver"));
    policies.add(new SubscriptionPolicy("Bronze"));
    Set<String> tags = new HashSet<>();
    tags.add("food");
    tags.add("beverage");
    BusinessInformation businessInformation = new BusinessInformation();
    businessInformation.setBusinessOwner("John Doe");
    businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
    businessInformation.setTechnicalOwner("Jane Doe");
    businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    corsConfiguration.setEnabled(true);
    corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
    corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
    corsConfiguration.setAllowCredentials(true);
    corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
    API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition("swagger definition").wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
    apiBuilder.uriTemplates(Collections.emptyMap());
    return apiBuilder;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) 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) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashSet(java.util.HashSet)

Example 17 with BusinessInformation

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

the class APIMappingUtilTestCase method createApi.

private static API.APIBuilder createApi(String provider, String apiId, String name, String version, String description, Map<String, Endpoint> endpointTypeToIdMap) throws APIManagementException {
    Set<String> transport = new HashSet<>();
    transport.add("http");
    Set<Policy> policies = new HashSet<>();
    policies.add(new SubscriptionPolicy("Silver"));
    policies.add(new SubscriptionPolicy("Bronze"));
    Set<String> tags = new HashSet<>();
    tags.add("food");
    tags.add("beverage");
    BusinessInformation businessInformation = new BusinessInformation();
    businessInformation.setBusinessOwner("John Doe");
    businessInformation.setBusinessOwnerEmail("john.doe@annonymous.com");
    businessInformation.setTechnicalOwner("Jane Doe");
    businessInformation.setBusinessOwnerEmail("jane.doe@annonymous.com");
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    corsConfiguration.setEnabled(true);
    corsConfiguration.setAllowMethods(Arrays.asList("GET", "POST", "DELETE"));
    corsConfiguration.setAllowHeaders(Arrays.asList("Authorization", "X-Custom"));
    corsConfiguration.setAllowCredentials(true);
    corsConfiguration.setAllowOrigins(Collections.singletonList("*"));
    API.APIBuilder apiBuilder = new API.APIBuilder(provider, name, version).id(apiId).context(UUID.randomUUID().toString()).description(description).lifeCycleStatus("CREATED").apiDefinition("").wsdlUri("http://www.webservicex.net/globalweather.asmx?op=GetWeather?wsdl").isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(new APIPolicy("Gold")).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList("customer", "manager", "employee"))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy("Adam Doe").lastUpdatedTime(LocalDateTime.now()).endpoint(endpointTypeToIdMap);
    apiBuilder.uriTemplates(Collections.emptyMap());
    return apiBuilder;
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashSet(java.util.HashSet)

Example 18 with BusinessInformation

use of org.wso2.carbon.apimgt.core.models.BusinessInformation 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 19 with BusinessInformation

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

BusinessInformation (org.wso2.carbon.apimgt.core.models.BusinessInformation)18 CorsConfiguration (org.wso2.carbon.apimgt.core.models.CorsConfiguration)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 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)12 Map (java.util.Map)8 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)7 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)7 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)7 ArrayList (java.util.ArrayList)6 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)5 HashedMap (org.apache.commons.collections.map.HashedMap)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)4 Contact (io.swagger.models.Contact)2 Info (io.swagger.models.Info)2