use of org.wso2.carbon.apimgt.solace.dtos.SolaceTopicsObjectDTO in project carbon-apimgt by wso2.
the class SolaceStoreUtils method populateSolaceTopics.
/**
* Populate Solace Topics from the response body
*
* @param solaceTopicsObjectDTO Solace Topic Object DTO
* @param permissionsObject Json Object of the body
* @param syntax Protocol Syntax
*/
private static void populateSolaceTopics(SolaceTopicsObjectDTO solaceTopicsObjectDTO, org.json.JSONObject permissionsObject, String syntax) {
SolaceTopicsDTO topicsDTO = new SolaceTopicsDTO();
if (permissionsObject.getJSONArray("publish") != null) {
List<String> publishTopics = new ArrayList<>();
for (int j = 0; j < permissionsObject.getJSONArray("publish").length(); j++) {
org.json.JSONObject channelObject = permissionsObject.getJSONArray("publish").getJSONObject(j);
for (Object x : channelObject.keySet()) {
org.json.JSONObject channel = channelObject.getJSONObject(x.toString());
JSONArray channelPermissions = channel.getJSONArray("permissions");
for (int k = 0; k < channelPermissions.length(); k++) {
if (!publishTopics.contains(channelPermissions.getString(k))) {
publishTopics.add(channelPermissions.getString(k));
}
}
}
}
topicsDTO.setPublishTopics(publishTopics);
}
if (permissionsObject.getJSONArray("subscribe") != null) {
List<String> subscribeTopics = new ArrayList<>();
for (int j = 0; j < permissionsObject.getJSONArray("subscribe").length(); j++) {
org.json.JSONObject channelObject = permissionsObject.getJSONArray("subscribe").getJSONObject(j);
for (Object x : channelObject.keySet()) {
org.json.JSONObject channel = channelObject.getJSONObject(x.toString());
JSONArray channelPermissions = channel.getJSONArray("permissions");
for (int k = 0; k < channelPermissions.length(); k++) {
if (!subscribeTopics.contains(channelPermissions.getString(k))) {
subscribeTopics.add(channelPermissions.getString(k));
}
}
}
}
topicsDTO.setSubscribeTopics(subscribeTopics);
}
if (SolaceConstants.MQTT_TRANSPORT_PROTOCOL_NAME.equalsIgnoreCase(syntax)) {
solaceTopicsObjectDTO.setMqttSyntax(topicsDTO);
} else {
solaceTopicsObjectDTO.setDefaultSyntax(topicsDTO);
}
}
use of org.wso2.carbon.apimgt.solace.dtos.SolaceTopicsObjectDTO 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.SolaceTopicsObjectDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method mapSolaceTopicObjects.
/**
* Map SolaceTopicsObjectDTO details from Solace package to DevPortal DTOs
*
* @param solaceTopicsObject SolaceTopicsObjectDTO object from Solace package
* @return AdditionalSubscriptionInfoSolaceTopicsObjectDTO object
*/
private static AdditionalSubscriptionInfoSolaceTopicsObjectDTO mapSolaceTopicObjects(SolaceTopicsObjectDTO solaceTopicsObject) {
AdditionalSubscriptionInfoSolaceTopicsObjectDTO solaceTopicsObjectDTO = new AdditionalSubscriptionInfoSolaceTopicsObjectDTO();
// Set default syntax object
org.wso2.carbon.apimgt.solace.dtos.SolaceTopicsDTO defaultSyntaxObject = solaceTopicsObject.getDefaultSyntax();
SolaceTopicsDTO storeDefaultSolaceTopicObject = new SolaceTopicsDTO();
storeDefaultSolaceTopicObject.setPublishTopics(defaultSyntaxObject.getPublishTopics());
storeDefaultSolaceTopicObject.setSubscribeTopics(defaultSyntaxObject.getSubscribeTopics());
solaceTopicsObjectDTO.setDefaultSyntax(storeDefaultSolaceTopicObject);
// Set mqtt syntax object
org.wso2.carbon.apimgt.solace.dtos.SolaceTopicsDTO mqttSyntaxObject = solaceTopicsObject.getMqttSyntax();
SolaceTopicsDTO storeMQTTSolaceTopicObject = new SolaceTopicsDTO();
storeMQTTSolaceTopicObject.setPublishTopics(mqttSyntaxObject.getPublishTopics());
storeMQTTSolaceTopicObject.setSubscribeTopics(mqttSyntaxObject.getSubscribeTopics());
solaceTopicsObjectDTO.setMqttSyntax(storeMQTTSolaceTopicObject);
return solaceTopicsObjectDTO;
}
Aggregations