use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class ExternalGatewayNotifier method unDeployApi.
/**
* Undeploy APIs from external gateway
*
* @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to undeploy APIs from external gateway
* @throws NotifierException if error occurs when undeploying APIs from external gateway
*/
private void unDeployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
boolean deleted;
Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
String apiId = deployAPIInGatewayEvent.getUuid();
try {
Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(deployAPIInGatewayEvent.getProvider());
API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
for (String deploymentEnv : gateways) {
if (environments.containsKey(deploymentEnv)) {
ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(environments.get(deploymentEnv).getProvider());
if (deployer != null) {
try {
deleted = deployer.undeploy(api.getId().getName(), api.getId().getVersion(), api.getContext(), environments.get(deploymentEnv));
if (!deleted) {
throw new NotifierException("Error while deleting API product from Solace broker");
}
} catch (DeployerException e) {
throw new NotifierException(e.getMessage());
}
}
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method unDeployedAPIRevision.
@Override
public Response unDeployedAPIRevision(UnDeployedAPIRevisionDTO unDeployedAPIRevisionDTO, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
apiProvider.removeUnDeployedAPIRevision(unDeployedAPIRevisionDTO.getApiUUID(), unDeployedAPIRevisionDTO.getRevisionUUID(), unDeployedAPIRevisionDTO.getEnvironment());
return Response.ok().build();
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIMappingUtil method getMonetizationInfoDTO.
/**
* This method creates the API monetization information DTO.
*
* @param apiId API apiid
* @param organization identifier of the organization
* @return monetization information DTO
* @throws APIManagementException if failed to construct the DTO
*/
public static APIMonetizationInfoDTO getMonetizationInfoDTO(String apiId, String organization) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
API api = apiProvider.getLightweightAPIByUUID(apiId, organization);
APIMonetizationInfoDTO apiMonetizationInfoDTO = new APIMonetizationInfoDTO();
// set the information relatated to monetization to the DTO
apiMonetizationInfoDTO.setEnabled(api.getMonetizationStatus());
Map<String, String> monetizationPropertiesMap = new HashMap<>();
if (api.getMonetizationProperties() != null) {
JSONObject monetizationProperties = api.getMonetizationProperties();
for (Object propertyKey : monetizationProperties.keySet()) {
String key = (String) propertyKey;
monetizationPropertiesMap.put(key, (String) monetizationProperties.get(key));
}
}
apiMonetizationInfoDTO.setProperties(monetizationPropertiesMap);
return apiMonetizationInfoDTO;
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIMappingUtil method getAPIScopesFromScopeDTOs.
/**
* Convert ScopeDTO List to APIScopesDTO List adding the attribute 'isShared'.
*
* @param scopeDTOS ScopeDTO List
* @return APIScopeDTO List
* @throws APIManagementException if an error occurs while converting ScopeDTOs to APIScopeDTOs
*/
private static List<APIScopeDTO> getAPIScopesFromScopeDTOs(List<ScopeDTO> scopeDTOS) throws APIManagementException {
List<APIScopeDTO> apiScopeDTOS = new ArrayList<>();
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain);
scopeDTOS.forEach(scopeDTO -> {
APIScopeDTO apiScopeDTO = new APIScopeDTO();
apiScopeDTO.setScope(scopeDTO);
apiScopeDTO.setShared(allSharedScopeKeys.contains(scopeDTO.getName()) ? Boolean.TRUE : Boolean.FALSE);
apiScopeDTOS.add(apiScopeDTO);
});
return apiScopeDTOS;
}
use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.
the class APIMappingUtil method getAPIScopesFromScopeDTOs.
/**
* Convert ScopeDTO List to APIScopesDTO List adding the attribute 'isShared'.
*
* @param scopeDTOS ScopeDTO List
* @return APIScopeDTO List
* @throws APIManagementException if an error occurs while converting ScopeDTOs to APIScopeDTOs
*/
private static List<APIScopeDTO> getAPIScopesFromScopeDTOs(List<ScopeDTO> scopeDTOS, APIProvider apiProvider) throws APIManagementException {
List<APIScopeDTO> apiScopeDTOS = new ArrayList<>();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain);
scopeDTOS.forEach(scopeDTO -> {
APIScopeDTO apiScopeDTO = new APIScopeDTO();
apiScopeDTO.setScope(scopeDTO);
apiScopeDTO.setShared(allSharedScopeKeys.contains(scopeDTO.getName()) ? Boolean.TRUE : Boolean.FALSE);
apiScopeDTOS.add(apiScopeDTO);
});
return apiScopeDTOS;
}
Aggregations