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