Project

General

Profile

« Previous | Next » 

Revision ea92da24

Added by Andreas Kohlbecker over 5 years ago

fixing wrong boolean operator combination for Restrictions with operator AND_NOT

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java
591 591
                        logger.debug("addRestrictions() predicate with " + propertyName + " " + (restriction.getMatchMode() == null ? "=" : restriction.getMatchMode().name()) + " " + v.toString());
592 592
                    }
593 593
                }
594
                perProperty.add(new CriterionWithOperator(restriction.getOperator(), Restrictions.or(predicates)));
594
                if(restriction.getOperator() == Operator.AND_NOT){
595
                    perProperty.add(new CriterionWithOperator(restriction.getOperator(), Restrictions.and(predicates)));
596
                } else {
597
                    perProperty.add(new CriterionWithOperator(restriction.getOperator(), Restrictions.or(predicates)));
598
                }
595 599
            } // check has values
596 600
        } // loop over restrictions
597 601

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/NameServiceImplTest.java
1022 1022
        result = nameService.findByTitleWithRestrictions(null, "Name", MatchMode.BEGINNING, restrictions, null, null, null, null);
1023 1023
        assertEquals(2l, result.getCount().longValue());
1024 1024

  
1025
        restrictions = Arrays.asList(new Restriction<String>("titleCache", Operator.AND_NOT, null, "Name1", "Name2"));
1026
        result = nameService.findByTitleWithRestrictions(null, "Name", MatchMode.BEGINNING, restrictions, null, null, null, null);
1027
        assertEquals(1l, result.getCount().longValue());
1028
        assertEquals("Name3", result.getRecords().get(0).getTitleCache());
1029

  
1025 1030
        restrictions = Arrays.asList(new Restriction<String>("typeDesignations.typeName.titleCache", Operator.OR, null, "Name1"));
1026 1031
        result = nameService.findByTitleWithRestrictions(null, "Name1", MatchMode.EXACT, restrictions, null, null, null, null);
1027 1032
        assertEquals(2l, result.getCount().longValue());

Also available in: Unified diff