use of org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromGlobalPolicyToGlobalPolicyListDTO.
/**
* Converts a list of global policy objects into a global policy list DTO object.
*
* @param globalPolicies list of global policy objects
* @return global policy list DTO
*/
public static GlobalPolicyListDTO fromGlobalPolicyToGlobalPolicyListDTO(List<GlobalPolicy> globalPolicies) {
GlobalPolicyListDTO globalPolicyListDTO = new GlobalPolicyListDTO();
if (globalPolicies != null) {
for (GlobalPolicy globalPolicy : globalPolicies) {
GlobalPolicyDTO globalPolicyDTO = new GlobalPolicyDTO();
globalPolicyDTO.setId(globalPolicy.getId());
globalPolicyDTO.setName(globalPolicy.getName());
globalPolicyDTO.setTenantId(globalPolicy.getTenantId());
globalPolicyDTO.setTenantDomain(globalPolicy.getTenantDomain());
globalPolicyDTO.setSiddhiQuery(globalPolicy.getSiddhiQuery());
globalPolicyDTO.setKeyTemplate(globalPolicy.getKeyTemplate());
globalPolicyListDTO.getList().add(globalPolicyDTO);
}
globalPolicyListDTO.setCount(globalPolicies.size());
} else {
globalPolicyListDTO.setCount(0);
}
return globalPolicyListDTO;
}
use of org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDAO method getGlobalPolicyByNameForTenant.
public GlobalPolicy getGlobalPolicyByNameForTenant(String policyName, String tenantDomain) {
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(SubscriptionValidationSQLConstants.GET_GLOBAL_POLICY_SQL)) {
int tenantId = 0;
try {
tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
log.error("Error in loading Global Policy for tenantDomain : " + tenantDomain, e);
}
ps.setString(1, policyName);
ps.setInt(2, tenantId);
try (ResultSet resultSet = ps.executeQuery()) {
if (resultSet.next()) {
GlobalPolicy globalPolicyDTO = new GlobalPolicy();
globalPolicyDTO.setId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
globalPolicyDTO.setName(resultSet.getString(ThrottlePolicyConstants.COLUMN_NAME));
globalPolicyDTO.setTenantId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
globalPolicyDTO.setTenantDomain(tenantDomain);
globalPolicyDTO.setKeyTemplate(resultSet.getString(ThrottlePolicyConstants.COLUMN_KEY_TEMPLATE));
InputStream siddhiQueryBlob = resultSet.getBinaryStream(ThrottlePolicyConstants.COLUMN_SIDDHI_QUERY);
String siddhiQuery = null;
if (siddhiQueryBlob != null) {
siddhiQuery = APIMgtDBUtil.getStringFromInputStream(siddhiQueryBlob);
}
globalPolicyDTO.setSiddhiQuery(siddhiQuery);
return globalPolicyDTO;
}
}
} catch (SQLException e) {
log.error("Error in loading global policies by policyId : " + policyName + " of " + policyName, e);
}
return null;
}
use of org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDAO method populateGlobalPolicyList.
private List<GlobalPolicy> populateGlobalPolicyList(ResultSet resultSet) throws SQLException {
List<GlobalPolicy> globalPolicies = new ArrayList<>();
if (resultSet != null) {
while (resultSet.next()) {
GlobalPolicy globalPolicyDTO = new GlobalPolicy();
globalPolicyDTO.setId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
globalPolicyDTO.setName(resultSet.getString(ThrottlePolicyConstants.COLUMN_NAME));
globalPolicyDTO.setTenantId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
String tenantDomain = APIUtil.getTenantDomainFromTenantId(globalPolicyDTO.getTenantId());
globalPolicyDTO.setTenantDomain(tenantDomain);
globalPolicyDTO.setKeyTemplate(resultSet.getString(ThrottlePolicyConstants.COLUMN_KEY_TEMPLATE));
InputStream siddhiQueryBlob = resultSet.getBinaryStream(ThrottlePolicyConstants.COLUMN_SIDDHI_QUERY);
String siddhiQuery = null;
if (siddhiQueryBlob != null) {
siddhiQuery = APIMgtDBUtil.getStringFromInputStream(siddhiQueryBlob);
}
globalPolicyDTO.setSiddhiQuery(siddhiQuery);
globalPolicies.add(globalPolicyDTO);
}
}
return globalPolicies;
}
Aggregations