Project

General

Profile

Revision c2447263

IDc244726396e6a40f1878aed1e9cfaa9019ded1f3
Parent 84cd43e7
Child 9ccf877c, 068072a1

Added by Andreas Kohlbecker about 1 year ago

ref #8330 completing documentation regarding wildcards and fixing bug with MatchMode LIKE when using Restrictions

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java
665 665
                logger.debug("createRestriction() " + propertyName + " " + matchMode.getMatchOperator() + " "
666 666
                        + matchMode.queryStringFrom(queryString));
667 667
            }
668
            if (matchMode == MatchMode.BEGINNING) {
668
            switch(matchMode){
669
            case BEGINNING:
669 670
                restriction = Restrictions.ilike(propertyName, queryString, org.hibernate.criterion.MatchMode.START);
670
            } else if (matchMode == MatchMode.END) {
671
                break;
672
            case END:
671 673
                restriction = Restrictions.ilike(propertyName, queryString, org.hibernate.criterion.MatchMode.END);
672
            } else if (matchMode == MatchMode.EXACT) {
674
                break;
675
            case LIKE:
676
                restriction = Restrictions.ilike(propertyName, matchMode.queryStringFrom(queryString), org.hibernate.criterion.MatchMode.ANYWHERE);
677
                break;
678
            case EXACT:
673 679
                restriction = Restrictions.ilike(propertyName, queryString, org.hibernate.criterion.MatchMode.EXACT);
674
            } else {
675
                restriction = Restrictions.ilike(propertyName, queryString, org.hibernate.criterion.MatchMode.ANYWHERE);
680
                break;
681
            default:
682
                throw new RuntimeException("Unknown MatchMode: " + matchMode.name());
676 683
            }
677 684
        }
678 685
        return restriction;
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IRegistrationService.java
93 93
     *            filters the Registration by the RegistrationStatus. Only
94 94
     *            Registration having one of the supplied status will included.
95 95
     * @param identifierFilterPattern
96
     *            filters the Registration by this pattern, The asterisk can be used
97
     *            * as wildcard in any position of the pattern string
96
     *            filters the Registration by this pattern, The asterisk '<code>*</code>' can be used
97
     *            as wildcard in any position of the pattern string
98 98
     * @param taxonNameFilterPattern
99
     *            filters the registered taxon name by this pattern, The asterisk can be used
100
     *            * as wildcard in any position of the pattern string
99
     *            filters the registered taxon name by this pattern, The asterisk '<code>*</code>' can be used
100
     *            as wildcard in any position of the pattern string
101 101
     * @param typeDesignationStatus
102 102
     * @param pageSize
103 103
     *            The maximum number of objects returned (can be null for all
......
132 132
     * @param identifierFilterPattern
133 133
     *    Filter by the {@link Registration#getIdentifier() Registration.identifier}.
134 134
     *    The method matches Registrations which contain the the passed pattern in the identifier.
135
     *    The asterisk '<code>*</code>' can be used as wildcard in any position of the pattern string
135 136
     * @param taxonNameFilterPattern
136 137
     *    The method matches Registrations which contain the the passed pattern in the
137
     *    {@link Registration#getName() Registration.name}
138
     *    {@link Registration#getName() Registration.name}. The asterisk '<code>*</code>' can be used
139
     *    as wildcard in any position of the pattern string
138 140
     * @param typeDesignationStatusUuids
139 141
     *    Filter by one or more {@link eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus} or {@link eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus}.
140 142
     *    Multiple status will be combined with OR.
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/RegistrationServiceImpl.java
181 181

  
182 182
        //Logger.getLogger("org.hibernate.SQL").setLevel(Level.DEBUG);
183 183
        long numberOfResults = dao.count(Registration.class, restrictions);
184
        // long numberOfResults = dao.count(submitterUuid, includedStatus, identifierFilterPattern, taxonNameFilterPattern, typeDesignationStatusUuids);
184 185
        //Logger.getLogger("org.hibernate.SQL").setLevel(Level.WARN);
185 186

  
186 187
        List<Registration> results = new ArrayList<>();
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/RegistrationServiceTest.java
126 126
        pager = repo.getRegistrationService().page((UUID)null, null, null, "Digilalus", null, null, null, null, null);
127 127
        assertEquals(pager.getRecords().size(), pager.getCount().intValue());
128 128
        assertEquals(3l, pager.getCount().longValue());
129

  
129
        
130
        pager = repo.getRegistrationService().page((UUID)null, null, null, "Dig*lus", null, null, null, null, null);
131
        assertEquals(pager.getRecords().size(), pager.getCount().intValue());
132
        assertEquals(3l, pager.getCount().longValue());
130 133

  
131 134
        pager = repo.getRegistrationService().page((UUID)null, null, null, "Digilalus prim", null, null, null, null, null);
132 135
        assertEquals(pager.getRecords().size(), pager.getCount().intValue());
133 136
        assertEquals(1l, pager.getCount().longValue());
134 137

  
138
        pager = repo.getRegistrationService().page((UUID)null, null, null, "Digila*", null, null, null, null, null);
139
        assertEquals(pager.getRecords().size(), pager.getCount().intValue());
140
        assertEquals(3l, pager.getCount().longValue());
141
        
142
        pager = repo.getRegistrationService().page((UUID)null, null, null, "*imus", null, null, null, null, null);
143
        assertEquals(pager.getRecords().size(), pager.getCount().intValue());
144
        assertEquals(1l, pager.getCount().longValue());
145

  
135 146
        // taxon name filter with user
136 147
        pager = repo.getRegistrationService().page(USER2_UUID, null, null, "Digilalus", null, null, null, null, null);
137 148
        assertEquals(pager.getRecords().size(), pager.getCount().intValue());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)