Search in sources :

Example 56 with APIProvider

use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.

the class APIProviderImplTest method testUpdateBlockCondition.

@Test
public void testUpdateBlockCondition() throws APIManagementException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(apimgtDAO.updateBlockConditionState(1, "testState")).thenReturn(false, true);
    BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
    blockConditionsDTO.setConditionType("testType");
    blockConditionsDTO.setConditionValue("USER");
    PowerMockito.mockStatic(MultitenantUtils.class);
    PowerMockito.when(MultitenantUtils.getTenantAwareUsername("User")).thenReturn("testValue");
    Mockito.when(apimgtDAO.getBlockCondition(1)).thenReturn(blockConditionsDTO);
    // updateState false
    assertFalse(apiProvider.updateBlockCondition(1, "testState"));
    // updateState true
    assertTrue(apiProvider.updateBlockCondition(1, "testState"));
}
Also used : BlockConditionsDTO(org.wso2.carbon.apimgt.api.model.BlockConditionsDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with APIProvider

use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.

the class APIManagerFactory method clearAll.

public void clearAll() {
    consumers.exclusiveLock();
    try {
        for (APIConsumer consumer : consumers.values()) {
            cleanupSilently(consumer);
        }
        consumers.clear();
    } finally {
        consumers.release();
    }
    providers.exclusiveLock();
    try {
        for (APIProvider provider : providers.values()) {
            cleanupSilently(provider);
        }
        providers.clear();
    } finally {
        providers.release();
    }
}
Also used : APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 58 with APIProvider

use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.

the class APIManagerFactory method getAPIProvider.

public APIProvider getAPIProvider(String username) throws APIManagementException {
    APIProvider provider = providers.get(username);
    if (provider == null) {
        synchronized (username.intern()) {
            provider = providers.get(username);
            if (provider != null) {
                return provider;
            }
            provider = newProvider(username);
            providers.put(username, provider);
        }
    }
    return provider;
}
Also used : APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 59 with APIProvider

use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.

the class OrganizationPurgeDAO method getAPIIdList.

/**
 * Get API data for given organization
 *
 * @param orgId organization Id
 * @return ArrayList<APIIdentifier>
 * @throws APIManagementException
 */
public ArrayList<APIIdentifier> getAPIIdList(String orgId) throws APIManagementException {
    ArrayList<APIIdentifier> apiList = new ArrayList<>();
    try (Connection conn = APIMgtDBUtil.getConnection();
        PreparedStatement ps = conn.prepareStatement(OrganizationPurgeConstants.GET_API_LIST_SQL_BY_ORG_SQL)) {
        ps.setString(1, orgId);
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                int apiId = rs.getInt("API_ID");
                String apiUuid = rs.getString("API_UUID");
                String apiName = rs.getString("API_Name");
                String apiProvider = rs.getString("API_Provider");
                String apiVersion = rs.getString("API_Version");
                APIIdentifier apiIdentifier = new APIIdentifier(apiProvider, apiName, apiVersion, apiUuid);
                apiIdentifier.setId(apiId);
                apiList.add(apiIdentifier);
            }
        }
    } catch (SQLException e) {
        log.error("Error while getting apiUuid list of organization" + orgId, e);
        handleException("Failed to get API apiUuid list of organization " + orgId, e);
    }
    return apiList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) PreparedStatement(java.sql.PreparedStatement)

Example 60 with APIProvider

use of org.wso2.carbon.apimgt.api.APIProvider in project carbon-apimgt by wso2.

the class ExternallyDeployedApiNotifier method undeployApiWhenRetiring.

/**
 * Undeploy APIs from external gateway when life cycle state changed to retire
 *
 * @param apiEvent APIEvent to undeploy APIs from external gateway
 * @throws NotifierException if error occurs when undeploying APIs from external gateway
 */
private void undeployApiWhenRetiring(APIEvent apiEvent) throws NotifierException {
    apiMgtDAO = ApiMgtDAO.getInstance();
    Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
    boolean deleted;
    String apiId = apiEvent.getUuid();
    if (!APIConstants.RETIRED.equals(apiEvent.getApiStatus())) {
        return;
    }
    try {
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
        List<APIRevisionDeployment> test = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiId);
        for (APIRevisionDeployment deployment : test) {
            String deploymentEnv = deployment.getDeployment();
            if (gatewayEnvironments.containsKey(deploymentEnv)) {
                ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(gatewayEnvironments.get(deploymentEnv).getProvider());
                if (deployer != null) {
                    try {
                        deleted = deployer.undeployWhenRetire(api, gatewayEnvironments.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) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

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