Search in sources :

Example 1 with PrimitiveConditionValidationException

use of org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException in project carbon-identity-framework by wso2.

the class PrimitiveConditionValidator method validate.

/**
 * Validate parameters in a {@link PrimitiveCondition} with the given Search bean
 *
 * @param primitiveCondition
 * @return A db qualified {@link PrimitiveCondition}.
 * @throws PrimitiveConditionValidationException
 */
public PrimitiveCondition validate(PrimitiveCondition primitiveCondition) throws PrimitiveConditionValidationException {
    if (searchBean == null) {
        throw new NullPointerException("Invalid search bean: null in the PrimitiveCondition validate.");
    }
    String property = primitiveCondition.getProperty();
    ConditionType.PrimitiveOperator operator = primitiveCondition.getOperator();
    Object value = primitiveCondition.getValue();
    if (property == null || operator == null || value == null) {
        throw new PrimitiveConditionValidationException("Invalid primitive condition parameters found in: property = " + property + (operator == null ? ", condition = null" : "") + (value == null ? ", value = null" : "") + ".");
    }
    try {
        Field field = this.searchBean.getClass().getDeclaredField(property);
        if (!field.getType().getName().equals(value.getClass().getName())) {
            throw new PrimitiveConditionValidationException("Value for the property: " + property + " is expected to be: " + field.getType().getName() + " but found: " + value.getClass().getName());
        }
    } catch (NoSuchFieldException e) {
        throw new PrimitiveConditionValidationException("Property: " + property + " is not found in the allowed search properties present in the bean " + "class: " + ResourceSearchBean.class.getName());
    }
    // If parameter validation are a success then build a database qualified primitive condition.
    PrimitiveCondition dbQualifiedPrimitiveCondition;
    dbQualifiedPrimitiveCondition = this.searchBean.mapPrimitiveCondition(primitiveCondition);
    dbQualifiedPrimitiveCondition.setProperty(this.searchBean.getDBQualifiedFieldName(dbQualifiedPrimitiveCondition.getProperty()));
    return dbQualifiedPrimitiveCondition;
}
Also used : Field(java.lang.reflect.Field) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) ConditionType(org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType) PrimitiveConditionValidationException(org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException)

Example 2 with PrimitiveConditionValidationException

use of org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method buildPlaceholderSQL.

private PlaceholderSQL buildPlaceholderSQL(Condition condition, boolean useCreatedTime) throws ConfigurationManagementException {
    String queryWithCreatedTime = GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL;
    String queryWithOutCreatedTime = GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME;
    try {
        if (isOracleDB() || isMSSqlDB()) {
            queryWithCreatedTime = GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE;
        }
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
    }
    StringBuilder sb = new StringBuilder();
    sb.append(useCreatedTime ? queryWithCreatedTime : queryWithOutCreatedTime);
    sb.append("WHERE\n");
    try {
        PlaceholderSQL placeholderSQL = condition.buildQuery(new PrimitiveConditionValidator(new ResourceSearchBean()));
        placeholderSQL.setQuery(sb.append(placeholderSQL.getQuery()).toString());
        return placeholderSQL;
    } catch (PrimitiveConditionValidationException e) {
        throw handleClientException(ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR, e.getMessage(), e);
    }
}
Also used : PlaceholderSQL(org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL) PrimitiveConditionValidator(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveConditionValidator) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) PrimitiveConditionValidationException(org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Aggregations

ResourceSearchBean (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean)2 PrimitiveConditionValidationException (org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException)2 Field (java.lang.reflect.Field)1 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)1 PlaceholderSQL (org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL)1 PrimitiveConditionValidator (org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveConditionValidator)1 ConditionType (org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType)1