use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription, ApiTypeWrapper apiTypeWrapper, String organization) throws APIManagementException {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getUUID());
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
Map<String, Tier> tierMap = APIUtil.getTiers(organization);
if (apiTypeWrapper != null && !apiTypeWrapper.isAPIProduct()) {
API api = apiTypeWrapper.getApi();
subscriptionDTO.setApiId(api.getUUID());
APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(api);
APIMappingUtil.setThrottlePoliciesAndMonetization(api, apiInfo, deniedTiers, tierMap);
subscriptionDTO.setApiInfo(apiInfo);
} else {
APIProduct apiProduct = apiTypeWrapper.getApiProduct();
subscriptionDTO.setApiId(apiProduct.getUuid());
APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiProduct, organization);
APIMappingUtil.setThrottlePoliciesAndMonetization(apiProduct, apiInfo, deniedTiers, tierMap);
subscriptionDTO.setApiInfo(apiInfo);
}
Application application = subscription.getApplication();
subscriptionDTO.setApplicationId(subscription.getApplication().getUUID());
subscriptionDTO.setStatus(SubscriptionDTO.StatusEnum.valueOf(subscription.getSubStatus()));
subscriptionDTO.setThrottlingPolicy(subscription.getTier().getName());
subscriptionDTO.setRequestedThrottlingPolicy(subscription.getRequestedTier().getName());
ApplicationInfoDTO applicationInfoDTO = ApplicationMappingUtil.fromApplicationToInfoDTO(application);
subscriptionDTO.setApplicationInfo(applicationInfoDTO);
return subscriptionDTO;
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method searchPaginatedDevPortalAPIs.
private DevPortalAPISearchResult searchPaginatedDevPortalAPIs(Registry userRegistry, int tenantIDLocal, String searchQuery, int start, int offset) throws APIManagementException {
int totalLength = 0;
DevPortalAPISearchResult searchResults = new DevPortalAPISearchResult();
try {
final int maxPaginationLimit = getMaxPaginationLimit();
PaginationContext.init(start, offset, "ASC", APIConstants.API_OVERVIEW_NAME, maxPaginationLimit);
log.debug("Dev portal list apis query " + searchQuery);
List<GovernanceArtifact> governanceArtifacts = GovernanceUtils.findGovernanceArtifacts(searchQuery, userRegistry, APIConstants.API_RXT_MEDIA_TYPE, true);
totalLength = PaginationContext.getInstance().getLength();
boolean isFound = true;
if (governanceArtifacts == null || governanceArtifacts.size() == 0) {
if (searchQuery.contains(APIConstants.API_OVERVIEW_PROVIDER)) {
searchQuery = searchQuery.replaceAll(APIConstants.API_OVERVIEW_PROVIDER, APIConstants.API_OVERVIEW_OWNER);
governanceArtifacts = GovernanceUtils.findGovernanceArtifacts(searchQuery, userRegistry, APIConstants.API_RXT_MEDIA_TYPE, true);
if (governanceArtifacts == null || governanceArtifacts.size() == 0) {
isFound = false;
}
} else {
isFound = false;
}
}
if (!isFound) {
return searchResults;
}
// Check to see if we can speculate that there are more APIs to be loaded
if (maxPaginationLimit == totalLength) {
// Remove the additional 1 added earlier when setting max pagination limit
--totalLength;
}
List<DevPortalAPIInfo> devPortalAPIInfoList = new ArrayList<DevPortalAPIInfo>();
int tempLength = 0;
for (GovernanceArtifact artifact : governanceArtifacts) {
DevPortalAPIInfo apiInfo = new DevPortalAPIInfo();
// devPortalAPIInfoList apiInfo = new devPortalAPIInfoList();
apiInfo.setType(artifact.getAttribute(APIConstants.API_OVERVIEW_TYPE));
apiInfo.setId(artifact.getId());
apiInfo.setApiName(artifact.getAttribute(APIConstants.API_OVERVIEW_NAME));
apiInfo.setDescription(artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
apiInfo.setContext(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
apiInfo.setProviderName(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER));
apiInfo.setStatus(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS));
apiInfo.setThumbnail(artifact.getAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL));
apiInfo.setBusinessOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER));
apiInfo.setVersion(artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
String tiers = artifact.getAttribute(APIConstants.API_OVERVIEW_TIER);
Set<String> availableTiers = new HashSet<String>();
if (tiers != null) {
String[] tiersArray = tiers.split("\\|\\|");
for (String tierName : tiersArray) {
availableTiers.add(tierName);
}
}
apiInfo.setAvailableTierNames(availableTiers);
apiInfo.setSubscriptionAvailability(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABILITY));
apiInfo.setSubscriptionAvailableOrgs(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABLE_TENANTS));
apiInfo.setGatewayVendor(artifact.getAttribute(APIConstants.API_GATEWAY_VENDOR));
devPortalAPIInfoList.add(apiInfo);
// Ensure the APIs returned matches the length, there could be an additional API
// returned due incrementing the pagination limit when getting from registry
tempLength++;
if (tempLength >= totalLength) {
break;
}
}
searchResults.setDevPortalAPIInfoList(devPortalAPIInfoList);
searchResults.setReturnedAPIsCount(devPortalAPIInfoList.size());
searchResults.setTotalAPIsCount(totalLength);
} catch (RegistryException e) {
String msg = "Failed to search APIs with type";
throw new APIManagementException(msg, e);
} finally {
PaginationContext.destroy();
}
return searchResults;
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPISubscriptionPolicies.
@Override
public Response getAPISubscriptionPolicies(String apiId, String ifNoneMatch, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIDTO apiInfo = getAPIByID(apiId, apiProvider, organization);
List<Tier> availableThrottlingPolicyList = new ThrottlingPoliciesApiServiceImpl().getThrottlingPolicyList(ThrottlingPolicyDTO.PolicyLevelEnum.SUBSCRIPTION.toString(), true);
if (apiInfo != null) {
List<String> apiPolicies = apiInfo.getPolicies();
if (apiPolicies != null && !apiPolicies.isEmpty()) {
List<Tier> apiThrottlingPolicies = new ArrayList<>();
for (Tier tier : availableThrottlingPolicyList) {
if (apiPolicies.contains(tier.getName())) {
apiThrottlingPolicies.add(tier);
}
}
return Response.ok().entity(apiThrottlingPolicies).build();
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method restoreAPIRevision.
/**
* Restore a revision to the working copy of the API
*
* @param apiId UUID of the API
* @param revisionId Revision ID of the API
* @param messageContext message context object
* @return response with 200 status code
*/
@Override
public Response restoreAPIRevision(String apiId, String revisionId, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate if api exists
APIInfo apiInfo = validateAPIExistence(apiId);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(apiInfo.getStatus().toString());
apiProvider.restoreAPIRevision(apiId, revisionId, organization);
APIDTO apiToReturn = getAPIByID(apiId, apiProvider, organization);
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiToReturn).build();
}
use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method updateWSDLOfAPI.
/**
* Update the WSDL of an API
*
* @param apiId UUID of the API
* @param fileInputStream file data as input stream
* @param fileDetail file details
* @param url URL of the WSDL
* @return 200 OK response if the operation is successful. 400 if the provided inputs are invalid. 500 if a server
* error occurred.
* @throws APIManagementException when error occurred while trying to retrieve the WSDL
*/
@Override
public Response updateWSDLOfAPI(String apiId, String ifMatch, InputStream fileInputStream, Attachment fileDetail, String url, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate if api exists
APIInfo apiInfo = validateAPIExistence(apiId);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(apiInfo.getStatus().toString());
WSDLValidationResponse validationResponse = validateWSDLAndReset(fileInputStream, fileDetail, url);
if (StringUtils.isNotBlank(url)) {
apiProvider.addWSDLResource(apiId, null, url, organization);
} else {
ResourceFile wsdlResource;
if (APIConstants.APPLICATION_ZIP.equals(fileDetail.getContentType().toString()) || APIConstants.APPLICATION_X_ZIP_COMPRESSED.equals(fileDetail.getContentType().toString())) {
wsdlResource = new ResourceFile(validationResponse.getWsdlProcessor().getWSDL(), APIConstants.APPLICATION_ZIP);
} else {
wsdlResource = new ResourceFile(validationResponse.getWsdlProcessor().getWSDL(), fileDetail.getContentType().toString());
}
apiProvider.addWSDLResource(apiId, wsdlResource, null, organization);
}
return Response.ok().build();
}
Aggregations