use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class MappingUtil method toAPIInfo.
/**
* Converts {@link API} List to an {@link APIInfoDTO} List.
*
* @param apiList
* @return
*/
private static List<APIInfoDTO> toAPIInfo(List<API> apiList) {
List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
for (API api : apiList) {
APIInfoDTO apiInfo = new APIInfoDTO();
apiInfo.setId(api.getId());
apiInfo.setContext(api.getContext());
apiInfo.setName(api.getName());
apiInfo.setLifeCycleStatus(api.getLifeCycleStatus());
apiInfo.setVersion(api.getVersion());
apiInfo.setSecurityScheme(api.getSecurityScheme());
for (String threatProtectionPolicyId : api.getThreatProtectionPolicies()) {
apiInfo.addThreatProtectionPoliciesItem(threatProtectionPolicyId);
}
apiInfoList.add(apiInfo);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class APIMappingUtil method toAPIInfo.
/**
* Converts {@link API} List to an {@link APIInfoDTO} List.
*
* @param apiSummaryList List of APIs
* @return List of APIInfoDTO
*/
private static List<APIInfoDTO> toAPIInfo(List<API> apiSummaryList) {
List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
for (API apiSummary : apiSummaryList) {
APIInfoDTO apiInfo = new APIInfoDTO();
apiInfo.setId(apiSummary.getId());
apiInfo.setContext(apiSummary.getContext());
apiInfo.setDescription(apiSummary.getDescription());
apiInfo.setName(apiSummary.getName());
apiInfo.setProvider(apiSummary.getProvider());
apiInfo.setLifeCycleStatus(apiSummary.getLifeCycleStatus());
apiInfo.setVersion(apiSummary.getVersion());
apiInfoList.add(apiInfo);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateApiFromSwaggerResource.
/**
* return API Object
*
* @param provider Provider of the API.
* @param apiDefinition API definition as string
* @return API object.
* @throws APIManagementException If failed to generate API from swagger.
*/
@Override
public API.APIBuilder generateApiFromSwaggerResource(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("Swagger doesn't contains the info");
} else {
String apiName = apiInfo.getTitle();
String apiVersion = apiInfo.getVersion();
String apiDescription = apiInfo.getDescription();
Contact contact = apiInfo.getContact();
BusinessInformation businessInformation = new BusinessInformation();
if (contact != null) {
businessInformation.setBusinessOwner(contact.getName());
businessInformation.setBusinessOwnerEmail(contact.getEmail());
}
API.APIBuilder apiBuilder = new API.APIBuilder(provider, apiName, apiVersion);
apiBuilder.businessInformation(businessInformation);
apiBuilder.description(apiDescription);
apiBuilder.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.api.model.APIInfo in project carbon-apimgt by wso2.
the class AnalyticsDAOImpl method getAPIInfo.
/**
* @see AnalyticsDAO#getAPIInfo(Instant, Instant, String)
*/
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<APIInfo> getAPIInfo(Instant fromTimestamp, Instant toTimestamp, String createdBy) throws APIMgtDAOException {
final String query;
if (StringUtils.isNotEmpty(createdBy)) {
query = "SELECT UUID,PROVIDER,NAME,CONTEXT,VERSION,CREATED_TIME,CURRENT_LC_STATUS, LC_WORKFLOW_STATUS " + "FROM AM_API " + "WHERE CREATED_TIME BETWEEN ? AND ? " + "AND CREATED_BY = ? " + "ORDER BY CREATED_TIME ASC";
} else {
query = "SELECT UUID,PROVIDER,NAME,CONTEXT,VERSION,CREATED_TIME,CURRENT_LC_STATUS, LC_WORKFLOW_STATUS " + "FROM AM_API " + "WHERE CREATED_TIME BETWEEN ? AND ? " + "ORDER BY CREATED_TIME ASC";
}
List<APIInfo> apiInfoList = new ArrayList<>();
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setTimestamp(1, Timestamp.from(fromTimestamp));
statement.setTimestamp(2, Timestamp.from(toTimestamp));
if (StringUtils.isNotEmpty(createdBy)) {
statement.setString(3, createdBy);
}
log.debug("Executing query: {} ", query);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
APIInfo apiInfo = new APIInfo();
apiInfo.setId(rs.getString("UUID"));
apiInfo.setProvider(rs.getString("PROVIDER"));
apiInfo.setName(rs.getString("NAME"));
apiInfo.setContext(rs.getString("CONTEXT"));
apiInfo.setVersion(rs.getString("VERSION"));
apiInfo.setCreatedTime(rs.getTimestamp("CREATED_TIME").getTime());
apiInfo.setLifeCycleStatus(rs.getString("CURRENT_LC_STATUS"));
apiInfo.setWorkflowStatus(rs.getString("LC_WORKFLOW_STATUS"));
apiInfoList.add(apiInfo);
}
}
} catch (SQLException e) {
throw new APIMgtDAOException("Error while creating database connection/prepared-statement", e);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class AnalyzerImplTestCase method testGetAPIInfo.
@Test(description = "Get API Info test")
public void testGetAPIInfo() throws APIManagementException {
AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
APIInfo apiInfo = new APIInfo();
List<APIInfo> apiInfos = new ArrayList<>();
apiInfos.add(apiInfo);
Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
when(analyticsDAO.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(apiInfos);
List<APIInfo> apiInfoResult = analyzer.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
Assert.assertNotNull(apiInfoResult);
verify(analyticsDAO, Mockito.times(1)).getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
// Error path
Mockito.when(analyticsDAO.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
try {
analyzer.getAPIInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while fetching API information");
}
}
Aggregations