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;
}
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;
}
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);
}
}
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;
}
Aggregations