Search in sources :

Example 6 with PrimitiveCondition

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

the class ServerApplicationManagementService method buildSearchCondition.

private Condition buildSearchCondition(SearchCondition searchCondition) {
    if (!(searchCondition.getStatement() == null)) {
        PrimitiveStatement primitiveStatement = searchCondition.getStatement();
        if (ApplicationManagementConstants.TemplateProperties.SEARCH_KEYS.contains(primitiveStatement.getProperty())) {
            List<Condition> list = new ArrayList<>();
            Condition attrKeyCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties.ATTR_KEY, EQUALS, primitiveStatement.getProperty());
            Condition attrValueCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties.ATTR_VALUE, getPrimitiveOperatorFromOdata(primitiveStatement.getCondition()), primitiveStatement.getValue());
            list.add(attrKeyCondition);
            list.add(attrValueCondition);
            return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND), list);
        } else if (ApplicationManagementConstants.TemplateProperties.SEARCH_KEY_NAME.equals(primitiveStatement.getProperty())) {
            return new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties.SEARCH_KEY_NAME_INTERNAL, getPrimitiveOperatorFromOdata(primitiveStatement.getCondition()), primitiveStatement.getValue());
        } else {
            throw buildClientError(ApplicationManagementConstants.ErrorMessage.ERROR_CODE_ERROR_INVALID_SEARCH_FILTER, null);
        }
    } else {
        List<Condition> conditions = new ArrayList<>();
        for (Object condition : searchCondition.getSearchConditions()) {
            Condition buildCondition = buildSearchCondition((SearchCondition) condition);
            conditions.add(buildCondition);
        }
        return new ComplexCondition(getComplexOperatorFromOdata(searchCondition.getConditionType()), conditions);
    }
}
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) PrimitiveStatement(org.apache.cxf.jaxrs.ext.search.PrimitiveStatement) ArrayList(java.util.ArrayList) PrimitiveCondition(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition) ComplexCondition(org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition)

Example 7 with PrimitiveCondition

use of org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition 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

ArrayList (java.util.ArrayList)6 ComplexCondition (org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition)6 Condition (org.wso2.carbon.identity.configuration.mgt.core.search.Condition)6 PrimitiveCondition (org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition)6 SearchCondition (org.apache.cxf.jaxrs.ext.search.SearchCondition)4 ResourceSearchBean (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean)3 PrimitiveStatement (org.apache.cxf.jaxrs.ext.search.PrimitiveStatement)2 Field (java.lang.reflect.Field)1 ConditionType (org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType)1 PrimitiveConditionValidationException (org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException)1