use of org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ExportUtils method createApplicationDTOToExport.
/**
* Create an aggregated Application DTO to be exported.
*
* @param application Application{@link Application} to be exported
* @param apiConsumer API Consumer
* @param withKeys Export the Application with keys or not
* @return Exported application
* @throws APIManagementException If an error occurs while retrieving subscribed APIs
*/
private static ExportedApplication createApplicationDTOToExport(Application application, APIConsumer apiConsumer, Boolean withKeys) throws APIManagementException {
ApplicationDTO applicationDto = ApplicationMappingUtil.fromApplicationtoDTO(application);
// Set keys if withKeys is true
if (withKeys == null || !withKeys) {
application.clearOAuthApps();
} else {
List<ApplicationKeyDTO> applicationKeyDTOs = new ArrayList<>();
for (APIKey apiKey : application.getKeys()) {
// Encode the consumer secret and set it
apiKey.setConsumerSecret(new String(Base64.encodeBase64(apiKey.getConsumerSecret().getBytes(Charset.defaultCharset()))));
ApplicationKeyDTO applicationKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
applicationKeyDTOs.add(applicationKeyDTO);
}
applicationDto.setKeys(applicationKeyDTOs);
}
// Get the subscribed API details and add it to a set
Set<SubscribedAPI> subscribedAPIs = apiConsumer.getSubscribedAPIs(application.getSubscriber(), application.getName(), application.getGroupId());
Set<ExportedSubscribedAPI> exportedSubscribedAPIs = new HashSet<>();
for (SubscribedAPI subscribedAPI : subscribedAPIs) {
ExportedSubscribedAPI exportedSubscribedAPI = new ExportedSubscribedAPI(subscribedAPI.getApiId(), subscribedAPI.getSubscriber(), subscribedAPI.getTier().getName());
exportedSubscribedAPIs.add(exportedSubscribedAPI);
}
// Set the subscription count by counting the number of subscribed APIs
applicationDto.setSubscriptionCount(exportedSubscribedAPIs.size());
// Set the application
ExportedApplication exportedApplication = new ExportedApplication(applicationDto);
// Set the subscribed APIs
exportedApplication.setSubscribedAPIs(exportedSubscribedAPIs);
return exportedApplication;
}
Aggregations