Search in sources :

Example 61 with APIProvider

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());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ExternalGatewayDeployer(org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer) Environment(org.wso2.carbon.apimgt.api.model.Environment) DeployerException(org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException) API(org.wso2.carbon.apimgt.api.model.API) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Example 62 with APIProvider

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();
}
Also used : APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 63 with APIProvider

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;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) API(org.wso2.carbon.apimgt.api.model.API) JSONObject(org.json.simple.JSONObject) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) APIMonetizationInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMonetizationInfoDTO)

Example 64 with APIProvider

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;
}
Also used : APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 65 with APIProvider

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;
}
Also used : APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) ArrayList(java.util.ArrayList)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)207 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)198 API (org.wso2.carbon.apimgt.api.model.API)92 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)83 Test (org.junit.Test)82 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)82 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)73 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)65 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)36 URISyntaxException (java.net.URISyntaxException)34 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)32 URI (java.net.URI)31 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)31 JSONObject (org.json.simple.JSONObject)29 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)29 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)29 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)28 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)28 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)23