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