use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO 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;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method setSolaceEnvironmentDetailsForSubscription.
/**
* Sets the solace environment details For Solace API subscription with the protocol details
*
* @param api API object
* @param tenantDomain Tenant Domain
* @return List containing AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO
* @throws APIManagementException if error occurred when retrieving protocols URLs
*/
private static List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> setSolaceEnvironmentDetailsForSubscription(API api, String tenantDomain) throws APIManagementException {
APIDTO apidto = APIMappingUtil.fromAPItoDTO(api, tenantDomain);
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
List<APIRevisionDeployment> revisionDeployments = apiConsumer.getAPIRevisionDeploymentListOfAPI(apidto.getId());
List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEndpointURLsList = new ArrayList<>();
// Get revision list of APIs and check Solace deployment environment
for (APIRevisionDeployment revisionDeployment : revisionDeployments) {
if (revisionDeployment.isDisplayOnDevportal()) {
if (gatewayEnvironments != null) {
// Deployed environment
Environment environment = gatewayEnvironments.get(revisionDeployment.getDeployment());
if (environment != null) {
// Set solace environment details if deployment is in Solace broker
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(environment.getProvider())) {
AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceEnvironmentDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
solaceEnvironmentDTO.setEnvironmentName(environment.getName());
solaceEnvironmentDTO.setEnvironmentDisplayName(environment.getDisplayName());
solaceEnvironmentDTO.setOrganizationName(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION));
// Get Solace endpoint URLs for provided protocols
solaceEnvironmentDTO.setSolaceURLs(mapSolaceURLsToStoreDTO(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION), environment.getName(), apidto.getAsyncTransportProtocols()));
solaceEndpointURLsList.add(solaceEnvironmentDTO);
}
}
}
}
}
return solaceEndpointURLsList;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method setEndpointURLsForApiDto.
/**
* Sets the Endpoint URLs for the APIDTO object using solace protocols
*
* @param api API object
* @param tenantDomain Tenant Domain
* @return List containing AdditionalSubscriptionInfoSolaceEndpointURLsDTOs
* @throws APIManagementException if error occurred when retrieving protocols URLs
*/
public static List<String> setEndpointURLsForApiDto(API api, String tenantDomain) throws APIManagementException {
List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> urlsList = setSolaceEnvironmentDetailsForSubscription(api, tenantDomain);
List<String> urlsStringList = new ArrayList<>();
if (!urlsList.isEmpty()) {
for (AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO item : urlsList) {
List<AdditionalSubscriptionInfoSolaceURLsDTO> protocols = item.getSolaceURLs();
for (AdditionalSubscriptionInfoSolaceURLsDTO protocol : protocols) {
// Create Json string to return
JSONObject asyncProtocolsObj = new JSONObject();
asyncProtocolsObj.put("protocol", protocol.getProtocol());
asyncProtocolsObj.put("endPointUrl", protocol.getEndpointURL());
urlsStringList.add(asyncProtocolsObj.toString());
}
}
}
return urlsStringList;
}
Aggregations