use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultAPIPolicyWithBandwidthLimit.
/**
* Create default api policy with bandwidth limit as quota policy
*
* @return APIPolicy object with bandwidth limit as quota policy is returned
*/
protected static APIPolicy createDefaultAPIPolicyWithBandwidthLimit() {
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_MONTH, 1, 1000, PolicyConstants.MB);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
defaultQuotaPolicy.setLimit(bandwidthLimit);
// set default API Policy
APIPolicy apiPolicy = new APIPolicy(SAMPLE_API_POLICY);
apiPolicy.setUuid(UUID.randomUUID().toString());
apiPolicy.setDisplayName(SAMPLE_API_POLICY);
apiPolicy.setDescription(SAMPLE_API_POLICY_DESCRIPTION);
apiPolicy.setUserLevel(APIMgtConstants.ThrottlePolicyConstants.API_LEVEL);
apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
return apiPolicy;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ExportApiServiceImpl method exportApisGet.
/**
* Exports an existing API
*
* @param query Search query
* @param limit maximum APIs to export
* @param offset Starting position of the search
* @param request ms4j request object
* @return Zip file containing the exported APIs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response exportApisGet(String query, Integer limit, Integer offset, Request request) throws NotFoundException {
APIPublisher publisher = null;
String exportedFilePath, zippedFilePath = null;
Set<APIDetails> apiDetails;
String exportedApiDirName = "exported-apis";
String pathToExportDir = System.getProperty("java.io.tmpdir") + File.separator + "exported-api-archives-" + UUID.randomUUID().toString();
try {
publisher = RestAPIPublisherUtil.getApiPublisher(RestApiUtil.getLoggedInUsername(request));
FileBasedApiImportExportManager importExportManager = new FileBasedApiImportExportManager(publisher, pathToExportDir);
apiDetails = importExportManager.getAPIDetails(limit, offset, query);
if (apiDetails.isEmpty()) {
// 404
String errorMsg = "No APIs found for query " + query;
log.error(errorMsg);
HashMap<String, String> paramList = new HashMap<>();
paramList.put("query", query);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(ExceptionCodes.API_NOT_FOUND, paramList);
return Response.status(Response.Status.NOT_FOUND).entity(errorDTO).build();
}
exportedFilePath = importExportManager.exportAPIs(apiDetails, exportedApiDirName);
zippedFilePath = importExportManager.createArchiveFromExportedApiArtifacts(exportedFilePath, pathToExportDir, exportedApiDirName);
} catch (APIManagementException e) {
String errorMessage = "Error while exporting APIs";
log.error(errorMessage, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
File exportedApiArchiveFile = new File(zippedFilePath);
Response.ResponseBuilder responseBuilder = Response.status(Response.Status.OK).entity(exportedApiArchiveFile);
responseBuilder.header("Content-Disposition", "attachment; filename=\"" + exportedApiArchiveFile.getName() + "\"");
Response response = responseBuilder.build();
return response;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<DocumentInfo> documentInfos = apiPublisher.getAllDocumentation(apiId, offset, limit);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
return Response.status(Response.Status.OK).entity(documentListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting list of documents" + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method getResponse.
private Response getResponse(String apiContext, String apiVersion) throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
Mockito.when(apiMgtAdminService.getAPISubscriptions(LIMIT)).thenReturn(createSubscriptionValidationDataList());
return subscriptionsApiService.subscriptionsGet(apiContext, apiVersion, LIMIT, null, getRequest());
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class TagsApiServiceImpl method tagsGet.
/**
* Retrieve tags of APIs
*
* @param limit Maximum number of tags to return
* @param offset Starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return A list of qualifying tags as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response tagsGet(Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
TagListDTO tagListDTO = null;
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<Tag> tagList = apiStore.getAllTags();
tagListDTO = TagMappingUtil.fromTagListToDTO(tagList, limit, offset);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving tags";
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(tagListDTO).build();
}
Aggregations