use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class ImportApiServiceImpl method importApisPut.
/**
* Imports an updates a set of existing APIs which have been exported as a zip file
*
* @param fileInputStream content stream of the zip file which contains exported API(s)
* @param fileDetail meta information of the zip file
* @param provider provider of the API (if it needs to be updated)
* @param request ms4j request object
* @return List of APIs that were imported
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response importApisPut(InputStream fileInputStream, FileInfo fileDetail, String provider, Request request) throws NotFoundException {
APIPublisher publisher = null;
try {
publisher = RestAPIPublisherUtil.getApiPublisher(RestApiUtil.getLoggedInUsername(request));
FileBasedApiImportExportManager importManager = new FileBasedApiImportExportManager(publisher, System.getProperty("java.io.tmpdir") + File.separator + "imported-api-archives-" + UUID.randomUUID().toString());
APIListDTO apiList = importManager.importAPIs(fileInputStream, provider);
return Response.status(Response.Status.OK).entity(apiList).build();
} catch (APIManagementException e) {
String errorMessage = "Error while importing the APIs";
log.error(errorMessage, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class ImportApiServiceImpl method importApisPost.
/**
* Imports a set of new APIs which have been exported as a zip file
*
* @param fileInputStream content stream of the zip file which contains exported API(s)
* @param fileDetail meta information of the zip file
* @param provider provider of the API (if it needs to be updated)
* @param request ms4j request object
* @return List of APIs that were imported
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response importApisPost(InputStream fileInputStream, FileInfo fileDetail, String provider, Request request) throws NotFoundException {
APIPublisher publisher = null;
try {
publisher = RestAPIPublisherUtil.getApiPublisher(RestApiUtil.getLoggedInUsername(request));
FileBasedApiImportExportManager importManager = new FileBasedApiImportExportManager(publisher, System.getProperty("java.io.tmpdir") + File.separator + "imported-api-archives-" + UUID.randomUUID().toString());
APIListDTO apiList = importManager.importAndCreateAPIs(fileInputStream, provider);
return Response.status(Response.Status.OK).entity(apiList).build();
} catch (APIManagementException e) {
String errorMessage = "Error while importing the APIs";
log.error(errorMessage, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisGet.
@Test
public void testApisGet() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
List<API> apiList = new ArrayList<>();
apiList.add(api);
Mockito.when(apiStore.searchAPIsByStoreLabels("", 0, 1, new ArrayList<>())).thenReturn(apiList);
Response response = apisApiService.apisGet(10, 0, "", null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class APIMappingUtilTestCase method testAPIListDTO.
@Test
public void testAPIListDTO() throws APIManagementException {
String api1Id = UUID.randomUUID().toString();
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api1 = createApi("provider1", api1Id, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
String api2Id = UUID.randomUUID().toString();
Endpoint api2SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd123").build();
Endpoint api2ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef123").build();
API api2 = createApi("provider1", api2Id, "testapi2", "1.0.0", "Test API 2 - version 1.0.0", createEndpointTypeToIdMap(api2SandBoxEndpointId, api2ProdEndpointId)).build();
List<API> apiList = new ArrayList<>();
apiList.add(api1);
apiList.add(api2);
APIMappingUtil apiMappingUtil = new APIMappingUtil();
APIListDTO apiListDTO = apiMappingUtil.toAPIListDTO(apiList);
Assert.assertEquals(apiListDTO.getList().get(0).getName(), "testapi1");
Assert.assertEquals(apiListDTO.getList().get(1).getName(), "testapi2");
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class APIProviderImpl method calculateVersionTimestamp.
private String calculateVersionTimestamp(String provider, String name, String version, String org) throws APIManagementException {
if (StringUtils.isEmpty(provider) || StringUtils.isEmpty(name) || StringUtils.isEmpty(org)) {
throw new APIManagementException("Invalid API information, name=" + name + " provider=" + provider + " organization=" + org);
}
TreeMap<String, API> apiSortedMap = new TreeMap<>();
List<API> apiList = getAPIVersionsByProviderAndName(provider, name, org);
for (API mappedAPI : apiList) {
apiSortedMap.put(mappedAPI.getVersionTimestamp(), mappedAPI);
}
APIVersionStringComparator comparator = new APIVersionStringComparator();
String latestVersion = version;
long previousTimestamp = 0L;
String latestTimestamp = "";
for (API tempAPI : apiSortedMap.values()) {
if (comparator.compare(tempAPI.getId().getVersion(), latestVersion) > 0) {
latestTimestamp = String.valueOf((previousTimestamp + Long.valueOf(tempAPI.getVersionTimestamp())) / 2);
break;
} else {
previousTimestamp = Long.valueOf(tempAPI.getVersionTimestamp());
}
}
if (StringUtils.isEmpty(latestTimestamp)) {
latestTimestamp = String.valueOf(System.currentTimeMillis());
}
return latestTimestamp;
}
Aggregations