use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersGet.
public Response keyManagersGet(String xWSO2Tenant, MessageContext messageContext) {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
try {
List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(organization);
return Response.ok(KeyManagerMappingUtil.toKeyManagerListDto(keyManagerConfigurations)).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving keyManager Details for organization " + organization, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesSubscriptionGet.
/**
* Retrieves all Subscription level policies
*
* @param accept Accept header value
* @return All matched Subscription Throttle policies to the given request
*/
@Override
public Response throttlingPoliciesSubscriptionGet(String accept, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
Policy[] subscriptionPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_SUB);
List<SubscriptionPolicy> policies = new ArrayList<>();
for (Policy policy : subscriptionPolicies) {
policies.add((SubscriptionPolicy) policy);
}
SubscriptionThrottlePolicyListDTO listDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(policies.toArray(new SubscriptionPolicy[policies.size()]));
return Response.ok().entity(listDTO).build();
} catch (APIManagementException | ParseException e) {
String errorMessage = "Error while retrieving Subscription level policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesAdvancedGet.
/**
* Retrieves all Advanced level policies
*
* @param accept Accept header value
* @return All matched Advanced Throttle policies to the given request
*/
@Override
public Response throttlingPoliciesAdvancedGet(String accept, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
Policy[] apiPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_API);
List<APIPolicy> policies = new ArrayList<>();
for (Policy policy : apiPolicies) {
policies.add((APIPolicy) policy);
}
AdvancedThrottlePolicyListDTO listDTO = AdvancedThrottlePolicyMappingUtil.fromAPIPolicyArrayToListDTO(policies.toArray(new APIPolicy[policies.size()]));
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Advanced level policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesCustomGet.
/**
* Retrieves all Global level policies
*
* @param accept Accept header value
* @return All matched Global Throttle policies to the given request
*/
@Override
public Response throttlingPoliciesCustomGet(String accept, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
// only super tenant is allowed to access global policies/custom rules
checkTenantDomainForCustomRules();
Policy[] globalPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_GLOBAL);
List<GlobalPolicy> policies = new ArrayList<>();
for (Policy policy : globalPolicies) {
policies.add((GlobalPolicy) policy);
}
CustomRuleListDTO listDTO = GlobalThrottlePolicyMappingUtil.fromGlobalPolicyArrayToListDTO(policies.toArray(new GlobalPolicy[policies.size()]));
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Global level policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class RestApiAdminUtils method restoreTenantTheme.
/**
* Restores the tenant theme which existed before the current import operation was performed
*
* @param tenantId tenant ID of the tenant to which the theme is imported
* @param tenantThemeDirectory directory in the file system to where the tenant theme is imported
* @param backupDirectory directory in the file system where the tenant theme is temporarily backed-up
* @param existingTenantTheme tenant theme which existed before the current import operation
* @throws APIManagementException if an error occurs when updating the tenant theme in the database
* @throws IOException if an error occurs when restoring the tenant theme directory
*/
public static void restoreTenantTheme(int tenantId, File tenantThemeDirectory, File backupDirectory, InputStream existingTenantTheme) throws APIManagementException, IOException {
APIAdmin apiAdmin = new APIAdminImpl();
FileUtils.copyDirectory(backupDirectory, tenantThemeDirectory);
FileUtils.deleteDirectory(backupDirectory);
apiAdmin.updateTenantTheme(tenantId, existingTenantTheme);
}
Aggregations