use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurations.
public List<KeyManagerConfigurationDTO> getKeyManagerConfigurations() throws APIManagementException {
List<KeyManagerConfigurationDTO> keyManagerConfigurationDTOS = new ArrayList<>();
final String query = "SELECT * FROM AM_KEY_MANAGER";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
String uuid = resultSet.getString("UUID");
keyManagerConfigurationDTO.setUuid(uuid);
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(resultSet.getString("ORGANIZATION"));
keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
String configurationContent = IOUtils.toString(configuration);
Map map = new Gson().fromJson(configurationContent, Map.class);
keyManagerConfigurationDTO.setAdditionalProperties(map);
} catch (IOException e) {
log.error("Error while converting configurations in " + uuid, e);
}
keyManagerConfigurationDTOS.add(keyManagerConfigurationDTO);
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while retrieving all key manager configurations", e);
}
return keyManagerConfigurationDTOS;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getConsumerKeysForApplication.
/**
* Retrieves the consumer keys and keymanager in a given application
*
* @param appId application id
* @return Map<ConsumerKey, Pair<keyManagerName, keyManagerTenantDomain>
* @throws APIManagementException
*/
public Map<String, Pair<String, String>> getConsumerKeysForApplication(int appId) throws APIManagementException {
Map<String, Pair<String, String>> consumerKeysOfApplication = new HashMap<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(SQLConstants.GET_CONSUMER_KEY_OF_APPLICATION_SQL)) {
preparedStatement.setInt(1, appId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String consumerKey = resultSet.getString("CONSUMER_KEY");
String keyManagerName = resultSet.getString("NAME");
String keyManagerOrganization = resultSet.getString("ORGANIZATION");
consumerKeysOfApplication.put(consumerKey, Pair.of(keyManagerName, keyManagerOrganization));
}
}
} catch (SQLException e) {
String msg = "Error occurred while getting consumer keys for application " + appId;
log.error(msg, e);
throw new APIManagementException(msg, e);
}
return consumerKeysOfApplication;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByID.
public KeyManagerConfigurationDTO getKeyManagerConfigurationByID(String organization, String id) throws APIManagementException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ? AND ORGANIZATION = ?";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
preparedStatement.setString(1, id);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
String uuid = resultSet.getString("UUID");
keyManagerConfigurationDTO.setUuid(uuid);
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(organization);
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
String configurationContent = IOUtils.toString(configuration);
Map map = new Gson().fromJson(configurationContent, Map.class);
keyManagerConfigurationDTO.setAdditionalProperties(map);
}
return keyManagerConfigurationDTO;
}
}
} catch (SQLException | IOException e) {
throw new APIManagementException("Error while retrieving key manager configuration for " + id + " in organization " + organization, e);
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method isKeyManagerConfigurationExistById.
public boolean isKeyManagerConfigurationExistById(String organization, String id) throws APIManagementException {
final String query = "SELECT 1 FROM AM_KEY_MANAGER WHERE UUID = ? AND ORGANIZATION = ?";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
preparedStatement.setString(1, id);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
return true;
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while retrieving key manager configuration for " + id + " in organization " + organization, e);
}
return false;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateAPIProductForStateChange.
@Test
public void testUpdateAPIProductForStateChange() throws Exception {
String provider = "admin";
PowerMockito.mockStatic(MultitenantUtils.class);
Mockito.when(MultitenantUtils.getTenantDomain(provider)).thenReturn(APIConstants.SUPER_TENANT_DOMAIN);
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
APIProduct apiProduct = createMockAPIProduct(provider);
prepareForLCStateChangeOfAPIProduct(apiProvider, apiProduct);
PublisherAPIProduct publisherAPIProduct = APIProductMapper.INSTANCE.toPublisherApiProduct(apiProduct);
Organization organization = new Organization(APIConstants.SUPER_TENANT_DOMAIN);
Mockito.when(apiPersistenceInstance.updateAPIProduct(organization, publisherAPIProduct)).thenReturn(publisherAPIProduct);
apiProvider.updateAPIProductForStateChange(apiProduct, APIConstants.CREATED, APIConstants.PUBLISHED);
}
Aggregations