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"));
}
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();
}
}
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;
}
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;
}
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());
}
}
Aggregations