use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateApiDefinition.
@Override
public void updateApiDefinition(String apiID, String apiDefinition, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
updateAPIDefinition(connection, apiID, apiDefinition, updatedBy);
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API definition of API: " + apiID, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API definition of API: " + apiID, e);
}
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateCompositeApiFromSwaggerResource.
@Override
public CompositeAPI.Builder generateCompositeApiFromSwaggerResource(String provider, String apiDefinition) throws APIManagementException {
SwaggerParser swaggerParser = new SwaggerParser();
Swagger swagger = swaggerParser.parse(apiDefinition);
if (swagger == null) {
throw new APIManagementException("Swagger could not be generated from provided API definition");
}
Info apiInfo = swagger.getInfo();
if (apiInfo == null) {
throw new APIManagementException("Provided Swagger definition doesn't contain API information");
} else {
String apiName = apiInfo.getTitle();
String apiVersion = apiInfo.getVersion();
String apiDescription = apiInfo.getDescription();
CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder().provider(provider).name(apiName).version(apiVersion).description(apiDescription).context(swagger.getBasePath());
List<APIResource> apiResourceList = parseSwaggerAPIResources(new StringBuilder(apiDefinition));
Map<String, UriTemplate> uriTemplateMap = new HashMap();
for (APIResource apiResource : apiResourceList) {
uriTemplateMap.put(apiResource.getUriTemplate().getTemplateId(), apiResource.getUriTemplate());
}
apiBuilder.uriTemplates(uriTemplateMap);
apiBuilder.id(UUID.randomUUID().toString());
return apiBuilder;
}
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createUniqueCompositeAPI.
public static CompositeAPI.Builder createUniqueCompositeAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
HashMap permissionMap = new HashMap();
permissionMap.put(DEVELOPER_ROLE_ID, 6);
permissionMap.put(ADMIN_ROLE_ID, 15);
permissionMap.put(ADMIN_ROLE_ID, 7);
Application app = createDefaultApplication();
// generate random name for each time when generating unique composite API
app.setName(UUID.randomUUID().toString());
try {
DAOFactory.getApplicationDAO().addApplication(app);
} catch (APIMgtDAOException e) {
log.error("Error adding application", e);
}
CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder().id(UUID.randomUUID().toString()).name(UUID.randomUUID().toString()).provider(UUID.randomUUID().toString()).version(API_VERSION).context(UUID.randomUUID().toString()).description("Get Food & Beverage Info").transport(transport).permissionMap(permissionMap).applicationId(app.getId()).createdTime(LocalDateTime.now()).createdBy(API_CREATOR).uriTemplates(Collections.emptyMap()).apiDefinition(apiDefinition).lastUpdatedTime(LocalDateTime.now()).threatProtectionPolicies(threatProtectionPolicies);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createUniqueAPI.
public static API.APIBuilder createUniqueAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
Set<String> tags = new HashSet<>();
tags.add(TAG_FOOD);
tags.add(TAG_BEVERAGE);
Set<Policy> policies = new HashSet<>();
policies.add(silverSubscriptionPolicy);
policies.add(bronzeSubscriptionPolicy);
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner(NAME_BUSINESS_OWNER_1);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_1);
businessInformation.setTechnicalOwner(NAME_BUSINESS_OWNER_2);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_2);
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList(APIMgtConstants.FunctionsConstants.GET, APIMgtConstants.FunctionsConstants.POST, APIMgtConstants.FunctionsConstants.DELETE));
corsConfiguration.setAllowHeaders(Arrays.asList(ALLOWED_HEADER_AUTHORIZATION, ALLOWED_HEADER_CUSTOM));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Arrays.asList("*"));
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Map permissionMap = new HashMap();
permissionMap.put(DEVELOPER_ROLE_ID, 6);
permissionMap.put(ADMIN_ROLE_ID, 15);
List<String> defaultLabels = getDefaultLabels();
API.APIBuilder apiBuilder = new API.APIBuilder(UUID.randomUUID().toString(), UUID.randomUUID().toString(), API_VERSION).id(UUID.randomUUID().toString()).context(UUID.randomUUID().toString()).description("Get Food & Beverage Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).endpoint(Collections.emptyMap()).isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(goldApiPolicy).transport(transport).tags(tags).labels(defaultLabels).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList(CUSTOMER_ROLE, MANAGER_ROLE, EMPLOYEE_ROLE))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).apiPermission(permissionJson).permissionMap(permissionMap).createdTime(LocalDateTime.now()).createdBy(API_CREATOR).uriTemplates(Collections.emptyMap()).apiDefinition(apiDefinition).lastUpdatedTime(LocalDateTime.now()).securityScheme(3).threatProtectionPolicies(threatProtectionPolicies);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetRating.
@Test
public void testAddGetRating() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Rating rating = SampleTestObjectCreator.createDefaultRating(api.getId());
apiDAO.addRating(api.getId(), rating);
Rating ratingFromDB = apiDAO.getRatingByUUID(api.getId(), rating.getUuid());
Assert.assertNotNull(ratingFromDB);
}
Aggregations