use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method getSampleApplication.
private Application getSampleApplication(String applicationId) {
String accessToken = UUID.randomUUID().toString();
String clientID = UUID.randomUUID().toString();
String clientSecret = UUID.randomUUID().toString();
ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
applicationTokenDTO.setAccessToken(accessToken);
applicationTokenDTO.setTokenScopes("SCOPE1");
applicationTokenDTO.setValidityTime((long) 100000);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
applicationKeysDTO.setConsumerKey(clientID);
applicationKeysDTO.setConsumerSecret(clientSecret);
applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
applicationKeysDTO.setCallbackUrl(null);
applicationKeysDTO.setSupportedGrantTypes(grantTypes);
List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
applicationKeysDTOList.add(applicationKeysDTO);
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(applicationId);
applicationDTO.setDescription("sample application");
applicationDTO.setName("app1");
applicationDTO.setSubscriber("subscriber");
applicationDTO.setPermission("permission");
applicationDTO.setLifeCycleStatus("APPROVED");
applicationDTO.setThrottlingTier("UNLIMITED");
applicationDTO.setToken(applicationTokenDTO);
applicationDTO.setKeys(applicationKeysDTOList);
return ApplicationMappingUtil.fromDTOtoApplication(applicationDTO, USER);
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application 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.common.analytics.publishers.dto.Application 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.common.analytics.publishers.dto.Application 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.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromDTOtoApplication.
public static Application fromDTOtoApplication(ApplicationDTO applicationDTO, String createdUser) {
// subscriber field of the body is not honored
Application application = new Application(applicationDTO.getName(), createdUser);
application.setPolicy(new ApplicationPolicy(applicationDTO.getThrottlingTier()));
application.setDescription(applicationDTO.getDescription());
application.setId(applicationDTO.getApplicationId());
application.setPermissionString(applicationDTO.getPermission());
application.setStatus(applicationDTO.getLifeCycleStatus());
// application.setGroupId(applicationDTO.getGroupId());
return application;
}
Aggregations