use of org.wso2.carbon.apimgt.rest.integration.tests.publisher.model.APIList in project carbon-apimgt by wso2.
the class OrganizationPurgeDAO method getAPIIdList.
/**
* Get API data for given organization
*
* @param orgId organization Id
* @return ArrayList<APIIdentifier>
* @throws APIManagementException
*/
public ArrayList<APIIdentifier> getAPIIdList(String orgId) throws APIManagementException {
ArrayList<APIIdentifier> apiList = new ArrayList<>();
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(OrganizationPurgeConstants.GET_API_LIST_SQL_BY_ORG_SQL)) {
ps.setString(1, orgId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
int apiId = rs.getInt("API_ID");
String apiUuid = rs.getString("API_UUID");
String apiName = rs.getString("API_Name");
String apiProvider = rs.getString("API_Provider");
String apiVersion = rs.getString("API_Version");
APIIdentifier apiIdentifier = new APIIdentifier(apiProvider, apiName, apiVersion, apiUuid);
apiIdentifier.setId(apiId);
apiList.add(apiIdentifier);
}
}
} catch (SQLException e) {
log.error("Error while getting apiUuid list of organization" + orgId, e);
handleException("Failed to get API apiUuid list of organization " + orgId, e);
}
return apiList;
}
use of org.wso2.carbon.apimgt.rest.integration.tests.publisher.model.APIList in project carbon-apimgt by wso2.
the class APIConsumerImpl method searchPaginatedAPIs.
@Override
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end, String sortBy, String sortOrder) throws APIManagementException {
Map<String, Object> result = new HashMap<String, Object>();
if (log.isDebugEnabled()) {
log.debug("Original search query received : " + searchQuery);
}
Organization org = new Organization(organization);
String userName = (userNameWithoutChange != null) ? userNameWithoutChange : username;
String[] roles = APIUtil.getListOfRoles(userName);
Map<String, Object> properties = APIUtil.getUserProperties(userName);
UserContext userCtx = new UserContext(userNameWithoutChange, org, properties, roles);
try {
DevPortalAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForDevPortal(org, searchQuery, start, end, userCtx);
if (log.isDebugEnabled()) {
log.debug("searched Devportal APIs for query : " + searchQuery + " :-->: " + searchAPIs.toString());
}
SortedSet<Object> apiSet = new TreeSet<>(new APIAPIProductNameComparator());
if (searchAPIs != null) {
List<DevPortalAPIInfo> list = searchAPIs.getDevPortalAPIInfoList();
List<Object> apiList = new ArrayList<>();
for (DevPortalAPIInfo devPortalAPIInfo : list) {
API mappedAPI = APIMapper.INSTANCE.toApi(devPortalAPIInfo);
mappedAPI.setRating(APIUtil.getAverageRating(mappedAPI.getUuid()));
apiList.add(mappedAPI);
}
apiSet.addAll(apiList);
result.put("apis", apiSet);
result.put("length", searchAPIs.getTotalAPIsCount());
result.put("isMore", true);
} else {
result.put("apis", apiSet);
result.put("length", 0);
result.put("isMore", false);
}
} catch (APIPersistenceException e) {
throw new APIManagementException("Error while searching the api ", e);
}
return result;
}
use of org.wso2.carbon.apimgt.rest.integration.tests.publisher.model.APIList in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIListToInfoDTO.
/**
* Converts a List object of APIs into Info DTO List.
*
* @param apiList List of APIs
* @return APIListDTO object containing APIDTOs
*/
public static APIListDTO fromAPIListToInfoDTO(List<API> apiList) throws APIManagementException {
APIListDTO apiListDTO = new APIListDTO();
List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
for (API api : apiList) {
apiInfoDTOs.add(fromAPIToInfoDTO(api));
}
apiListDTO.setCount(apiInfoDTOs.size());
return apiListDTO;
}
use of org.wso2.carbon.apimgt.rest.integration.tests.publisher.model.APIList in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
public Response apisGet(String context, String version, String tenantDomain, MessageContext messageContext) {
tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
if (subscriptionDataStore == null) {
log.warn("Subscription data store is not initialized for " + tenantDomain);
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isNotEmpty(context) && StringUtils.isNotEmpty(version)) {
API api = subscriptionDataStore.getApiByContextAndVersion(context, version);
if (api == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(Collections.singletonList(api));
return Response.ok().entity(apiListDTO).build();
} else if ((StringUtils.isEmpty(context) && StringUtils.isNotEmpty(version)) || (StringUtils.isNotEmpty(context) && StringUtils.isEmpty(version))) {
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
} else {
List<API> apiList = subscriptionDataStore.getAPIs();
APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(apiList);
return Response.status(Response.Status.OK).entity(apiListDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.integration.tests.publisher.model.APIList in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIListToDTO.
/**
* Converts a List object of APIs into a DTO
*
* @param apiList List of APIs
* @return APIListDTO object containing APIDTOs
* @throws APIManagementException
*/
public static APIListDTO fromAPIListToDTO(List<Object> apiList, String organization) throws APIManagementException {
APIListDTO apiListDTO = new APIListDTO();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
Map<String, Tier> tierMap = APIUtil.getTiers(organization);
List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
if (apiList != null) {
for (Object api : apiList) {
APIInfoDTO apiInfoDTO = null;
if (api instanceof API) {
API api1 = (API) api;
apiInfoDTO = fromAPIToInfoDTO((API) api);
setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
} else if (api instanceof APIProduct) {
APIProduct api1 = (APIProduct) api;
apiInfoDTO = fromAPIToInfoDTO((API) api);
setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
}
apiInfoDTOs.add(apiInfoDTO);
}
}
apiListDTO.setCount(apiInfoDTOs.size());
return apiListDTO;
}
Aggregations