use of org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition in project carbon-identity-framework by wso2.
the class TestUtils method getSampleSearchCondition.
public static ComplexCondition getSampleSearchCondition() {
PrimitiveCondition tenantDomainEqSuper = new PrimitiveCondition(RESOURCE_SEARCH_BEAN_FIELD_TENANT_DOMAIN, ConditionType.PrimitiveOperator.EQUALS, SUPER_TENANT_DOMAIN_NAME);
PrimitiveCondition tenantDomainEqABC = new PrimitiveCondition(RESOURCE_SEARCH_BEAN_FIELD_TENANT_DOMAIN, ConditionType.PrimitiveOperator.EQUALS, SAMPLE_TENANT_DOMAIN_ABC);
PrimitiveCondition attributeKeyEqFrom = new PrimitiveCondition(RESOURCE_SEARCH_BEAN_FIELD_ATTRIBUTE_KEY, ConditionType.PrimitiveOperator.EQUALS, SAMPLE_ATTRIBUTE_NAME1);
List<Condition> tenantDomainConditions = new ArrayList<>();
tenantDomainConditions.add(tenantDomainEqSuper);
tenantDomainConditions.add(tenantDomainEqABC);
ComplexCondition eitherTenantDomain = new ComplexCondition(ConditionType.ComplexOperator.OR, tenantDomainConditions);
List<Condition> conditions = new ArrayList<>();
conditions.add(eitherTenantDomain);
conditions.add(attributeKeyEqFrom);
return new ComplexCondition(ConditionType.ComplexOperator.AND, conditions);
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition 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;
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition 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;
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition in project identity-api-server by wso2.
the class ServerIdpManagementService method buildSearchCondition.
private Condition buildSearchCondition(SearchCondition searchCondition) {
if (!(searchCondition.getStatement() == null)) {
PrimitiveStatement primitiveStatement = searchCondition.getStatement();
if (Constants.SEARCH_KEY_NAME.equals(primitiveStatement.getProperty())) {
return new PrimitiveCondition(Constants.SEARCH_KEY_NAME_INTERNAL, getPrimitiveOperatorFromOdata(primitiveStatement.getCondition()), primitiveStatement.getValue());
} else if (Constants.SEARCH_KEY_SERVICES.equals(primitiveStatement.getProperty()) && getPrimitiveOperatorFromOdata(primitiveStatement.getCondition()) == EQUALS) {
Condition servicesAttrKeyCondition = new PrimitiveCondition(Constants.ATTR_KEY, EQUALS, Constants.SEARCH_KEY_SERVICES);
Condition servicesAttrValueCondition = new PrimitiveCondition(Constants.ATTR_VALUE, EQUALS, primitiveStatement.getValue());
Condition servicesCondition = new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND), Arrays.asList(servicesAttrKeyCondition, servicesAttrValueCondition));
Condition servicesCombinedAttrKeyCondition = new PrimitiveCondition(Constants.ATTR_KEY, EQUALS, Constants.SEARCH_KEY_SERVICES);
Condition servicesCombinedAttrValueCondition = new PrimitiveCondition(Constants.ATTR_VALUE, EQUALS, Constants.SEARCH_VALUE_AUTHENTICATION_PROVISIONING);
Condition servicesCombinedCondition = new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND), Arrays.asList(servicesCombinedAttrKeyCondition, servicesCombinedAttrValueCondition));
return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.OR), Arrays.asList(servicesCondition, servicesCombinedCondition));
} else if (Constants.SEARCH_KEYS.contains(primitiveStatement.getProperty())) {
List<Condition> list = new ArrayList<>();
Condition attrKeyCondition = new PrimitiveCondition(Constants.ATTR_KEY, EQUALS, primitiveStatement.getProperty());
Condition attrValueCondition = new PrimitiveCondition(Constants.ATTR_VALUE, getPrimitiveOperatorFromOdata(primitiveStatement.getCondition()), primitiveStatement.getValue());
list.add(attrKeyCondition);
list.add(attrValueCondition);
return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND), list);
} else {
throw handleException(Response.Status.BAD_REQUEST, Constants.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);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition in project carbon-identity-framework by wso2.
the class ConfigurationManagerImpl method getTenantSpecificSearchCondition.
/**
* Append tenant domain search to then search condition.
*
* @param tenantDomain Tenant domain.
* @param searchCondition Search condition.
* @return Condition.
*/
private Condition getTenantSpecificSearchCondition(String tenantDomain, Condition searchCondition) {
if (searchCondition != null) {
Condition tenantCondition = new PrimitiveCondition(ConfigurationConstants.RESOURCE_SEARCH_BEAN_FIELD_TENANT_DOMAIN, EQUALS, tenantDomain);
List<Condition> list = new ArrayList<>();
list.add(searchCondition);
list.add(tenantCondition);
return new ComplexCondition(ConditionType.ComplexOperator.AND, list);
} else {
if (log.isDebugEnabled()) {
log.debug("Search condition is null");
}
return new PrimitiveCondition(ConfigurationConstants.RESOURCE_SEARCH_BEAN_FIELD_TENANT_DOMAIN, EQUALS, tenantDomain);
}
}
Aggregations