use of org.wso2.carbon.apimgt.solace.dtos.SolaceDeployedEnvironmentDTO in project carbon-apimgt by wso2.
the class SolaceStoreUtils method getSolaceDeployedEnvsInfo.
/**
* Get SolaceDeployedEnvironmentDTO using admin APIs and map into DTOs to parse Devportal
*
* @param solaceEnvironment Solace environment Object
* @param solaceOrganization Solace broker organization name
* @param applicationUuid Subscribed Application UUID
* @return List of SolaceDeployedEnvironmentDTO to use in Devportal
* @throws APIManagementException if error occurred when creating SolaceDeployedEnvironmentDTO
*/
public static List<SolaceDeployedEnvironmentDTO> getSolaceDeployedEnvsInfo(Environment solaceEnvironment, String solaceOrganization, String applicationUuid) throws APIManagementException {
Map<String, Environment> gatewayEnvironmentMap = APIUtil.getReadOnlyGatewayEnvironments();
// Create solace admin APIs instance
SolaceAdminApis solaceAdminApis = new SolaceAdminApis(solaceEnvironment.getServerURL(), solaceEnvironment.getUserName(), solaceEnvironment.getPassword(), solaceEnvironment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_DEV_NAME));
HttpResponse response = solaceAdminApis.applicationGet(solaceOrganization, applicationUuid, "default");
List<SolaceDeployedEnvironmentDTO> solaceEnvironments = new ArrayList<>();
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
try {
String responseString = EntityUtils.toString(response.getEntity());
org.json.JSONObject jsonObject = new org.json.JSONObject(responseString);
// Get solace environments attached with the Solace application
if (jsonObject.getJSONArray("environments") != null) {
JSONArray environmentsArray = jsonObject.getJSONArray("environments");
for (int i = 0; i < environmentsArray.length(); i++) {
SolaceDeployedEnvironmentDTO solaceDeployedEnvironmentsDTO = new SolaceDeployedEnvironmentDTO();
org.json.JSONObject environmentObject = environmentsArray.getJSONObject(i);
// Get details of Solace environment attached to the solace application
if (environmentObject.getString("name") != null) {
String environmentName = environmentObject.getString("name");
Environment gatewayEnvironment = gatewayEnvironmentMap.get(environmentName);
if (gatewayEnvironment != null) {
// Set Solace environment details
solaceDeployedEnvironmentsDTO.setEnvironmentName(gatewayEnvironment.getName());
solaceDeployedEnvironmentsDTO.setEnvironmentDisplayName(gatewayEnvironment.getDisplayName());
solaceDeployedEnvironmentsDTO.setOrganizationName(gatewayEnvironment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION));
boolean containsMQTTProtocol = false;
// Get messaging protocols from the response body
if (environmentObject.getJSONArray("messagingProtocols") != null) {
List<SolaceURLsDTO> endpointUrls = new ArrayList<>();
JSONArray protocolsArray = environmentObject.getJSONArray("messagingProtocols");
for (int j = 0; j < protocolsArray.length(); j++) {
SolaceURLsDTO solaceURLsDTO = new SolaceURLsDTO();
String protocol = protocolsArray.getJSONObject(j).getJSONObject("protocol").getString("name");
if (SolaceConstants.MQTT_TRANSPORT_PROTOCOL_NAME.equalsIgnoreCase(protocol)) {
containsMQTTProtocol = true;
}
String uri = protocolsArray.getJSONObject(j).getString("uri");
solaceURLsDTO.setProtocol(protocol);
solaceURLsDTO.setEndpointURL(uri);
endpointUrls.add(solaceURLsDTO);
}
solaceDeployedEnvironmentsDTO.setSolaceURLs(endpointUrls);
}
// Get topic permissions from the solace application response body
if (environmentObject.getJSONObject("permissions") != null) {
org.json.JSONObject permissionsObject = environmentObject.getJSONObject("permissions");
SolaceTopicsObjectDTO solaceTopicsObjectDTO = new SolaceTopicsObjectDTO();
populateSolaceTopics(solaceTopicsObjectDTO, permissionsObject, "default");
// Handle the special case of MQTT protocol
if (containsMQTTProtocol) {
HttpResponse responseForMqtt = solaceAdminApis.applicationGet(solaceOrganization, applicationUuid, SolaceConstants.MQTT_TRANSPORT_PROTOCOL_NAME.toUpperCase());
org.json.JSONObject permissionsObjectForMqtt = extractPermissionsFromSolaceApplicationGetResponse(responseForMqtt, i, gatewayEnvironmentMap);
if (permissionsObjectForMqtt != null) {
populateSolaceTopics(solaceTopicsObjectDTO, permissionsObjectForMqtt, SolaceConstants.MQTT_TRANSPORT_PROTOCOL_NAME.toUpperCase());
}
}
solaceDeployedEnvironmentsDTO.setSolaceTopicsObject(solaceTopicsObjectDTO);
}
}
}
solaceEnvironments.add(solaceDeployedEnvironmentsDTO);
}
}
} catch (IOException e) {
log.error(e.getMessage());
}
return solaceEnvironments;
} else {
throw new APIManagementException("Solace Environment configurations are not provided properly");
}
}
use of org.wso2.carbon.apimgt.solace.dtos.SolaceDeployedEnvironmentDTO 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