use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
/**
* Retrieves APIs qualifying under given search condition
*
* @param limit maximum number of APIs returns
* @param offset starting index
* @param labels Labels of the store for which the apis need to be retrieved
* @param query search condition
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return matched APIs for the given search condition
*/
@Override
public Response apisGet(Integer limit, Integer offset, String labels, String query, String ifNoneMatch, Request request) throws NotFoundException {
List<API> apisResult = null;
APIListDTO apiListDTO = null;
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIStore apiStore = RestApiUtil.getConsumer(username);
List<String> labelList = new ArrayList<>();
if (labels != null) {
labelList = Arrays.asList(labels.split(","));
}
apisResult = apiStore.searchAPIsByStoreLabels(query, offset, limit, labelList);
// convert API
apiListDTO = APIMappingUtil.toAPIListDTO(apisResult);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving APIs ";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_NAME, query);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(apiListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIListDTO in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method importAPIs.
/**
* Imports a set of APIs to API Manager by reading and decoding the input stream
*
* @param uploadedApiArchiveInputStream InputStream to be read ana decoded to a set of APIs
* @param provider API provider, if needs to be updated
* @return {@link APIListDTO} object comprising of successfully imported APIs
* @throws APIMgtEntityImportExportException if any error occurs while importing or no APIs are imported successfully
*/
public APIListDTO importAPIs(InputStream uploadedApiArchiveInputStream, String provider) throws APIMgtEntityImportExportException {
String apiArchiveLocation = path + File.separator + IMPORTED_APIS_DIRECTORY_NAME + ".zip";
String archiveExtractLocation = null;
try {
archiveExtractLocation = APIFileUtils.extractUploadedArchive(uploadedApiArchiveInputStream, IMPORTED_APIS_DIRECTORY_NAME, apiArchiveLocation, path);
} catch (APIMgtDAOException e) {
String errorMsg = "Error in accessing uploaded API archive " + apiArchiveLocation;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, e, ExceptionCodes.API_IMPORT_ERROR);
}
// List to contain newly created/updated APIs
Set<APIDetails> apiDetailsSet = decodeApiInformationFromDirectoryStructure(archiveExtractLocation, provider);
List<API> apis = new ArrayList<>();
for (APIDetails apiDetails : apiDetailsSet) {
try {
apis.add(importApi(apiDetails));
} catch (APIManagementException e) {
log.error("Error while importing API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
// skip importing the API
continue;
}
log.info("Successfully imported API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
}
try {
APIFileUtils.deleteDirectory(path);
} catch (APIMgtDAOException e) {
log.warn("Unable to remove directory " + path);
}
// if no APIs are corrected exported, throw an error
if (apis.isEmpty()) {
String errorMsg = "No APIs imported successfully";
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
return MappingUtil.toAPIListDTO(apis);
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIListDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromAPIToAPIListDTO.
public static APIListDTO fromAPIToAPIListDTO(API model) {
APIListDTO apiListdto = new APIListDTO();
if (model != null) {
APIDTO apidto = new APIDTO();
apidto.setUuid(model.getApiUUID());
apidto.setApiId(model.getApiId());
apidto.setVersion(model.getVersion());
apidto.setContext(model.getContext());
apidto.setPolicy(model.getPolicy());
apidto.setProvider(model.getProvider());
apidto.setApiType(model.getApiType());
apidto.setName(model.getName());
apidto.setStatus(model.getStatus());
apidto.setIsDefaultVersion(model.isDefaultVersion());
Map<String, URLMapping> urlMappings = model.getAllResources();
List<URLMappingDTO> urlMappingsDTO = new ArrayList<>();
for (URLMapping urlMapping : urlMappings.values()) {
URLMappingDTO urlMappingDTO = new URLMappingDTO();
urlMappingDTO.setAuthScheme(urlMapping.getAuthScheme());
urlMappingDTO.setHttpMethod(urlMapping.getHttpMethod());
urlMappingDTO.setThrottlingPolicy(urlMapping.getThrottlingPolicy());
urlMappingDTO.setUrlPattern(urlMapping.getUrlPattern());
urlMappingDTO.setScopes(urlMapping.getScopes());
urlMappingsDTO.add(urlMappingDTO);
}
apidto.setUrlMappings(urlMappingsDTO);
apiListdto.setCount(1);
apiListdto.getList().add(apidto);
} else {
apiListdto.setCount(0);
}
return apiListdto;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
@Override
public Response apisGet(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept, MessageContext messageContext) throws APIManagementException {
SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
APIListDTO apiListDTO;
if (StringUtils.isNotEmpty(gatewayLabel)) {
if (StringUtils.isNotEmpty(apiId)) {
API api = subscriptionValidationDAO.getApiByUUID(apiId, gatewayLabel, xWSO2Tenant);
apiListDTO = SubscriptionValidationDataUtil.fromAPIToAPIListDTO(api);
} else if (StringUtils.isNotEmpty(context) && StringUtils.isNotEmpty(version)) {
if (!context.startsWith("/t/" + xWSO2Tenant.toLowerCase())) {
apiListDTO = new APIListDTO();
}
API api = subscriptionValidationDAO.getAPIByContextAndVersion(context, version, gatewayLabel);
apiListDTO = SubscriptionValidationDataUtil.fromAPIToAPIListDTO(api);
} else {
// Retrieve API Detail according to Gateway label.
apiListDTO = SubscriptionValidationDataUtil.fromAPIListToAPIListDTO(subscriptionValidationDAO.getAllApis(xWSO2Tenant, gatewayLabel));
}
} else {
apiListDTO = SubscriptionValidationDataUtil.fromAPIListToAPIListDTO(subscriptionValidationDAO.getAllApis(xWSO2Tenant));
}
if (APIConstants.APPLICATION_GZIP.equals(accept)) {
try {
File zippedResponse = GZIPUtils.constructZippedResponse(apiListDTO);
return Response.ok().entity(zippedResponse).header("Content-Disposition", "attachment").header("Content-Encoding", "gzip").build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError(e.getMessage(), e, log);
}
} else {
return Response.ok().entity(apiListDTO).build();
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIListDTO in project carbon-apimgt by wso2.
the class GatewayUtils method generateAPIListDTO.
public static APIListDTO generateAPIListDTO(List<API> apiList) {
APIListDTO apiListDTO = new APIListDTO();
List<APIMetaDataDTO> apiMetaDataDTOList = new ArrayList<>();
for (API api : apiList) {
APIMetaDataDTO apiMetaDataDTO = new APIMetaDataDTO().apiId(api.getApiId()).name(api.getApiName()).version(api.getApiVersion()).apiUUID(api.getUuid()).apiType(api.getApiType()).provider(api.getApiProvider()).context(api.getContext()).isDefaultVersion(api.isDefaultVersion()).name(api.getApiName()).policy(api.getApiTier()).apiType(api.getApiType());
apiMetaDataDTOList.add(apiMetaDataDTO);
}
apiListDTO.setList(apiMetaDataDTOList);
apiListDTO.count(apiMetaDataDTOList.size());
return apiListDTO;
}
Aggregations