Search in sources :

Example 1 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project qcadoo by qcadoo.

the class GridComponentFilterUtils method addMultiSearchFilter.

public static void addMultiSearchFilter(GridComponentMultiSearchFilter multiSearchFilter, Map<String, GridComponentColumn> columns, DataDefinition dataDefinition, SearchCriteriaBuilder criteria) throws GridComponentFilterException {
    LinkedList<SearchCriterion> searchRules = Lists.newLinkedList();
    for (GridComponentMultiSearchFilterRule rule : multiSearchFilter.getRules()) {
        String field = getFieldNameByColumnName(columns, rule.getField());
        if (field != null) {
            try {
                FieldDefinition fieldDefinition = getFieldDefinition(dataDefinition, field);
                if ("".equals(rule.getData()) && !ISNULL.equals(rule.getFilterOperator())) {
                    continue;
                }
                field = addAliases(criteria, field, JoinType.LEFT);
                SearchCriterion searchRule;
                if (fieldDefinition != null && String.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    searchRule = createStringCriterion(rule.getFilterOperator(), rule.getData(), field);
                } else if (fieldDefinition != null && Boolean.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    searchRule = createSimpleCriterion(rule.getFilterOperator(), "1".equals(rule.getData()), field);
                } else if (fieldDefinition != null && Date.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    searchRule = createDateCriterion(rule.getFilterOperator(), rule.getData(), field);
                } else if (fieldDefinition != null && BigDecimal.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    searchRule = createDecimalCriterion(rule.getFilterOperator(), rule.getData(), field);
                } else if (fieldDefinition != null && Integer.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    searchRule = createIntegerCriterion(rule.getFilterOperator(), rule.getData(), field);
                } else {
                    searchRule = createSimpleCriterion(rule.getFilterOperator(), rule.getData(), field);
                }
                searchRules.add(searchRule);
            } catch (Exception pe) {
                throw new GridComponentFilterException(rule.getData());
            }
        }
    }
    SearchCriterion groupedRules = null;
    if (searchRules.size() == 1) {
        groupedRules = searchRules.pollFirst();
    } else if (searchRules.size() == 2) {
        if (multiSearchFilter.getGroupOperator() == GridComponentFilterGroupOperator.AND) {
            groupedRules = SearchRestrictions.and(searchRules.pollFirst(), searchRules.pollFirst());
        } else if (multiSearchFilter.getGroupOperator() == GridComponentFilterGroupOperator.OR) {
            groupedRules = SearchRestrictions.or(searchRules.pollFirst(), searchRules.pollFirst());
        }
    } else if (searchRules.size() > 2) {
        SearchCriterion firstRule = searchRules.pollFirst();
        SearchCriterion secondRule = searchRules.pollFirst();
        SearchCriterion[] otherRules = new SearchCriterion[searchRules.size()];
        searchRules.toArray(otherRules);
        if (multiSearchFilter.getGroupOperator() == GridComponentFilterGroupOperator.AND) {
            groupedRules = SearchRestrictions.and(firstRule, secondRule, otherRules);
        } else if (multiSearchFilter.getGroupOperator() == GridComponentFilterGroupOperator.OR) {
            groupedRules = SearchRestrictions.or(firstRule, secondRule, otherRules);
        }
    }
    if (groupedRules != null) {
        criteria.add(groupedRules);
    }
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Date(java.util.Date) ParseException(java.text.ParseException)

Example 2 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class GeneratorContextDataProvider method getCriteria.

private SearchCriterion getCriteria(final Date threshold) {
    SearchCriterion updateDateIsEarlierThanThreshold = lt(GeneratorContextFields.UPDATE_DATE, threshold);
    SearchCriterion updateDateIsNull = isNull(GeneratorContextFields.UPDATE_DATE);
    SearchCriterion createDateIsEarlierThanThreshold = lt(GeneratorContextFields.UPDATE_DATE, threshold);
    return or(updateDateIsEarlierThanThreshold, and(updateDateIsNull, createDateIsEarlierThanThreshold));
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 3 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class MainTocOutputProductCriteriaBuilder method create.

public SearchCriteriaBuilder create(final MasterOutputProductCriteria criteria) {
    SearchCriteriaBuilder tocScb = getTocDataDefinition().findWithAlias(Aliases.TOC);
    applyCriteriaIfPresent(tocScb, criteria.getTocCriteria());
    SearchCriteriaBuilder opocScb = tocScb.createCriteria(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Aliases.OPERATION_PROD_OUT_COMPONENT, JoinType.INNER);
    applyCriteriaIfPresent(opocScb, criteria.getOpocCriteria());
    SearchCriteriaBuilder prodScb = opocScb.createCriteria(OperationProductOutComponentFields.PRODUCT, Aliases.OPERATION_OUTPUT_PRODUCT, JoinType.INNER);
    applyCriteriaIfPresent(prodScb, criteria.getProdCriteria());
    SearchCriteriaBuilder techScb = tocScb.createCriteria(TechnologyOperationComponentFields.TECHNOLOGY, Aliases.TECHNOLOGY, JoinType.INNER);
    applyCriteriaIfPresent(techScb, criteria.getTechCriteria());
    SearchCriteriaBuilder parentTocScb = tocScb.createCriteria(TechnologyOperationComponentFields.PARENT, Aliases.TOC_PARENT, JoinType.LEFT);
    applyCriteriaIfPresent(parentTocScb, criteria.getParentTocCriteria());
    SearchCriteriaBuilder parentOpicScb = parentTocScb.createCriteria(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS, Aliases.TOC_PARENT_OPIC, JoinType.LEFT);
    parentOpicScb.createCriteria(OperationProductInComponentFields.PRODUCT, Aliases.TOC_PARENT_INPUT_PRODUCT, JoinType.LEFT);
    applyCriteriaIfPresent(parentOpicScb, criteria.getParentOpicCriteria());
    techScb.createCriteria(TechnologyFields.PRODUCT, Aliases.TECHNOLOGY_PRODUCT, JoinType.INNER);
    SearchCriterion productIsConsumedByParentOp = eqField(Aliases.OPERATION_OUTPUT_PRODUCT + ".id", Aliases.TOC_PARENT_INPUT_PRODUCT + ".id");
    SearchCriterion opIsRootAndItsProductMatchTechProduct = and(isNull(Aliases.TOC + "." + TechnologyOperationComponentFields.PARENT), eqField(Aliases.TECHNOLOGY_PRODUCT + ".id", Aliases.OPERATION_OUTPUT_PRODUCT + ".id"));
    tocScb.add(or(productIsConsumedByParentOp, opIsRootAndItsProductMatchTechProduct));
    return tocScb;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 4 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class ActionCriteriaModifiers method addCriteriaForElementAndWorkstationType.

private void addCriteriaForElementAndWorkstationType(final SearchCriteriaBuilder searchCriteriaBuilder, final FilterValueHolder filterValueHolder, Long elementId, String alias) {
    SearchCriterion searchCriterion;
    String other = translationService.translate("cmmsMachineParts.action.name.other", LocaleContextHolder.getLocale());
    if (filterValueHolder.has(WorkstationFields.WORKSTATION_TYPE)) {
        Long workstationTypeId = filterValueHolder.getLong(WorkstationFields.WORKSTATION_TYPE);
        searchCriterion = SearchRestrictions.or(SearchRestrictions.eq(ActionFields.WORKSTATION_TYPES + ".id", workstationTypeId), SearchRestrictions.eq(alias + ".id", elementId));
    } else {
        searchCriterion = SearchRestrictions.eq(alias + ".id", elementId);
    }
    searchCriteriaBuilder.createAlias(ActionFields.WORKSTATION_TYPES, ActionFields.WORKSTATION_TYPES, JoinType.LEFT).createAlias(alias, alias, JoinType.LEFT).add(SearchRestrictions.or(searchCriterion, SearchRestrictions.eq(ActionFields.NAME, other)));
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 5 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class EventCriteriaModifiersCMP method addCriteriaRestrictions.

private void addCriteriaRestrictions(final SearchCriteriaBuilder searchCriteriaBuilder, final FilterValueHolder filterValueHolder, Long elementId, String alias) {
    SearchCriterion searchCriterion;
    if (filterValueHolder.has(MaintenanceEventFields.SUBASSEMBLY) || filterValueHolder.has(MaintenanceEventFields.WORKSTATION)) {
        if (filterValueHolder.has(WorkstationFields.WORKSTATION_TYPE)) {
            Long workstationTypeId = filterValueHolder.getLong(WorkstationFields.WORKSTATION_TYPE);
            searchCriterion = SearchRestrictions.or(SearchRestrictions.eq(FaultTypeFields.WORKSTATION_TYPES + ".id", workstationTypeId), SearchRestrictions.eq(alias + ".id", elementId));
        } else {
            searchCriterion = SearchRestrictions.eq(alias + ".id", elementId);
        }
        searchCriteriaBuilder.createAlias(FaultTypeFields.WORKSTATION_TYPES, FaultTypeFields.WORKSTATION_TYPES, JoinType.LEFT).createAlias(alias, alias, JoinType.LEFT).add(SearchRestrictions.or(SearchRestrictions.and(SearchRestrictions.in(FaultTypeFields.APPLIES_TO, getFaultTypeAppliesToStringValues()), searchCriterion), SearchRestrictions.eq(FaultTypeFields.IS_DEFAULT, true)));
    } else {
        searchCriteriaBuilder.add(SearchRestrictions.or(SearchRestrictions.in(FaultTypeFields.APPLIES_TO, getFaultTypeAppliesToStringValues()), SearchRestrictions.isNull(FaultTypeFields.APPLIES_TO), SearchRestrictions.eq(FaultTypeFields.IS_DEFAULT, true)));
    }
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Aggregations

SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)41 Entity (com.qcadoo.model.api.Entity)16 Test (org.junit.Test)12 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 DataDefinition (com.qcadoo.model.api.DataDefinition)4 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 SearchResult (com.qcadoo.model.api.search.SearchResult)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableList (com.google.common.collect.ImmutableList)1 BatchNumberUniqueness (com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)1 AssignmentToShiftCriteria (com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria)1 SearchDisjunction (com.qcadoo.model.api.search.SearchDisjunction)1 SearchOrder (com.qcadoo.model.api.search.SearchOrder)1 ParseException (java.text.ParseException)1 List (java.util.List)1