use of org.wso2.carbon.apimgt.rest.api.admin.NotFoundException in project carbon-apimgt by wso2.
the class ExportApiServiceImpl method exportApplicationsGet.
/**
* Export an existing Application
*
* @param appId Search query
* @param request msf4j request object
* @return Zip file containing exported Applications
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response exportApplicationsGet(String appId, Request request) throws NotFoundException {
APIStore consumer = null;
String exportedFilePath, zippedFilePath = null;
Application applicationDetails;
String exportedAppDirName = "exported-application";
String pathToExportDir = System.getProperty("java.io.tmpdir") + File.separator + "exported-app-archives-" + // creates a directory in default temporary-file directory
UUID.randomUUID().toString();
String username = RestApiUtil.getLoggedInUsername(request);
try {
consumer = RestApiUtil.getConsumer(username);
FileBasedApplicationImportExportManager importExportManager = new FileBasedApplicationImportExportManager(consumer, pathToExportDir);
applicationDetails = importExportManager.getApplicationDetails(appId, username);
if (applicationDetails == null) {
// 404
String errorMsg = "No application found for query " + appId;
log.error(errorMsg);
HashMap<String, String> paramList = new HashMap<>();
paramList.put("query", appId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(ExceptionCodes.APPLICATION_NOT_FOUND, paramList);
return Response.status(Response.Status.NOT_FOUND).entity(errorDTO).build();
}
exportedFilePath = importExportManager.exportApplication(applicationDetails, exportedAppDirName);
zippedFilePath = importExportManager.createArchiveFromExportedAppArtifacts(exportedFilePath, pathToExportDir, exportedAppDirName);
} catch (APIManagementException e) {
String errorMessage = "Error while exporting Application";
log.error(errorMessage, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
File exportedApplicationArchiveFile = new File(zippedFilePath);
Response.ResponseBuilder responseBuilder = Response.status(Response.Status.OK).entity(exportedApplicationArchiveFile);
responseBuilder.header("Content-Disposition", "attachment; filename=\"" + exportedApplicationArchiveFile.getName() + "\"");
Response response = responseBuilder.build();
return response;
}
use of org.wso2.carbon.apimgt.rest.api.admin.NotFoundException in project carbon-apimgt by wso2.
the class ImportApiServiceImpl method importApplicationsPut.
@Override
public Response importApplicationsPut(InputStream fileInputStream, FileInfo fileDetail, Request request) throws NotFoundException {
APIStore consumer = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
consumer = RestApiUtil.getConsumer(RestApiUtil.getLoggedInUsername(request));
FileBasedApplicationImportExportManager importExportManager = new FileBasedApplicationImportExportManager(consumer, System.getProperty("java.io.tmpdir") + File.separator + "exported-app-archives-" + UUID.randomUUID().toString());
Application applicationDetails = importExportManager.importApplication(fileInputStream);
applicationDetails.setCreatedUser(username);
applicationDetails.setUpdatedUser(username);
Application updatedApplication = importExportManager.updateApplication(applicationDetails, username);
return Response.status(Response.Status.OK).entity(updatedApplication).build();
} catch (APIManagementException e) {
String errorMsg = "Error while importing the Applications";
log.error(errorMsg, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.NotFoundException in project carbon-apimgt by wso2.
the class ImportApiServiceImpl method importApplicationsPost.
/**
* Import an Application which has been exported to a zip file
*
* @param fileInputStream content stream of the zip file which contains exported Application
* @param fileDetail meta information of the zip file
* @param request msf4j request object
* @return Application that was imported
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response importApplicationsPost(InputStream fileInputStream, FileInfo fileDetail, Request request) throws NotFoundException {
APIStore consumer = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
consumer = RestApiUtil.getConsumer(username);
FileBasedApplicationImportExportManager importExportManager = new FileBasedApplicationImportExportManager(consumer, System.getProperty("java.io.tmpdir") + File.separator + "exported-app-archives-" + UUID.randomUUID().toString());
Application applicationDetails = importExportManager.importApplication(fileInputStream);
applicationDetails.setCreatedUser(username);
applicationDetails.setUpdatedUser(username);
ApplicationCreationResponse response = consumer.addApplication(applicationDetails);
return Response.status(Response.Status.OK).entity(response).build();
} catch (APIManagementException e) {
String errorMsg = "Error while importing the Applications";
log.error(errorMsg, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.NotFoundException in project carbon-apimgt by wso2.
the class ApiApiServiceImpl method apiCountOverTimeGet.
/**
* Get list of API count information
*
* @param startTime Filter for start time stamp
* @param endTime Filter for end time stamp
* @param createdBy Filter for created user
* @param request MSF4J request
* @return API Count information
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apiCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
log.debug("Retrieving APIs created over time. [From: {} To: {} Created By: {}]", startTime, endTime, createdBy);
Analyzer analyzer = RestApiUtil.getAnalyzer(username);
ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
List<APICount> apiCountList = analyzer.getAPICount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, requestTimezone);
return Response.ok().entity(apiCountListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API created over time info";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.NotFoundException in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTest method blacklistConditionIdPutTest.
@Test
public void blacklistConditionIdPutTest() throws APIManagementException, NotFoundException {
printTestMethodName();
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
String uuid = UUID.randomUUID().toString();
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(UUID.randomUUID().toString());
dto.setStatus(true);
dto.setConditionType(BLOCKING_CONDITIONS_IP);
dto.setConditionValue("12.32.45.3");
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
BlockConditions conditions = BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto);
Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(adminService).updateBlockConditionStateByUUID(uuid, true);
Mockito.doReturn(conditions).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditionByUUID(uuid);
Response response = blacklistApiService.blacklistConditionIdPut(uuid, dto, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
Aggregations