use of org.wso2.ballerinalang.compiler.util.Names in project carbon-apimgt by wso2.
the class APIUtilTierTest method testGetAvailableTiersWithExistingTier.
@Test
public void testGetAvailableTiersWithExistingTier() throws Exception {
Map<String, Tier> definedTiers = getDefinedTiers();
// Select valid tier names to be assigned to the API
Set<Tier> expectedTiers = getRoundRobinTierString(validTierNames);
String apiName = "testApi";
Set<Tier> availableTiers = APIUtil.getAvailableTiers(definedTiers, getTiersAsString(expectedTiers), apiName);
Assert.assertEquals("Expected tiers do not match", expectedTiers, availableTiers);
}
use of org.wso2.ballerinalang.compiler.util.Names in project carbon-apimgt by wso2.
the class ExportUtils method getEndpointURLs.
/**
* Get endpoint url list from endpoint config.
*
* @param endpointConfig JSON converted endpoint config
* @param type End point type - production/sandbox
* @return List of host names
*/
private static List<String> getEndpointURLs(JSONObject endpointConfig, String type, String apiName) throws APIImportExportException {
List<String> urls = new ArrayList<>();
if (endpointConfig != null) {
try {
if (endpointConfig.has(type)) {
Object item = endpointConfig.get(type);
if (item instanceof JSONArray) {
JSONArray endpointsJSON = new JSONArray(endpointConfig.getJSONArray(type).toString());
for (int i = 0; i < endpointsJSON.length(); i++) {
try {
String urlValue = endpointsJSON.getJSONObject(i).get(APIConstants.API_DATA_URL).toString();
urls.add(urlValue);
} catch (JSONException ex) {
log.error("Endpoint URL extraction from endpoints JSON object failed in API: " + apiName, ex);
}
}
} else if (item instanceof JSONObject) {
JSONObject endpointJSON = new JSONObject(endpointConfig.getJSONObject(type).toString());
try {
String urlValue = endpointJSON.get(APIConstants.API_DATA_URL).toString();
urls.add(urlValue);
} catch (JSONException ex) {
log.error("Endpoint URL extraction from endpoint JSON object failed in API: " + apiName, ex);
}
}
}
} catch (JSONException ex) {
throw new APIImportExportException("Endpoint type: " + type + " not found in API: " + apiName);
}
}
return urls;
}
use of org.wso2.ballerinalang.compiler.util.Names in project carbon-apimgt by wso2.
the class AbstractAPIManager method getDocPaths.
/**
* Get API Documents within the provided registry collection
* In case the document names contained '/' character, need to get only leaf node documents within them
*
* @param docCollection registry collection
* @param apiOrAPIProductDocPath base api/api product document path
* @return
* @throws APIManagementException
*/
private List<String> getDocPaths(org.wso2.carbon.registry.core.Collection docCollection, String apiOrAPIProductDocPath) throws APIManagementException {
List<String> docPaths = new ArrayList<>();
String pathToContent = apiOrAPIProductDocPath + APIConstants.INLINE_DOCUMENT_CONTENT_DIR;
String pathToDocFile = apiOrAPIProductDocPath + APIConstants.DOCUMENT_FILE_DIR;
try {
String[] resourcePaths = docCollection.getChildren();
for (String resourcePath : resourcePaths) {
if (!(resourcePath.equals(pathToContent) || resourcePath.equals(pathToDocFile))) {
Resource resource = registry.get(resourcePath);
if (resource instanceof org.wso2.carbon.registry.core.Collection) {
docPaths.addAll(getDocPaths((org.wso2.carbon.registry.core.Collection) resource, apiOrAPIProductDocPath));
} else {
docPaths.add(resourcePath);
}
}
}
} catch (RegistryException e) {
String msg = "Failed to get documents for api/product";
throw new APIManagementException(msg, e);
}
return docPaths;
}
use of org.wso2.ballerinalang.compiler.util.Names in project carbon-apimgt by wso2.
the class AbstractAPIManager method getTiers.
/**
* Returns a list of pre-defined # {@link org.wso2.carbon.apimgt.api.model.Tier} in the system.
*
* @param tierType type of the tiers (api,resource ot application)
* @param username current logged user
* @return Set<Tier> return list of tier names
* @throws APIManagementException APIManagementException if failed to get the predefined tiers
*/
public Set<Tier> getTiers(int tierType, String username) throws APIManagementException {
Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator());
String tenantDomain = getTenantDomain(username);
Map<String, Tier> tierMap;
int tenantIdFromUsername = APIUtil.getTenantId(username);
if (tierType == APIConstants.TIER_API_TYPE) {
tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_SUB, tenantIdFromUsername);
} else if (tierType == APIConstants.TIER_RESOURCE_TYPE) {
tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_API, tenantIdFromUsername);
} else if (tierType == APIConstants.TIER_APPLICATION_TYPE) {
tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_APP, tenantIdFromUsername);
} else {
throw new APIManagementException("No such a tier type : " + tierType);
}
tiers.addAll(tierMap.values());
return tiers;
}
use of org.wso2.ballerinalang.compiler.util.Names in project carbon-apimgt by wso2.
the class PublisherCommonUtils method validateAdditionalProperties.
/**
* To validate the additional properties.
* Validation will be done for the keys of additional properties. Property keys should not contain spaces in it
* and property keys should not conflict with reserved key words.
*
* @param additionalProperties Map<String, String> properties to validate
* @return error message if there is an validation error with additional properties.
*/
public static String validateAdditionalProperties(List<APIInfoAdditionalPropertiesDTO> additionalProperties) {
if (additionalProperties != null) {
for (APIInfoAdditionalPropertiesDTO property : additionalProperties) {
String propertyKey = property.getName();
String propertyValue = property.getValue();
if (propertyKey.contains(" ")) {
return "Property names should not contain space character. Property '" + propertyKey + "' " + "contains space in it.";
}
if (Arrays.asList(APIConstants.API_SEARCH_PREFIXES).contains(propertyKey.toLowerCase())) {
return "Property '" + propertyKey + "' conflicts with the reserved keywords. Reserved keywords " + "are [" + Arrays.toString(APIConstants.API_SEARCH_PREFIXES) + "]";
}
// restricting them to be within 80 and 900.
if (propertyKey.length() > 80) {
return "Property name can have maximum of 80 characters. Property '" + propertyKey + "' + contains " + propertyKey.length() + "characters";
}
if (propertyValue.length() > 900) {
return "Property value can have maximum of 900 characters. Property '" + propertyKey + "' + " + "contains a value with " + propertyValue.length() + "characters";
}
}
}
return "";
}
Aggregations