Search in sources :

Example 1 with GlobalPolicyDTO

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;
}
Also used : GlobalPolicyListDTO(org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyListDTO) GlobalPolicyDTO(org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyDTO) GlobalPolicy(org.wso2.carbon.apimgt.api.model.subscription.GlobalPolicy)

Example 2 with GlobalPolicyDTO

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;
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.api.model.subscription.GlobalPolicy) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) Connection(java.sql.Connection) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with GlobalPolicyDTO

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;
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.api.model.subscription.GlobalPolicy) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Aggregations

GlobalPolicy (org.wso2.carbon.apimgt.api.model.subscription.GlobalPolicy)3 InputStream (java.io.InputStream)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 GlobalPolicyDTO (org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyDTO)1 GlobalPolicyListDTO (org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyListDTO)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1