Project

General

Profile

Revision 95d1b8c8

ID95d1b8c824bad46931400e9c9458d7eafff2ed37
Parent c26f3c40
Child e6bec461

Added by Andreas Müller almost 4 years ago

ref #7166 remove distributions with absent status from filter results

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeFilterDaoHibernateImpl.java
40 40
    private static final String FEATURE_UUID = "9fc9d10c-ba50-49ee-b174-ce83fc3f80c6";
41 41

  
42 42
    private static final String HQL_TRUE = " 1 "; //maybe we can/should use 'true' instead, needs to be checked for all DB types
43
    private static final String HQL_FALSE = " 0 "; //maybe we can/should use 'false' instead, needs to be checked for all DB types
43 44

  
44 45
    @Autowired
45 46
    private ITaxonNodeDao taxonNodeDao;
......
145 146
        for (LogicFilter<NamedArea> singleFilter : areaFilter){
146 147
            areaIds = getChildAreasRecursively(singleFilter.getUuid());
147 148
            String op = isFirst ? "" : op2Hql(singleFilter.getOperator());
148
            result = String.format("(%s%s("+DESCRIPTION_ELEMENTS+".feature.uuid='"+FEATURE_UUID+"' AND "+DESCRIPTION_ELEMENTS+".area.id in (%s)))",
149
                    result, op, StringUtils.collectionToCommaDelimitedString(areaIds));
149
            result = String.format("(%s%s(" + DESCRIPTION_ELEMENTS + ".feature.uuid='" + FEATURE_UUID + "' "
150
                    + " AND " + DESCRIPTION_ELEMENTS + ".area.id in (%s)))"
151
                    + " AND " + DESCRIPTION_ELEMENTS + ".status.absenceTerm = %s " ,
152
                    result, op, StringUtils.collectionToCommaDelimitedString(areaIds),
153
                    HQL_FALSE);
150 154
            isFirst = false;
151 155
        }
152 156
        return result;
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeFilterDaoHibernateImplTest.java
107 107
        NamedArea denmark = (NamedArea) termDao.load(denmarkUuid);
108 108
        NamedArea france = (NamedArea) termDao.load(franceUuid);
109 109
        TaxonDescription.NewInstance(taxon1).addElement(Distribution.NewInstance(europe, PresenceAbsenceTerm.NATIVE()));
110
        TaxonDescription.NewInstance(taxon3).addElement(Distribution.NewInstance(germany, PresenceAbsenceTerm.NATIVE()));
111
        TaxonDescription.NewInstance(taxon4).addElement(Distribution.NewInstance(denmark, PresenceAbsenceTerm.NATIVE()));
112 110
        TaxonDescription.NewInstance(taxon2).addElement(Distribution.NewInstance(france, PresenceAbsenceTerm.NATIVE()));
111
        TaxonDescription.NewInstance(taxon3).addElement(Distribution.NewInstance(germany, PresenceAbsenceTerm.NATIVE()));
112
        TaxonDescription.NewInstance(taxon4).addElement(Distribution.NewInstance(denmark, PresenceAbsenceTerm.ABSENT()));
113 113

  
114 114
        node1 = classification1.addChildTaxon(taxon1, citation, microCitation);
115 115
        node1= taxonNodeDao.save(node1);
......
148 148

  
149 149
        TaxonNodeFilter filter = new TaxonNodeFilter(europe);
150 150
        List<UUID> listUuid = filterDao.listUuids(filter);
151
        assertEquals(message, 4, listUuid.size());
151
        assertEquals(message, 3, listUuid.size());
152 152
        Assert.assertTrue(listUuid.contains(node1.getUuid()));
153 153
        Assert.assertTrue(listUuid.contains(node2.getUuid()));
154 154
        Assert.assertTrue(listUuid.contains(node3.getUuid()));
155
        Assert.assertTrue(listUuid.contains(node4.getUuid()));
155
        Assert.assertFalse(listUuid.contains(node4.getUuid())); //status is absent
156 156

  
157 157
        filter = new TaxonNodeFilter(germany);
158 158
        listUuid = filterDao.listUuids(filter);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)