Search in sources :

Example 1 with ResourceSearchBean

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean in project identity-api-server by wso2.

the class ServerApplicationManagementService method getSearchCondition.

/**
 * Retrieve search condition from @{SearchContext}.
 *
 * @param templateType  Template type.
 * @param tenantDomain  Tenant domain.
 * @param searchContext Search context.
 * @return Condition.
 */
private Condition getSearchCondition(String templateType, String tenantDomain, SearchContext searchContext) {
    if (searchContext != null) {
        SearchCondition<ResourceSearchBean> searchCondition = searchContext.getCondition(ResourceSearchBean.class);
        if (searchCondition != null) {
            Condition result = buildSearchCondition(searchCondition);
            List<Condition> list = new ArrayList<>();
            Condition typeCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties.TEMPLATE_TYPE_KEY, EQUALS, templateType);
            Condition tenantCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties.TENANT_DOMAIN_KEY, EQUALS, tenantDomain);
            if (result instanceof ComplexCondition) {
                list = ((ComplexCondition) result).getConditions();
                list.add(typeCondition);
                list.add(tenantCondition);
            } else if (result instanceof PrimitiveCondition) {
                list.add(result);
                list.add(typeCondition);
                list.add(tenantCondition);
            }
            return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND), list);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Search condition parsed from the search expression is invalid.");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find a valid search context.");
        }
    }
    return null;
}
Also used : PrimitiveCondition(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) ComplexCondition(org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) ArrayList(java.util.ArrayList) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) PrimitiveCondition(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition) ComplexCondition(org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition)

Example 2 with ResourceSearchBean

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean 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)

Example 3 with ResourceSearchBean

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean in project identity-api-server by wso2.

the class ServerIdpManagementService method getSearchCondition.

/**
 * Retrieve search condition from @{SearchContext}.
 *
 * @param templateType  Template type.
 * @param tenantDomain  Tenant domain.
 * @param searchContext Search context.
 * @return  Condition.
 */
private Condition getSearchCondition(String templateType, String tenantDomain, SearchContext searchContext) {
    if (searchContext != null) {
        SearchCondition<ResourceSearchBean> searchCondition = searchContext.getCondition(ResourceSearchBean.class);
        if (searchCondition != null) {
            Condition result = buildSearchCondition(searchCondition);
            Condition typeCondition = new PrimitiveCondition(Constants.TEMPLATE_TYPE_KEY, EQUALS, templateType);
            Condition tenantCondition = new PrimitiveCondition(Constants.TENANT_DOMAIN_KEY, EQUALS, tenantDomain);
            List<Condition> list = new ArrayList<>();
            list.add(result);
            list.add(typeCondition);
            list.add(tenantCondition);
            return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND), list);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Search condition parsed from the search expression is invalid.");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find a valid search context.");
        }
    }
    return null;
}
Also used : PrimitiveCondition(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) ComplexCondition(org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) ArrayList(java.util.ArrayList) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) PrimitiveCondition(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition) ComplexCondition(org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition)

Aggregations

ResourceSearchBean (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean)3 ArrayList (java.util.ArrayList)2 SearchCondition (org.apache.cxf.jaxrs.ext.search.SearchCondition)2 ComplexCondition (org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition)2 Condition (org.wso2.carbon.identity.configuration.mgt.core.search.Condition)2 PrimitiveCondition (org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition)2 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 PrimitiveConditionValidationException (org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException)1