use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoListToDTO.
/**
* Converts a List object of SubscribedAPIs into a DTO
*
* @param subscriptions a list of SubscribedAPI objects
* @param limit max number of objects returned
* @param offset starting index
* @param organization identifier of the organization
* @return SubscriptionListDTO object containing SubscriptionDTOs
* @throws APIManagementException if error occurred when creating AdditionalSubscriptionInfoListDTO
*/
public static AdditionalSubscriptionInfoListDTO fromAdditionalSubscriptionInfoListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset, String organization) throws APIManagementException {
AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO = new AdditionalSubscriptionInfoListDTO();
List<AdditionalSubscriptionInfoDTO> additionalSubscriptionInfoDTOs = additionalSubscriptionInfoListDTO.getList();
if (additionalSubscriptionInfoDTOs == null) {
additionalSubscriptionInfoDTOs = new ArrayList<>();
additionalSubscriptionInfoListDTO.setList(additionalSubscriptionInfoDTOs);
}
// Identifying the proper start and end indexes
int size = subscriptions.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
try {
SubscribedAPI subscription = subscriptions.get(i);
additionalSubscriptionInfoDTOs.add(fromAdditionalSubscriptionInfoToDTO(subscription, organization));
} catch (APIManagementException e) {
log.error("Error while obtaining additional info of subscriptions", e);
}
}
// Set count for list
additionalSubscriptionInfoListDTO.setCount(additionalSubscriptionInfoDTOs.size());
return additionalSubscriptionInfoListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoToDTO.
/**
* Converts a AdditionalSubscriptionInfo object into AdditionalSubscriptionInfoDTO
*
* @param subscription SubscribedAPI object
* @param organization Identifier of the organization
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static AdditionalSubscriptionInfoDTO fromAdditionalSubscriptionInfoToDTO(SubscribedAPI subscription, String organization) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
AdditionalSubscriptionInfoDTO additionalSubscriptionInfoDTO = new AdditionalSubscriptionInfoDTO();
additionalSubscriptionInfoDTO.setSubscriptionId(subscription.getUUID());
APIIdentifier apiId = subscription.getApiId();
API api = null;
if (apiId != null) {
try {
api = apiConsumer.getLightweightAPIByUUID(apiId.getUUID(), organization);
} catch (APIManagementException e) {
String msg = "User :" + username + " does not have access to the API " + apiId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
}
additionalSubscriptionInfoDTO.setApiId(api.getUuid());
// Set Application information
Application application = subscription.getApplication();
application = apiConsumer.getApplicationByUUID(application.getUUID());
additionalSubscriptionInfoDTO.setApplicationId(subscription.getApplication().getUUID());
additionalSubscriptionInfoDTO.setApplicationName(application.getName());
additionalSubscriptionInfoDTO.setIsSolaceAPI(SolaceNotifierUtils.checkWhetherAPIDeployedToSolaceUsingRevision(api));
if (additionalSubscriptionInfoDTO.isIsSolaceAPI()) {
// Set Solace organization details if API is a Solace API
additionalSubscriptionInfoDTO.setSolaceOrganization(SolaceNotifierUtils.getThirdPartySolaceBrokerOrganizationNameOfAPIDeployment(api));
Map<String, Environment> gatewayEnvironmentMap = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = null;
for (Map.Entry<String, Environment> entry : gatewayEnvironmentMap.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
if (solaceEnvironment != null) {
List<SolaceDeployedEnvironmentDTO> solaceDeployedEnvironmentsDTOS = SolaceStoreUtils.getSolaceDeployedEnvsInfo(solaceEnvironment, additionalSubscriptionInfoDTO.getSolaceOrganization(), application.getUUID());
List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEnvironments = new ArrayList<>();
for (SolaceDeployedEnvironmentDTO solaceDeployedEnvironmentEntry : solaceDeployedEnvironmentsDTOS) {
// Set Solace environment details
AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceDeployedEnvironmentsDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
solaceDeployedEnvironmentsDTO.setEnvironmentName(solaceDeployedEnvironmentEntry.getEnvironmentName());
solaceDeployedEnvironmentsDTO.setEnvironmentDisplayName(solaceDeployedEnvironmentEntry.getEnvironmentDisplayName());
solaceDeployedEnvironmentsDTO.setOrganizationName(solaceDeployedEnvironmentEntry.getOrganizationName());
// Set Solace URLs
List<AdditionalSubscriptionInfoSolaceURLsDTO> endpointUrls = new ArrayList<>();
List<SolaceURLsDTO> solaceURLsDTOS = solaceDeployedEnvironmentEntry.getSolaceURLs();
for (SolaceURLsDTO entry : solaceURLsDTOS) {
AdditionalSubscriptionInfoSolaceURLsDTO solaceURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
solaceURLsDTO.setProtocol(entry.getProtocol());
solaceURLsDTO.setEndpointURL(entry.getEndpointURL());
endpointUrls.add(solaceURLsDTO);
}
solaceDeployedEnvironmentsDTO.setSolaceURLs(endpointUrls);
// Set Solace Topic Objects
solaceDeployedEnvironmentsDTO.setSolaceTopicsObject(mapSolaceTopicObjects(solaceDeployedEnvironmentEntry.getSolaceTopicsObject()));
solaceEnvironments.add(solaceDeployedEnvironmentsDTO);
}
additionalSubscriptionInfoDTO.setSolaceDeployedEnvironments(solaceEnvironments);
}
}
return additionalSubscriptionInfoDTO;
}
Aggregations